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
4298752c
Commit
4298752c
authored
Dec 30, 2016
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let the driver handle most stuff
parent
acb74cd5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
31 deletions
+54
-31
src/CMakeLists.txt
src/CMakeLists.txt
+1
-1
src/codegen.h
src/codegen.h
+7
-6
src/driver.cpp
src/driver.cpp
+32
-0
src/driver.h
src/driver.h
+13
-15
src/main.cpp
src/main.cpp
+1
-9
No files found.
src/CMakeLists.txt
View file @
4298752c
...
...
@@ -13,7 +13,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
include_directories
(
${
LLVM_INCLUDE_DIRS
}
)
add_definitions
(
${
LLVM_DEFINITIONS
}
)
add_executable
(
bpftrace main.cpp parser.tab.cc lex.yy.cc ast.cpp printer.cpp codegen.cpp
)
add_executable
(
bpftrace main.cpp
driver.cpp
parser.tab.cc lex.yy.cc ast.cpp printer.cpp codegen.cpp
)
llvm_map_components_to_libnames
(
llvm_libs support core irreader
)
target_link_libraries
(
bpftrace
${
llvm_libs
}
)
src/codegen.h
View file @
4298752c
...
...
@@ -13,9 +13,10 @@ using namespace llvm;
class
Codegen
:
public
Visitor
{
public:
Codegen
()
:
b_
(
context_
),
module_
(
"bpftrace"
,
context_
)
{
}
Codegen
(
Module
&
mod
,
LLVMContext
&
context
)
:
context_
(
context
),
module_
(
mod
),
b_
(
context_
)
{
}
void
visit
(
Integer
&
integer
)
override
;
void
visit
(
Variable
&
var
)
override
;
...
...
@@ -27,10 +28,10 @@ public:
void
visit
(
Probe
&
probe
)
override
;
void
visit
(
Program
&
program
)
override
;
//private:
LLVMContext
context_
;
private:
LLVMContext
&
context_
;
Module
&
module_
;
IRBuilder
<>
b_
;
Module
module_
;
Value
*
expr_
=
nullptr
;
};
...
...
src/driver.cpp
0 → 100644
View file @
4298752c
#include <istream>
#include <ostream>
#include "driver.h"
#include "printer.h"
#include "codegen.h"
namespace
ebpf
{
namespace
bpftrace
{
int
Driver
::
parse
()
{
return
parser_
.
parse
();
}
int
Driver
::
parse
(
const
std
::
string
&
f
)
{
if
(
!
(
yyin
=
fopen
(
f
.
c_str
(),
"r"
)))
{
std
::
cerr
<<
"Could not open file"
<<
std
::
endl
;
return
-
1
;
}
return
parser_
.
parse
();
}
int
Driver
::
dump_ast
(
std
::
ostream
&
out
)
{
ast
::
Printer
p
=
ebpf
::
bpftrace
::
ast
::
Printer
(
out
);
root_
->
accept
(
p
);
}
}
// namespace bpftrace
}
// namespace ebpf
src/driver.h
View file @
4298752c
#pragma once
#include <istream>
#include "parser.tab.hh"
#include "ast.h"
#include <llvm/IR/Module.h>
#define YY_DECL ebpf::bpftrace::Parser::symbol_type yylex(ebpf::bpftrace::Driver &driver)
YY_DECL
;
...
...
@@ -12,23 +13,17 @@ extern FILE *yyin;
namespace
ebpf
{
namespace
bpftrace
{
using
namespace
llvm
;
class
Driver
{
public:
Driver
()
:
parser_
(
*
this
)
{
}
int
parse
()
{
return
parser_
.
parse
();
}
Driver
()
:
parser_
(
*
this
),
module_
(
"bpftrace"
,
context_
)
{
}
int
parse
(
const
std
::
string
&
f
)
{
if
(
!
(
yyin
=
fopen
(
f
.
c_str
(),
"r"
)))
{
std
::
cerr
<<
"Could not open file"
<<
std
::
endl
;
return
-
1
;
}
return
parser_
.
parse
();
}
int
parse
();
int
parse
(
const
std
::
string
&
f
);
int
dump_ast
(
std
::
ostream
&
out
);
void
error
(
const
location
&
l
,
const
std
::
string
&
m
)
{
...
...
@@ -41,8 +36,11 @@ public:
}
ast
::
Program
*
root_
;
private:
Parser
parser_
;
LLVMContext
context_
;
Module
module_
;
};
}
// namespace bpftrace
...
...
src/main.cpp
View file @
4298752c
#include <iostream>
#include "driver.h"
#include "ast.h"
#include "printer.h"
#include "codegen.h"
int
main
(
int
argc
,
char
*
argv
[])
{
...
...
@@ -16,12 +13,7 @@ int main(int argc, char *argv[])
}
if
(
!
result
)
{
ebpf
::
bpftrace
::
ast
::
Printer
p
=
ebpf
::
bpftrace
::
ast
::
Printer
(
std
::
cout
);
driver
.
root_
->
accept
(
p
);
ebpf
::
bpftrace
::
ast
::
Codegen
c
;
driver
.
root_
->
accept
(
c
);
c
.
module_
.
dump
();
driver
.
dump_ast
(
std
::
cout
);
}
return
result
;
...
...
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