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
2534466f
Commit
2534466f
authored
Sep 10, 2017
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add code generation tests
parent
9f227ee1
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
445 additions
and
9 deletions
+445
-9
CMakeLists.txt
CMakeLists.txt
+6
-0
src/CMakeLists.txt
src/CMakeLists.txt
+0
-6
src/codegen_llvm.cpp
src/codegen_llvm.cpp
+6
-2
src/codegen_llvm.h
src/codegen_llvm.h
+4
-1
tests/CMakeLists.txt
tests/CMakeLists.txt
+10
-0
tests/codegen.cpp
tests/codegen.cpp
+419
-0
No files found.
CMakeLists.txt
View file @
2534466f
...
...
@@ -41,6 +41,12 @@ add_flex_bison_dependency(flex_lexer bison_parser)
add_library
(
parser
${
BISON_bison_parser_OUTPUTS
}
${
FLEX_flex_lexer_OUTPUTS
}
)
target_include_directories
(
parser PUBLIC src
${
CMAKE_BINARY_DIR
}
)
find_package
(
LLVM REQUIRED CONFIG
)
include_directories
(
${
LLVM_INCLUDE_DIRS
}
)
add_definitions
(
${
LLVM_DEFINITIONS
}
)
set
(
DYNAMIC_LINKING OFF CACHE BOOL
"Build bpftrace as a dynamically linked executable"
)
add_subdirectory
(
src/arch
)
add_subdirectory
(
src
)
add_subdirectory
(
tests
)
src/CMakeLists.txt
View file @
2534466f
find_package
(
LLVM REQUIRED CONFIG
)
include_directories
(
${
LLVM_INCLUDE_DIRS
}
)
add_definitions
(
${
LLVM_DEFINITIONS
}
)
set
(
DYNAMIC_LINKING OFF CACHE BOOL
"Build bpftrace as a dynamically linked executable"
)
if
(
NOT DYNAMIC_LINKING
)
set
(
CMAKE_EXE_LINKER_FLAGS
"-static"
)
endif
()
...
...
src/codegen_llvm.cpp
View file @
2534466f
...
...
@@ -4,6 +4,7 @@
#include "arch/arch.h"
#include <llvm/ExecutionEngine/SectionMemoryManager.h>
#include <llvm/Support/raw_os_ostream.h>
#include <llvm/Support/TargetRegistry.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/Transforms/IPO.h>
...
...
@@ -614,7 +615,7 @@ void CodegenLLVM::createStrcmpFunction()
b_
.
CreateRet
(
b_
.
getInt1
(
0
));
}
int
CodegenLLVM
::
compile
(
bool
debug
)
int
CodegenLLVM
::
compile
(
bool
debug
,
std
::
ostream
&
out
)
{
createLog2Function
();
createStrcmpFunction
();
...
...
@@ -657,7 +658,10 @@ int CodegenLLVM::compile(bool debug)
PM
.
run
(
*
module_
.
get
());
if
(
debug
)
module_
->
dump
();
{
raw_os_ostream
llvm_ostream
(
out
);
module_
->
print
(
llvm_ostream
,
nullptr
,
false
,
true
);
}
EngineBuilder
builder
(
move
(
module_
));
builder
.
setMCJITMemoryManager
(
std
::
make_unique
<
BPFtraceMemoryManager
>
(
bpftrace_
.
sections_
));
...
...
src/codegen_llvm.h
View file @
2534466f
#pragma once
#include <iostream>
#include <ostream>
#include "ast.h"
#include "bpftrace.h"
#include "irbuilderbpf.h"
...
...
@@ -45,7 +48,7 @@ public:
void
createLog2Function
();
void
createStrcmpFunction
();
int
compile
(
bool
debug
=
false
);
int
compile
(
bool
debug
=
false
,
std
::
ostream
&
out
=
std
::
cerr
);
private:
Node
*
root_
;
...
...
tests/CMakeLists.txt
View file @
2534466f
if
(
NOT DYNAMIC_LINKING
)
set
(
CMAKE_EXE_LINKER_FLAGS
"-static"
)
endif
()
add_compile_options
(
"-Wno-undef"
)
add_compile_options
(
"-Wno-switch-default"
)
add_compile_options
(
"-Wno-switch-enum"
)
...
...
@@ -8,13 +12,16 @@ include_directories(${CMAKE_BINARY_DIR}/src)
add_executable
(
bpftrace_test
ast.cpp
bpftrace.cpp
codegen.cpp
main.cpp
parser.cpp
semantic_analyser.cpp
${
CMAKE_SOURCE_DIR
}
/src/ast.cpp
${
CMAKE_SOURCE_DIR
}
/src/attached_probe.cpp
${
CMAKE_SOURCE_DIR
}
/src/bpftrace.cpp
${
CMAKE_SOURCE_DIR
}
/src/codegen_llvm.cpp
${
CMAKE_SOURCE_DIR
}
/src/driver.cpp
${
CMAKE_SOURCE_DIR
}
/src/irbuilderbpf.cpp
${
CMAKE_SOURCE_DIR
}
/src/map.cpp
${
CMAKE_SOURCE_DIR
}
/src/mapkey.cpp
${
CMAKE_SOURCE_DIR
}
/src/printer.cpp
...
...
@@ -25,6 +32,9 @@ add_executable(bpftrace_test
target_link_libraries
(
bpftrace_test arch parser
)
llvm_map_components_to_libnames
(
llvm_libs bpfcodegen ipo irreader mcjit
)
target_link_libraries
(
bpftrace_test
${
llvm_libs
}
)
add_dependencies
(
bpftrace_test bcc-build
)
ExternalProject_Get_Property
(
bcc source_dir binary_dir
)
include_directories
(
${
source_dir
}
/src/cc
)
...
...
tests/codegen.cpp
0 → 100644
View file @
2534466f
This diff is collapsed.
Click to expand it.
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