@ -0,0 +1,21 @@
### 人员 1:基础表达式与赋值支持(lc)
- 任务 1.1:支持更多二元运算符(Sub, Mul, Div, Mod)
- 任务 1.2:支持一元运算符(正负号)
- 任务 1.3:支持赋值表达式
- 任务 1.4:支持逗号分隔的多个变量声明
### 人员 2:控制流支持
- 任务 2.1:支持 if-else 条件语句
- 任务 2.2:支持 while 循环语句
- 任务 2.3:支持 break/continue 语句
- 任务 2.4:支持比较和逻辑表达式
### 人员 3:函数与全局变量支持
- 任务 3.1:支持全局变量声明与初始化
- 任务 3.2:支持函数参数处理
- 任务 3.3:支持函数调用生成
- 任务 3.4:支持 const 常量声明
@ -152,7 +152,8 @@ class ConstantInt : public ConstantValue {
};
// 后续还需要扩展更多指令类型。
enum class Opcode { Add, Sub, Mul, Alloca, Load, Store, Ret };
// enum class Opcode { Add, Sub, Mul, Alloca, Load, Store, Ret };
enum class Opcode { Add, Sub, Mul, Div, Mod, Alloca, Load, Store, Ret };
// User 是所有“会使用其他 Value 作为输入”的 IR 对象的抽象基类。
// 当前实现中只有 Instruction 继承自 User。
@ -86,4 +86,12 @@ ReturnInst* IRBuilder::CreateRet(Value* v) {
return insert_block_->Append<ReturnInst>(Type::GetVoidType(), v);
}
BinaryInst* IRBuilder::CreateSub(Value* lhs, Value* rhs, const std::string& name) {
return CreateBinary(Opcode::Sub, lhs, rhs, name);
BinaryInst* IRBuilder::CreateMul(Value* lhs, Value* rhs, const std::string& name) {
return CreateBinary(Opcode::Mul, lhs, rhs, name);
} // namespace ir