mirror of
https://github.com/creeperlv/SVM.git
synced 2026-01-11 21:09:53 +00:00
Working on the new Definition.
This commit is contained in:
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
using System.Xml.Linq;
|
||||
using System.Xml.Serialization;
|
||||
|
||||
namespace SVM.Assembler.Core
|
||||
@@ -18,7 +19,7 @@ namespace SVM.Assembler.Core
|
||||
{
|
||||
foreach (var item in InstructionDefinitions)
|
||||
{
|
||||
foreach (var alias in item.Value.aliases)
|
||||
foreach (var alias in item.Value.Aliases)
|
||||
{
|
||||
if (!InstructionDefinitionAliases.TryAdd(alias, item.Value))
|
||||
{
|
||||
@@ -57,13 +58,77 @@ namespace SVM.Assembler.Core
|
||||
}
|
||||
}
|
||||
}
|
||||
static bool ParseDefinition(XmlNode node, ref ISADefinition definition)
|
||||
{
|
||||
|
||||
InstructionDefinition instDefinition = new InstructionDefinition();
|
||||
foreach (XmlNode item in node.ChildNodes)
|
||||
{
|
||||
switch (item.Name)
|
||||
{
|
||||
case "Aliases":
|
||||
foreach (XmlNode aliasNode in item.ChildNodes)
|
||||
{
|
||||
if (aliasNode.Name == "Alias")
|
||||
{
|
||||
instDefinition.Aliases.Add(aliasNode.Attributes["Name"].Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case "Parameters":
|
||||
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (item.Name != "InstructionDefinition")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
static bool ParseDefinitions(XmlNode node, ref ISADefinition definition)
|
||||
{
|
||||
foreach (XmlNode item in node.ChildNodes)
|
||||
{
|
||||
if (item.Name != "InstructionDefinition")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ParseDefinition(node, ref definition) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public static bool TryParse(Stream inputStream, [MaybeNullWhen(false)] out ISADefinition definition)
|
||||
{
|
||||
XmlDocument xmlDocument = new XmlDocument();
|
||||
xmlDocument.Load(inputStream);
|
||||
ISADefinition isaDefinition = new ISADefinition();
|
||||
foreach (XmlNode item in xmlDocument.ChildNodes)
|
||||
{
|
||||
ShowNode(item, 0);
|
||||
switch (item.Name)
|
||||
{
|
||||
case "Enums":
|
||||
break;
|
||||
case "Definitions":
|
||||
if (ParseDefinitions(item, ref isaDefinition) == false)
|
||||
{
|
||||
definition = null;
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
definition = null;
|
||||
return false;
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SVM.Assembler.Core
|
||||
public class InstructionDefinition
|
||||
{
|
||||
public PrimaryInstruction PrimaryInstruction = PrimaryInstruction.Nop;
|
||||
public List<string> aliases = new List<string>();
|
||||
public List<string> Aliases = new List<string>();
|
||||
public List<InstructionParameter> ParameterPattern = new List<InstructionParameter>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user