2025-07-20 20:45:10 +08:00
|
|
|
|
using SVM.Core;
|
2025-07-21 01:47:31 +08:00
|
|
|
|
using System;
|
2025-07-20 20:45:10 +08:00
|
|
|
|
using System.Collections.Generic;
|
2025-07-21 01:47:31 +08:00
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
using System.Xml.Serialization;
|
2025-07-20 20:45:10 +08:00
|
|
|
|
|
|
|
|
|
|
namespace SVM.Assembler.Core
|
|
|
|
|
|
{
|
2025-07-21 01:47:31 +08:00
|
|
|
|
[Serializable]
|
2025-07-20 20:45:10 +08:00
|
|
|
|
public class ISADefinition
|
|
|
|
|
|
{
|
2025-07-21 01:47:31 +08:00
|
|
|
|
public Dictionary<PrimaryInstruction, InstructionDefinition> InstructionDefinitions = new Dictionary<PrimaryInstruction, InstructionDefinition>();
|
|
|
|
|
|
[NonSerialized]
|
|
|
|
|
|
public Dictionary<string, InstructionDefinition> InstructionDefinitionAliases = new Dictionary<string, InstructionDefinition>();
|
2025-07-20 20:45:10 +08:00
|
|
|
|
public void Init()
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var item in InstructionDefinitions)
|
|
|
|
|
|
{
|
2025-07-21 01:47:31 +08:00
|
|
|
|
foreach (var alias in item.Value.aliases)
|
2025-07-20 20:45:10 +08:00
|
|
|
|
{
|
2025-07-21 01:47:31 +08:00
|
|
|
|
if (!InstructionDefinitionAliases.TryAdd(alias, item.Value))
|
|
|
|
|
|
{
|
|
|
|
|
|
InstructionDefinitionAliases[alias] = item.Value;
|
|
|
|
|
|
}
|
2025-07-20 20:45:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-07-21 01:47:31 +08:00
|
|
|
|
static void PrintDepth(int depth)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < depth; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
Console.Write("\t");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
static void ShowNode(XmlNode node, int depth = 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
PrintDepth(depth);
|
|
|
|
|
|
Console.WriteLine($"[+]{node.NodeType}:{node.Name}");
|
|
|
|
|
|
foreach (XmlAttribute item in node.Attributes)
|
|
|
|
|
|
{
|
|
|
|
|
|
PrintDepth(depth + 1);
|
|
|
|
|
|
Console.WriteLine($"[i]{item.NodeType}:{item.Name}={item.InnerText}");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (XmlElement item in node.ChildNodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (item is XmlNode cnode)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowNode(cnode, depth + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
PrintDepth(depth + 1);
|
|
|
|
|
|
Console.Write($"[?]{item.NodeType}:{item.Name}");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public static bool TryParse(Stream inputStream, [MaybeNullWhen(false)] out ISADefinition definition)
|
|
|
|
|
|
{
|
|
|
|
|
|
XmlDocument xmlDocument = new XmlDocument();
|
|
|
|
|
|
xmlDocument.Load(inputStream);
|
|
|
|
|
|
foreach (XmlNode item in xmlDocument.ChildNodes)
|
|
|
|
|
|
{
|
|
|
|
|
|
ShowNode(item, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
definition = null;
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
2025-07-20 20:45:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|