mirror of
https://github.com/asmjit/asmjit.git
synced 2025-12-17 12:34:35 +03:00
78 lines
2.0 KiB
C++
78 lines
2.0 KiB
C++
// [AsmJit]
|
|
// Complete x86/x64 JIT and Remote Assembler for C++.
|
|
//
|
|
// [License]
|
|
// Zlib - See LICENSE.md file in the package.
|
|
|
|
// This file is used to test opcodes generated by AsmJit. Output can be
|
|
// disassembled in your IDE or by your favourite disassembler. Instructions
|
|
// are grouped by category and then sorted alphabetically.
|
|
|
|
// [Dependencies]
|
|
#include "../asmjit/asmjit.h"
|
|
#include "./asmjit_test_opcode.h"
|
|
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
typedef void (*VoidFunc)(void);
|
|
|
|
struct OpcodeDumpInfo {
|
|
uint32_t arch;
|
|
bool useRex1;
|
|
bool useRex2;
|
|
};
|
|
|
|
static const char* archIdToString(uint32_t archId) {
|
|
switch (archId) {
|
|
case asmjit::kArchNone : return "None";
|
|
case asmjit::kArchX86 : return "X86";
|
|
case asmjit::kArchX64 : return "X64";
|
|
case asmjit::kArchArm32: return "ARM32";
|
|
case asmjit::kArchArm64: return "ARM64";
|
|
default: return "<unknown>";
|
|
}
|
|
}
|
|
|
|
int main(int argc, char* argv[]) {
|
|
asmjit::FileLogger logger(stdout);
|
|
logger.addOptions(asmjit::Logger::kOptionBinaryForm);
|
|
|
|
OpcodeDumpInfo infoList[] = {
|
|
# if defined(ASMJIT_BUILD_X86)
|
|
{ asmjit::kArchX86, false, false },
|
|
# endif // ASMJIT_BUILD_X86
|
|
# if defined(ASMJIT_BUILD_X64)
|
|
{ asmjit::kArchX64, false, false },
|
|
{ asmjit::kArchX64, false, true },
|
|
{ asmjit::kArchX64, true , false },
|
|
{ asmjit::kArchX64, true , true }
|
|
# endif // ASMJIT_BUILD_X64
|
|
};
|
|
|
|
for (int i = 0; i < ASMJIT_ARRAY_SIZE(infoList); i++) {
|
|
const OpcodeDumpInfo& info = infoList[i];
|
|
|
|
printf("Opcodes [ARCH=%s REX1=%s REX2=%s]\n",
|
|
archIdToString(info.arch),
|
|
info.useRex1 ? "true" : "false",
|
|
info.useRex2 ? "true" : "false");
|
|
|
|
asmjit::JitRuntime runtime;
|
|
asmjit::X86Assembler a(&runtime, info.arch);
|
|
a.setLogger(&logger);
|
|
|
|
asmgen::opcode(a, info.useRex1, info.useRex2);
|
|
VoidFunc p = asmjit_cast<VoidFunc>(a.make());
|
|
|
|
// Only run if disassembly makes sense.
|
|
if (info.arch == asmjit::kArchHost)
|
|
p();
|
|
|
|
runtime.release((void*)p);
|
|
}
|
|
|
|
return 0;
|
|
}
|