fix(ir): 修改了一下context的管理
This commit is contained in:
@@ -39,14 +39,14 @@ void IRGenImpl::GenVarDecl(SysYParser::VarDeclContext& decl) {
|
||||
if (storage_map_.find(&decl) != storage_map_.end()) {
|
||||
throw std::runtime_error("[irgen] 声明重复生成存储槽位");
|
||||
}
|
||||
auto* slot = builder_.CreateAllocaI32(ir::DefaultContext().NextTemp());
|
||||
auto* slot = builder_.CreateAllocaI32(module_.context().NextTemp());
|
||||
storage_map_[&decl] = slot;
|
||||
|
||||
ir::Value* init = nullptr;
|
||||
if (decl.exp()) {
|
||||
init = GenExpr(*decl.exp());
|
||||
} else {
|
||||
init = ir::DefaultContext().GetConstInt(0);
|
||||
init = builder_.CreateConstInt(0);
|
||||
}
|
||||
builder_.CreateStore(init, slot);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,10 @@ void VerifyFunctionStructure(const ir::Function& func) {
|
||||
} // namespace
|
||||
|
||||
IRGenImpl::IRGenImpl(ir::Module& module, const SemanticContext& sema)
|
||||
: module_(module), sema_(sema), func_(nullptr), builder_(nullptr) {}
|
||||
: module_(module),
|
||||
sema_(sema),
|
||||
func_(nullptr),
|
||||
builder_(module.context(), nullptr) {}
|
||||
|
||||
void IRGenImpl::Gen(SysYParser::CompUnitContext& cu) {
|
||||
if (!cu.funcDef()) {
|
||||
@@ -37,7 +40,9 @@ void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) {
|
||||
throw std::runtime_error("[irgen] 缺少函数名");
|
||||
}
|
||||
|
||||
func_ = module_.CreateFunction(func.Ident()->getText(), ir::Type::Int32());
|
||||
func_ = module_.CreateFunction(
|
||||
func.Ident()->getText(),
|
||||
std::make_shared<ir::Type>(ir::Type::Kind::Int32));
|
||||
builder_.SetInsertPoint(func_->entry());
|
||||
storage_map_.clear();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user