@@ -39,27 +39,37 @@ export function passIfStatement(parent: ts.IfStatement, ctx: Context, builder: l
3939 const positiveBlock = llvm . BasicBlock . create ( ctx . llvmContext , "if.true" ) ;
4040 ctx . scope . currentFunction . addBasicBlock ( positiveBlock ) ;
4141
42- const negativeBlock = llvm . BasicBlock . create ( ctx . llvmContext , "if.false" ) ;
43- ctx . scope . currentFunction . addBasicBlock ( negativeBlock ) ;
44-
4542 const next = llvm . BasicBlock . create ( ctx . llvmContext , "if.end" ) ;
4643 ctx . scope . currentFunction . addBasicBlock ( next ) ;
4744
48- emitCondition (
49- parent . expression ,
50- ctx ,
51- builder ,
52- positiveBlock ,
53- negativeBlock
54- ) ;
45+ if ( parent . elseStatement ) {
46+ const negativeBlock = llvm . BasicBlock . create ( ctx . llvmContext , "if.false" ) ;
47+ ctx . scope . currentFunction . addBasicBlock ( negativeBlock ) ;
5548
56- builder . setInsertionPoint ( positiveBlock ) ;
57- passNode ( parent . thenStatement , ctx , builder ) ;
49+ emitCondition (
50+ parent . expression ,
51+ ctx ,
52+ builder ,
53+ positiveBlock ,
54+ negativeBlock
55+ ) ;
5856
59- builder . createBr ( next ) ;
57+ builder . setInsertionPoint ( negativeBlock ) ;
58+ passNode ( parent . elseStatement , ctx , builder ) ;
6059
61- builder . setInsertionPoint ( negativeBlock ) ;
62- passNode ( parent . elseStatement , ctx , builder ) ;
60+ builder . createBr ( next ) ;
61+ } else {
62+ emitCondition (
63+ parent . expression ,
64+ ctx ,
65+ builder ,
66+ positiveBlock ,
67+ next
68+ ) ;
69+ }
70+
71+ builder . setInsertionPoint ( positiveBlock ) ;
72+ passNode ( parent . thenStatement , ctx , builder ) ;
6373
6474 builder . createBr ( next ) ;
6575
0 commit comments