-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhileStatement.cs
More file actions
38 lines (31 loc) · 1.22 KB
/
WhileStatement.cs
File metadata and controls
38 lines (31 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace MiniSharpCompiler
{
using LLVMSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
public partial class LLVMIRGenerationVisitor
{
/// <summary>
/// 8.8.1
/// </summary>
public override void VisitWhileStatement(WhileStatementSyntax node)
{
LLVMBasicBlockRef condBB = LLVM.AppendBasicBlock(this.function, "while.cond");
LLVMBasicBlockRef bodyBB = LLVM.AppendBasicBlock(this.function, "while.body");
LLVMBasicBlockRef endBB = LLVM.AppendBasicBlock(this.function, "while.end");
this.controlFlowStack.Push(new ControlFlowTarget(condBB, endBB));
LLVM.BuildBr(this.builder, condBB);
// condition
LLVM.PositionBuilderAtEnd(this.builder, condBB);
LLVM.BuildCondBr(this.builder, this.Pop(node.Condition), bodyBB, endBB);
// body
LLVM.PositionBuilderAtEnd(this.builder, bodyBB);
this.EnterScope();
this.Visit(node.Statement);
this.LeaveScope();
LLVM.BuildBr(this.builder, condBB);
// end
LLVM.PositionBuilderAtEnd(this.builder, endBB);
this.controlFlowStack.Pop();
}
}
}