Commit 796f9c9a authored by Alastair Robertson's avatar Alastair Robertson

Move code out of parser driver back into main.cpp

parent 918e4c82
#include <iostream> #include <iostream>
#include "codegen_llvm.h"
#include "driver.h" #include "driver.h"
#include "printer.h"
#include "semantic_analyser.h"
namespace ebpf { namespace ebpf {
namespace bpftrace { namespace bpftrace {
...@@ -22,23 +19,5 @@ int Driver::parse(const std::string &f) ...@@ -22,23 +19,5 @@ int Driver::parse(const std::string &f)
return parser_.parse(); return parser_.parse();
} }
void Driver::dump_ast(std::ostream &out)
{
ast::Printer p = ebpf::bpftrace::ast::Printer(out);
root_->accept(p);
}
int Driver::analyse()
{
ast::SemanticAnalyser semantics(root_, bpftrace_);
return semantics.analyse();
}
int Driver::compile()
{
ast::CodegenLLVM llvm(root_, bpftrace_);
return llvm.compile();
}
} // namespace bpftrace } // namespace bpftrace
} // namespace ebpf } // namespace ebpf
#pragma once #pragma once
#include "ast.h" #include "ast.h"
#include "bpftrace.h"
#include "parser.tab.hh" #include "parser.tab.hh"
#define YY_DECL ebpf::bpftrace::Parser::symbol_type yylex(ebpf::bpftrace::Driver &driver) #define YY_DECL ebpf::bpftrace::Parser::symbol_type yylex(ebpf::bpftrace::Driver &driver)
...@@ -18,9 +17,6 @@ public: ...@@ -18,9 +17,6 @@ public:
int parse(); int parse();
int parse(const std::string &f); int parse(const std::string &f);
void dump_ast(std::ostream &out);
int analyse();
int compile();
void error(const location &l, const std::string &m) void error(const location &l, const std::string &m)
{ {
...@@ -36,7 +32,6 @@ public: ...@@ -36,7 +32,6 @@ public:
private: private:
Parser parser_; Parser parser_;
BPFtrace bpftrace_;
}; };
} // namespace bpftrace } // namespace bpftrace
......
#include <iostream> #include <iostream>
#include "bpftrace.h"
#include "codegen_llvm.h"
#include "driver.h" #include "driver.h"
#include "printer.h"
#include "semantic_analyser.h"
using namespace ebpf::bpftrace;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
int result; int result;
ebpf::bpftrace::Driver driver; Driver driver;
if (argc == 1) { if (argc == 1)
result = driver.parse(); result = driver.parse();
} else
else {
result = driver.parse(argv[1]); result = driver.parse(argv[1]);
}
if (result) { if (result)
return result; return result;
}
driver.dump_ast(std::cout); BPFtrace bpftrace;
ast::Printer p = ebpf::bpftrace::ast::Printer(std::cout);
driver.root_->accept(p);
ast::SemanticAnalyser semantics(driver.root_, bpftrace);
result = semantics.analyse();
if (result)
return result;
result = driver.analyse(); ast::CodegenLLVM llvm(driver.root_, bpftrace);
if (result) { result = llvm.compile();
if (result)
return result; return result;
}
driver.compile(); bpftrace.attach_probes();
return 0; return 0;
} }
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