|
|
|
|
@ -181,7 +181,7 @@ class ConstantFloat : public ConstantValue {
|
|
|
|
|
|
|
|
|
|
// 后续还需要扩展更多指令类型。
|
|
|
|
|
// enum class Opcode { Add, Sub, Mul, Alloca, Load, Store, Ret };
|
|
|
|
|
enum class Opcode { Add, Sub, Mul, Div, Mod, Neg, Alloca, Load, Store, Ret, Cmp, Zext, Br, CondBr };
|
|
|
|
|
enum class Opcode { Add, Sub, Mul, Div, Mod, Neg, Alloca, Load, Store, Ret, Cmp, Zext, Br, CondBr, Call };
|
|
|
|
|
|
|
|
|
|
enum class CmpOp { Eq, Ne, Lt, Gt, Le, Ge };
|
|
|
|
|
|
|
|
|
|
@ -298,6 +298,17 @@ class CondBranchInst : public Instruction {
|
|
|
|
|
BasicBlock* GetFalseBlock() const;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class CallInst : public Instruction {
|
|
|
|
|
public:
|
|
|
|
|
CallInst(Function* func, std::vector<Value*> args, std::string name = "");
|
|
|
|
|
Function* GetFunc() const;
|
|
|
|
|
const std::vector<Value*>& GetArgs() const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Function* func_;
|
|
|
|
|
std::vector<Value*> args_;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// BasicBlock 已纳入 Value 体系,便于后续向更完整 IR 类图靠拢。
|
|
|
|
|
// 当前其类型仍使用 void 作为占位,后续可替换为专门的 label type。
|
|
|
|
|
class BasicBlock : public Value {
|
|
|
|
|
@ -395,6 +406,7 @@ class IRBuilder {
|
|
|
|
|
ZextInst* CreateZext(Value* val, const std::string& name);
|
|
|
|
|
BranchInst* CreateBr(BasicBlock* dest);
|
|
|
|
|
CondBranchInst* CreateCondBr(Value* cond, BasicBlock* true_bb, BasicBlock* false_bb);
|
|
|
|
|
CallInst* CreateCall(Function* func, std::vector<Value*> args, const std::string& name);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Context& ctx_;
|
|
|
|
|
|