Commit 2534466f authored by Alastair Robertson's avatar Alastair Robertson

Add code generation tests

parent 9f227ee1
......@@ -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)
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()
......
......@@ -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_));
......
#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_;
......
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)
......
This diff is collapsed.
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