refactor(dev): 统一 IR/MIR 接口命名风格

This commit is contained in:
Lane0218
2026-03-12 15:17:02 +08:00
parent f26551a896
commit b1155d8fa9
18 changed files with 170 additions and 167 deletions

View File

@@ -11,13 +11,13 @@ namespace ir {
Instruction::Instruction(Opcode op, std::shared_ptr<Type> ty, std::string name)
: Value(std::move(ty), std::move(name)), opcode_(op) {}
Opcode Instruction::opcode() const { return opcode_; }
Opcode Instruction::GetOpcode() const { return opcode_; }
bool Instruction::IsTerminator() const { return opcode_ == Opcode::Ret; }
BasicBlock* Instruction::parent() const { return parent_; }
BasicBlock* Instruction::GetParent() const { return parent_; }
void Instruction::set_parent(BasicBlock* parent) { parent_ = parent; }
void Instruction::SetParent(BasicBlock* parent) { parent_ = parent; }
BinaryInst::BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs,
Value* rhs, std::string name)
@@ -28,11 +28,11 @@ BinaryInst::BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs,
if (!lhs_ || !rhs_) {
throw std::runtime_error(FormatError("ir", "BinaryInst 缺少操作数"));
}
if (!type_ || !lhs_->type() || !rhs_->type()) {
if (!type_ || !lhs_->GetType() || !rhs_->GetType()) {
throw std::runtime_error(FormatError("ir", "BinaryInst 缺少类型信息"));
}
if (lhs_->type()->kind() != rhs_->type()->kind() ||
type_->kind() != lhs_->type()->kind()) {
if (lhs_->GetType()->GetKind() != rhs_->GetType()->GetKind() ||
type_->GetKind() != lhs_->GetType()->GetKind()) {
throw std::runtime_error(FormatError("ir", "BinaryInst 类型不匹配"));
}
if (!type_->IsInt32()) {
@@ -46,9 +46,9 @@ BinaryInst::BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs,
}
}
Value* BinaryInst::lhs() const { return lhs_; }
Value* BinaryInst::GetLhs() const { return lhs_; }
Value* BinaryInst::rhs() const { return rhs_; }
Value* BinaryInst::GetRhs() const { return rhs_; }
ReturnInst::ReturnInst(std::shared_ptr<Type> void_ty, Value* val)
: Instruction(Opcode::Ret, std::move(void_ty), ""),
@@ -62,7 +62,7 @@ ReturnInst::ReturnInst(std::shared_ptr<Type> void_ty, Value* val)
value_->AddUser(this);
}
Value* ReturnInst::value() const { return value_; }
Value* ReturnInst::GetValue() const { return value_; }
AllocaInst::AllocaInst(std::shared_ptr<Type> ptr_ty, std::string name)
: Instruction(Opcode::Alloca, std::move(ptr_ty), std::move(name)) {
@@ -80,14 +80,14 @@ LoadInst::LoadInst(std::shared_ptr<Type> val_ty, Value* ptr, std::string name)
if (!type_ || !type_->IsInt32()) {
throw std::runtime_error(FormatError("ir", "LoadInst 当前只支持加载 i32"));
}
if (!ptr_->type() || !ptr_->type()->IsPtrInt32()) {
if (!ptr_->GetType() || !ptr_->GetType()->IsPtrInt32()) {
throw std::runtime_error(
FormatError("ir", "LoadInst 当前只支持从 i32* 加载"));
}
ptr_->AddUser(this);
}
Value* LoadInst::ptr() const { return ptr_; }
Value* LoadInst::GetPtr() const { return ptr_; }
StoreInst::StoreInst(std::shared_ptr<Type> void_ty, Value* val, Value* ptr)
: Instruction(Opcode::Store, std::move(void_ty), ""),
@@ -102,10 +102,10 @@ StoreInst::StoreInst(std::shared_ptr<Type> void_ty, Value* val, Value* ptr)
if (!type_ || !type_->IsVoid()) {
throw std::runtime_error(FormatError("ir", "StoreInst 返回类型必须为 void"));
}
if (!value_->type() || !value_->type()->IsInt32()) {
if (!value_->GetType() || !value_->GetType()->IsInt32()) {
throw std::runtime_error(FormatError("ir", "StoreInst 当前只支持存储 i32"));
}
if (!ptr_->type() || !ptr_->type()->IsPtrInt32()) {
if (!ptr_->GetType() || !ptr_->GetType()->IsPtrInt32()) {
throw std::runtime_error(
FormatError("ir", "StoreInst 当前只支持写入 i32*"));
}
@@ -113,8 +113,8 @@ StoreInst::StoreInst(std::shared_ptr<Type> void_ty, Value* val, Value* ptr)
ptr_->AddUser(this);
}
Value* StoreInst::value() const { return value_; }
Value* StoreInst::GetValue() const { return value_; }
Value* StoreInst::ptr() const { return ptr_; }
Value* StoreInst::GetPtr() const { return ptr_; }
} // namespace ir