Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
4aeeaff0
Commit
4aeeaff0
authored
Dec 22, 2016
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more binops and set precedences
parent
7b3ec506
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
102 additions
and
13 deletions
+102
-13
src/ast.cpp
src/ast.cpp
+46
-1
src/lexer.l
src/lexer.l
+13
-1
src/parser.yy
src/parser.yy
+43
-11
No files found.
src/ast.cpp
View file @
4aeeaff0
...
...
@@ -30,8 +30,53 @@ void Binop::print_ast(std::ostream &out, unsigned int depth) const
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
EQ
:
opstr
=
"=="
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
NE
:
opstr
=
"!="
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
LE
:
opstr
=
"<="
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
GE
:
opstr
=
">="
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
LT
:
opstr
=
"<"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
GT
:
opstr
=
">"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
LAND
:
opstr
=
"&&"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
LOR
:
opstr
=
"||"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
PLUS
:
opstr
=
"+"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
MINUS
:
opstr
=
"-"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
MUL
:
opstr
=
"*"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
DIV
:
opstr
=
"/"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
MOD
:
opstr
=
"%"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
BAND
:
opstr
=
"&"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
BOR
:
opstr
=
"|"
;
break
;
case
ebpf
:
:
bpftrace
::
Parser
::
token
::
BXOR
:
opstr
=
"^"
;
break
;
default:
std
::
cerr
<<
"Bad binop: "
<<
op
<<
std
::
endl
;
opstr
=
"???"
;
break
;
}
...
...
src/lexer.l
View file @
4aeeaff0
...
...
@@ -34,15 +34,27 @@ using namespace ebpf::bpftrace;
"}" { return Parser::make_RBRACE(loc); }
"[" { return Parser::make_LBRACKET(loc); }
"]" { return Parser::make_RBRACKET(loc); }
\//[ \t\n\r]*[\/\{] { return Parser::make_ENDPRED(loc); } // If "/" is followed by "/" or "{", choose ENDPRED, otherwise DIV
"," { return Parser::make_COMMA(loc); }
"=" { return Parser::make_ASSIGN(loc); }
"/" { return Parser::make_FSLASH(loc); }
"==" { return Parser::make_EQ(loc); }
"!=" { return Parser::make_NE(loc); }
"<=" { return Parser::make_LE(loc); }
">=" { return Parser::make_GE(loc); }
"<" { return Parser::make_LT(loc); }
">" { return Parser::make_GT(loc); }
"&&" { return Parser::make_LAND(loc); }
"||" { return Parser::make_LOR(loc); }
"+" { return Parser::make_PLUS(loc); }
"-" { return Parser::make_MINUS(loc); }
"*" { return Parser::make_MUL(loc); }
"/" { return Parser::make_DIV(loc); }
"%" { return Parser::make_MOD(loc); }
"&" { return Parser::make_BAND(loc); }
"|" { return Parser::make_BOR(loc); }
"^" { return Parser::make_BXOR(loc); }
"!" { return Parser::make_LNOT(loc); }
"~" { return Parser::make_BNOT(loc); }
. { driver.error(loc, std::string("invalid character: ")+std::string(yytext)); exit(1); }
...
...
src/parser.yy
View file @
4aeeaff0
...
...
@@ -43,15 +43,27 @@ void yyerror(ebpf::bpftrace::Driver &driver, const char *s);
RBRACE "}"
LBRACKET "["
RBRACKET "]"
ENDPRED "end predicate"
COMMA ","
ASSIGN "="
FSLASH "/"
EQ "=="
NE "!="
LE "<="
GE ">="
LT "<"
GT ">"
LAND "&&"
LOR "||"
PLUS "+"
MINUS "-"
MUL "*"
DIV "/"
MOD "%"
BAND "&"
BOR "|"
BXOR "^"
LNOT "!"
BNOT "~"
;
%token <std::string> IDENT "identifier"
...
...
@@ -67,7 +79,17 @@ void yyerror(ebpf::bpftrace::Driver &driver, const char *s);
%printer { yyoutput << %%; } <*>;
%left EQ NE LE GE LT GT
%right ASSIGN
%left LOR
%left LAND
%left BOR
%left BXOR
%left BAND
%left EQ NE
%left LE GE LT GT
%left PLUS MINUS
%left MUL DIV MOD
%right LNOT BNOT
%start program
...
...
@@ -81,7 +103,7 @@ probes : probes probe { $$ = $1; $1->push_back($2); }
;
probe : IDENT ":" IDENT block { $$ = new ast::Probe($1, $3, $4); }
| IDENT ":" IDENT
"/" expr "/"
block { $$ = new ast::Probe($1, $3, $5, $7); }
| IDENT ":" IDENT
DIV expr ENDPRED
block { $$ = new ast::Probe($1, $3, $5, $7); }
;
block : "{" stmts "}" { $$ = $2; }
...
...
@@ -95,14 +117,24 @@ stmt : expr { $$ = new ast::ExprStatement($1); }
| var "=" expr { $$ = new ast::AssignStatement($1, $3); }
;
expr : INT { $$ = new ast::Integer($1); }
| var { $$ = $1; }
| expr EQ expr { $$ = new ast::Binop($1, token::EQ, $3); }
| expr NE expr { $$ = new ast::Binop($1, token::NE, $3); }
| expr LE expr { $$ = new ast::Binop($1, token::LE, $3); }
| expr GE expr { $$ = new ast::Binop($1, token::GE, $3); }
| expr LT expr { $$ = new ast::Binop($1, token::LT, $3); }
| expr GT expr { $$ = new ast::Binop($1, token::GT, $3); }
expr : INT { $$ = new ast::Integer($1); }
| var { $$ = $1; }
| expr EQ expr { $$ = new ast::Binop($1, token::EQ, $3); }
| expr NE expr { $$ = new ast::Binop($1, token::NE, $3); }
| expr LE expr { $$ = new ast::Binop($1, token::LE, $3); }
| expr GE expr { $$ = new ast::Binop($1, token::GE, $3); }
| expr LT expr { $$ = new ast::Binop($1, token::LT, $3); }
| expr GT expr { $$ = new ast::Binop($1, token::GT, $3); }
| expr LAND expr { $$ = new ast::Binop($1, token::LAND, $3); }
| expr LOR expr { $$ = new ast::Binop($1, token::LOR, $3); }
| expr PLUS expr { $$ = new ast::Binop($1, token::PLUS, $3); }
| expr MINUS expr { $$ = new ast::Binop($1, token::MINUS, $3); }
| expr MUL expr { $$ = new ast::Binop($1, token::MUL, $3); }
| expr DIV expr { $$ = new ast::Binop($1, token::DIV, $3); }
| expr MOD expr { $$ = new ast::Binop($1, token::MOD, $3); }
| expr BAND expr { $$ = new ast::Binop($1, token::BAND, $3); }
| expr BOR expr { $$ = new ast::Binop($1, token::BOR, $3); }
| expr BXOR expr { $$ = new ast::Binop($1, token::BXOR, $3); }
;
var : IDENT { $$ = new ast::Variable($1); }
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment