summaryrefslogtreecommitdiff
path: root/Driver.cc
blob: 2d7441df92adeaf05451613650695bbbb4b39cc1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "Driver.hh"
#include "Log.hh"
#include "Parser.hh"

namespace pcc {
Driver::Driver(const char* name)
    : context_(name) {}

Driver::~Driver() {}

std::shared_ptr<ProgramNode> Driver::Parse(std::string& filename) {
    location_.initialize(&filename);
    if (StartLexer(filename) != 0) {
        return nullptr;
    }
    Parser parser(*this, &context_);
    if (GetLogLevel() == pcc::PCC_DEBUG) {
        parser.set_debug_level(1);
    }
    parser.parse();
    StopLexer();
    return root_;
}

void Driver::SetRoot(std::shared_ptr<ProgramNode> root) { root_ = root; }

Context* Driver::GetContext() { return &context_; }
} // namespace pcc