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.
30 lines
642 B
30 lines
642 B
// 声明翻译模块:
|
|
// - 处理全局变量与局部变量声明
|
|
// - 处理数组初始化、空间分配与初值生成等
|
|
|
|
#include "irgen/IRGen.h"
|
|
|
|
#include <memory>
|
|
|
|
#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;
|
|
}
|