}
namespace ebpf {
-class BPFTable;
+class TableDesc;
class BLoader;
class ClangLoader;
std::unique_ptr<BLoader> b_loader_;
std::unique_ptr<ClangLoader> clang_loader_;
std::map<std::string, std::tuple<uint8_t *, uintptr_t>> sections_;
- std::unique_ptr<std::map<std::string, BPFTable>> tables_;
+ std::unique_ptr<std::map<std::string, TableDesc>> tables_;
std::vector<std::string> table_names_;
std::vector<std::string> function_names_;
};
return mkstatus(0);
}
-StatusTuple CodegenLLVM::visit(Node* root, map<string, BPFTable> &tables) {
+StatusTuple CodegenLLVM::visit(Node* root, map<string, TableDesc> &tables) {
scopes_->set_current(scopes_->top_state());
scopes_->set_current(scopes_->top_var());
//TRY2(print_parser());
for (auto table : tables_) {
- BPFTable desc = {
+ TableDesc desc = {
table_fds_[table.first],
table.first->key_type_->bit_width_ >> 3,
table.first->leaf_type_->bit_width_ >> 3,
}
namespace ebpf {
-class BPFTable;
+class TableDesc;
namespace cc {
EXPAND_NODES(VISIT)
#undef VISIT
- virtual STATUS_RETURN visit(Node* n, std::map<string, BPFTable> &tables);
+ virtual STATUS_RETURN visit(Node* n, std::map<string, TableDesc> &tables);
int get_table_fd(const std::string &name) const;
}
int BLoader::parse(llvm::Module *mod, const string &filename, const string &proto_filename,
- unique_ptr<map<string, BPFTable>> *tables) {
+ unique_ptr<map<string, TableDesc>> *tables) {
int rc;
proto_parser_ = make_unique<ebpf::cc::Parser>(proto_filename);
return -1;
}
- *tables = make_unique<map<string, BPFTable>>();
+ *tables = make_unique<map<string, TableDesc>>();
codegen_ = ebpf::make_unique<ebpf::cc::CodegenLLVM>(mod, parser_->scopes_.get(), proto_parser_->scopes_.get());
ret = codegen_->visit(parser_->root_node_, **tables);
namespace ebpf {
-class BPFTable;
+class TableDesc;
namespace cc {
class Parser;
BLoader();
~BLoader();
int parse(llvm::Module *mod, const std::string &filename, const std::string &proto_filename,
- std::unique_ptr<std::map<std::string, BPFTable>> *tables);
+ std::unique_ptr<std::map<std::string, TableDesc>> *tables);
int get_table_fd(const std::string &name) const;
private:
std::unique_ptr<cc::Parser> parser_;
result += "}\n";
}
-BTypeVisitor::BTypeVisitor(ASTContext &C, Rewriter &rewriter, map<string, BPFTable> &tables)
+BTypeVisitor::BTypeVisitor(ASTContext &C, Rewriter &rewriter, map<string, TableDesc> &tables)
: C(C), rewriter_(rewriter), out_(llvm::errs()), tables_(tables) {
}
return false;
}
const RecordDecl *RD = R->getDecl()->getDefinition();
- BPFTable table;
+ TableDesc table;
unsigned i = 0;
for (auto F : RD->fields()) {
size_t sz = C.getTypeSize(F->getType()) >> 3;
return true;
}
-BTypeConsumer::BTypeConsumer(ASTContext &C, Rewriter &rewriter, map<string, BPFTable> &tables)
+BTypeConsumer::BTypeConsumer(ASTContext &C, Rewriter &rewriter, map<string, TableDesc> &tables)
: visitor_(C, rewriter, tables) {
}
}
BFrontendAction::BFrontendAction(llvm::raw_ostream &os)
- : rewriter_(new Rewriter), os_(os), tables_(new map<string, BPFTable>) {
+ : rewriter_(new Rewriter), os_(os), tables_(new map<string, TableDesc>) {
}
void BFrontendAction::EndSourceFileAction() {
class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> {
public:
explicit BTypeVisitor(clang::ASTContext &C, clang::Rewriter &rewriter,
- std::map<std::string, BPFTable> &tables);
+ std::map<std::string, TableDesc> &tables);
bool TraverseCallExpr(clang::CallExpr *Call);
bool TraverseMemberExpr(clang::MemberExpr *E);
bool VisitFunctionDecl(clang::FunctionDecl *D);
clang::ASTContext &C;
clang::Rewriter &rewriter_; /// modifications to the source go into this class
llvm::raw_ostream &out_; /// for debugging
- std::map<std::string, BPFTable> &tables_; /// store the open FDs
+ std::map<std::string, TableDesc> &tables_; /// store the open FDs
std::vector<clang::ParmVarDecl *> fn_args_;
};
class BTypeConsumer : public clang::ASTConsumer {
public:
explicit BTypeConsumer(clang::ASTContext &C, clang::Rewriter &rewriter,
- std::map<std::string, BPFTable> &tables);
+ std::map<std::string, TableDesc> &tables);
bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
private:
BTypeVisitor visitor_;
CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef InFile) override;
// take ownership of the table-to-fd mapping data structure
- std::unique_ptr<std::map<std::string, BPFTable>> take_tables() { return move(tables_); }
+ std::unique_ptr<std::map<std::string, TableDesc>> take_tables() { return move(tables_); }
private:
std::unique_ptr<clang::Rewriter> rewriter_;
llvm::raw_ostream &os_;
- std::unique_ptr<std::map<std::string, BPFTable>> tables_;
+ std::unique_ptr<std::map<std::string, TableDesc>> tables_;
};
} // namespace visitor
ClangLoader::~ClangLoader() {}
int ClangLoader::parse(unique_ptr<llvm::Module> *mod,
- unique_ptr<map<string, BPFTable>> *tables,
+ unique_ptr<map<string, TableDesc>> *tables,
const string &file, bool in_memory) {
using namespace clang;
namespace ebpf {
-class BPFTable;
+class TableDesc;
namespace cc {
class Parser;
explicit ClangLoader(llvm::LLVMContext *ctx);
~ClangLoader();
int parse(std::unique_ptr<llvm::Module> *mod,
- std::unique_ptr<std::map<std::string, BPFTable>> *tables,
+ std::unique_ptr<std::map<std::string, TableDesc>> *tables,
const std::string &file, bool in_memory);
private:
llvm::LLVMContext *ctx_;
namespace ebpf {
-struct BPFTable {
+struct TableDesc {
int fd;
size_t key_size; // sizes are in bytes
size_t leaf_size;