refactor(ir): ir改为更标准的实现

This commit is contained in:
jing
2026-03-18 01:53:54 +08:00
parent 1b283856b3
commit 7d4d60c546
9 changed files with 397 additions and 172 deletions

View File

@@ -46,7 +46,7 @@ AllocaInst* IRBuilder::CreateAllocaI32(const std::string& name) {
if (!insert_block_) {
throw std::runtime_error(FormatError("ir", "IRBuilder 未设置插入点"));
}
return insert_block_->Append<AllocaInst>(ctx_.PtrInt32(), name);
return insert_block_->Append<AllocaInst>(Type::GetPtrInt32Type(), name);
}
LoadInst* IRBuilder::CreateLoad(Value* ptr, const std::string& name) {
@@ -57,7 +57,7 @@ LoadInst* IRBuilder::CreateLoad(Value* ptr, const std::string& name) {
throw std::runtime_error(
FormatError("ir", "IRBuilder::CreateLoad 缺少 ptr"));
}
return insert_block_->Append<LoadInst>(ctx_.Int32(), ptr, name);
return insert_block_->Append<LoadInst>(Type::GetInt32Type(), ptr, name);
}
StoreInst* IRBuilder::CreateStore(Value* val, Value* ptr) {
@@ -72,7 +72,7 @@ StoreInst* IRBuilder::CreateStore(Value* val, Value* ptr) {
throw std::runtime_error(
FormatError("ir", "IRBuilder::CreateStore 缺少 ptr"));
}
return insert_block_->Append<StoreInst>(ctx_.Void(), val, ptr);
return insert_block_->Append<StoreInst>(Type::GetVoidType(), val, ptr);
}
ReturnInst* IRBuilder::CreateRet(Value* v) {
@@ -83,7 +83,7 @@ ReturnInst* IRBuilder::CreateRet(Value* v) {
throw std::runtime_error(
FormatError("ir", "IRBuilder::CreateRet 缺少返回值"));
}
return insert_block_->Append<ReturnInst>(ctx_.Void(), v);
return insert_block_->Append<ReturnInst>(Type::GetVoidType(), v);
}
} // namespace ir