style(ir): 纠正代码位置

This commit is contained in:
jing
2026-03-11 22:08:27 +08:00
parent 62dde8d7ab
commit fab6983d40
17 changed files with 193 additions and 88 deletions

View File

@@ -18,6 +18,17 @@ bool IsPtrInt32Type(const std::shared_ptr<Type>& ty) {
} // namespace
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_; }
bool Instruction::IsTerminator() const { return opcode_ == Opcode::Ret; }
BasicBlock* Instruction::parent() const { return parent_; }
void Instruction::set_parent(BasicBlock* parent) { parent_ = parent; }
BinaryInst::BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs,
Value* rhs, std::string name)
: Instruction(op, std::move(ty), std::move(name)), lhs_(lhs), rhs_(rhs) {
@@ -45,6 +56,10 @@ BinaryInst::BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs,
}
}
Value* BinaryInst::lhs() const { return lhs_; }
Value* BinaryInst::rhs() const { return rhs_; }
ReturnInst::ReturnInst(Value* val)
: Instruction(Opcode::Ret, Type::Void(), ""), value_(val) {
if (!value_) {
@@ -53,6 +68,8 @@ ReturnInst::ReturnInst(Value* val)
value_->AddUser(this);
}
Value* ReturnInst::value() const { return value_; }
AllocaInst::AllocaInst(std::string name)
: Instruction(Opcode::Alloca, Type::PtrInt32(), std::move(name)) {}
@@ -67,6 +84,8 @@ LoadInst::LoadInst(Value* ptr, std::string name)
ptr_->AddUser(this);
}
Value* LoadInst::ptr() const { return ptr_; }
StoreInst::StoreInst(Value* val, Value* ptr)
: Instruction(Opcode::Store, Type::Void(), ""), value_(val), ptr_(ptr) {
if (!value_) {
@@ -85,4 +104,8 @@ StoreInst::StoreInst(Value* val, Value* ptr)
ptr_->AddUser(this);
}
Value* StoreInst::value() const { return value_; }
Value* StoreInst::ptr() const { return ptr_; }
} // namespace ir