mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-10 20:39:54 +00:00
Added Register Naming support in ISADefinition.
This commit is contained in:
@@ -239,6 +239,24 @@ LabelConstant InternalLbl
|
||||
public Dictionary<string, string> data = new Dictionary<string, string>();
|
||||
public Dictionary<string, string> consts = new Dictionary<string, string>();
|
||||
public List<IntermediateInstruction> instructions = new List<IntermediateInstruction>();
|
||||
public bool TryGetConst(string str, out string value)
|
||||
{
|
||||
return consts.TryGetValue(str, out value);
|
||||
}
|
||||
public bool TryGetLabelPC(string label, out int PC)
|
||||
{
|
||||
for (int i = 0; i < instructions.Count; i++)
|
||||
{
|
||||
IntermediateInstruction? item = instructions[i];
|
||||
if (item.Label != null && item.Label.Content == label)
|
||||
{
|
||||
PC = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
PC = -1;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
[Serializable]
|
||||
public class IntermediateInstruction
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace SVM.Assembler.Core
|
||||
[Serializable]
|
||||
public class ISADefinition
|
||||
{
|
||||
public Dictionary<string, byte> RegisterNames = new Dictionary<string, byte>();
|
||||
public Dictionary<string, Dictionary<string, string>> Enums = new Dictionary<string, Dictionary<string, string>>();
|
||||
public Dictionary<PrimaryInstruction, InstructionDefinition> InstructionDefinitions = new Dictionary<PrimaryInstruction, InstructionDefinition>();
|
||||
[NonSerialized]
|
||||
@@ -240,6 +241,36 @@ namespace SVM.Assembler.Core
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Registers":
|
||||
{
|
||||
foreach (XmlNode enumNode in item.ChildNodes)
|
||||
{
|
||||
if (enumNode.Name == "Item")
|
||||
{
|
||||
|
||||
var keyAttr = enumNode.Attributes.GetNamedItem("Key");
|
||||
var valueAttr = enumNode.Attributes.GetNamedItem("Value");
|
||||
if (keyAttr == null || valueAttr == null)
|
||||
{
|
||||
definition = null;
|
||||
return false;
|
||||
}
|
||||
if (!byte.TryParse(valueAttr.InnerText, out var RegID))
|
||||
{
|
||||
definition = null;
|
||||
return false;
|
||||
}
|
||||
isaDefinition.RegisterNames.Add(keyAttr.InnerText, RegID);
|
||||
}
|
||||
else
|
||||
{
|
||||
definition = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Definitions":
|
||||
if (ParseDefinitions(item, ref isaDefinition) == false)
|
||||
{
|
||||
|
||||
@@ -37,10 +37,44 @@ namespace SVM.Assembler.Core
|
||||
}
|
||||
return operationResult;
|
||||
}
|
||||
public bool TryParseRegister(string input, IntermediateObject obj, LinkingContext context, out byte registerID)
|
||||
{
|
||||
if (input.StartsWith("$"))
|
||||
{
|
||||
|
||||
}
|
||||
registerID = byte.MaxValue;
|
||||
return false;
|
||||
}
|
||||
public static OperationResult<SVMInstruction> translate(InstructionDefinition def, LinkingContext context, IntermediateInstruction iinstruction)
|
||||
{
|
||||
OperationResult<SVMInstruction> result = new OperationResult<SVMInstruction>();
|
||||
for (int i = 0; i < iinstruction.Parameters.Count; i++)
|
||||
{
|
||||
var para = iinstruction.Parameters[i];
|
||||
var paraDef = def.ParameterPattern[i];
|
||||
string converter = paraDef.ExpectdValue.Converter;
|
||||
if (converter.StartsWith("InternalEnum:"))
|
||||
{
|
||||
var enumName = converter["InternalEnum:".Length..];
|
||||
switch (enumName)
|
||||
{
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (converter)
|
||||
{
|
||||
case "Register":
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public unsafe static OperationResult<ManagedSVMProgram?> Finialize(ISADefinition definition, IntermediateObject Obj)
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
<Item Key="A" Value="0"/>
|
||||
</Enum>
|
||||
</Enums>
|
||||
<Registers>
|
||||
<Item Key="pc" Value="1"/>
|
||||
<Item Key="sp" Value="2"/>
|
||||
</Registers>
|
||||
<Definitions>
|
||||
<InstructionDefinition PrimaryInstruction="BMath">
|
||||
<Aliases>
|
||||
|
||||
Reference in New Issue
Block a user