2024-01-29 21:42:06 -06:00
|
|
|
using Microsoft.Iris.Markup;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2024-01-29 21:57:00 -06:00
|
|
|
namespace Microsoft.Iris.Asm;
|
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
|
|
|
|
|
{
|
|
|
|
|
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-30 23:30:11 -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 NamespaceImport(string Uri, string Name) : IImport
|
2024-01-29 21:42:06 -06:00
|
|
|
{
|
2024-01-30 22:44:48 -06:00
|
|
|
public override string ToString() => $".import-ns {Uri} as {Name}";
|
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
|
|
|
{
|
|
|
|
|
public override string ToString() => string.Join("\r\n", Imports.Select(i => i.ToString()).Concat(Body.Select(b => b.ToString())));
|
|
|
|
|
}
|