2025-07-20 20:45:10 +08:00
|
|
|
|
using SVM.Core;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SVM.Assembler.Core
|
|
|
|
|
|
{
|
|
|
|
|
|
public class LinkingContext
|
|
|
|
|
|
{
|
2025-07-25 00:06:07 +10:00
|
|
|
|
public ISADefinition Definition;
|
2025-07-20 20:45:10 +08:00
|
|
|
|
public Dictionary<string, uint> DataOffsets = new Dictionary<string, uint>();
|
|
|
|
|
|
public ManagedSVMProgram Program;
|
|
|
|
|
|
public Dictionary<string, int> label = new Dictionary<string, int>();
|
|
|
|
|
|
public IntermediateObject IntermediateObject;
|
2025-07-25 00:06:07 +10:00
|
|
|
|
public LinkingContext(ManagedSVMProgram program, IntermediateObject intermediateObject, ISADefinition definition)
|
2025-07-20 20:45:10 +08:00
|
|
|
|
{
|
|
|
|
|
|
Program = program;
|
|
|
|
|
|
IntermediateObject = intermediateObject;
|
2025-07-25 00:06:07 +10:00
|
|
|
|
Definition = definition;
|
2025-07-20 20:45:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|