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