diff --git a/src/SysYIRGenerator.cpp b/src/SysYIRGenerator.cpp index 09b1214..9f0f012 100644 --- a/src/SysYIRGenerator.cpp +++ b/src/SysYIRGenerator.cpp @@ -408,7 +408,7 @@ std::any SysYIRGenerator::visitFuncDef(SysYParser::FuncDefContext *ctx){ // 在处理函数体之前,创建一个新的基本块作为函数体的实际入口 // 这样 entryBB 就可以在完成初始化后跳转到这里 - BasicBlock* funcBodyEntry = function->addBasicBlock("funcBodyEntry"); + BasicBlock* funcBodyEntry = function->addBasicBlock("funcBodyEntry_" + name); // 从 entryBB 无条件跳转到 funcBodyEntry builder.createUncondBrInst(funcBodyEntry, {}); diff --git a/src/SysYIRPrinter.cpp b/src/SysYIRPrinter.cpp index 952d500..689fd50 100644 --- a/src/SysYIRPrinter.cpp +++ b/src/SysYIRPrinter.cpp @@ -150,9 +150,7 @@ void SysYPrinter::printFunction(Function *function) { for (const auto &blockIter : function->getBasicBlocks()) { // Basic block label BasicBlock* blockPtr = blockIter.get(); - if (blockPtr == function->getEntryBlock()) { - std::cout << "entry:" << std::endl; - } else if (!blockPtr->getName().empty()) { + if (!blockPtr->getName().empty()) { std::cout << blockPtr->getName() << ":" << std::endl; } diff --git a/src/include/IR.h b/src/include/IR.h index 1e64582..99bf003 100644 --- a/src/include/IR.h +++ b/src/include/IR.h @@ -1248,7 +1248,7 @@ class Function : public Value { friend class Module; protected: Function(Module *parent, Type *type, const std::string &name) : Value(type, name), parent(parent) { - blocks.emplace_back(new BasicBlock(this)); + blocks.emplace_back(new BasicBlock(this, "entry_" + name)); ///< 创建一个入口基本块 } public: