Commit d6922022 authored by Alastair Robertson's avatar Alastair Robertson

Rename Codegen class to CodegenLLVM

parent e8461e74
...@@ -6,22 +6,22 @@ namespace ebpf { ...@@ -6,22 +6,22 @@ namespace ebpf {
namespace bpftrace { namespace bpftrace {
namespace ast { namespace ast {
void Codegen::visit(Integer &integer) void CodegenLLVM::visit(Integer &integer)
{ {
expr_ = ConstantInt::get(module_.getContext(), APInt(64, integer.n)); // TODO fix bit width expr_ = ConstantInt::get(module_.getContext(), APInt(64, integer.n)); // TODO fix bit width
} }
void Codegen::visit(Builtin &builtin) void CodegenLLVM::visit(Builtin &builtin)
{ {
expr_ = b_.getInt64(0); expr_ = b_.getInt64(0);
} }
void Codegen::visit(Call &call) void CodegenLLVM::visit(Call &call)
{ {
expr_ = b_.getInt64(0); expr_ = b_.getInt64(0);
} }
void Codegen::visit(Map &map) void CodegenLLVM::visit(Map &map)
{ {
int mapfd; int mapfd;
if (maps_.find(map.ident) == maps_.end()) { if (maps_.find(map.ident) == maps_.end()) {
...@@ -33,7 +33,7 @@ void Codegen::visit(Map &map) ...@@ -33,7 +33,7 @@ void Codegen::visit(Map &map)
// CALL(BPF_FUNC_map_lookup_elem) // CALL(BPF_FUNC_map_lookup_elem)
} }
void Codegen::visit(Binop &binop) void CodegenLLVM::visit(Binop &binop)
{ {
Value *lhs, *rhs; Value *lhs, *rhs;
binop.left->accept(*this); binop.left->accept(*this);
...@@ -62,7 +62,7 @@ void Codegen::visit(Binop &binop) ...@@ -62,7 +62,7 @@ void Codegen::visit(Binop &binop)
} }
} }
void Codegen::visit(Unop &unop) void CodegenLLVM::visit(Unop &unop)
{ {
unop.expr->accept(*this); unop.expr->accept(*this);
...@@ -73,12 +73,12 @@ void Codegen::visit(Unop &unop) ...@@ -73,12 +73,12 @@ void Codegen::visit(Unop &unop)
} }
} }
void Codegen::visit(ExprStatement &expr) void CodegenLLVM::visit(ExprStatement &expr)
{ {
expr.expr->accept(*this); expr.expr->accept(*this);
} }
void Codegen::visit(AssignMapStatement &assignment) void CodegenLLVM::visit(AssignMapStatement &assignment)
{ {
Value *map, *val; Value *map, *val;
assignment.map->accept(*this); assignment.map->accept(*this);
...@@ -89,11 +89,11 @@ void Codegen::visit(AssignMapStatement &assignment) ...@@ -89,11 +89,11 @@ void Codegen::visit(AssignMapStatement &assignment)
// CALL(BPF_FUNC_map_update_elem) // CALL(BPF_FUNC_map_update_elem)
} }
void Codegen::visit(AssignMapCallStatement &assignment) void CodegenLLVM::visit(AssignMapCallStatement &assignment)
{ {
} }
void Codegen::visit(Predicate &pred) void CodegenLLVM::visit(Predicate &pred)
{ {
Function *parent = b_.GetInsertBlock()->getParent(); Function *parent = b_.GetInsertBlock()->getParent();
BasicBlock *pred_false_block = BasicBlock::Create(module_.getContext(), "pred_false", parent); BasicBlock *pred_false_block = BasicBlock::Create(module_.getContext(), "pred_false", parent);
...@@ -109,7 +109,7 @@ void Codegen::visit(Predicate &pred) ...@@ -109,7 +109,7 @@ void Codegen::visit(Predicate &pred)
b_.SetInsertPoint(pred_true_block); b_.SetInsertPoint(pred_true_block);
} }
void Codegen::visit(Probe &probe) void CodegenLLVM::visit(Probe &probe)
{ {
FunctionType *func_type = FunctionType::get(b_.getInt64Ty(), false); FunctionType *func_type = FunctionType::get(b_.getInt64Ty(), false);
Function *func = Function::Create(func_type, Function::ExternalLinkage, probe.name, &module_); Function *func = Function::Create(func_type, Function::ExternalLinkage, probe.name, &module_);
...@@ -126,7 +126,7 @@ void Codegen::visit(Probe &probe) ...@@ -126,7 +126,7 @@ void Codegen::visit(Probe &probe)
b_.CreateRet(ConstantInt::get(module_.getContext(), APInt(64, 0))); b_.CreateRet(ConstantInt::get(module_.getContext(), APInt(64, 0)));
} }
void Codegen::visit(Program &program) void CodegenLLVM::visit(Program &program)
{ {
for (Probe *probe : *program.probes) { for (Probe *probe : *program.probes) {
probe->accept(*this); probe->accept(*this);
......
...@@ -12,9 +12,9 @@ namespace ast { ...@@ -12,9 +12,9 @@ namespace ast {
using namespace llvm; using namespace llvm;
class Codegen : public Visitor { class CodegenLLVM : public Visitor {
public: public:
Codegen(Module &mod, LLVMContext &context) : context_(context), CodegenLLVM(Module &mod, LLVMContext &context) : context_(context),
module_(mod), module_(mod),
b_(context_) b_(context_)
{ } { }
......
...@@ -32,7 +32,7 @@ void Driver::dump_ast(std::ostream &out) ...@@ -32,7 +32,7 @@ void Driver::dump_ast(std::ostream &out)
int Driver::compile() int Driver::compile()
{ {
ast::Codegen c(*module_, context_); ast::CodegenLLVM c(*module_, context_);
root_->accept(c); root_->accept(c);
module_->dump(); module_->dump();
......
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