-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableDeclaration.cs
More file actions
29 lines (28 loc) · 1.04 KB
/
VariableDeclaration.cs
File metadata and controls
29 lines (28 loc) · 1.04 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
namespace MiniSharpCompiler
{
using LLVMSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
public partial class LLVMIRGenerationVisitor
{
/// <summary>
/// For every declaration, lookup the alloca that was allocated in the
/// first basic block, and add it to the current symbol table.
///
/// For every variable initializer, build a store to its expression,
/// and then push it on the value stack for equals binary expr to pick
/// it up.
/// </summary>
public override void VisitVariableDeclaration(VariableDeclarationSyntax node)
{
var variables = node.Variables;
foreach (VariableDeclaratorSyntax variable in variables)
{
LLVMValueRef alloca = this.symbolTable[variable];
if (variable.Initializer != null)
{
this.Push(node.Type, LLVM.BuildStore(this.builder, this.Pop(variable.Initializer.Value), alloca));
}
}
}
}
}