refactor(irgen): IR改成alloca和store形式

This commit is contained in:
jing
2026-03-01 15:36:50 +08:00
parent 29bf99727f
commit 730280abb8
10 changed files with 180 additions and 10 deletions

View File

@@ -20,6 +20,27 @@ BinaryInst* IRBuilder::CreateBinary(Opcode op, Value* lhs, Value* rhs,
return insertBlock_->Append<BinaryInst>(op, Type::Int32(), lhs, rhs, name);
}
AllocaInst* IRBuilder::CreateAllocaI32(const std::string& name) {
if (!insertBlock_) {
throw std::runtime_error("IRBuilder 未设置插入点");
}
return insertBlock_->Append<AllocaInst>(name);
}
LoadInst* IRBuilder::CreateLoad(Value* ptr, const std::string& name) {
if (!insertBlock_) {
throw std::runtime_error("IRBuilder 未设置插入点");
}
return insertBlock_->Append<LoadInst>(ptr, name);
}
StoreInst* IRBuilder::CreateStore(Value* val, Value* ptr) {
if (!insertBlock_) {
throw std::runtime_error("IRBuilder 未设置插入点");
}
return insertBlock_->Append<StoreInst>(val, ptr);
}
ReturnInst* IRBuilder::CreateRet(Value* v) {
if (!insertBlock_) {
throw std::runtime_error("IRBuilder 未设置插入点");