style(ir): 纠正代码位置

This commit is contained in:
jing
2026-03-11 22:08:27 +08:00
parent 62dde8d7ab
commit fab6983d40
17 changed files with 193 additions and 88 deletions

View File

@@ -9,6 +9,7 @@
#include "SysYParser.h"
#include "ir/IR.h"
#include "sem/Sema.h"
namespace antlr4 {
namespace tree {
@@ -25,7 +26,7 @@ class Value;
class IRGenImpl {
public:
explicit IRGenImpl(ir::Module& module);
IRGenImpl(ir::Module& module, const SemanticContext& sema);
void Gen(SysYParser::CompUnitContext& cu);
@@ -43,10 +44,12 @@ class IRGenImpl {
ir::Value* GenPrimary(SysYParser::PrimaryContext& primary);
ir::Module& module_;
const SemanticContext& sema_;
ir::Function* func_;
ir::IRBuilder builder_;
// 当前只维护函数级局部变量表;若后续引入嵌套块作用域,需要改成作用域栈
std::unordered_map<std::string, ir::Value*> locals_;
// 名称绑定由 Sema 负责IRGen 只维护“声明 -> 存储槽位”的代码生成状态
std::unordered_map<SysYParser::VarDeclContext*, ir::Value*> storage_map_;
};
std::unique_ptr<ir::Module> GenerateIR(antlr4::tree::ParseTree* tree);
std::unique_ptr<ir::Module> GenerateIR(SysYParser::CompUnitContext& tree,
const SemanticContext& sema);