|
|
|
|
@ -153,7 +153,7 @@ class ConstantInt : public ConstantValue {
|
|
|
|
|
|
|
|
|
|
// 后续还需要扩展更多指令类型。
|
|
|
|
|
// enum class Opcode { Add, Sub, Mul, Alloca, Load, Store, Ret };
|
|
|
|
|
enum class Opcode { Add, Sub, Mul, Div, Mod, Alloca, Load, Store, Ret };
|
|
|
|
|
enum class Opcode { Add, Sub, Mul, Div, Mod, Neg, Alloca, Load, Store, Ret };
|
|
|
|
|
|
|
|
|
|
// User 是所有“会使用其他 Value 作为输入”的 IR 对象的抽象基类。
|
|
|
|
|
// 当前实现中只有 Instruction 继承自 User。
|
|
|
|
|
@ -197,7 +197,14 @@ class BinaryInst : public Instruction {
|
|
|
|
|
BinaryInst(Opcode op, std::shared_ptr<Type> ty, Value* lhs, Value* rhs,
|
|
|
|
|
std::string name);
|
|
|
|
|
Value* GetLhs() const;
|
|
|
|
|
Value* GetRhs() const;
|
|
|
|
|
Value* GetRhs() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class UnaryInst : public Instruction {
|
|
|
|
|
public:
|
|
|
|
|
UnaryInst(Opcode op, std::shared_ptr<Type> ty, Value* operand,
|
|
|
|
|
std::string name);
|
|
|
|
|
Value* GetUnaryOperand() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ReturnInst : public Instruction {
|
|
|
|
|
@ -303,6 +310,7 @@ class IRBuilder {
|
|
|
|
|
BinaryInst* CreateAdd(Value* lhs, Value* rhs, const std::string& name);
|
|
|
|
|
BinaryInst* CreateSub(Value* lhs, Value* rhs, const std::string& name);
|
|
|
|
|
BinaryInst* CreateMul(Value* lhs, Value* rhs, const std::string& name);
|
|
|
|
|
UnaryInst* CreateNeg(Value* operand, const std::string& name);
|
|
|
|
|
AllocaInst* CreateAllocaI32(const std::string& name);
|
|
|
|
|
LoadInst* CreateLoad(Value* ptr, const std::string& name);
|
|
|
|
|
StoreInst* CreateStore(Value* val, Value* ptr);
|
|
|
|
|
|