From 39e50838bd12057d9305575f50c63990984df01a Mon Sep 17 00:00:00 2001 From: _ov4 Date: Sat, 17 Oct 2026 09:15:18 +0000 Subject: feat(codegen): GLOBAL variables as LLVM globals Co-Authored-By: Claude Opus 5.5 --- lib/CodeGen/CodeGen.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/CodeGen/CodeGen.cc') diff --git a/lib/CodeGen/CodeGen.cc b/lib/CodeGen/CodeGen.cc index e7116dd..6aa1558 100644 --- a/lib/CodeGen/CodeGen.cc +++ b/lib/CodeGen/CodeGen.cc @@ -166,8 +166,9 @@ void CodeGen::selectUnit(size_t Unit) { void CodeGen::importSymbols() { Symbols.clear(); for (size_t I = 0; I < Exports.size(); ++I) { - if (I != CurrentUnit && isVisible(I)) - Symbols.insert(Exports[I].begin(), Exports[I].end()); + if (!isVisible(I)) continue; + for (const auto &[Name, Info] : Exports[I]) + if (I != CurrentUnit || Info.IsGlobal) Symbols.emplace(Name, Info); } } @@ -286,6 +287,13 @@ void CodeGen::compile(const std::vector &Sources) { } Exports[I] = Symbols; } + for (int Phase = 0; Phase < 2; ++Phase) { + for (size_t I = 0; I < Sources.size(); ++I) { + selectUnit(I); + importSymbols(); + runGlobalPrePass(Sources[I], Phase); + } + } for (size_t I = 0; I < Sources.size(); ++I) { selectUnit(I); importSymbols(); -- cgit v1.3.1-4-g156e