Working on improving ISA Linker.

This commit is contained in:
2025-07-21 01:47:31 +08:00
parent b164fc1798
commit 49d6d463bd
11 changed files with 228 additions and 24 deletions

View File

@@ -1,21 +1,72 @@
using SVM.Core;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
namespace SVM.Assembler.Core
{
[Serializable]
public class ISADefinition
{
public Dictionary<string, InstructionDefinition> InstructionDefinitions = new Dictionary<string, InstructionDefinition>();
public Dictionary<PrimaryInstruction, LinkerFunction> LinkerFunctions = new Dictionary<PrimaryInstruction, LinkerFunction>();
public Dictionary<PrimaryInstruction, InstructionDefinition> InstructionDefinitions = new Dictionary<PrimaryInstruction, InstructionDefinition>();
[NonSerialized]
public Dictionary<string, InstructionDefinition> InstructionDefinitionAliases = new Dictionary<string, InstructionDefinition>();
public void Init()
{
foreach (var item in InstructionDefinitions)
{
if (!LinkerFunctions.TryAdd(item.Value.PrimaryInstruction, item.Value.linkerFunction))
foreach (var alias in item.Value.aliases)
{
LinkerFunctions[item.Value.PrimaryInstruction] = item.Value.linkerFunction;
if (!InstructionDefinitionAliases.TryAdd(alias, item.Value))
{
InstructionDefinitionAliases[alias] = item.Value;
}
}
}
}
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;
}
}
}