Commit 4a09dd56 authored by Brenden Blanco's avatar Brenden Blanco

Add printf key/leaf writer functionality

This extends upon the sscanf reader functionality, with the intent of
providing key/leaf pretty printing
Signed-off-by: default avatarBrenden Blanco <bblanco@plumgrid.com>
parent 3381c792
......@@ -182,4 +182,15 @@ int bpf_table_update_id(void *program, size_t id, const char *key, const char *l
return mod->table_update(id, key, leaf);
}
int bpf_table_key_snprintf(void *program, size_t id, char *buf, size_t buflen, const void *key) {
auto mod = static_cast<ebpf::BPFModule *>(program);
if (!mod) return 0;
return mod->table_key_printf(id, buf, buflen, key);
}
int bpf_table_leaf_snprintf(void *program, size_t id, char *buf, size_t buflen, const void *leaf) {
auto mod = static_cast<ebpf::BPFModule *>(program);
if (!mod) return 0;
return mod->table_key_printf(id, buf, buflen, leaf);
}
}
......@@ -48,6 +48,10 @@ size_t bpf_table_key_size(void *program, const char *table_name);
size_t bpf_table_key_size_id(void *program, size_t id);
size_t bpf_table_leaf_size(void *program, const char *table_name);
size_t bpf_table_leaf_size_id(void *program, size_t id);
int bpf_table_key_snprintf(void *program, size_t id, char *buf, size_t buflen, const void *key);
int bpf_table_leaf_snprintf(void *program, size_t id, char *buf, size_t buflen, const void *leaf);
//int bpf_table_key_sscanf(void *program, size_t id, const char *buf, void *key);
//int bpf_table_leaf_sscanf(void *program, size_t id, const char *buf, void *leaf);
int bpf_table_update(void *program, const char *table_name, const char *key, const char *leaf);
int bpf_table_update_id(void *program, size_t id, const char *key, const char *leaf);
......
This diff is collapsed.
......@@ -42,8 +42,9 @@ class BPFModule {
int parse(llvm::Module *mod);
int finalize();
int annotate();
std::unique_ptr<llvm::ExecutionEngine> finalize_reader(std::unique_ptr<llvm::Module> mod);
std::unique_ptr<llvm::ExecutionEngine> finalize_rw(std::unique_ptr<llvm::Module> mod);
llvm::Function * make_reader(llvm::Module *mod, llvm::Type *type);
llvm::Function * make_writer(llvm::Module *mod, llvm::Type *type);
void dump_ir(llvm::Module &mod);
int load_file_module(std::unique_ptr<llvm::Module> *mod, const std::string &file, bool in_memory);
int load_includes(const std::string &tmpfile);
......@@ -70,10 +71,12 @@ class BPFModule {
const char * table_key_desc(const std::string &name) const;
size_t table_key_size(size_t id) const;
size_t table_key_size(const std::string &name) const;
int table_key_printf(size_t id, char *buf, size_t buflen, const void *key);
const char * table_leaf_desc(size_t id) const;
const char * table_leaf_desc(const std::string &name) const;
size_t table_leaf_size(size_t id) const;
size_t table_leaf_size(const std::string &name) const;
int table_leaf_printf(size_t id, char *buf, size_t buflen, const void *leaf);
int table_update(size_t id, const char *key, const char *leaf);
int table_update(const std::string &name, const char *key, const char *leaf);
char * license() const;
......@@ -84,7 +87,7 @@ class BPFModule {
std::string proto_filename_;
std::unique_ptr<llvm::LLVMContext> ctx_;
std::unique_ptr<llvm::ExecutionEngine> engine_;
std::unique_ptr<llvm::ExecutionEngine> reader_engine_;
std::unique_ptr<llvm::ExecutionEngine> rw_engine_;
std::unique_ptr<llvm::Module> mod_;
std::unique_ptr<BLoader> b_loader_;
std::unique_ptr<ClangLoader> clang_loader_;
......@@ -93,6 +96,7 @@ class BPFModule {
std::map<std::string, size_t> table_names_;
std::vector<std::string> function_names_;
std::map<llvm::Type *, llvm::Function *> readers_;
std::map<llvm::Type *, llvm::Function *> writers_;
};
} // namespace ebpf
......@@ -33,6 +33,8 @@ struct TableDesc {
std::string leaf_desc;
llvm::Function *key_reader;
llvm::Function *leaf_reader;
llvm::Function *key_writer;
llvm::Function *leaf_writer;
};
} // namespace ebpf
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