forked from NUDT-compiler/nudt-compiler-cpp
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
556 B
25 lines
556 B
#include "irgen/IRGen.h"
|
|
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
|
|
#include "SysYParser.h"
|
|
#include "antlr4-runtime.h"
|
|
#include "ir/IR.h"
|
|
|
|
std::unique_ptr<ir::Module> GenerateIR(antlr4::tree::ParseTree* tree) {
|
|
if (!tree) {
|
|
throw std::runtime_error("[irgen] parse tree 为空");
|
|
}
|
|
|
|
auto* cu = dynamic_cast<SysYParser::CompUnitContext*>(tree);
|
|
if (!cu) {
|
|
throw std::runtime_error("[irgen] parse tree 根节点不是 compUnit");
|
|
}
|
|
|
|
auto module = std::make_unique<ir::Module>();
|
|
IRGenImpl gen(*module);
|
|
gen.Gen(*cu);
|
|
return module;
|
|
}
|