refactor(dev): 统一 IR/MIR 接口命名风格
This commit is contained in:
@@ -40,7 +40,7 @@ void IRGenImpl::GenVarDecl(SysYParser::VarDeclContext& decl) {
|
||||
if (storage_map_.find(&decl) != storage_map_.end()) {
|
||||
throw std::runtime_error(FormatError("irgen", "声明重复生成存储槽位"));
|
||||
}
|
||||
auto* slot = builder_.CreateAllocaI32(module_.context().NextTemp());
|
||||
auto* slot = builder_.CreateAllocaI32(module_.GetContext().NextTemp());
|
||||
storage_map_[&decl] = slot;
|
||||
|
||||
ir::Value* init = nullptr;
|
||||
|
||||
@@ -23,7 +23,7 @@ ir::Value* IRGenImpl::GenAddExpr(SysYParser::AddExpContext& add) {
|
||||
ir::Value* acc = GenPrimary(*terms[0]);
|
||||
for (size_t i = 1; i < terms.size(); ++i) {
|
||||
ir::Value* rhs = GenPrimary(*terms[i]);
|
||||
std::string name = module_.context().NextTemp();
|
||||
std::string name = module_.GetContext().NextTemp();
|
||||
acc = builder_.CreateBinary(ir::Opcode::Add, acc, rhs, name);
|
||||
}
|
||||
return acc;
|
||||
@@ -46,7 +46,7 @@ ir::Value* IRGenImpl::GenPrimary(SysYParser::PrimaryContext& primary) {
|
||||
FormatError("irgen",
|
||||
"变量声明缺少存储槽位: " + primary.Ident()->getText()));
|
||||
}
|
||||
return builder_.CreateLoad(it->second, module_.context().NextTemp());
|
||||
return builder_.CreateLoad(it->second, module_.GetContext().NextTemp());
|
||||
}
|
||||
if (primary.exp()) {
|
||||
return GenExpr(*primary.exp());
|
||||
|
||||
@@ -10,11 +10,11 @@ namespace {
|
||||
|
||||
void VerifyFunctionStructure(const ir::Function& func) {
|
||||
// 当前 IRGen 仍是单入口、顺序生成;这里在生成结束后补一层块终结校验。
|
||||
for (const auto& bb : func.blocks()) {
|
||||
for (const auto& bb : func.GetBlocks()) {
|
||||
if (!bb || !bb->HasTerminator()) {
|
||||
throw std::runtime_error(
|
||||
FormatError("irgen", "基本块未正确终结: " +
|
||||
(bb ? bb->name() : std::string("<null>"))));
|
||||
(bb ? bb->GetName() : std::string("<null>"))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ IRGenImpl::IRGenImpl(ir::Module& module, const SemanticContext& sema)
|
||||
: module_(module),
|
||||
sema_(sema),
|
||||
func_(nullptr),
|
||||
builder_(module.context(), nullptr) {}
|
||||
builder_(module.GetContext(), nullptr) {}
|
||||
|
||||
void IRGenImpl::Gen(SysYParser::CompUnitContext& cu) {
|
||||
if (!cu.funcDef()) {
|
||||
@@ -43,8 +43,8 @@ void IRGenImpl::GenFuncDef(SysYParser::FuncDefContext& func) {
|
||||
}
|
||||
|
||||
func_ = module_.CreateFunction(
|
||||
func.Ident()->getText(), module_.context().Int32());
|
||||
builder_.SetInsertPoint(func_->entry());
|
||||
func.Ident()->getText(), module_.GetContext().Int32());
|
||||
builder_.SetInsertPoint(func_->GetEntry());
|
||||
storage_map_.clear();
|
||||
|
||||
GenBlock(*func.block());
|
||||
|
||||
Reference in New Issue
Block a user