// load an entire c file as a module
int BPFModule::load_cfile(const string &file, bool in_memory) {
- clang_loader_ = make_unique<ClangLoader>(&*ctx_);
+ clang_loader_ = make_unique<ClangLoader>(&*ctx_, flags_);
if (clang_loader_->parse(&mod_, &tables_, file, in_memory))
return -1;
return 0;
// Load in a pre-built list of functions into the initial Module object, then
// build an ExecutionEngine.
int BPFModule::load_includes(const string &tmpfile) {
- clang_loader_ = make_unique<ClangLoader>(&*ctx_);
+ clang_loader_ = make_unique<ClangLoader>(&*ctx_, flags_);
if (clang_loader_->parse(&mod_, &tables_, tmpfile, false))
return -1;
return 0;
if (int rc = load_includes(BCC_INSTALL_PREFIX "/share/bcc/include/bcc/helpers.h"))
return rc;
- b_loader_.reset(new BLoader);
+ b_loader_.reset(new BLoader(flags_));
if (int rc = b_loader_->parse(&*mod_, filename, proto_filename, &tables_))
return rc;
if (int rc = annotate())
namespace ebpf {
-BLoader::BLoader() {
+BLoader::BLoader(unsigned flags) : flags_(flags) {
+ (void)flags_;
}
BLoader::~BLoader() {
class BLoader {
public:
- BLoader();
+ explicit BLoader(unsigned flags);
~BLoader();
int parse(llvm::Module *mod, const std::string &filename, const std::string &proto_filename,
std::unique_ptr<std::vector<TableDesc>> *tables);
private:
+ unsigned flags_;
std::unique_ptr<cc::Parser> parser_;
std::unique_ptr<cc::Parser> proto_parser_;
std::unique_ptr<cc::CodegenLLVM> codegen_;
return true;
}
-BFrontendAction::BFrontendAction(llvm::raw_ostream &os)
- : rewriter_(new Rewriter), os_(os), tables_(new vector<TableDesc>) {
+BFrontendAction::BFrontendAction(llvm::raw_ostream &os, unsigned flags)
+ : os_(os), flags_(flags), rewriter_(new Rewriter), tables_(new vector<TableDesc>) {
}
void BFrontendAction::EndSourceFileAction() {
// uncomment to see rewritten source
- //rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(llvm::errs());
+ if (flags_ & 0x4)
+ rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(llvm::errs());
rewriter_->getEditBuffer(rewriter_->getSourceMgr().getMainFileID()).write(os_);
os_.flush();
}
bool VisitCallExpr(clang::CallExpr *Call);
bool VisitVarDecl(clang::VarDecl *Decl);
bool VisitMemberExpr(clang::MemberExpr *E);
- bool VisitDeclRefExpr(clang::DeclRefExpr *E);
bool VisitBinaryOperator(clang::BinaryOperator *E);
bool VisitImplicitCastExpr(clang::ImplicitCastExpr *E);
public:
// Initialize with the output stream where the new source file contents
// should be written.
- explicit BFrontendAction(llvm::raw_ostream &os);
+ BFrontendAction(llvm::raw_ostream &os, unsigned flags);
// Called by clang when the AST has been completed, here the output stream
// will be flushed.
// take ownership of the table-to-fd mapping data structure
std::unique_ptr<std::vector<TableDesc>> take_tables() { return move(tables_); }
private:
- std::unique_ptr<clang::Rewriter> rewriter_;
llvm::raw_ostream &os_;
+ unsigned flags_;
+ std::unique_ptr<clang::Rewriter> rewriter_;
std::unique_ptr<std::vector<TableDesc>> tables_;
};
namespace ebpf {
-ClangLoader::ClangLoader(llvm::LLVMContext *ctx)
- : ctx_(ctx)
+ClangLoader::ClangLoader(llvm::LLVMContext *ctx, unsigned flags)
+ : ctx_(ctx), flags_(flags)
{}
ClangLoader::~ClangLoader() {}
// capture the rewritten c file
string out_str;
llvm::raw_string_ostream os(out_str);
- BFrontendAction bact(os);
+ BFrontendAction bact(os, flags_);
if (!compiler1.ExecuteAction(bact))
return -1;
// this contains the open FDs
class ClangLoader {
public:
- explicit ClangLoader(llvm::LLVMContext *ctx);
+ explicit ClangLoader(llvm::LLVMContext *ctx, unsigned flags);
~ClangLoader();
int parse(std::unique_ptr<llvm::Module> *mod, std::unique_ptr<std::vector<TableDesc>> *tables,
const std::string &file, bool in_memory);
private:
llvm::LLVMContext *ctx_;
+ unsigned flags_;
};
} // namespace ebpf