mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Add binary encoded constants to lexer and disassembler
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
namespace Microsoft.Iris.Asm.Models;
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.Iris.Asm.Models;
|
||||
|
||||
public record SectionDirective : Directive
|
||||
{
|
||||
@@ -28,9 +31,9 @@ public record ConstantDirective : Directive
|
||||
public override string ToString() => $"{base.ToString()} {Name} = {Constructor}";
|
||||
}
|
||||
|
||||
public record EncodedConstantDirective : ConstantDirective
|
||||
public record StringEncodedConstantDirective : ConstantDirective
|
||||
{
|
||||
public EncodedConstantDirective(string name, QualifiedTypeName typeName, string content)
|
||||
public StringEncodedConstantDirective(string name, QualifiedTypeName typeName, string content)
|
||||
: base(name, typeName, $"{typeName}({content})")
|
||||
{
|
||||
Content = content;
|
||||
@@ -41,6 +44,34 @@ public record EncodedConstantDirective : ConstantDirective
|
||||
public override string ToString() => base.ToString();
|
||||
}
|
||||
|
||||
public record BinaryEncodedConstantDirective : ConstantDirective
|
||||
{
|
||||
public BinaryEncodedConstantDirective(string name, QualifiedTypeName typeName, byte[] content)
|
||||
: base(name, typeName, GetConstructor(typeName, content))
|
||||
{
|
||||
Content = content;
|
||||
}
|
||||
|
||||
public byte[] Content { get; }
|
||||
|
||||
public override string ToString() => base.ToString();
|
||||
|
||||
private static string GetConstructor(QualifiedTypeName typeName, byte[] content)
|
||||
{
|
||||
string contentStr;
|
||||
if (content.Length == 1)
|
||||
contentStr = $"0x{content[0]:X2}";
|
||||
else if (content.Length == 2)
|
||||
contentStr = $"0x{BitConverter.ToUInt16(content, 0):X4}";
|
||||
else if (content.Length == 4)
|
||||
contentStr = $"0x{BitConverter.ToUInt32(content, 0):X8}";
|
||||
else
|
||||
contentStr = string.Join(", ", content.Select(b => $"0x{b:X2}"));
|
||||
|
||||
return $"{typeName}.bin({contentStr})";
|
||||
}
|
||||
}
|
||||
|
||||
public record ExportDirective : Directive
|
||||
{
|
||||
public ExportDirective(string labelPrefix, uint listenerCount, string baseTypeName) : base("export")
|
||||
|
||||
Reference in New Issue
Block a user