Skip to content

[codegen] extract global variable generation from llvm-generator#755

Merged
cs01 merged 2 commits intomainfrom
decompose/extract-global-vars
Apr 27, 2026
Merged

[codegen] extract global variable generation from llvm-generator#755
cs01 merged 2 commits intomainfrom
decompose/extract-global-vars

Conversation

@cs01
Copy link
Copy Markdown
Owner

@cs01 cs01 commented Apr 27, 2026

Before

llvm-generator.ts contained ~1300 lines of global variable classification and generation logic, contributing to its 4893-line god file status.

After

No user-facing change. Internal refactor only. Global variable logic now lives in src/codegen/infrastructure/global-variable-generator.ts (1412 lines), reducing llvm-generator.ts to 3623 lines.

Description

Extracts 9 methods from LLVMGenerator into free functions taking a GlobalVarContext interface:

  • prePopulateFromSema — seeds symbol table from sema results
  • generateGlobalVariableDeclarations — main entry point for global var IR
  • tryHandleGlobalCallReturn, tryHandleGlobalJSONParse, tryHandleGlobalDeclaredType, tryHandleGlobalExpressionType, classifyGlobalCatchAll, tryGetConstLiteralValue, handleUninitializedGlobalVar — internal helpers

Uses flat interface methods (no chained calls like ctx.symbolTable.define()) for native compiler compatibility.

Part of #727.

@cs01 cs01 merged commit 3a1d0f3 into main Apr 27, 2026
9 checks passed
@cs01 cs01 deleted the decompose/extract-global-vars branch April 27, 2026 04:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant