diff --git a/.gitignore b/.gitignore index 9442d2b..2bd624b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -build_* +build_* diff --git a/.travis.yml b/.travis.yml index ee1a965..4e49b40 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,11 @@ compiler: - clang - gcc +before_install: + - sudo add-apt-repository ppa:kubuntu-ppa/backports -y + - sudo apt-get update -qq + - sudo apt-get install -qq cmake + before_script: - mkdir build - cd build diff --git a/src/asmjit/base/assembler.h b/src/asmjit/base/assembler.h index c3ebdc7..21de496 100644 --- a/src/asmjit/base/assembler.h +++ b/src/asmjit/base/assembler.h @@ -55,7 +55,6 @@ ASMJIT_ENUM(kInstOptions) { //! to large displacement, in such case an error happens and the whole //! assembler/compiler stream is unusable. kInstOptionShortForm = 0x01, - //! Emit long form of the instruction. //! //! X86/X64: @@ -65,9 +64,9 @@ ASMJIT_ENUM(kInstOptions) { //! supporting both 8-bit and 32-bit immediates. kInstOptionLongForm = 0x02, - //! Condition is likely to be taken (instruction). + //! Condition is likely to be taken. kInstOptionTaken = 0x04, - //! Condition is unlikely to be taken (instruction). + //! Condition is unlikely to be taken. kInstOptionNotTaken = 0x08 }; diff --git a/src/asmjit/base/intutil.cpp b/src/asmjit/base/intutil.cpp index c377399..3a811b6 100644 --- a/src/asmjit/base/intutil.cpp +++ b/src/asmjit/base/intutil.cpp @@ -71,29 +71,61 @@ UNIT(base_intutil) { EXPECT(IntUtil::inInterval(101, 10, 20) == false, "IntUtil::inInterval should return false if outside."); - INFO("IntUtil::isInt?()."); - EXPECT(IntUtil::isInt8(-128) == true, - "IntUtil::isInt8 should return true if >= -128."); - EXPECT(IntUtil::isInt8(127) == true, - "IntUtil::isInt8 should return true if <= 127."); - EXPECT(IntUtil::isInt8(-129) == false, - "IntUtil::isInt8 should return false if < -128."); - EXPECT(IntUtil::isInt8(128) == false, - "IntUtil::isInt8 should return false if > 127."); + INFO("IntUtil::isInt8()."); + EXPECT(IntUtil::isInt8(-128) == true, + "IntUtil::isInt8<> should return true if inside."); + EXPECT(IntUtil::isInt8(127) == true, + "IntUtil::isInt8<> should return true if inside."); + EXPECT(IntUtil::isInt8(-129) == false, + "IntUtil::isInt8<> should return false if outside."); + EXPECT(IntUtil::isInt8(128) == false, + "IntUtil::isInt8<> should return false if outside."); - EXPECT(IntUtil::isInt16(-32768) == true, - "IntUtil::isInt16 should return true if >= -32768."); - EXPECT(IntUtil::isInt16(32767) == true, - "IntUtil::isInt16 should return true if <= 32767."); - EXPECT(IntUtil::isInt16(-32769) == false, - "IntUtil::isInt16 should return false if < -32768."); - EXPECT(IntUtil::isInt16(32768) == false, - "IntUtil::isInt16 should return false if > 32767."); + INFO("IntUtil::isUInt8()."); + EXPECT(IntUtil::isUInt8(255) == true, + "IntUtil::isUInt8<> should return true if inside."); + EXPECT(IntUtil::isUInt8(256) == false, + "IntUtil::isUInt8<> should return false if outside."); + EXPECT(IntUtil::isUInt8(-1) == false, + "IntUtil::isUInt8<> should return false if negative."); - EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0x100000000)) == false, + INFO("IntUtil::isInt16()."); + EXPECT(IntUtil::isInt16(-32768) == true, + "IntUtil::isInt16<> should return true if inside."); + EXPECT(IntUtil::isInt16(32767) == true, + "IntUtil::isInt16<> should return true if inside."); + EXPECT(IntUtil::isInt16(-32769) == false, + "IntUtil::isInt16<> should return false if outside."); + EXPECT(IntUtil::isInt16(32768) == false, + "IntUtil::isInt16<> should return false if outside."); + + INFO("IntUtil::isUInt16()."); + EXPECT(IntUtil::isUInt16(65535) == true, + "IntUtil::isUInt16<> should return true if inside."); + EXPECT(IntUtil::isUInt16(65536) == false, + "IntUtil::isUInt16<> should return false if outside."); + EXPECT(IntUtil::isUInt16(-1) == false, + "IntUtil::isUInt16<> should return false if negative."); + + INFO("IntUtil::isInt32()."); + EXPECT(IntUtil::isInt32(2147483647) == true, + "IntUtil::isInt32 should return true if inside."); + EXPECT(IntUtil::isInt32(-2147483647 - 1) == true, + "IntUtil::isInt32 should return true if inside."); + EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(2147483648)) == false, "IntUtil::isInt32 should return false if outside."); - EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0x100000000)) == false, + EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0xFFFFFFFF)) == false, "IntUtil::isInt32 should return false if outside."); + EXPECT(IntUtil::isInt32(ASMJIT_UINT64_C(0xFFFFFFFF) + 1) == false, + "IntUtil::isInt32 should return false if outside."); + + INFO("IntUtil::isUInt32()."); + EXPECT(IntUtil::isUInt32(ASMJIT_UINT64_C(0xFFFFFFFF)) == true, + "IntUtil::isUInt32 should return true if inside."); + EXPECT(IntUtil::isUInt32(ASMJIT_UINT64_C(0xFFFFFFFF) + 1) == false, + "IntUtil::isUInt32 should return false if outside."); + EXPECT(IntUtil::isUInt32(-1) == false, + "IntUtil::isUInt32 should return false if negative."); INFO("IntUtil::isPower2()."); for (i = 0; i < 64; i++) { diff --git a/src/asmjit/base/intutil.h b/src/asmjit/base/intutil.h index 4214d4b..fe56479 100644 --- a/src/asmjit/base/intutil.h +++ b/src/asmjit/base/intutil.h @@ -184,7 +184,7 @@ struct IntUtil { template static ASMJIT_INLINE bool isInt32(T x) { if (IntTraits::kIsSigned) - return sizeof(T) <= sizeof(int32_t) ? true : x >= T(-32768) && x <= T(32767); + return sizeof(T) <= sizeof(int32_t) ? true : x >= T(-2147483647) - 1 && x <= T(2147483647); else return x >= T(0) && (sizeof(T) <= sizeof(int32_t) ? true : x <= T(2147483647)); } diff --git a/src/asmjit/base/operand.h b/src/asmjit/base/operand.h index 3dd11b3..426a04c 100644 --- a/src/asmjit/base/operand.h +++ b/src/asmjit/base/operand.h @@ -726,6 +726,7 @@ struct BaseMem : public Operand { // [asmjit::BaseVar] // ============================================================================ +#if !defined(ASMJIT_DISABLE_COMPILER) //! Base class for all variables. struct BaseVar : public Operand { // -------------------------------------------------------------------------- @@ -763,6 +764,7 @@ struct BaseVar : public Operand { ASMJIT_INLINE bool operator==(const BaseVar& other) const { return _packed[0] == other._packed[0]; } ASMJIT_INLINE bool operator!=(const BaseVar& other) const { return !operator==(other); } }; +#endif // !ASMJIT_DISABLE_COMPILER // ============================================================================ // [asmjit::Imm] diff --git a/src/asmjit/build.h b/src/asmjit/build.h index 924335d..04ef205 100644 --- a/src/asmjit/build.h +++ b/src/asmjit/build.h @@ -31,6 +31,14 @@ // [Dependencies - C++] #include +// ============================================================================ +// [asmjit::build - Sanity] +// ============================================================================ + +#if defined(ASMJIT_DISABLE_INST_NAMES) && !defined(ASMJIT_DISABLE_LOGGER) +# error "ASMJIT_DISABLE_INST_NAMES requires ASMJIT_DISABLE_LOGGER to be defined." +#endif // ASMJIT_DISABLE_INST_NAMES && !ASMJIT_DISABLE_LOGGER + // ============================================================================ // [asmjit::build - OS] // ============================================================================ diff --git a/src/asmjit/config.h b/src/asmjit/config.h index 9f4d543..cc7351c 100644 --- a/src/asmjit/config.h +++ b/src/asmjit/config.h @@ -18,15 +18,15 @@ // [AsmJit - Debugging] // ============================================================================ -// #define ASMJIT_DEBUG // Define to enable debug-mode. -// #define ASMJIT_RELEASE // Define to enable release-mode. +// #define ASMJIT_DEBUG // Define to enable debug-mode. +// #define ASMJIT_RELEASE // Define to enable release-mode. // ============================================================================ // [AsmJit - Library] // ============================================================================ -// #define ASMJIT_EMBED // Asmjit is embedded (implies ASMJIT_STATIC). -// #define ASMJIT_STATIC // Define to enable static-library build. +// #define ASMJIT_EMBED // Asmjit is embedded (implies ASMJIT_STATIC). +// #define ASMJIT_STATIC // Define to enable static-library build. // ============================================================================ // [AsmJit - Features] @@ -34,12 +34,13 @@ // If none of these is defined AsmJit will select host architecture by default. -// #define ASMJIT_BUILD_X86 // Define to enable x86 instruction set (32-bit). -// #define ASMJIT_BUILD_X64 // Define to enable x64 instruction set (64-bit). -// #define ASMJIT_BUILD_HOST // Define to enable host instruction set. +// #define ASMJIT_BUILD_X86 // Define to enable x86 instruction set (32-bit). +// #define ASMJIT_BUILD_X64 // Define to enable x64 instruction set (64-bit). +// #define ASMJIT_BUILD_HOST // Define to enable host instruction set. -// #define ASMJIT_DISABLE_COMPILER // Disable Compiler. -// #define ASMJIT_DISABLE_LOGGER // Disable Logger (completely). +// #define ASMJIT_DISABLE_COMPILER // Disable Compiler. +// #define ASMJIT_DISABLE_LOGGER // Disable Logger (completely). +// #define ASMJIT_DISABLE_INST_NAMES // Disable Instruction names (and API). // [Guard] #endif // _ASMJIT_CONFIG_H diff --git a/src/asmjit/contrib/winremoteruntime.cpp b/src/asmjit/contrib/winremoteruntime.cpp index 927625c..8d62f35 100644 --- a/src/asmjit/contrib/winremoteruntime.cpp +++ b/src/asmjit/contrib/winremoteruntime.cpp @@ -44,7 +44,7 @@ uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) { } // Allocate temporary memory where the code will be stored and relocated. - void* codeData = ::malloc(codeSize); + void* codeData = ASMJIT_ALLOC(codeSize); if (codeData == NULL) { *dest = NULL; @@ -55,7 +55,7 @@ uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) { void* processMemPtr = _memMgr.alloc(codeSize, kVMemAllocPermanent); if (processMemPtr == NULL) { - ::free(codeData); + ASMJIT_FREE(codeData); *dest = NULL; return kErrorNoVirtualMemory; } @@ -64,7 +64,7 @@ uint32_t WinRemoteRuntime::add(void** dest, BaseAssembler* assembler) { assembler->relocCode(codeData, (uintptr_t)processMemPtr); ::WriteProcessMemory(getProcessHandle(), processMemPtr, codeData, codeSize, NULL); - ::free(codeData); + ASMJIT_FREE(codeData); *dest = processMemPtr; return kErrorOk; diff --git a/src/asmjit/test/main.cpp b/src/asmjit/test/main.cpp index 4b13b8e..7157dc9 100644 --- a/src/asmjit/test/main.cpp +++ b/src/asmjit/test/main.cpp @@ -130,7 +130,6 @@ static void dumpSizeOf() { INFO("SizeOf Base:"); DUMP_SIZE(asmjit::CodeGen); DUMP_SIZE(asmjit::ConstPool); - DUMP_SIZE(asmjit::Logger); DUMP_SIZE(asmjit::Runtime); DUMP_SIZE(asmjit::Zone); INFO(""); @@ -150,6 +149,7 @@ static void dumpSizeOf() { DUMP_SIZE(asmjit::RelocData); INFO(""); +#if !defined(ASMJIT_DISABLE_COMPILER) INFO("SizeOf Compiler:"); DUMP_SIZE(asmjit::BaseCompiler); DUMP_SIZE(asmjit::Node); @@ -170,6 +170,7 @@ static void dumpSizeOf() { DUMP_SIZE(asmjit::BaseVarInst); DUMP_SIZE(asmjit::BaseVarState); INFO(""); +#endif // !ASMJIT_DISABLE_COMPILER // -------------------------------------------------------------------------- // [X86/X64] diff --git a/src/asmjit/x86/x86inst.cpp b/src/asmjit/x86/x86inst.cpp index 6124fd3..01aa912 100644 --- a/src/asmjit/x86/x86inst.cpp +++ b/src/asmjit/x86/x86inst.cpp @@ -24,6 +24,7 @@ namespace x86x64 { // [asmjit::x86x64::Inst] // ============================================================================ +#if !defined(ASMJIT_DISABLE_INST_NAMES) // Autogenerated by src-gendefs.js: // // ${kInstData:Begin} @@ -2127,9 +2128,16 @@ enum kInstData_NameIndex { kInstXorps_NameIndex = 8133 }; // ${kInstData:End} +#endif // !ASMJIT_DISABLE_INST_NAMES + +#if !defined(ASMJIT_DISABLE_INST_NAMES) +# define INST_NAME_INDEX(_Code_) _Code_##_NameIndex +#else +# define INST_NAME_INDEX(_Code_) 0 +#endif #define INST(_Code_, _Name_, _Group_, _Flags_, _MoveSize_, _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_, _OpCode0_, _OpCode1_) \ - { _Code_##_NameIndex, _Flags_, _Group_, _MoveSize_, { 0, 0 }, { _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_ }, { _OpCode0_, _OpCode1_ } } + { INST_NAME_INDEX(_Code_), _Flags_, _Group_, _MoveSize_, { 0, 0 }, { _OpFlags0_, _OpFlags1_, _OpFlags2_, _OpFlags3_ }, { _OpCode0_, _OpCode1_ } } #define G(_Group_) kInstGroup##_Group_ #define F(_Flags_) kInstFlag##_Flags_ @@ -3247,6 +3255,7 @@ const InstInfo _instInfo[] = { // [asmjit::x86x64::X86Util] // ============================================================================ +#if !defined(ASMJIT_DISABLE_INST_NAMES) // Compare two instruction names. // // `a` is null terminated instruction name from `_instName[]` table. @@ -3323,12 +3332,13 @@ uint32_t X86InstUtil::getInstIdByName(const char* name, size_t len) { return kInstNone; } +#endif // ASMJIT_DISABLE_INST_NAMES // ============================================================================ // [asmjit::x86x64::X86Util - Test] // ============================================================================ -#if defined(ASMJIT_TEST) +#if defined(ASMJIT_TEST) && !defined(ASMJIT_DISABLE_INST_NAMES) UNIT(x86_inst_name) { // All known instructions should be matched. for (uint32_t a = 0; a < _kInstCount; a++) { @@ -3353,7 +3363,7 @@ UNIT(x86_inst_name) { EXPECT(X86InstUtil::getInstIdByName("123xyz") == kInstNone, "Should return kInstNone for unknown instruction."); } -#endif // ASMJIT_TEST +#endif // ASMJIT_TEST && !ASMJIT_DISABLE_INST_NAMES } // x86x64 namespace } // asmjit namespace diff --git a/src/asmjit/x86/x86inst.h b/src/asmjit/x86/x86inst.h index 8eb0f98..91b3c92 100644 --- a/src/asmjit/x86/x86inst.h +++ b/src/asmjit/x86/x86inst.h @@ -35,10 +35,12 @@ struct InstInfo; // [asmjit::x86x64::Inst/Cond - Globals] // ============================================================================ +#if !defined(ASMJIT_DISABLE_INST_NAMES) //! \internal //! //! X86/X64 instructions' names. ASMJIT_VAR const char _instName[]; +#endif // !ASMJIT_DISABLE_INST_NAMES //! \internal //! @@ -725,14 +727,14 @@ ASMJIT_ENUM(kInstCode) { kInstVfmaddps, // FMA4 kInstVfmaddsd, // FMA4 kInstVfmaddss, // FMA4 - kInstVfmaddsubpd, // FMA4 - kInstVfmaddsubps, // FMA4 kInstVfmaddsub132pd, // FMA3 kInstVfmaddsub132ps, // FMA3 kInstVfmaddsub213pd, // FMA3 kInstVfmaddsub213ps, // FMA3 kInstVfmaddsub231pd, // FMA3 kInstVfmaddsub231ps, // FMA3 + kInstVfmaddsubpd, // FMA4 + kInstVfmaddsubps, // FMA4 kInstVfmsub132pd, // FMA3 kInstVfmsub132ps, // FMA3 kInstVfmsub132sd, // FMA3 @@ -745,14 +747,14 @@ ASMJIT_ENUM(kInstCode) { kInstVfmsub231ps, // FMA3 kInstVfmsub231sd, // FMA3 kInstVfmsub231ss, // FMA3 - kInstVfmsubaddpd, // FMA4 - kInstVfmsubaddps, // FMA4 kInstVfmsubadd132pd, // FMA3 kInstVfmsubadd132ps, // FMA3 kInstVfmsubadd213pd, // FMA3 kInstVfmsubadd213ps, // FMA3 kInstVfmsubadd231pd, // FMA3 kInstVfmsubadd231ps, // FMA3 + kInstVfmsubaddpd, // FMA4 + kInstVfmsubaddps, // FMA4 kInstVfmsubpd, // FMA4 kInstVfmsubps, // FMA4 kInstVfmsubsd, // FMA4 @@ -1383,7 +1385,7 @@ ASMJIT_ENUM(kInstOpCode) { kInstOpCode_PP_66 = 0x01U << kInstOpCode_PP_Shift, kInstOpCode_PP_F3 = 0x02U << kInstOpCode_PP_Shift, kInstOpCode_PP_F2 = 0x03U << kInstOpCode_PP_Shift, - kInstOpCode_PP_9B = 0x07U << kInstOpCode_PP_Shift, //Ext/Not part of AVX. + kInstOpCode_PP_9B = 0x07U << kInstOpCode_PP_Shift, // Ext/Not part of AVX. // 'L' field in AVX/XOP instruction. kInstOpCode_L_Shift = 24, @@ -1706,6 +1708,7 @@ struct InstInfo { // [Accessors] // -------------------------------------------------------------------------- +#if !defined(ASMJIT_DISABLE_INST_NAMES) //! Get instruction name string (null terminated). ASMJIT_INLINE const char* getName() const { return _instName + static_cast(_nameIndex); @@ -1715,6 +1718,7 @@ struct InstInfo { ASMJIT_INLINE uint32_t _getNameIndex() const { return _nameIndex; } +#endif // !ASMJIT_DISABLE_INST_NAMES //! Get instruction group, see `kInstGroup`. ASMJIT_INLINE uint32_t getGroup() const { @@ -1828,6 +1832,7 @@ struct InstInfo { // ============================================================================ struct X86InstUtil { +#if !defined(ASMJIT_DISABLE_INST_NAMES) //! Get an instruction ID from a given instruction `name`. //! //! If there is an exact match the instruction id is returned, otherwise @@ -1836,6 +1841,7 @@ struct X86InstUtil { //! The given `name` doesn't have to be null-terminated if `len` is provided. ASMJIT_API static uint32_t getInstIdByName( const char* name, size_t len = kInvalidIndex); +#endif // !ASMJIT_DISABLE_INST_NAMES }; //! \} diff --git a/src/asmjit/x86/x86operand.h b/src/asmjit/x86/x86operand.h index 7d61907..1ab4306 100644 --- a/src/asmjit/x86/x86operand.h +++ b/src/asmjit/x86/x86operand.h @@ -938,7 +938,7 @@ struct X86Var : public BaseVar { // [Memory Cast] // -------------------------------------------------------------------------- - //! Cast this variable to memory operand. + //! Cast this variable to a memory operand. //! //! \note Size of operand depends on native variable type, you can use other //! variants if you want specific one.