-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVariableDeclarationVisitor.cs
More file actions
42 lines (35 loc) · 1.3 KB
/
VariableDeclarationVisitor.cs
File metadata and controls
42 lines (35 loc) · 1.3 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
39
40
41
42
namespace MiniSharpCompiler
{
using System;
using System.Collections.Generic;
using LLVMSharp;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
internal sealed class VariableDeclarationVisitor : CSharpSyntaxWalker
{
private readonly SemanticModel model;
private readonly LLVMBuilderRef builder;
public VariableDeclarationVisitor(SemanticModel model, LLVMBuilderRef builder)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
this.model = model;
this.builder = builder;
this.Variables = new Dictionary<VariableDeclaratorSyntax, LLVMValueRef>();
}
public Dictionary<VariableDeclaratorSyntax, LLVMValueRef> Variables;
public override void VisitVariableDeclaration(VariableDeclarationSyntax node)
{
var llvmType = this.model.GetTypeInfo(node.Type).LLVMTypeRef();
var variables = node.Variables;
foreach (var variable in variables)
{
var value = LLVM.BuildAlloca(this.builder, llvmType, variable.Identifier.Text);
this.Variables.Add(variable, value);
}
}
}
}