Commit c2c6bf3d authored by Brendan Gregg's avatar Brendan Gregg

support negative integers

parent 97001f83
......@@ -106,6 +106,7 @@ std::string opstr(Unop &unop)
switch (unop.op) {
case bpftrace::Parser::token::LNOT: return "!";
case bpftrace::Parser::token::BNOT: return "~";
case bpftrace::Parser::token::MINUS: return "-";
case bpftrace::Parser::token::MUL: return "dereference";
default: abort();
}
......
......@@ -625,6 +625,7 @@ void CodegenLLVM::visit(Unop &unop)
switch (unop.op) {
case bpftrace::Parser::token::LNOT: expr_ = b_.CreateNot(expr_); break;
case bpftrace::Parser::token::BNOT: expr_ = b_.CreateNeg(expr_); break;
case bpftrace::Parser::token::MINUS: expr_ = b_.CreateNeg(expr_); break;
case bpftrace::Parser::token::MUL:
{
int size = type.size;
......
......@@ -53,7 +53,7 @@ pid|tid|uid|gid|nsecs|cpu|comm|stack|ustack|arg[0-9]|retval|func|name|curtask|ra
{path} { return Parser::make_PATH(yytext, loc); }
{map} { return Parser::make_MAP(yytext, loc); }
{var} { return Parser::make_VAR(yytext, loc); }
{int} { return Parser::make_INT(strtoul(yytext, NULL, 0), loc); }
{int} { return Parser::make_INT(strtoll(yytext, NULL, 0), loc); }
":" { return Parser::make_COLON(loc); }
";" { return Parser::make_SEMI(loc); }
"{" { return Parser::make_LBRACE(loc); }
......
......@@ -198,6 +198,7 @@ expr : INT { $$ = new ast::Integer($1); }
| expr BXOR expr { $$ = new ast::Binop($1, token::BXOR, $3); }
| LNOT expr { $$ = new ast::Unop(token::LNOT, $2); }
| BNOT expr { $$ = new ast::Unop(token::BNOT, $2); }
| MINUS expr { $$ = new ast::Unop(token::MINUS, $2); }
| MUL expr %prec DEREF { $$ = new ast::Unop(token::MUL, $2); }
| expr DOT ident { $$ = new ast::FieldAccess($1, $3); }
| expr PTR ident { $$ = new ast::FieldAccess(new ast::Unop(token::MUL, $1), $3); }
......
......@@ -125,6 +125,13 @@ TEST(Parser, variable_assign)
" =\n"
" variable: $x\n"
" int: 1\n");
test("kprobe:sys_open { $x = -1; }",
"Program\n"
" kprobe:sys_open\n"
" =\n"
" variable: $x\n"
" -\n"
" int: 1\n");
}
TEST(Parser, integer_sizes)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment