mirror of
https://github.com/ZuneDev/ZuneUIXTools.git
synced 2026-07-27 13:11:59 -07:00
Create object section encoder
This commit is contained in:
@@ -170,18 +170,16 @@ internal class AsmMarkupLoader
|
|||||||
_loadResult.SetImportTables(importTables);
|
_loadResult.SetImportTables(importTables);
|
||||||
}
|
}
|
||||||
|
|
||||||
MarkupLineNumberTable lineNumberTable = new MarkupLineNumberTable();
|
MarkupLineNumberTable lineNumberTable = new();
|
||||||
MarkupConstantsTable constantsTable = _loadResult.BinaryDataTable == null
|
MarkupConstantsTable constantsTable = _loadResult.BinaryDataTable?.ConstantsTable ?? new();
|
||||||
? new MarkupConstantsTable()
|
|
||||||
: _loadResult.BinaryDataTable.ConstantsTable;
|
|
||||||
|
|
||||||
_loadResult.SetDataMappingsTable(PrepareDataMappingTable());
|
_loadResult.SetDataMappingsTable(PrepareDataMappingTable());
|
||||||
_loadResult.ValidationComplete();
|
_loadResult.ValidationComplete();
|
||||||
|
|
||||||
ByteCodeReader reader = null;
|
ByteCodeReader reader = null;
|
||||||
|
ObjectSection objectSection = new(_program, _loadResult);
|
||||||
if (!HasErrors)
|
if (!HasErrors)
|
||||||
EncodeOBJECTSection();
|
reader = objectSection.Encode();
|
||||||
// reader = new MarkupEncoder(importTables, constantsTable, lineNumberTable).EncodeOBJECTSection(_parseResult, _loadResult.Uri, null);
|
|
||||||
|
|
||||||
if (!_usingSharedBinaryDataTable)
|
if (!_usingSharedBinaryDataTable)
|
||||||
{
|
{
|
||||||
@@ -207,12 +205,12 @@ internal class AsmMarkupLoader
|
|||||||
|
|
||||||
private LoadResult[] PrepareDependenciesTable()
|
private LoadResult[] PrepareDependenciesTable()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private MarkupDataMapping[] PrepareDataMappingTable()
|
private MarkupDataMapping[] PrepareDataMappingTable()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReportError(string error, int line, int column)
|
public void ReportError(string error, int line, int column)
|
||||||
@@ -220,9 +218,4 @@ internal class AsmMarkupLoader
|
|||||||
MarkHasErrors();
|
MarkHasErrors();
|
||||||
ErrorManager.ReportError(line, column, error);
|
ErrorManager.ReportError(line, column, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EncodeOBJECTSection()
|
|
||||||
{
|
|
||||||
var instructions = _program.Body.OfType<Instruction>();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using Microsoft.Iris.Asm.Models;
|
||||||
|
using Microsoft.Iris.Markup;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace Microsoft.Iris.Asm;
|
||||||
|
|
||||||
|
public class ObjectSection
|
||||||
|
{
|
||||||
|
readonly IEnumerable<Instruction> _instructions;
|
||||||
|
readonly MarkupLoadResult _loadResult;
|
||||||
|
|
||||||
|
public ObjectSection(IEnumerable<Instruction> instructions, MarkupLoadResult loadResult)
|
||||||
|
{
|
||||||
|
_instructions = instructions;
|
||||||
|
_loadResult = loadResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectSection(IEnumerable<IBodyItem> body, MarkupLoadResult loadResult)
|
||||||
|
: this(body.OfType<Instruction>(), loadResult)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectSection(Program program, MarkupLoadResult loadResult)
|
||||||
|
: this(program.Body, loadResult)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public ByteCodeReader Encode()
|
||||||
|
{
|
||||||
|
ByteCodeWriter writer = new();
|
||||||
|
|
||||||
|
foreach (var instruction in _instructions)
|
||||||
|
{
|
||||||
|
var opCode = instruction.OpCode;
|
||||||
|
writer.WriteByte(opCode);
|
||||||
|
|
||||||
|
foreach (var operand in instruction.Operands)
|
||||||
|
{
|
||||||
|
switch (operand.Value)
|
||||||
|
{
|
||||||
|
case OperationType opType:
|
||||||
|
writer.WriteByte((byte)opType);
|
||||||
|
break;
|
||||||
|
case byte b:
|
||||||
|
writer.WriteByte(b);
|
||||||
|
break;
|
||||||
|
case ushort uint16:
|
||||||
|
writer.WriteUInt16(uint16);
|
||||||
|
break;
|
||||||
|
case uint uint32:
|
||||||
|
writer.WriteUInt32(uint32);
|
||||||
|
break;
|
||||||
|
case int int32:
|
||||||
|
writer.WriteInt32(int32);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
if (opCode == OpCode.ConstructFromBinary)
|
||||||
|
{
|
||||||
|
ushort cbinTypeIndex = (UInt16)instruction.Operands.First().Value;
|
||||||
|
TypeSchema cbinTypeSchema = _loadResult.ImportTables.TypeImports[cbinTypeIndex];
|
||||||
|
cbinTypeSchema.EncodeBinary(writer, operand.Value);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new InvalidOperationException($"Unexpected operand '{operand.Value}' of type '{operand.Value.GetType()}'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return writer.CreateReader();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user