Title: ProXPL Compiler Backend Fixes Version: 1.0 Date: 2025-12-11 Author: ProgrammerKR
Version 1.3.3 includes critical stability and correctness fixes across the ProXPL compiler's Intermediate Representation (IR) generation, optimization passes, and the LLVM backend. These fixes address malformed control-flow graphs, memory bounds errors, and strictly enforce LLVM IR validator constraints for PHI nodes.
addEdge()Logic: The edge creation logic has been re-implemented to correctly handle bidirectional links (successors and predecessors) without aborting early on overlapping edge inserts. This ensures accurate graph traversal for dominator and SSA passes.- Conditional Branches (
computeCFGLinks):IR_OP_JUMP_IFparsing was updated to explicitly bind both theThenandElsesuccessor branches to the CFG, fixing lost control-flow paths.
- Function Calls (
EXPR_CALL): Added complete generation logic to recursively evaluate callee and argument expressions, finally emitting validIR_OP_CALLinstructions. - Terminator Strictness: Rewrote
STMT_IFandSTMT_WHILEjump logic to construct single 3-operand conditional terminators (IR_OP_JUMP_IF(Cond, Then, Else)) instead of relying on subsequent redundant unconditional jumps, which violated LLVM basic block rules.
- Heap Overflow Prevention: The memory-to-register promotion pass (
promoteMemoryToRegisters) was upgraded to dynamically resize (realloc) tracking buffers for variable allocations instead of hitting a hard 1024-slot limit, preventing buffer overflows on large functions. - Zero-Initialization: The
isConsttracking array in the constant folding pass is now safely zero-initialized usingmemsetduring reallocation. - Phi Node Operands: When variables lack a reaching definition from a predecessor (
currentVersion == -1), the optimizer now intentionally pushes a-1placeholder into the Phi operand list instead of dropping the operand entirely, preserving the structural integrity required by LLVM.
- Dummy NIL Values: The LLVM emitter's Pass 3 (
addIncoming) has been fortified to intercept-1(uninitialized) SSA references and inject a dummyNILLLVM constant (0x7ffc000000000001). This ensures that every LLVMPHINodereceives exactly one incoming value per predecessor, completely resolving LLVM IR Verifier rejections.
The architectural foundation has been reviewed for future performance milestones, specifically targeting compilation speed:
- Translating string-based token operators to native Enums (
ast.h). - Adopting O(1) hash maps for variable symbol lookups.
- Replacing iterative dataflow algorithms with Lengauer-Tarjan dominator trees.