// 声明翻译模块: // - 处理全局变量与局部变量声明 // - 处理数组初始化、空间分配与初值生成等 #include "irgen/IRGen.h" #include #include "ast/AstNodes.h" #include "ir/IR.h" void IRGenImpl::GenBlock(const ast::Block& block) { for (const auto& decl : block.varDecls) { GenVarDecl(*decl); } for (const auto& stmt : block.stmts) { GenStmt(*stmt); } } void IRGenImpl::GenVarDecl(const ast::VarDecl& decl) { ir::Value* init = nullptr; if (decl.init) { init = GenExpr(*decl.init); } else { init = ir::DefaultContext().GetConstInt(0); } locals_[decl.name] = init; }