001package gudusoft.gsqlparser.ir.builder; 002 003import gudusoft.gsqlparser.TStatementList; 004import gudusoft.gsqlparser.analyzer.v2.AnalyzerV2Config; 005import gudusoft.gsqlparser.analyzer.v2.IRProgram; 006import gudusoft.gsqlparser.ir.bound.BoundProgram; 007 008/** 009 * Orchestrates the three-phase IR translation pipeline. 010 * <p> 011 * Phase 1: AST → Bound IR (name resolution, scope binding) 012 * Phase 2: Bound IR → Logical IR (relational + procedural plans) 013 * Phase 3: Logical IR → Flow IR (CFG/DFG/CallGraph/Provenance) 014 * <p> 015 * In Phase A, only Phase 1 is active. 016 */ 017public class IRTranslator { 018 019 private final AnalyzerV2Config config; 020 private final IBoundIRBuilder boundBuilder; 021 private final ILogicalIRBuilder logicalBuilder; 022 private final IFlowPlanner flowPlanner; 023 024 /** 025 * Full pipeline constructor (all three phases). 026 */ 027 public IRTranslator(AnalyzerV2Config config, 028 IBoundIRBuilder boundBuilder, 029 ILogicalIRBuilder logicalBuilder, 030 IFlowPlanner flowPlanner) { 031 this.config = config; 032 this.boundBuilder = boundBuilder; 033 this.logicalBuilder = logicalBuilder; 034 this.flowPlanner = flowPlanner; 035 } 036 037 /** 038 * Phase A constructor (bound IR only). 039 */ 040 public IRTranslator(AnalyzerV2Config config, IBoundIRBuilder boundBuilder) { 041 this(config, boundBuilder, null, null); 042 } 043 044 /** 045 * Translates AST statements through all available IR phases. 046 */ 047 public IRProgram translate(TStatementList stmts) { 048 // Phase 1: Binding 049 BoundProgram bound = boundBuilder.build(stmts, config); 050 051 // Phase 2: Logical IR (when available) 052 // LogicalProgram logical = null; 053 // if (logicalBuilder != null) { 054 // logical = logicalBuilder.build(bound, config); 055 // } 056 057 // Phase 3: Flow IR (when available) 058 // FlowBundle flow = null; 059 // if (flowPlanner != null && logical != null) { 060 // flow = flowPlanner.build(logical, config); 061 // } 062 063 return new IRProgram(bound); 064 } 065}