diff options
Diffstat (limited to 'ARMeilleure/CodeGen/X86/Assembler.cs')
| -rw-r--r-- | ARMeilleure/CodeGen/X86/Assembler.cs | 33 |
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; } |
