// 函数翻译模块: // - 处理函数定义、参数列表与返回值翻译 // - 创建并填充对应的 IR Function 对象 #include "irgen/IRGen.h" #include #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 IRGenImpl::TakeModule() { return std::make_unique(std::move(module_)); }