Skip to content

Commit 3aaa66a

Browse files
committed
Feature(compiler): DoStatement - initial support
1 parent b7755e0 commit 3aaa66a

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/backend/llvm/index.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,35 @@ export function passForStatement(parent: ts.ForStatement, ctx: Context, builder:
107107
builder.setInsertionPoint(next);
108108
}
109109

110+
export function passDoStatement(parent: ts.DoStatement, ctx: Context, builder: llvm.IRBuilder) {
111+
const conditionBlock = llvm.BasicBlock.create(ctx.llvmContext, "for.condition");
112+
ctx.scope.currentFunction.addBasicBlock(conditionBlock);
113+
114+
const positiveBlock = llvm.BasicBlock.create(ctx.llvmContext, "for.true");
115+
ctx.scope.currentFunction.addBasicBlock(positiveBlock);
116+
117+
const next = llvm.BasicBlock.create(ctx.llvmContext, "for.end");
118+
ctx.scope.currentFunction.addBasicBlock(next);
119+
120+
builder.createBr(positiveBlock);
121+
builder.setInsertionPoint(positiveBlock);
122+
123+
passStatement(<any>parent.statement, ctx, builder);
124+
125+
builder.createBr(conditionBlock);
126+
builder.setInsertionPoint(conditionBlock);
127+
128+
emitCondition(
129+
parent.expression,
130+
ctx,
131+
builder,
132+
positiveBlock,
133+
next
134+
);
135+
136+
builder.setInsertionPoint(next);
137+
}
138+
110139
export function emitCondition(
111140
condition: ts.Expression,
112141
ctx: Context,
@@ -527,6 +556,9 @@ export function passStatement(stmt: ts.Statement, ctx: Context, builder: llvm.IR
527556
case ts.SyntaxKind.ForStatement:
528557
passForStatement(<any>stmt, ctx, builder);
529558
break;
559+
case ts.SyntaxKind.DoStatement:
560+
passDoStatement(<any>stmt, ctx, builder);
561+
break;
530562
case ts.SyntaxKind.BinaryExpression:
531563
buildFromBinaryExpression(<any>stmt, ctx, builder);
532564
break;

0 commit comments

Comments
 (0)