Skip to content

Commit 530708d

Browse files
committed
Split instruction sets into their own packages
1 parent 3d5abb6 commit 530708d

37 files changed

+429
-924
lines changed

Cpp2IL.Core.Tests/Cpp2IL.Core.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
<ItemGroup>
99
<ProjectReference Include="..\Cpp2IL.Core\Cpp2IL.Core.csproj" />
10+
<ProjectReference Include="..\Cpp2IL.InstructionSets.All\Cpp2IL.InstructionSets.All.csproj" />
1011
</ItemGroup>
1112

1213
<ItemGroup>

Cpp2IL.Core.Tests/GameLoader.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using AssetRipper.VersionUtilities;
2-
using Cpp2IL.Core.Api;
3-
using Cpp2IL.Core.InstructionSets;
42
using Cpp2IL.Core.Model.Contexts;
3+
using Cpp2IL.InstructionSets.All;
54
using LibCpp2IL;
65

76
namespace Cpp2IL.Core.Tests;
@@ -10,20 +9,7 @@ public static class GameLoader
109
{
1110
static GameLoader()
1211
{
13-
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_32);
14-
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_64);
15-
InstructionSetRegistry.RegisterInstructionSet<WasmInstructionSet>(DefaultInstructionSets.WASM);
16-
InstructionSetRegistry.RegisterInstructionSet<ArmV7InstructionSet>(DefaultInstructionSets.ARM_V7);
17-
var useNewArm64 = true;
18-
if (useNewArm64)
19-
{
20-
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8);
21-
}
22-
else
23-
{
24-
InstructionSetRegistry.RegisterInstructionSet<Arm64InstructionSet>(DefaultInstructionSets.ARM_V8);
25-
}
26-
12+
AllInstructionSets.Register();
2713
LibCpp2IlBinaryRegistry.RegisterBuiltInBinarySupport();
2814
}
2915

Cpp2IL.Core/Cpp2IL.Core.csproj

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
<!--Needed for DLL output-->
1414
<PackageReference Include="AsmResolver.DotNet" Version="5.2.0" />
1515

16-
<!--For ARM64 dissassembly-->
17-
<PackageReference Include="Disarm" Version="2022.1.0-master.26" />
18-
19-
<!--For X86/X64 disassembly-->
20-
<PackageReference Include="Iced" Version="1.18.0" />
21-
22-
<!--For ARM64 and ARMv7 disassembly. Future: Remove once disarm is stable and move ARMv7 to CapstoneSharp by 6pak-->
23-
<PackageReference Include="js6pak.Gee.External.Capstone" Version="2.1.0" />
24-
2516
<!--Not used at runtime, but needed for the build-->
2617
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
2718

Cpp2IL.Core/Cpp2IlCorePlugin.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
using System;
21
using Cpp2IL.Core;
32
using Cpp2IL.Core.Api;
43
using Cpp2IL.Core.Attributes;
5-
using Cpp2IL.Core.InstructionSets;
64
using Cpp2IL.Core.OutputFormats;
75
using Cpp2IL.Core.ProcessingLayers;
86
//Need this for the assembly attribute definition below.
@@ -22,19 +20,7 @@ public override void OnLoad()
2220
{
2321
Logger.VerboseNewline("Initializing...", "Core Plugin");
2422
var start = DateTime.Now;
25-
26-
Logger.VerboseNewline("\tRegistering built-in instruction set handlers...", "Core Plugin");
27-
28-
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_32);
29-
InstructionSetRegistry.RegisterInstructionSet<X86InstructionSet>(DefaultInstructionSets.X86_64);
30-
InstructionSetRegistry.RegisterInstructionSet<WasmInstructionSet>(DefaultInstructionSets.WASM);
31-
InstructionSetRegistry.RegisterInstructionSet<ArmV7InstructionSet>(DefaultInstructionSets.ARM_V7);
32-
33-
if(Environment.GetEnvironmentVariable("CPP2IL_NEW_ARM64") != null)
34-
InstructionSetRegistry.RegisterInstructionSet<NewArmV8InstructionSet>(DefaultInstructionSets.ARM_V8);
35-
else
36-
InstructionSetRegistry.RegisterInstructionSet<Arm64InstructionSet>(DefaultInstructionSets.ARM_V8);
37-
23+
3824
Logger.VerboseNewline("\tRegistering built-in binary parsers...", "Core Plugin");
3925

4026
LibCpp2IlBinaryRegistry.RegisterBuiltInBinarySupport();
@@ -44,7 +30,6 @@ public override void OnLoad()
4430
OutputFormatRegistry.Register<AsmResolverDummyDllOutputFormat>();
4531
OutputFormatRegistry.Register<DiffableCsOutputFormat>();
4632
OutputFormatRegistry.Register<IsilDumpOutputFormat>();
47-
OutputFormatRegistry.Register<WasmMappingOutputFormat>();
4833

4934
Logger.VerboseNewline("\tRegistering built-in processing layers", "Core Plugin");
5035

Cpp2IL.Core/Extensions/MiscExtensions.cs

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,9 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Diagnostics.CodeAnalysis;
4-
using System.Linq;
51
using System.Text;
6-
using Cpp2IL.Core.ISIL;
7-
using Gee.External.Capstone.Arm;
8-
using Gee.External.Capstone.Arm64;
9-
using Iced.Intel;
10-
using Instruction = Iced.Intel.Instruction;
112

123
namespace Cpp2IL.Core.Extensions
134
{
145
public static class MiscExtensions
156
{
16-
public static InstructionSetIndependentOperand MakeIndependent(this Register reg) => InstructionSetIndependentOperand.MakeRegister(reg.ToString().ToLower());
17-
18-
public static ulong GetImmediateSafe(this Instruction instruction, int op) => instruction.GetOpKind(op).IsImmediate() ? instruction.GetImmediate(op) : 0;
19-
20-
public static bool IsJump(this Mnemonic mnemonic) => mnemonic is Mnemonic.Call or >= Mnemonic.Ja and <= Mnemonic.Js;
21-
public static bool IsConditionalJump(this Mnemonic mnemonic) => mnemonic.IsJump() && mnemonic != Mnemonic.Jmp && mnemonic != Mnemonic.Call;
22-
23-
//Arm Extensions
24-
public static ArmRegister? RegisterSafe(this ArmOperand operand) => operand.Type != ArmOperandType.Register ? null : operand.Register;
25-
public static bool IsImmediate(this ArmOperand operand) => operand.Type is ArmOperandType.CImmediate or ArmOperandType.Immediate or ArmOperandType.PImmediate;
26-
public static int ImmediateSafe(this ArmOperand operand) => operand.IsImmediate() ? operand.Immediate : 0;
27-
private static ArmOperand? MemoryOperand(ArmInstruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == ArmOperandType.Memory);
28-
29-
public static ArmRegister? MemoryBase(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Base;
30-
public static ArmRegister? MemoryIndex(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Index;
31-
public static int MemoryOffset(this ArmInstruction instruction) => MemoryOperand(instruction)?.Memory.Displacement ?? 0;
32-
33-
//Arm64 Extensions
34-
public static Arm64Register? RegisterSafe(this Arm64Operand operand) => operand.Type != Arm64OperandType.Register ? null : operand.Register;
35-
public static bool IsImmediate(this Arm64Operand operand) => operand.Type is Arm64OperandType.CImmediate or Arm64OperandType.Immediate;
36-
public static long ImmediateSafe(this Arm64Operand operand) => operand.IsImmediate() ? operand.Immediate : 0;
37-
internal static Arm64Operand? MemoryOperand(this Arm64Instruction instruction) => instruction.Details.Operands.FirstOrDefault(a => a.Type == Arm64OperandType.Memory);
38-
39-
public static Arm64Register? MemoryBase(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Base;
40-
public static Arm64Register? MemoryIndex(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Index;
41-
public static int MemoryOffset(this Arm64Instruction instruction) => instruction.MemoryOperand()?.Memory.Displacement ?? 0;
42-
43-
public static bool IsConditionalMove(this Instruction instruction)
44-
{
45-
switch (instruction.Mnemonic)
46-
{
47-
case Mnemonic.Cmove:
48-
case Mnemonic.Cmovne:
49-
case Mnemonic.Cmovs:
50-
case Mnemonic.Cmovns:
51-
case Mnemonic.Cmovg:
52-
case Mnemonic.Cmovge:
53-
case Mnemonic.Cmovl:
54-
case Mnemonic.Cmovle:
55-
case Mnemonic.Cmova:
56-
case Mnemonic.Cmovae:
57-
case Mnemonic.Cmovb:
58-
case Mnemonic.Cmovbe:
59-
return true;
60-
default:
61-
return false;
62-
}
63-
}
647
public static Stack<T> Clone<T>(this Stack<T> original)
658
{
669
var arr = new T[original.Count];
@@ -130,9 +73,6 @@ public static T[] SubArray<T>(this T[] source, Range range)
13073
return arr[i];
13174
}
13275

133-
public static bool IsImmediate(this OpKind opKind) => opKind is >= OpKind.Immediate8 and <= OpKind.Immediate32to64;
134-
135-
13676
public static void TrimEndWhile<T>(this List<T> instructions, Func<T, bool> predicate)
13777
{
13878
var i = instructions.Count - 1;

0 commit comments

Comments
 (0)