This commit is contained in:
jing
2025-12-29 20:11:51 +08:00
parent c153604c2e
commit e1c1f2a40d
14 changed files with 402 additions and 27 deletions

View File

@@ -2,3 +2,29 @@
// - 管理插入点(当前基本块/位置)
// - 提供创建各类指令的便捷接口,降低 IRGen 复杂度
#include "ir/IR.h"
#include <stdexcept>
namespace ir {
ConstantInt* IRBuilder::CreateConstInt(int v) {
// 常量不需要挂在基本块里,由 Context 负责去重与生命周期。
return DefaultContext().GetConstInt(v);
}
BinaryInst* IRBuilder::CreateBinary(Opcode op, Value* lhs, Value* rhs,
const std::string& name) {
if (!insertBlock_) {
throw std::runtime_error("IRBuilder 未设置插入点");
}
return insertBlock_->Append<BinaryInst>(op, Type::Int32(), lhs, rhs, name);
}
ReturnInst* IRBuilder::CreateRet(Value* v) {
if (!insertBlock_) {
throw std::runtime_error("IRBuilder 未设置插入点");
}
return insertBlock_->Append<ReturnInst>(v);
}
} // namespace ir