Commit 8c5661e8 authored by Brenden Blanco's avatar Brenden Blanco

Rename BPFTable to TableDesc

This whole project is about bpf, prefixing everything with the same
acronym is redundant.
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 5a19f90a
...@@ -29,7 +29,7 @@ class Module; ...@@ -29,7 +29,7 @@ class Module;
} }
namespace ebpf { namespace ebpf {
class BPFTable; class TableDesc;
class BLoader; class BLoader;
class ClangLoader; class ClangLoader;
...@@ -83,7 +83,7 @@ class BPFModule { ...@@ -83,7 +83,7 @@ class BPFModule {
std::unique_ptr<BLoader> b_loader_; std::unique_ptr<BLoader> b_loader_;
std::unique_ptr<ClangLoader> clang_loader_; std::unique_ptr<ClangLoader> clang_loader_;
std::map<std::string, std::tuple<uint8_t *, uintptr_t>> sections_; 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> table_names_;
std::vector<std::string> function_names_; std::vector<std::string> function_names_;
}; };
......
...@@ -1221,7 +1221,7 @@ StatusTuple CodegenLLVM::visit_func_decl_stmt_node(FuncDeclStmtNode *n) { ...@@ -1221,7 +1221,7 @@ StatusTuple CodegenLLVM::visit_func_decl_stmt_node(FuncDeclStmtNode *n) {
return mkstatus(0); 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_state());
scopes_->set_current(scopes_->top_var()); scopes_->set_current(scopes_->top_var());
...@@ -1235,7 +1235,7 @@ StatusTuple CodegenLLVM::visit(Node* root, map<string, BPFTable> &tables) { ...@@ -1235,7 +1235,7 @@ StatusTuple CodegenLLVM::visit(Node* root, map<string, BPFTable> &tables) {
//TRY2(print_parser()); //TRY2(print_parser());
for (auto table : tables_) { for (auto table : tables_) {
BPFTable desc = { TableDesc desc = {
table_fds_[table.first], table_fds_[table.first],
table.first->key_type_->bit_width_ >> 3, table.first->key_type_->bit_width_ >> 3,
table.first->leaf_type_->bit_width_ >> 3, table.first->leaf_type_->bit_width_ >> 3,
......
...@@ -41,7 +41,7 @@ class GlobalVariable; ...@@ -41,7 +41,7 @@ class GlobalVariable;
} }
namespace ebpf { namespace ebpf {
class BPFTable; class TableDesc;
namespace cc { namespace cc {
...@@ -63,7 +63,7 @@ class CodegenLLVM : public Visitor { ...@@ -63,7 +63,7 @@ class CodegenLLVM : public Visitor {
EXPAND_NODES(VISIT) EXPAND_NODES(VISIT)
#undef 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 get_table_fd(const std::string &name) const;
......
...@@ -34,7 +34,7 @@ BLoader::~BLoader() { ...@@ -34,7 +34,7 @@ BLoader::~BLoader() {
} }
int BLoader::parse(llvm::Module *mod, const string &filename, const string &proto_filename, 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; int rc;
proto_parser_ = make_unique<ebpf::cc::Parser>(proto_filename); proto_parser_ = make_unique<ebpf::cc::Parser>(proto_filename);
...@@ -61,7 +61,7 @@ int BLoader::parse(llvm::Module *mod, const string &filename, const string &prot ...@@ -61,7 +61,7 @@ int BLoader::parse(llvm::Module *mod, const string &filename, const string &prot
return -1; 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()); codegen_ = ebpf::make_unique<ebpf::cc::CodegenLLVM>(mod, parser_->scopes_.get(), proto_parser_->scopes_.get());
ret = codegen_->visit(parser_->root_node_, **tables); ret = codegen_->visit(parser_->root_node_, **tables);
......
...@@ -26,7 +26,7 @@ class Module; ...@@ -26,7 +26,7 @@ class Module;
namespace ebpf { namespace ebpf {
class BPFTable; class TableDesc;
namespace cc { namespace cc {
class Parser; class Parser;
...@@ -38,7 +38,7 @@ class BLoader { ...@@ -38,7 +38,7 @@ class BLoader {
BLoader(); BLoader();
~BLoader(); ~BLoader();
int parse(llvm::Module *mod, const std::string &filename, const std::string &proto_filename, 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; int get_table_fd(const std::string &name) const;
private: private:
std::unique_ptr<cc::Parser> parser_; std::unique_ptr<cc::Parser> parser_;
......
...@@ -145,7 +145,7 @@ void BScanfVisitor::finalize(string &result) { ...@@ -145,7 +145,7 @@ void BScanfVisitor::finalize(string &result) {
result += "}\n"; 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) { : C(C), rewriter_(rewriter), out_(llvm::errs()), tables_(tables) {
} }
...@@ -419,7 +419,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) { ...@@ -419,7 +419,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
return false; return false;
} }
const RecordDecl *RD = R->getDecl()->getDefinition(); const RecordDecl *RD = R->getDecl()->getDefinition();
BPFTable table; TableDesc table;
unsigned i = 0; unsigned i = 0;
for (auto F : RD->fields()) { for (auto F : RD->fields()) {
size_t sz = C.getTypeSize(F->getType()) >> 3; size_t sz = C.getTypeSize(F->getType()) >> 3;
...@@ -489,7 +489,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) { ...@@ -489,7 +489,7 @@ bool BTypeVisitor::VisitVarDecl(VarDecl *Decl) {
return true; 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) { : visitor_(C, rewriter, tables) {
} }
...@@ -500,7 +500,7 @@ bool BTypeConsumer::HandleTopLevelDecl(DeclGroupRef D) { ...@@ -500,7 +500,7 @@ bool BTypeConsumer::HandleTopLevelDecl(DeclGroupRef D) {
} }
BFrontendAction::BFrontendAction(llvm::raw_ostream &os) 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() { void BFrontendAction::EndSourceFileAction() {
......
...@@ -79,7 +79,7 @@ class BScanfVisitor : public clang::RecursiveASTVisitor<BScanfVisitor> { ...@@ -79,7 +79,7 @@ class BScanfVisitor : public clang::RecursiveASTVisitor<BScanfVisitor> {
class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> { class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> {
public: public:
explicit BTypeVisitor(clang::ASTContext &C, clang::Rewriter &rewriter, 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 TraverseCallExpr(clang::CallExpr *Call);
bool TraverseMemberExpr(clang::MemberExpr *E); bool TraverseMemberExpr(clang::MemberExpr *E);
bool VisitFunctionDecl(clang::FunctionDecl *D); bool VisitFunctionDecl(clang::FunctionDecl *D);
...@@ -94,7 +94,7 @@ class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> { ...@@ -94,7 +94,7 @@ class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> {
clang::ASTContext &C; clang::ASTContext &C;
clang::Rewriter &rewriter_; /// modifications to the source go into this class clang::Rewriter &rewriter_; /// modifications to the source go into this class
llvm::raw_ostream &out_; /// for debugging 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_; std::vector<clang::ParmVarDecl *> fn_args_;
}; };
...@@ -102,7 +102,7 @@ class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> { ...@@ -102,7 +102,7 @@ class BTypeVisitor : public clang::RecursiveASTVisitor<BTypeVisitor> {
class BTypeConsumer : public clang::ASTConsumer { class BTypeConsumer : public clang::ASTConsumer {
public: public:
explicit BTypeConsumer(clang::ASTContext &C, clang::Rewriter &rewriter, 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; bool HandleTopLevelDecl(clang::DeclGroupRef D) override;
private: private:
BTypeVisitor visitor_; BTypeVisitor visitor_;
...@@ -125,11 +125,11 @@ class BFrontendAction : public clang::ASTFrontendAction { ...@@ -125,11 +125,11 @@ class BFrontendAction : public clang::ASTFrontendAction {
CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef InFile) override; CreateASTConsumer(clang::CompilerInstance &Compiler, llvm::StringRef InFile) override;
// take ownership of the table-to-fd mapping data structure // 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: private:
std::unique_ptr<clang::Rewriter> rewriter_; std::unique_ptr<clang::Rewriter> rewriter_;
llvm::raw_ostream &os_; llvm::raw_ostream &os_;
std::unique_ptr<std::map<std::string, BPFTable>> tables_; std::unique_ptr<std::map<std::string, TableDesc>> tables_;
}; };
} // namespace visitor } // namespace visitor
...@@ -65,7 +65,7 @@ ClangLoader::ClangLoader(llvm::LLVMContext *ctx) ...@@ -65,7 +65,7 @@ ClangLoader::ClangLoader(llvm::LLVMContext *ctx)
ClangLoader::~ClangLoader() {} ClangLoader::~ClangLoader() {}
int ClangLoader::parse(unique_ptr<llvm::Module> *mod, 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) { const string &file, bool in_memory) {
using namespace clang; using namespace clang;
......
...@@ -27,7 +27,7 @@ class LLVMContext; ...@@ -27,7 +27,7 @@ class LLVMContext;
namespace ebpf { namespace ebpf {
class BPFTable; class TableDesc;
namespace cc { namespace cc {
class Parser; class Parser;
...@@ -39,7 +39,7 @@ class ClangLoader { ...@@ -39,7 +39,7 @@ class ClangLoader {
explicit ClangLoader(llvm::LLVMContext *ctx); explicit ClangLoader(llvm::LLVMContext *ctx);
~ClangLoader(); ~ClangLoader();
int parse(std::unique_ptr<llvm::Module> *mod, 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); const std::string &file, bool in_memory);
private: private:
llvm::LLVMContext *ctx_; llvm::LLVMContext *ctx_;
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
namespace ebpf { namespace ebpf {
struct BPFTable { struct TableDesc {
int fd; int fd;
size_t key_size; // sizes are in bytes size_t key_size; // sizes are in bytes
size_t leaf_size; size_t leaf_size;
......
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