mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Use two-way mapping for mnemonics -> opcodes
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using Microsoft.Iris.Markup;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.Iris.Asm.Models;
|
||||
|
||||
@@ -9,6 +10,15 @@ public interface IImport { }
|
||||
|
||||
public record Instruction(string Mnemonic, IEnumerable<Operand> Operands) : IBodyItem
|
||||
{
|
||||
public Instruction(OpCode opCode, OperationType? operationType, IEnumerable<Operand> Operands)
|
||||
: this(LexerMaps.GetMnemonic(opCode, operationType), Operands)
|
||||
{
|
||||
}
|
||||
public Instruction(OpCode opCode, IEnumerable<Operand> Operands)
|
||||
: this(opCode, null, Operands)
|
||||
{
|
||||
}
|
||||
|
||||
public OpCode OpCode => LexerMaps.MnemonicToOpCode(Mnemonic);
|
||||
public OperationType? OperationType => LexerMaps.TryOperationMnemonicToType(Mnemonic);
|
||||
|
||||
@@ -27,5 +37,13 @@ public record Operand(object Value, string Content = null)
|
||||
|
||||
public record Program(IEnumerable<IImport> Imports, IEnumerable<IBodyItem> Body)
|
||||
{
|
||||
public override string ToString() => string.Join("\r\n", Imports.Select(i => i.ToString()).Concat(Body.Select(b => b.ToString())));
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
sb.AppendJoin("\r\n", Imports.Select(i => i.ToString()));
|
||||
sb.AppendJoin("\r\n", Body.Select(b => b.ToString()));
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user