Ryujinx/ARMeilleure/Translation/PTC/PtcInfo.cs
LDj3SNuD dc0adb533d
PPTC & Pool Enhancements. (#1968)
* PPTC & Pool Enhancements.

* Avoid buffer allocations in CodeGenContext.GetCode(). Avoid stream allocations in PTC.PtcInfo.

Refactoring/nits.

* Use XXHash128, for Ptc.Load & Ptc.Save, x10 faster than Md5.

* Why not a nice Span.

* Added a simple PtcFormatter library for deserialization/serialization, which does not require reflection, in use at PtcJumpTable and PtcProfiler; improves maintainability and simplicity/readability of affected code.

* Nits.

* Revert #1987.

* Revert "Revert #1987."

This reverts commit 998be765cf.
2021-02-22 03:23:48 +01:00

62 lines
1.9 KiB
C#

using ARMeilleure.CodeGen.Unwinding;
using System;
using System.IO;
namespace ARMeilleure.Translation.PTC
{
class PtcInfo : IDisposable
{
private readonly BinaryWriter _relocWriter;
private readonly BinaryWriter _unwindInfoWriter;
public byte[] Code { get; set; }
public MemoryStream RelocStream { get; }
public MemoryStream UnwindInfoStream { get; }
public int RelocEntriesCount { get; private set; }
public PtcInfo()
{
RelocStream = new MemoryStream();
UnwindInfoStream = new MemoryStream();
_relocWriter = new BinaryWriter(RelocStream, EncodingCache.UTF8NoBOM, true);
_unwindInfoWriter = new BinaryWriter(UnwindInfoStream, EncodingCache.UTF8NoBOM, true);
RelocEntriesCount = 0;
}
public void WriteRelocEntry(RelocEntry relocEntry)
{
_relocWriter.Write((int)relocEntry.Position);
_relocWriter.Write((int)relocEntry.Index);
RelocEntriesCount++;
}
public void WriteUnwindInfo(UnwindInfo unwindInfo)
{
_unwindInfoWriter.Write((int)unwindInfo.PushEntries.Length);
foreach (UnwindPushEntry unwindPushEntry in unwindInfo.PushEntries)
{
_unwindInfoWriter.Write((int)unwindPushEntry.PseudoOp);
_unwindInfoWriter.Write((int)unwindPushEntry.PrologOffset);
_unwindInfoWriter.Write((int)unwindPushEntry.RegIndex);
_unwindInfoWriter.Write((int)unwindPushEntry.StackOffsetOrAllocSize);
}
_unwindInfoWriter.Write((int)unwindInfo.PrologSize);
}
public void Dispose()
{
_relocWriter.Dispose();
_unwindInfoWriter.Dispose();
RelocStream.Dispose();
UnwindInfoStream.Dispose();
}
}
}