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.
27 lines
694 B
27 lines
694 B
// 函数翻译模块:
|
|
// - 处理函数定义、参数列表与返回值翻译
|
|
// - 创建并填充对应的 IR Function 对象
|
|
|
|
#include "irgen/IRGen.h"
|
|
|
|
#include <stdexcept>
|
|
|
|
#include "ast/AstNodes.h"
|
|
#include "ir/IR.h"
|
|
|
|
IRGenImpl::IRGenImpl(ir::Module& module)
|
|
: module_(module),
|
|
func_(module_.CreateFunction("main", ir::Type::Int32())),
|
|
builder_(func_->entry()) {}
|
|
|
|
void IRGenImpl::Gen(const ast::CompUnit& ast) {
|
|
if (!ast.func || !ast.func->body) {
|
|
throw std::runtime_error("AST 不完整:缺少 main 定义");
|
|
}
|
|
GenBlock(*ast.func->body);
|
|
}
|
|
|
|
std::unique_ptr<ir::Module> IRGenImpl::TakeModule() {
|
|
return std::make_unique<ir::Module>(std::move(module_));
|
|
}
|