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
a5ae3ec4
Commit
a5ae3ec4
authored
Dec 15, 2016
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add print_ast()
parent
0ac2f44a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
25 deletions
+56
-25
src/ast.cpp
src/ast.cpp
+45
-0
src/ast.h
src/ast.h
+8
-11
src/lexer.l
src/lexer.l
+0
-1
src/main.cpp
src/main.cpp
+1
-3
src/parser.yy
src/parser.yy
+2
-10
No files found.
src/ast.cpp
0 → 100644
View file @
a5ae3ec4
#include "ast.h"
namespace
ebpf
{
namespace
bpftrace
{
namespace
ast
{
void
Integer
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
out
<<
"int: "
<<
n
<<
std
::
endl
;
}
void
Identifier
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
out
<<
"ident: "
<<
ident
<<
std
::
endl
;
}
void
Statement
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
out
<<
"stmt"
<<
std
::
endl
;
out
<<
std
::
string
(
depth
,
' '
);
expr
->
print_ast
(
out
,
depth
+
1
);
}
void
Probe
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
out
<<
"Probe"
<<
std
::
endl
;
for
(
Statement
*
stmt
:
*
stmts
)
{
out
<<
std
::
string
(
depth
,
' '
);
stmt
->
print_ast
(
out
,
depth
+
1
);
}
}
void
Program
::
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
)
const
{
out
<<
"Program"
<<
std
::
endl
;
++
depth
;
for
(
Probe
*
probe
:
*
probes
)
{
out
<<
std
::
string
(
depth
,
' '
);
probe
->
print_ast
(
out
,
depth
+
1
);
}
}
}
// namespace ast
}
// namespace bpftrace
}
// namespace ebpf
src/ast.h
View file @
a5ae3ec4
...
...
@@ -2,6 +2,7 @@
#include <string>
#include <vector>
#include <ostream>
namespace
ebpf
{
namespace
bpftrace
{
...
...
@@ -10,6 +11,7 @@ namespace ast {
class
Node
{
public:
virtual
~
Node
()
{
}
virtual
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
=
0
;
};
class
Expression
:
public
Node
{
...
...
@@ -18,34 +20,30 @@ class Expression : public Node {
class
Integer
:
public
Expression
{
public:
explicit
Integer
(
int
n
)
:
n
(
n
)
{
}
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
override
;
int
n
;
};
class
Identifier
:
public
Expression
{
public:
explicit
Identifier
(
std
::
string
&
ident
)
:
ident
(
ident
)
{
}
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
override
;
std
::
string
ident
;
};
class
Statement
:
public
Node
{
public:
explicit
Statement
(
Expression
*
expr
)
:
expr
(
expr
)
{
}
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
override
;
Expression
*
expr
;
};
using
StatementList
=
std
::
vector
<
Statement
*>
;
class
PreProcessor
:
public
Node
{
public:
explicit
PreProcessor
(
const
std
::
string
&
line
)
:
line
(
line
)
{
}
std
::
string
line
;
};
using
PreProcessorList
=
std
::
vector
<
PreProcessor
*>
;
class
Probe
:
public
Node
{
public:
Probe
(
std
::
string
type
,
std
::
string
attach_point
,
StatementList
*
stmts
)
:
type
(
type
),
attach_point
(
attach_point
),
stmts
(
stmts
)
{
}
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
override
;
std
::
string
type
;
std
::
string
attach_point
;
...
...
@@ -55,9 +53,8 @@ using ProbeList = std::vector<Probe *>;
class
Program
:
public
Node
{
public:
Program
(
PreProcessorList
*
preprocs
,
ProbeList
*
probes
)
:
preprocs
(
preprocs
),
probes
(
probes
)
{
}
PreProcessorList
*
preprocs
;
explicit
Program
(
ProbeList
*
probes
)
:
probes
(
probes
)
{
}
void
print_ast
(
std
::
ostream
&
out
,
unsigned
int
depth
=
0
)
const
override
;
ProbeList
*
probes
;
};
...
...
src/lexer.l
View file @
a5ae3ec4
...
...
@@ -25,7 +25,6 @@ using namespace ebpf::bpftrace;
[\n\r]+ { loc.lines(yyleng); loc.step(); }
"//".*$ // Comments
^"#".*$ { return Parser::make_PREPROCESSOR(yytext, loc); }
[_a-zA-Z][_a-zA-Z0-9]* { return Parser::make_IDENT(yytext, loc); }
[0-9]+ { return Parser::make_INT(strtoul(yytext, NULL, 0), loc); }
0[xX][0-9a-fA-F]+ { return Parser::make_INT(strtoul(yytext, NULL, 0), loc); }
...
...
src/main.cpp
View file @
a5ae3ec4
...
...
@@ -12,8 +12,6 @@ int main(int argc, char *argv[])
result
=
driver
.
parse
(
argv
[
1
]);
}
for
(
auto
&
preproc
:
*
(
driver
.
root_
->
preprocs
))
{
std
::
cout
<<
preproc
->
line
<<
std
::
endl
;
}
driver
.
root_
->
print_ast
(
std
::
cout
);
return
result
;
}
src/parser.yy
View file @
a5ae3ec4
...
...
@@ -44,11 +44,9 @@ void yyerror(ebpf::bpftrace::Driver &driver, const char *s);
RBRACE "}"
;
%token <std::string> PREPROCESSOR "preprocessor"
%token <std::string> IDENT "identifier"
%token <int> INT "integer"
%type <ast::PreProcessorList *> preprocs
%type <ast::ProbeList *> probes
%type <ast::StatementList *> block stmts
%type <ast::Probe *> probe
...
...
@@ -61,17 +59,11 @@ void yyerror(ebpf::bpftrace::Driver &driver, const char *s);
%%
program : preprocs probes { driver.root_ = new ast::Program($1, $2); }
| probes
program : probes { driver.root_ = new ast::Program($1); }
;
preprocs : preprocs PREPROCESSOR { $$ = $1; $1->push_back(new ast::PreProcessor($2)); }
| PREPROCESSOR { $$ = new ast::PreProcessorList;
$$->push_back(new ast::PreProcessor($1)); }
probes : probes probe { $$ = $1; $1->push_back($2); }
| probe { $$ = new ast::ProbeList;
$$->push_back($1); }
| probe { $$ = new ast::ProbeList; $$->push_back($1); }
;
probe : IDENT ":" IDENT block { $$ = new ast::Probe($1, $3, $4); }
...
...
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