2024-02-08 10:50:57 -06:00
|
|
|
using System.Collections.Generic;
|
2024-02-04 22:09:21 -06:00
|
|
|
using System.Diagnostics;
|
2024-01-29 21:42:06 -06:00
|
|
|
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
|
|
|
|
2024-02-04 22:09:21 -06:00
|
|
|
[DebuggerDisplay("{Name} " + DebuggerDisplay)]
|
2024-02-04 18:50:45 -06:00
|
|
|
public record Label(string Name) : BodyItem
|
2024-01-29 21:42:06 -06:00
|
|
|
{
|
|
|
|
|
public override string ToString() => $"{Name}:";
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 07:38:51 -06:00
|
|
|
public enum OperandDataType : byte
|
|
|
|
|
{
|
|
|
|
|
Byte,
|
|
|
|
|
UInt16,
|
|
|
|
|
UInt32,
|
|
|
|
|
Int32,
|
|
|
|
|
Bytes,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public record Operand(object Value, OperandDataType DataType, string Content = null) : AsmItem
|
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-02-08 10:50:57 -06:00
|
|
|
public record Program(IEnumerable<IDirective> Directives, IEnumerable<IBodyItem> Body)
|
2024-01-29 21:42:06 -06:00
|
|
|
{
|
2024-01-31 16:58:28 -06:00
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2024-01-31 18:43:04 -06:00
|
|
|
const string lineEnding = "\r\n";
|
|
|
|
|
const string indent = " ";
|
2024-01-31 16:58:28 -06:00
|
|
|
StringBuilder sb = new();
|
|
|
|
|
|
2024-02-08 10:50:57 -06:00
|
|
|
sb.AppendJoin(lineEnding, Directives.Select(i => i.ToString()));
|
2024-01-31 18:43:04 -06:00
|
|
|
sb.Append(lineEnding);
|
|
|
|
|
sb.Append(lineEnding);
|
|
|
|
|
|
|
|
|
|
foreach (var bodyItem in Body)
|
|
|
|
|
{
|
|
|
|
|
if (bodyItem is Instruction)
|
|
|
|
|
sb.Append(indent);
|
|
|
|
|
|
|
|
|
|
sb.Append(bodyItem.ToString());
|
|
|
|
|
sb.Append(lineEnding);
|
|
|
|
|
}
|
2024-01-31 16:58:28 -06:00
|
|
|
|
|
|
|
|
return sb.ToString();
|
|
|
|
|
}
|
2024-01-29 21:42:06 -06:00
|
|
|
}
|