mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 04:49:53 +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> data = new Dictionary<string, string>();
|
||||||
public Dictionary<string, string> consts = new Dictionary<string, string>();
|
public Dictionary<string, string> consts = new Dictionary<string, string>();
|
||||||
public List<IntermediateInstruction> instructions = new List<IntermediateInstruction>();
|
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]
|
[Serializable]
|
||||||
public class IntermediateInstruction
|
public class IntermediateInstruction
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ namespace SVM.Assembler.Core
|
|||||||
[Serializable]
|
[Serializable]
|
||||||
public class ISADefinition
|
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<string, Dictionary<string, string>> Enums = new Dictionary<string, Dictionary<string, string>>();
|
||||||
public Dictionary<PrimaryInstruction, InstructionDefinition> InstructionDefinitions = new Dictionary<PrimaryInstruction, InstructionDefinition>();
|
public Dictionary<PrimaryInstruction, InstructionDefinition> InstructionDefinitions = new Dictionary<PrimaryInstruction, InstructionDefinition>();
|
||||||
[NonSerialized]
|
[NonSerialized]
|
||||||
@@ -240,6 +241,36 @@ namespace SVM.Assembler.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
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":
|
case "Definitions":
|
||||||
if (ParseDefinitions(item, ref isaDefinition) == false)
|
if (ParseDefinitions(item, ref isaDefinition) == false)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -37,10 +37,44 @@ namespace SVM.Assembler.Core
|
|||||||
}
|
}
|
||||||
return operationResult;
|
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)
|
public static OperationResult<SVMInstruction> translate(InstructionDefinition def, LinkingContext context, IntermediateInstruction iinstruction)
|
||||||
{
|
{
|
||||||
OperationResult<SVMInstruction> result = new OperationResult<SVMInstruction>();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
public unsafe static OperationResult<ManagedSVMProgram?> Finialize(ISADefinition definition, IntermediateObject Obj)
|
public unsafe static OperationResult<ManagedSVMProgram?> Finialize(ISADefinition definition, IntermediateObject Obj)
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
<Item Key="A" Value="0"/>
|
<Item Key="A" Value="0"/>
|
||||||
</Enum>
|
</Enum>
|
||||||
</Enums>
|
</Enums>
|
||||||
|
<Registers>
|
||||||
|
<Item Key="pc" Value="1"/>
|
||||||
|
<Item Key="sp" Value="2"/>
|
||||||
|
</Registers>
|
||||||
<Definitions>
|
<Definitions>
|
||||||
<InstructionDefinition PrimaryInstruction="BMath">
|
<InstructionDefinition PrimaryInstruction="BMath">
|
||||||
<Aliases>
|
<Aliases>
|
||||||
|
|||||||
Reference in New Issue
Block a user