mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 12:59:54 +00:00
Finished basic Assembler and Linker framework.
This commit is contained in:
38
src/SVM.Assembler.Core/LinkingContext.cs
Normal file
38
src/SVM.Assembler.Core/LinkingContext.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using SVM.Core;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SVM.Assembler.Core
|
||||
{
|
||||
public class LinkingContext
|
||||
{
|
||||
public Dictionary<string, uint> DataOffsets = new Dictionary<string, uint>();
|
||||
public ManagedSVMProgram Program;
|
||||
public Dictionary<string, int> label = new Dictionary<string, int>();
|
||||
public IntermediateObject IntermediateObject;
|
||||
public LinkingContext(ManagedSVMProgram program, IntermediateObject intermediateObject)
|
||||
{
|
||||
Program = program;
|
||||
IntermediateObject = intermediateObject;
|
||||
}
|
||||
public bool TryFindLabel(string label, out int offset)
|
||||
{
|
||||
label = label + ":";
|
||||
if (this.label.TryGetValue(label, out offset))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
for (int i = 0; i < IntermediateObject.instructions.Count; i++)
|
||||
{
|
||||
IntermediateInstruction? item = IntermediateObject.instructions[i];
|
||||
if (item.Label != null)
|
||||
if (item.Label.Content == label)
|
||||
{
|
||||
this.label.Add(label, i);
|
||||
offset = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user