2024-01-29 21:42:06 -06:00
|
|
|
using Microsoft.Iris.Markup;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2024-01-31 16:58:28 -06:00
|
|
|
using System.Text;
|
2024-01-29 21:42:06 -06:00
|
|
|
|
2024-01-31 09:21:30 -06:00
|
|
|
namespace Microsoft.Iris.Asm.Models;
|
2024-01-29 21:42:06 -06:00
|
|
|
|
|
|
|
|
public interface IBodyItem { }
|
2024-01-30 22:44:48 -06:00
|
|
|
public interface IImport { }
|
2024-01-29 21:42:06 -06:00
|
|
|
|
|
|
|
|
public record Instruction(string Mnemonic, IEnumerable<Operand> Operands) : IBodyItem
|
|
|
|
|
{
|
2024-01-31 16:58:28 -06:00
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-29 21:42:06 -06:00
|
|
|
public OpCode OpCode => LexerMaps.MnemonicToOpCode(Mnemonic);
|
|
|
|
|
public OperationType? OperationType => LexerMaps.TryOperationMnemonicToType(Mnemonic);
|
|
|
|
|
|
|
|
|
|
public override string ToString() => $"{Mnemonic} {string.Join(", ", Operands)}";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public record Label(string Name) : IBodyItem
|
|
|
|
|
{
|
|
|
|
|
public override string ToString() => $"{Name}:";
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-31 09:21:30 -06:00
|
|
|
public record Operand(object Value, string Content = null)
|
2024-01-29 21:42:06 -06:00
|
|
|
{
|
2024-01-30 23:30:11 -06:00
|
|
|
public override string ToString() => Content ?? Value.ToString();
|
2024-01-29 21:42:06 -06:00
|
|
|
}
|
|
|
|
|
|
2024-01-30 22:44:48 -06:00
|
|
|
public record Program(IEnumerable<IImport> Imports, IEnumerable<IBodyItem> Body)
|
2024-01-29 21:42:06 -06:00
|
|
|
{
|
2024-01-31 16:58:28 -06:00
|
|
|
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();
|
|
|
|
|
}
|
2024-01-29 21:42:06 -06:00
|
|
|
}
|