aboutsummaryrefslogtreecommitdiff
path: root/ARMeilleure/CodeGen/X86/Assembler.cs
diff options
context:
space:
mode:
authorFICTURE7 <FICTURE7@gmail.com>2021-09-14 03:23:37 +0400
committerGitHub <noreply@github.com>2021-09-14 01:23:37 +0200
commita9343c9364246d3288b4e7f20919ca1ad2e1fd3e (patch)
treeba8ada2c2f5d2b4b0c92fbc5258bc43ad4809913 /ARMeilleure/CodeGen/X86/Assembler.cs
parentac4ec1a0151fd958d7ec58146169763b446836fe (diff)
Refactor `PtcInfo` (#2625)
* Refactor `PtcInfo` This change reduces the coupling of `PtcInfo` by moving relocation tracking to the backend. `RelocEntry`s remains as `RelocEntry`s through out the pipeline until it actually needs to be written to the PTC streams. Keeping this representation makes inspecting and manipulating relocations after compilations less painful. This is something I needed to do to patch relocations to 0 to diff dumps. Contributes to #1125. * Turn `Symbol` & `RelocInfo` into readonly structs * Add documentation to `CompiledFunction` * Remove `Compiler.Compile<T>` Remove `Compiler.Compile<T>` and replace it by `Map<T>` of the `CompiledFunction` returned.
Diffstat (limited to 'ARMeilleure/CodeGen/X86/Assembler.cs')
-rw-r--r--ARMeilleure/CodeGen/X86/Assembler.cs33
1 files changed, 16 insertions, 17 deletions
diff --git a/ARMeilleure/CodeGen/X86/Assembler.cs b/ARMeilleure/CodeGen/X86/Assembler.cs
index 044f6047..95608756 100644
--- a/ARMeilleure/CodeGen/X86/Assembler.cs
+++ b/ARMeilleure/CodeGen/X86/Assembler.cs
@@ -1,6 +1,7 @@
+using ARMeilleure.CodeGen.Linking;
using ARMeilleure.IntermediateRepresentation;
-using ARMeilleure.Translation.PTC;
using System;
+using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
@@ -61,12 +62,12 @@ namespace ARMeilleure.CodeGen.X86
}
}
- private static InstructionInfo[] _instTable;
+ private readonly static InstructionInfo[] _instTable;
- private Stream _stream;
+ private readonly Stream _stream;
- private PtcInfo _ptcInfo;
- private bool _ptcDisabled;
+ public List<RelocEntry> Relocs { get; }
+ public bool HasRelocs => Relocs != null;
static Assembler()
{
@@ -294,12 +295,10 @@ namespace ARMeilleure.CodeGen.X86
_instTable[(int)inst] = info;
}
- public Assembler(Stream stream, PtcInfo ptcInfo = null)
+ public Assembler(Stream stream, bool relocatable)
{
_stream = stream;
-
- _ptcInfo = ptcInfo;
- _ptcDisabled = ptcInfo == null;
+ Relocs = relocatable ? new List<RelocEntry>() : null;
}
public void Add(Operand dest, Operand source, OperandType type)
@@ -498,7 +497,7 @@ namespace ARMeilleure.CodeGen.X86
public void Jcc(X86Condition condition, long offset)
{
- if (_ptcDisabled && ConstFitsOnS8(offset))
+ if (!HasRelocs && ConstFitsOnS8(offset))
{
WriteByte((byte)(0x70 | (int)condition));
@@ -519,7 +518,7 @@ namespace ARMeilleure.CodeGen.X86
public void Jmp(long offset)
{
- if (_ptcDisabled && ConstFitsOnS8(offset))
+ if (!HasRelocs && ConstFitsOnS8(offset))
{
WriteByte(0xeb);
@@ -980,9 +979,9 @@ namespace ARMeilleure.CodeGen.X86
WriteByte((byte)(info.OpRImm64 + (dest.GetRegister().Index & 0b111)));
- if (_ptcInfo != default && source.Relocatable)
+ if (HasRelocs && source.Relocatable)
{
- _ptcInfo.WriteRelocEntry(new RelocEntry((int)_stream.Position, source.Symbol));
+ Relocs.Add(new RelocEntry((int)_stream.Position, source.Symbol));
}
WriteUInt64(imm);
@@ -1396,9 +1395,9 @@ namespace ARMeilleure.CodeGen.X86
return ConstFitsOnS32(value);
}
- public static int GetJccLength(long offset, bool ptcDisabled = true)
+ public static int GetJccLength(long offset, bool relocatable = false)
{
- if (ptcDisabled && ConstFitsOnS8(offset < 0 ? offset - 2 : offset))
+ if (!relocatable && ConstFitsOnS8(offset < 0 ? offset - 2 : offset))
{
return 2;
}
@@ -1412,9 +1411,9 @@ namespace ARMeilleure.CodeGen.X86
}
}
- public static int GetJmpLength(long offset, bool ptcDisabled = true)
+ public static int GetJmpLength(long offset, bool relocatable = false)
{
- if (ptcDisabled && ConstFitsOnS8(offset < 0 ? offset - 2 : offset))
+ if (!relocatable && ConstFitsOnS8(offset < 0 ? offset - 2 : offset))
{
return 2;
}