diff options
| author | _ov4 <ov4@ov4.org> | 2026-10-16 10:09:47 +0000 |
|---|---|---|
| committer | _ov4 <ov4@ov4.org> | 2026-10-16 10:09:47 +0000 |
| commit | e2c65706e61be09ddb7eeb28cd1957acd4317bcf (patch) | |
| tree | 15447a03d67d395a722c5be3f0b05bc9f197197a /lib/CodeGen/FunctionGen.cc | |
| parent | 45c9d37eb27d204a6202b33cb37e890af0171357 (diff) | |
feat(constants): implement literal constants with lexical scope
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Diffstat (limited to 'lib/CodeGen/FunctionGen.cc')
| -rw-r--r-- | lib/CodeGen/FunctionGen.cc | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/CodeGen/FunctionGen.cc b/lib/CodeGen/FunctionGen.cc index ca8fa45..957a1f5 100644 --- a/lib/CodeGen/FunctionGen.cc +++ b/lib/CodeGen/FunctionGen.cc @@ -178,7 +178,7 @@ Function *FunctionGen::emitPrototype(PrototypeAST *Proto) { } Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST, - const std::function<void(StmtAST*)> &StmtEmitter) { + const std::function<void(StmtAST*)> &StmtEmitter, unsigned ScopeID) { PrototypeAST *Proto = FuncAST->getProto(); Function *TheFunction = emitPrototype(Proto); @@ -194,8 +194,15 @@ Function *FunctionGen::emitFunctionDef(FunctionDefAST *FuncAST, std::map<std::string, SymbolInfo> OldSymbols = Symbols; Symbols.clear(); + for (const auto &[Name, Info] : OldSymbols) { + if (Info.ConstantValue && Info.ScopeID == 0) Symbols.emplace(Name, Info); + } createArgumentAllocas(TheFunction, Proto->getParams()); + for (const auto &P : Proto->getParams()) { + auto It = Symbols.find(P.Name); + if (It != Symbols.end()) It->second.ScopeID = ScopeID; + } for (const auto &Stmt : FuncAST->getBody()) { StmtEmitter(Stmt.get()); |
