├── .gitignore ├── CMakeLists.txt ├── COPYING ├── COPYING.AsmJit ├── README.md ├── asmjit ├── AsmJit.py ├── TODO ├── __init__.py └── asmjit.py ├── deps └── AsmJit-1.0-beta4 │ ├── AsmJit │ ├── ApiBegin.h │ ├── ApiEnd.h │ ├── AsmJit.h │ ├── Assembler.h │ ├── AssemblerX86X64.cpp │ ├── AssemblerX86X64.h │ ├── Build.h │ ├── CodeGenerator.cpp │ ├── CodeGenerator.h │ ├── Compiler.cpp │ ├── Compiler.h │ ├── CompilerX86X64.cpp │ ├── CompilerX86X64.h │ ├── Config.h │ ├── CpuInfo.cpp │ ├── CpuInfo.h │ ├── Defs.cpp │ ├── Defs.h │ ├── DefsX86X64.cpp │ ├── DefsX86X64.h │ ├── Logger.cpp │ ├── Logger.h │ ├── MemoryManager.cpp │ ├── MemoryManager.h │ ├── MemoryMarker.cpp │ ├── MemoryMarker.h │ ├── Operand.h │ ├── OperandX86X64.cpp │ ├── OperandX86X64.h │ ├── Platform.cpp │ ├── Platform.h │ ├── Regenerate.py │ ├── Util.cpp │ ├── Util.h │ └── Util_p.h │ ├── Build │ ├── CMakeFiles │ │ ├── CMakeDirectoryInformation.cmake │ │ ├── Makefile.cmake │ │ ├── Makefile2 │ │ ├── TargetDirectories.txt │ │ └── progress.marks │ ├── Makefile │ └── cmake_install.cmake │ ├── CHANGELOG.txt │ ├── CMakeLists.txt │ ├── COPYING.txt │ ├── Documentation │ ├── Doxygen.conf │ └── Doxygen.css │ ├── README.txt │ ├── Test │ ├── testcorecpu.cpp │ ├── testcoresize.cpp │ ├── testdummy.cpp │ ├── testfuncalign.cpp │ ├── testfunccall1.cpp │ ├── testfunccall2.cpp │ ├── testfunccall3.cpp │ ├── testfuncmanyargs.cpp │ ├── testfuncmemcpy.cpp │ ├── testfuncrecursive1.cpp │ ├── testfuncret.cpp │ ├── testjit.cpp │ ├── testjump1.cpp │ ├── testmem1.cpp │ ├── testopcode.cpp │ ├── testspecial1.cpp │ ├── testspecial2.cpp │ ├── testspecial3.cpp │ ├── testspecial4.cpp │ ├── testtrampoline.cpp │ ├── testvar2.cpp │ ├── testvar3.cpp │ ├── testvar4.cpp │ └── testvar5.cpp │ └── Util │ ├── code-fix.py │ ├── configure-borland-dbg.bat │ ├── configure-borland-rel.bat │ ├── configure-mac-xcode.sh │ ├── configure-unix-makefiles-dbg.sh │ ├── configure-unix-makefiles-rel.sh │ ├── configure-windows-mingw-dbg.bat │ ├── configure-windows-mingw-rel.bat │ ├── configure-windows-msvc6.bat │ ├── configure-windows-vs2005-x64.bat │ ├── configure-windows-vs2005-x86.bat │ ├── configure-windows-vs2008-x64.bat │ ├── configure-windows-vs2008-x86.bat │ ├── configure-windows-vs2010-x64.bat │ └── configure-windows-vs2010-x86.bat ├── scripts └── clean_preprocessed.pl ├── setup.cfg ├── swig ├── AsmJitLib.i ├── Compiler.i └── Defs.i └── tests ├── compilertests.py ├── extensiontests.py └── jittests.py /.gitignore: -------------------------------------------------------------------------------- 1 | CMakeCache.txt 2 | CMakeFiles 3 | Makefile 4 | cmake_install.cmake 5 | install_manifest.txt 6 | lib/* 7 | obj/* 8 | *#* 9 | *.cxx 10 | *.pyc 11 | *.so 12 | *.o -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.6) 2 | 3 | # We need SWIG 4 | FIND_PACKAGE(SWIG REQUIRED) 5 | INCLUDE(${SWIG_USE_FILE}) 6 | 7 | # Add Python 8 | FIND_PACKAGE(PythonLibs) 9 | INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH}) 10 | 11 | # Add AsmJit 12 | SET(ASMJIT_BASE ${CMAKE_CURRENT_SOURCE_DIR}/deps/AsmJit-1.0-beta4) 13 | SET(ASMJIT_DIR ${ASMJIT_BASE}/AsmJit) 14 | # AsmJit sources 15 | SET(ASMJIT_SOURCES 16 | ${ASMJIT_DIR}/AssemblerX86X64.cpp 17 | ${ASMJIT_DIR}/CodeGenerator.cpp 18 | ${ASMJIT_DIR}/Compiler.cpp 19 | ${ASMJIT_DIR}/CompilerX86X64.cpp 20 | ${ASMJIT_DIR}/CpuInfo.cpp 21 | ${ASMJIT_DIR}/Defs.cpp 22 | ${ASMJIT_DIR}/DefsX86X64.cpp 23 | ${ASMJIT_DIR}/Logger.cpp 24 | ${ASMJIT_DIR}/MemoryManager.cpp 25 | ${ASMJIT_DIR}/MemoryMarker.cpp 26 | ${ASMJIT_DIR}/OperandX86X64.cpp 27 | ${ASMJIT_DIR}/Platform.cpp 28 | ${ASMJIT_DIR}/Util.cpp 29 | ) 30 | 31 | # AsmJit C++ headers 32 | SET(ASMJIT_HEADERS 33 | ${ASMJIT_DIR}/ApiBegin.h 34 | ${ASMJIT_DIR}/ApiEnd.h 35 | ${ASMJIT_DIR}/AsmJit.h 36 | ${ASMJIT_DIR}/Assembler.h 37 | ${ASMJIT_DIR}/AssemblerX86X64.h 38 | ${ASMJIT_DIR}/Build.h 39 | ${ASMJIT_DIR}/CodeGenerator.h 40 | ${ASMJIT_DIR}/Compiler.h 41 | ${ASMJIT_DIR}/CompilerX86X64.h 42 | ${ASMJIT_DIR}/Config.h 43 | ${ASMJIT_DIR}/CpuInfo.h 44 | ${ASMJIT_DIR}/Defs.h 45 | ${ASMJIT_DIR}/DefsX86X64.h 46 | ${ASMJIT_DIR}/Logger.h 47 | ${ASMJIT_DIR}/MemoryManager.h 48 | ${ASMJIT_DIR}/MemoryMarker.h 49 | ${ASMJIT_DIR}/Operand.h 50 | ${ASMJIT_DIR}/OperandX86X64.h 51 | ${ASMJIT_DIR}/Platform.h 52 | ${ASMJIT_DIR}/Util.h 53 | ${ASMJIT_DIR}/Util_p.h 54 | ) 55 | INCLUDE_DIRECTORIES(${ASMJIT_BASE}) 56 | 57 | # Setup output directories 58 | SET(LIBRARY_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/lib) 59 | SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/bin) 60 | 61 | SET(CMAKE_SWIG_FLAGS "") 62 | SET(CMAKE_SWIG_OUTDIR "lib") 63 | SET_SOURCE_FILES_PROPERTIES(swig/AsmJitLib.i PROPERTIES CPLUSPLUS ON) 64 | SET_SOURCE_FILES_PROPERTIES(swig/AsmJitLib.i SWIG_FLAGS "-includeall") 65 | SWIG_ADD_MODULE(AsmJitLib python swig/AsmJitLib.i ${ASMJIT_SOURCES}) 66 | SWIG_LINK_LIBRARIES(AsmJitLib ${PYTHON_LIBRARIES}) 67 | 68 | 69 | -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | AsmJit Python Bindings 2 | Please see COPYING.AsmJit for the AsmJit licensing 3 | Copyright (c) 2012, Falaina 4 | 5 | This software is provided 'as-is', without any express or implied 6 | warranty. In no event will the authors be held liable for any damages 7 | arising from the use of this software. 8 | 9 | Permission is granted to anyone to use this software for any purpose, 10 | including commercial applications, and to alter it and redistribute it 11 | freely, subject to the following restrictions: 12 | 13 | 1. The origin of this software must not be misrepresented; you must not 14 | claim that you wrote the original software. If you use this software 15 | in a product, an acknowledgment in the product documentation would be 16 | appreciated but is not required. 17 | 2. Altered source versions must be plainly marked as such, and must not be 18 | misrepresented as being the original software. 19 | 3. This notice may not be removed or altered from any source distribution. 20 | -------------------------------------------------------------------------------- /COPYING.AsmJit: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2012, Petr Kobalicek 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Simple Python wrapper for AsmJit using SWIG. 2 | 3 | Thanks to Petr Kobalicek and the AsmJit developers for this wonderful library! 4 | 5 | asmjit homepage: http://code.google.com/p/asmjit/ -------------------------------------------------------------------------------- /asmjit/AsmJit.py: -------------------------------------------------------------------------------- 1 | ../lib/AsmJit.py -------------------------------------------------------------------------------- /asmjit/TODO: -------------------------------------------------------------------------------- 1 | # -*- mode: org -*- 2 | * Immediate 3 | ** TODO asmjit.py:125 4 | Make a push buffer 5 | -------------------------------------------------------------------------------- /asmjit/__init__.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os, os.path as path 3 | 4 | # Setup the path to the lib while developing 5 | MODULE_DIR = path.dirname(__file__) 6 | AsmJit_path = path.join(MODULE_DIR, '..', 'lib') 7 | __path__.append(AsmJit_path) 8 | from asmjit import * 9 | 10 | _ALL_ = asmjit._ALL_ 11 | 12 | -------------------------------------------------------------------------------- /asmjit/asmjit.py: -------------------------------------------------------------------------------- 1 | import AsmJit 2 | import array 3 | from ctypes import POINTER, pointer, c_uint8, c_uint32, create_string_buffer, cast, addressof, CFUNCTYPE, c_int, c_char, memmove 4 | from binascii import hexlify 5 | import sys 6 | import logging 7 | logging.basicConfig(format='%(asctime)-15s %(message)s') 8 | log = logging.getLogger('asmjit') 9 | logging.getLogger().setLevel(logging.INFO) 10 | log.setLevel(logging.INFO) 11 | __pychecker__ = 'unusednames=_ALL_' 12 | 13 | try: 14 | import platform 15 | arch = platform.architecture() 16 | assert arch[0] == '32bit', 'asmjit Python bindings only work on 32-bit x86' 17 | except ImportError: 18 | sys.stderr.write('Unable to determine system platform\n') 19 | raise 20 | 21 | # TODO: x86-64 22 | TRAMPOLINE_SIZE = 2 + 4 + 4 # JMP Instruction(2), Indirect Address(4), Direct Address(4) 23 | 24 | # Some private globals 25 | _JMP_INSTN = 'JMP' 26 | _CALL_INSTN = 'CALL' 27 | 28 | # Bring reg names into global namespace 29 | _REGS_ = ['eax', 'ecx', 'edx', 'ebx', 'esp', 'ebp', 'edi', 'esi'] 30 | # Functions worth exporting directly to importers 31 | _FUNCS_ = ['AbsPtr', 'imm', 'uimm', 'GPVar', 'UIntFunctionBuilder0'] 32 | _GLOBALS_ = ['CALL_CONV_DEFAULT'] 33 | _MODULE_ = sys.modules[__name__] 34 | for reg in (_REGS_ + _FUNCS_ + _GLOBALS_): 35 | setattr(_MODULE_, reg, getattr(AsmJit, reg)) 36 | 37 | def MakeIntPtr(num): 38 | return (c_int * 1).from_address(num) 39 | 40 | def MakeInt(num): 41 | return c_int(num) 42 | 43 | def MakeIntFromPtr(var): 44 | return c_int(addressof(var)) 45 | 46 | def MakeFunction(ptr, *args): 47 | """ 48 | Takes an integer that points to a function 49 | and creates a callable for that function. 50 | args contains the arguments types for the function. 51 | All functions return c_uint 52 | """ 53 | return CFUNCTYPE(c_uint32, *args)(ptr) 54 | 55 | class Code(object): 56 | """ 57 | Wrapper around the byte buffer that represents 58 | code generated by AsmJit 59 | """ 60 | def __init__(self, code, code_size, code_maxlen=20): 61 | self.ptr = int(code) 62 | self.size = code_size 63 | self.code_maxlen = code_maxlen 64 | 65 | # Create ctypes to represent the code 66 | self.code_reprtype = (c_uint8 * min(code_maxlen, code_size)) 67 | self.code_type = (c_uint8 * code_size) 68 | 69 | def toarray(self): 70 | code = self.code_type.from_address(self.ptr) 71 | return array.array('B', code) 72 | 73 | def tohex(self): 74 | return hex(self) 75 | 76 | def __hex__(self): 77 | return hexlify(self.toarray()) 78 | 79 | def __repr__(self): 80 | postfix = '' 81 | if self.size > self.code_maxlen: 82 | postfix = '...' 83 | code = self.code_reprtype.from_address(self.ptr) 84 | return 'Code - ' + repr(array.array('B', code)) + postfix 85 | 86 | class LibWrapper(object): 87 | def __init__(self, base): 88 | self.base = base 89 | 90 | def __getattr__(self, attr): 91 | if attr not in self.__dict__: 92 | return getattr(self.base, attr) 93 | return self.__dict__[attr] 94 | 95 | class Assembler(LibWrapper): 96 | """ 97 | Wrapper around AsmJit.Assembler 98 | """ 99 | def __init__(self): 100 | self.assembler = AsmJit.Assembler() 101 | super(Assembler, self).__init__(self.assembler) 102 | 103 | def __repr__(self): 104 | return 'Assembler - ' + repr(self.code) 105 | 106 | def __hex__(self): 107 | return hex(self.code) 108 | 109 | def toarray(self): 110 | return self.code.toarray() 111 | 112 | def _py_emit_call_or_jmp(self, dest, instn): 113 | __pychecker__ = 'no-classattr' 114 | 115 | if instn == _JMP_INSTN: 116 | opcode2 = 0x25 117 | elif instn == _CALL_INSTN: 118 | opcode2 = 0x15 119 | else: 120 | raise ValueError, 'Unsupported instn %x' % (instn,) 121 | 122 | self._emitByte(0xFF) 123 | self._emitByte(opcode2) 124 | self._emitDWord(int(self.getCode()) + 6) 125 | self._emitDWord(dest) 126 | 127 | def py_make_cfunc(self): 128 | return MakeFunction(self.py_make()) 129 | 130 | def py_make(self): 131 | return int(self.make()) 132 | 133 | def py_call(self, dest): 134 | raise NotImplementedError 135 | 136 | def py_jmp(self, dest): 137 | return self._py_emit_call_or_jmp(dest, _JMP_INSTN) 138 | 139 | @property 140 | def code(self): 141 | c = Code(self.getCode(), self.getCodeSize()) 142 | return c 143 | 144 | class Compiler(LibWrapper): 145 | """ 146 | Wrapper around AsmJit.Compiler 147 | """ 148 | def __init__(self): 149 | self.compiler = AsmJit.Compiler() 150 | super(Compiler, self).__init__(self.compiler) 151 | def DerefUInt32(p): 152 | return c_uint32.from_address(p).value 153 | 154 | # Exports from this module 155 | _EXPORTS_ = ['AsmJit', 'DerefUInt32', 'MakeFunction', 'MakeIntPtr', 'TRAMPOLINE_SIZE'] 156 | 157 | # Give importers a direct reference to underlying AsmJit 158 | _ALL_ = _EXPORTS_ + _REGS_ + _FUNCS_ 159 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/ApiBegin.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // MSVC 8 | #if defined(_MSC_VER) 9 | 10 | // Disable some warnings we know about 11 | #pragma warning(push) 12 | #pragma warning(disable: 4127) // conditional expression is constant 13 | #pragma warning(disable: 4251) // struct needs to have dll-interface to be used 14 | // by clients of struct ... 15 | #pragma warning(disable: 4275) // non dll-interface struct ... used as base for 16 | // dll-interface struct 17 | #pragma warning(disable: 4355) // this used in base member initializer list 18 | #pragma warning(disable: 4800) // forcing value to bool 'true' or 'false' 19 | 20 | // Rename symbols. 21 | #define vsnprintf _vsnprintf 22 | #define snprintf _snprintf 23 | 24 | #endif // _MSC_VER 25 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/ApiEnd.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | #if defined(_MSC_VER) 8 | 9 | // Pop disabled warnings by ApiBegin.h 10 | #pragma warning(pop) 11 | 12 | // Rename symbols back. 13 | #undef vsnprintf 14 | #undef snprintf 15 | 16 | #endif // _MSC_VER 17 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Assembler.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_ASSEMBLER_H 9 | #define _ASMJIT_ASSEMBLER_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | 14 | namespace AsmJit { 15 | 16 | // ============================================================================ 17 | // [Forward Declarations] 18 | // ============================================================================ 19 | 20 | struct Logger; 21 | struct MemoryManager; 22 | struct EInstruction; 23 | 24 | } // AsmJit namespace 25 | 26 | // ============================================================================ 27 | // [Platform Specific] 28 | // ============================================================================ 29 | 30 | // [X86 / X64] 31 | #if defined(ASMJIT_X86) || defined(ASMJIT_X64) 32 | #include "AssemblerX86X64.h" 33 | #endif // ASMJIT_X86 || ASMJIT_X64 34 | 35 | // [Guard] 36 | #endif // _ASMJIT_ASSEMBLER_H 37 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Build.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_BUILD_H 9 | #define _ASMJIT_BUILD_H 10 | 11 | // [Include] 12 | #include "Config.h" 13 | 14 | // Here should be optional include files that's needed fo successfuly 15 | // use macros defined here. Remember, AsmJit uses only AsmJit namespace 16 | // and all macros are used within it. 17 | #include 18 | #include 19 | 20 | // ---------------------------------------------------------------------------- 21 | // [AsmJit - OS] 22 | // ---------------------------------------------------------------------------- 23 | 24 | #if defined(WINDOWS) || defined(__WINDOWS__) || defined(_WIN32) || defined(_WIN64) 25 | # define ASMJIT_WINDOWS 26 | #elif defined(__linux__) || defined(__unix__) || \ 27 | defined(__OpenBSD__) || defined(__FreeBSD__) || defined(__NetBSD__) || \ 28 | defined(__DragonFly__) || defined(__BSD__) || defined(__FREEBSD__) || \ 29 | defined(__APPLE__) 30 | # define ASMJIT_POSIX 31 | #else 32 | # warning "AsmJit - Can't match operating system, using ASMJIT_POSIX" 33 | # define ASMJIT_POSIX 34 | #endif 35 | 36 | // ---------------------------------------------------------------------------- 37 | // [AsmJit - Architecture] 38 | // ---------------------------------------------------------------------------- 39 | 40 | // define it only if it's not defined. In some systems we can 41 | // use -D command in compiler to bypass this autodetection. 42 | #if !defined(ASMJIT_X86) && !defined(ASMJIT_X64) 43 | # if defined(__x86_64__) || defined(__LP64) || defined(__IA64__) || \ 44 | defined(_M_X64) || defined(_WIN64) 45 | # define ASMJIT_X64 // x86-64 46 | # else 47 | // _M_IX86, __INTEL__, __i386__ 48 | # define ASMJIT_X86 49 | # endif 50 | #endif 51 | 52 | // ---------------------------------------------------------------------------- 53 | // [AsmJit - API] 54 | // ---------------------------------------------------------------------------- 55 | 56 | // Hide AsmJit symbols that we don't want to export (AssemblerIntrinsics class for example). 57 | #if !defined(ASMJIT_HIDDEN) 58 | # if defined(__GNUC__) && __GNUC__ >= 4 59 | # define ASMJIT_HIDDEN __attribute__((visibility("hidden"))) 60 | # endif // __GNUC__ && __GNUC__ >= 4 61 | #endif // ASMJIT_HIDDEN 62 | 63 | // Make AsmJit as shared library by default. 64 | #if !defined(ASMJIT_API) 65 | # if defined(ASMJIT_WINDOWS) 66 | # if defined(__GNUC__) 67 | # if defined(AsmJit_EXPORTS) 68 | # define ASMJIT_API __attribute__((dllexport)) 69 | # else 70 | # define ASMJIT_API __attribute__((dllimport)) 71 | # endif // AsmJit_EXPORTS 72 | # else 73 | # if defined(AsmJit_EXPORTS) 74 | # define ASMJIT_API __declspec(dllexport) 75 | # else 76 | # define ASMJIT_API __declspec(dllimport) 77 | # endif // AsmJit_EXPORTS 78 | # endif // __GNUC__ 79 | # else 80 | # if defined(__GNUC__) 81 | # if __GNUC__ >= 4 82 | # define ASMJIT_API __attribute__((visibility("default"))) 83 | # define ASMJIT_VAR extern ASMJIT_API 84 | # endif // __GNUC__ >= 4 85 | # endif // __GNUC__ 86 | # endif 87 | #endif // ASMJIT_API 88 | 89 | #if defined(ASMJIT_API) 90 | # define ASMJIT_VAR extern ASMJIT_API 91 | #else 92 | # define ASMJIT_API 93 | # define ASMJIT_VAR 94 | #endif // ASMJIT_API 95 | 96 | // If not detected, fallback to nothing. 97 | #if !defined(ASMJIT_HIDDEN) 98 | # define ASMJIT_HIDDEN 99 | #endif // ASMJIT_HIDDEN 100 | 101 | #if !defined(ASMJIT_NOTHROW) 102 | #define ASMJIT_NOTHROW throw() 103 | #endif // ASMJIT_NOTHROW 104 | 105 | // [AsmJit - Memory Management] 106 | #if !defined(ASMJIT_MALLOC) 107 | # define ASMJIT_MALLOC ::malloc 108 | #endif // ASMJIT_MALLOC 109 | 110 | #if !defined(ASMJIT_REALLOC) 111 | # define ASMJIT_REALLOC ::realloc 112 | #endif // ASMJIT_REALLOC 113 | 114 | #if !defined(ASMJIT_FREE) 115 | # define ASMJIT_FREE ::free 116 | #endif // ASMJIT_FREE 117 | 118 | // ---------------------------------------------------------------------------- 119 | // [AsmJit - Calling Conventions] 120 | // ---------------------------------------------------------------------------- 121 | 122 | #if defined(ASMJIT_X86) 123 | # if defined(__GNUC__) 124 | # define ASMJIT_REGPARM_1 __attribute__((regparm(1))) 125 | # define ASMJIT_REGPARM_2 __attribute__((regparm(2))) 126 | # define ASMJIT_REGPARM_3 __attribute__((regparm(3))) 127 | # define ASMJIT_FASTCALL __attribute__((fastcall)) 128 | # define ASMJIT_STDCALL __attribute__((stdcall)) 129 | # define ASMJIT_CDECL __attribute__((cdecl)) 130 | # else 131 | # define ASMJIT_FASTCALL __fastcall 132 | # define ASMJIT_STDCALL __stdcall 133 | # define ASMJIT_CDECL __cdecl 134 | # endif 135 | #else 136 | # define ASMJIT_FASTCALL 137 | # define ASMJIT_STDCALL 138 | # define ASMJIT_CDECL 139 | #endif // ASMJIT_X86 140 | 141 | #if !defined(ASMJIT_UNUSED) 142 | # define ASMJIT_UNUSED(var) ((void)var) 143 | #endif // ASMJIT_UNUSED 144 | 145 | #if !defined(ASMJIT_NOP) 146 | # define ASMJIT_NOP() ((void)0) 147 | #endif // ASMJIT_NOP 148 | 149 | // [AsmJit - C++ Compiler Support] 150 | #define ASMJIT_TYPE_TO_TYPE(type) type 151 | #define ASMJIT_HAS_STANDARD_DEFINE_OPTIONS 152 | #define ASMJIT_HAS_PARTIAL_TEMPLATE_SPECIALIZATION 153 | 154 | // Support for VC6 155 | #if defined(_MSC_VER) && (_MSC_VER < 1400) 156 | #undef ASMJIT_TYPE_TO_TYPE 157 | namespace AsmJit { 158 | template 159 | struct _Type2Type { typedef T Type; }; 160 | } 161 | #define ASMJIT_TYPE_TO_TYPE(T) _Type2Type::Type 162 | 163 | #undef ASMJIT_HAS_STANDARD_DEFINE_OPTIONS 164 | #undef ASMJIT_HAS_PARTIAL_TEMPLATE_SPECIALIZATION 165 | 166 | #endif 167 | 168 | // ---------------------------------------------------------------------------- 169 | // [AsmJit - Types] 170 | // ---------------------------------------------------------------------------- 171 | 172 | #if defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1600) 173 | 174 | // Use 175 | #include 176 | 177 | #else 178 | 179 | // Use typedefs. 180 | #if defined(_MSC_VER) 181 | #if (_MSC_VER < 1300) 182 | typedef char int8_t; 183 | typedef short int16_t; 184 | typedef int int32_t; 185 | typedef unsigned char uint8_t; 186 | typedef unsigned short uint16_t; 187 | typedef unsigned int uint32_t; 188 | typedef __int64 int64_t; 189 | typedef unsigned __int64 uint64_t; 190 | #else 191 | typedef __int8 int8_t; 192 | typedef __int16 int16_t; 193 | typedef __int32 int32_t; 194 | typedef __int64 int64_t; 195 | typedef unsigned __int8 uint8_t; 196 | typedef unsigned __int16 uint16_t; 197 | typedef unsigned __int32 uint32_t; 198 | typedef unsigned __int64 uint64_t; 199 | #endif 200 | #endif // _MSC_VER 201 | #endif // STDINT.H 202 | 203 | typedef unsigned char uchar; 204 | typedef unsigned short ushort; 205 | typedef unsigned int uint; 206 | typedef unsigned long ulong; 207 | 208 | #if defined(ASMJIT_X86) 209 | typedef int32_t sysint_t; 210 | typedef uint32_t sysuint_t; 211 | #else 212 | typedef int64_t sysint_t; 213 | typedef uint64_t sysuint_t; 214 | #endif 215 | 216 | #if defined(_MSC_VER) 217 | # define ASMJIT_INT64_C(num) num##i64 218 | # define ASMJIT_UINT64_C(num) num##ui64 219 | #else 220 | # define ASMJIT_INT64_C(num) num##LL 221 | # define ASMJIT_UINT64_C(num) num##ULL 222 | #endif 223 | 224 | // ---------------------------------------------------------------------------- 225 | // [AsmJit - C++ Macros] 226 | // ---------------------------------------------------------------------------- 227 | 228 | #define ASMJIT_ARRAY_SIZE(A) (sizeof(A) / sizeof(*A)) 229 | 230 | #define ASMJIT_DISABLE_COPY(__type__) \ 231 | private: \ 232 | inline __type__(const __type__& other); \ 233 | inline __type__& operator=(const __type__& other); 234 | 235 | // ---------------------------------------------------------------------------- 236 | // [AsmJit - Debug] 237 | // ---------------------------------------------------------------------------- 238 | 239 | // If ASMJIT_DEBUG and ASMJIT_NO_DEBUG is not defined then ASMJIT_DEBUG will be 240 | // detected using the compiler specific macros. This enables to set the build 241 | // type using IDE. 242 | #if !defined(ASMJIT_DEBUG) && !defined(ASMJIT_NO_DEBUG) 243 | 244 | #if defined(_DEBUG) 245 | #define ASMJIT_DEBUG 246 | #endif // _DEBUG 247 | 248 | #endif // !ASMJIT_DEBUG && !ASMJIT_NO_DEBUG 249 | 250 | // ---------------------------------------------------------------------------- 251 | // [AsmJit - Assert] 252 | // ---------------------------------------------------------------------------- 253 | 254 | namespace AsmJit { 255 | ASMJIT_API void assertionFailure(const char* file, int line, const char* exp); 256 | } // AsmJit namespace 257 | 258 | #if defined(ASMJIT_DEBUG) 259 | # if !defined(ASMJIT_ASSERT) 260 | # define ASMJIT_ASSERT(exp) do { if (!(exp)) ::AsmJit::assertionFailure(__FILE__, __LINE__, #exp); } while(0) 261 | # endif 262 | #else 263 | # if !defined(ASMJIT_ASSERT) 264 | # define ASMJIT_ASSERT(exp) ASMJIT_NOP() 265 | # endif 266 | #endif // DEBUG 267 | 268 | // GCC warnings fix: I can't understand why GCC has no interface to push/pop 269 | // specific warnings. 270 | // #if defined(__GNUC__) 271 | // # if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 402001 272 | // # pragma GCC diagnostic ignored "-w" 273 | // # endif 274 | // #endif // __GNUC__ 275 | 276 | // ---------------------------------------------------------------------------- 277 | // [AsmJit - OS Support] 278 | // ---------------------------------------------------------------------------- 279 | 280 | #if defined(ASMJIT_WINDOWS) 281 | #include 282 | #endif // ASMJIT_WINDOWS 283 | 284 | // [Guard] 285 | #endif // _ASMJIT_BUILD_H 286 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/CodeGenerator.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include "Assembler.h" 9 | #include "CodeGenerator.h" 10 | #include "Defs.h" 11 | #include "MemoryManager.h" 12 | #include "MemoryMarker.h" 13 | 14 | namespace AsmJit { 15 | 16 | // ============================================================================ 17 | // [AsmJit::CodeGenerator - Construction / Destruction] 18 | // ============================================================================ 19 | 20 | CodeGenerator::CodeGenerator() 21 | { 22 | } 23 | 24 | CodeGenerator::~CodeGenerator() 25 | { 26 | } 27 | 28 | // ============================================================================ 29 | // [AsmJit::CodeGenerator - GetGlobal] 30 | // ============================================================================ 31 | 32 | JitCodeGenerator* CodeGenerator::getGlobal() 33 | { 34 | static JitCodeGenerator global; 35 | return &global; 36 | } 37 | 38 | // ============================================================================ 39 | // [AsmJit::JitCodeGenerator - Construction / Destruction] 40 | // ============================================================================ 41 | 42 | JitCodeGenerator::JitCodeGenerator() : 43 | _memoryManager(NULL), 44 | _memoryMarker(NULL), 45 | _allocType(MEMORY_ALLOC_FREEABLE) 46 | { 47 | } 48 | 49 | JitCodeGenerator::~JitCodeGenerator() 50 | { 51 | } 52 | 53 | // ============================================================================ 54 | // [AsmJit::JitCodeGenerator - Generate] 55 | // ============================================================================ 56 | 57 | uint32_t JitCodeGenerator::generate(void** dest, Assembler* assembler) 58 | { 59 | // Disallow empty code generation. 60 | sysuint_t codeSize = assembler->getCodeSize(); 61 | if (codeSize == 0) 62 | { 63 | *dest = NULL; 64 | return AsmJit::ERROR_NO_FUNCTION; 65 | } 66 | 67 | // Switch to global memory manager if not provided. 68 | MemoryManager* memmgr = getMemoryManager(); 69 | 70 | if (memmgr == NULL) 71 | { 72 | memmgr = MemoryManager::getGlobal(); 73 | } 74 | 75 | void* p = memmgr->alloc(codeSize, getAllocType()); 76 | if (p == NULL) 77 | { 78 | *dest = NULL; 79 | return ERROR_NO_VIRTUAL_MEMORY; 80 | } 81 | 82 | // Relocate the code. 83 | sysuint_t relocatedSize = assembler->relocCode(p); 84 | 85 | // Return unused memory to MemoryManager. 86 | if (relocatedSize < codeSize) 87 | { 88 | memmgr->shrink(p, relocatedSize); 89 | } 90 | 91 | // Mark memory if MemoryMarker provided. 92 | if (_memoryMarker) 93 | { 94 | _memoryMarker->mark(p, relocatedSize); 95 | } 96 | 97 | // Return the code. 98 | *dest = p; 99 | return ERROR_NONE; 100 | } 101 | 102 | } // AsmJit namespace 103 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/CodeGenerator.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_CODEGENERATOR_H 9 | #define _ASMJIT_CODEGENERATOR_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | 14 | namespace AsmJit { 15 | 16 | // ============================================================================ 17 | // [Forward Declarations] 18 | // ============================================================================ 19 | 20 | struct Assembler; 21 | struct JitCodeGenerator; 22 | struct MemoryManager; 23 | struct MemoryMarker; 24 | 25 | // ============================================================================ 26 | // [AsmJit::CodeGenerator] 27 | // ============================================================================ 28 | 29 | //! @brief Code generator is core class for changing behavior of code generated 30 | //! by @c Assembler or @c Compiler. 31 | struct ASMJIT_API CodeGenerator 32 | { 33 | // -------------------------------------------------------------------------- 34 | // [Construction / Destruction] 35 | // -------------------------------------------------------------------------- 36 | 37 | //! @brief Create a @c CodeGenerator instance. 38 | CodeGenerator(); 39 | //! @brief Destroy the @c CodeGenerator instance. 40 | virtual ~CodeGenerator(); 41 | 42 | // -------------------------------------------------------------------------- 43 | // [Interface] 44 | // -------------------------------------------------------------------------- 45 | 46 | //! @brief Allocate memory for code generated in @a assembler and reloc it 47 | //! to target location. 48 | //! 49 | //! This method is universal allowing any pre-process / post-process work 50 | //! with code generated by @c Assembler or @c Compiler. Because @c Compiler 51 | //! always uses @c Assembler it's allowed to access only the @c Assembler 52 | //! instance. 53 | //! 54 | //! This method is always last step when using code generation. You can use 55 | //! it to allocate memory for JIT code, saving code to remote process or a 56 | //! shared library. 57 | //! 58 | //! @retrurn Error value, see @c ERROR_CODE. 59 | virtual uint32_t generate(void** dest, Assembler* assembler) = 0; 60 | 61 | // -------------------------------------------------------------------------- 62 | // [Statics] 63 | // -------------------------------------------------------------------------- 64 | 65 | static JitCodeGenerator* getGlobal(); 66 | 67 | private: 68 | ASMJIT_DISABLE_COPY(CodeGenerator) 69 | }; 70 | 71 | // ============================================================================ 72 | // [AsmJit::JitCodeGenerator] 73 | // ============================================================================ 74 | 75 | struct JitCodeGenerator : public CodeGenerator 76 | { 77 | // -------------------------------------------------------------------------- 78 | // [Construction / Destruction] 79 | // -------------------------------------------------------------------------- 80 | 81 | //! @brief Create a @c JitCodeGenerator instance. 82 | JitCodeGenerator(); 83 | //! @brief Destroy the @c JitCodeGenerator instance. 84 | virtual ~JitCodeGenerator(); 85 | 86 | // -------------------------------------------------------------------------- 87 | // [Memory Manager and Alloc Type] 88 | // -------------------------------------------------------------------------- 89 | 90 | // Note: These members can be ignored by all derived classes. They are here 91 | // only to privide default implementation. All other implementations (remote 92 | // code patching or making dynamic loadable libraries/executables) ignore 93 | // members accessed by these accessors. 94 | 95 | //! @brief Get the @c MemoryManager instance. 96 | inline MemoryManager* getMemoryManager() const { return _memoryManager; } 97 | //! @brief Set the @c MemoryManager instance. 98 | inline void setMemoryManager(MemoryManager* memoryManager) { _memoryManager = memoryManager; } 99 | 100 | //! @brief Get the type of allocation. 101 | inline uint32_t getAllocType() const { return _allocType; } 102 | //! @brief Set the type of allocation. 103 | inline void setAllocType(uint32_t allocType) { _allocType = allocType; } 104 | 105 | // -------------------------------------------------------------------------- 106 | // [Memory Marker] 107 | // -------------------------------------------------------------------------- 108 | 109 | //! @brief Get the @c MemoryMarker instance. 110 | inline MemoryMarker* getMemoryMarker() const { return _memoryMarker; } 111 | //! @brief Set the @c MemoryMarker instance. 112 | inline void setMemoryMarker(MemoryMarker* memoryMarker) { _memoryMarker = memoryMarker; } 113 | 114 | // -------------------------------------------------------------------------- 115 | // [Interface] 116 | // -------------------------------------------------------------------------- 117 | 118 | virtual uint32_t generate(void** dest, Assembler* assembler); 119 | 120 | // -------------------------------------------------------------------------- 121 | // [Members] 122 | // -------------------------------------------------------------------------- 123 | 124 | protected: 125 | //! @brief Memory manager. 126 | MemoryManager* _memoryManager; 127 | //! @brief Memory marker. 128 | MemoryMarker* _memoryMarker; 129 | 130 | //! @brief Type of allocation. 131 | uint32_t _allocType; 132 | 133 | private: 134 | ASMJIT_DISABLE_COPY(JitCodeGenerator) 135 | }; 136 | 137 | } // AsmJit namespace 138 | 139 | // [Guard] 140 | #endif // _ASMJIT_CODEGENERATOR_H 141 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Compiler.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // We are using sprintf() here. 8 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) 9 | #define _CRT_SECURE_NO_WARNINGS 10 | #endif // _MSC_VER 11 | 12 | // [Dependencies] 13 | #include "Assembler.h" 14 | #include "Compiler.h" 15 | #include "CpuInfo.h" 16 | #include "Logger.h" 17 | #include "Util.h" 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | // [Api-Begin] 24 | #include "ApiBegin.h" 25 | 26 | namespace AsmJit { 27 | 28 | // ============================================================================ 29 | // [AsmJit::Emittable] 30 | // ============================================================================ 31 | 32 | Emittable::Emittable(Compiler* c, uint32_t type) ASMJIT_NOTHROW : 33 | _compiler(c), 34 | _next(NULL), 35 | _prev(NULL), 36 | _comment(NULL), 37 | _type((uint8_t)type), 38 | _translated(false), 39 | _reserved0(0), 40 | _reserved1(0), 41 | _offset(INVALID_VALUE) 42 | { 43 | } 44 | 45 | Emittable::~Emittable() ASMJIT_NOTHROW 46 | { 47 | } 48 | 49 | void Emittable::prepare(CompilerContext& cc) ASMJIT_NOTHROW 50 | { 51 | _offset = cc._currentOffset; 52 | } 53 | 54 | Emittable* Emittable::translate(CompilerContext& cc) ASMJIT_NOTHROW 55 | { 56 | return translated(); 57 | } 58 | 59 | void Emittable::emit(Assembler& a) ASMJIT_NOTHROW 60 | { 61 | } 62 | 63 | void Emittable::post(Assembler& a) ASMJIT_NOTHROW 64 | { 65 | } 66 | 67 | int Emittable::getMaxSize() const ASMJIT_NOTHROW 68 | { 69 | // Default maximum size is -1 which means that it's not known. 70 | return -1; 71 | } 72 | 73 | bool Emittable::_tryUnuseVar(VarData* v) ASMJIT_NOTHROW 74 | { 75 | return false; 76 | } 77 | 78 | void Emittable::setComment(const char* str) ASMJIT_NOTHROW 79 | { 80 | _comment = _compiler->getZone().zstrdup(str); 81 | } 82 | 83 | void Emittable::setCommentF(const char* fmt, ...) ASMJIT_NOTHROW 84 | { 85 | // I'm really not expecting larger inline comments:) 86 | char buf[256]; 87 | 88 | va_list ap; 89 | va_start(ap, fmt); 90 | vsnprintf(buf, 255, fmt, ap); 91 | va_end(ap); 92 | 93 | // I don't know if vsnprintf can produce non-null terminated string, in case 94 | // it can, we terminate it here. 95 | buf[255] = '\0'; 96 | 97 | setComment(buf); 98 | } 99 | 100 | // ============================================================================ 101 | // [AsmJit::EDummy] 102 | // ============================================================================ 103 | 104 | EDummy::EDummy(Compiler* c) ASMJIT_NOTHROW : 105 | Emittable(c, EMITTABLE_DUMMY) 106 | { 107 | } 108 | 109 | EDummy::~EDummy() ASMJIT_NOTHROW 110 | { 111 | } 112 | 113 | int EDummy::getMaxSize() const ASMJIT_NOTHROW 114 | { 115 | return 0; 116 | } 117 | 118 | // ============================================================================ 119 | // [AsmJit::EFunctionEnd] 120 | // ============================================================================ 121 | 122 | EFunctionEnd::EFunctionEnd(Compiler* c) ASMJIT_NOTHROW : 123 | EDummy(c) 124 | { 125 | _type = EMITTABLE_FUNCTION_END; 126 | } 127 | 128 | EFunctionEnd::~EFunctionEnd() ASMJIT_NOTHROW 129 | { 130 | } 131 | 132 | Emittable* EFunctionEnd::translate(CompilerContext& cc) ASMJIT_NOTHROW 133 | { 134 | _translated = true; 135 | return NULL; 136 | } 137 | 138 | // ============================================================================ 139 | // [AsmJit::EComment] 140 | // ============================================================================ 141 | 142 | EComment::EComment(Compiler* c, const char* str) ASMJIT_NOTHROW : 143 | Emittable(c, EMITTABLE_COMMENT) 144 | { 145 | setComment(str); 146 | } 147 | 148 | EComment::~EComment() ASMJIT_NOTHROW 149 | { 150 | } 151 | 152 | void EComment::emit(Assembler& a) ASMJIT_NOTHROW 153 | { 154 | if (a.getLogger()) 155 | { 156 | a.getLogger()->logString(getComment()); 157 | } 158 | } 159 | 160 | int EComment::getMaxSize() const ASMJIT_NOTHROW 161 | { 162 | return 0; 163 | } 164 | 165 | // ============================================================================ 166 | // [AsmJit::EData] 167 | // ============================================================================ 168 | 169 | EData::EData(Compiler* c, const void* data, sysuint_t length) ASMJIT_NOTHROW : 170 | Emittable(c, EMITTABLE_EMBEDDED_DATA) 171 | { 172 | _length = length; 173 | memcpy(_data, data, length); 174 | } 175 | 176 | EData::~EData() ASMJIT_NOTHROW 177 | { 178 | } 179 | 180 | void EData::emit(Assembler& a) ASMJIT_NOTHROW 181 | { 182 | a.embed(_data, _length); 183 | } 184 | 185 | int EData::getMaxSize() const ASMJIT_NOTHROW 186 | { 187 | return (int)_length;; 188 | } 189 | 190 | // ============================================================================ 191 | // [AsmJit::EAlign] 192 | // ============================================================================ 193 | 194 | EAlign::EAlign(Compiler* c, uint32_t size) ASMJIT_NOTHROW : 195 | Emittable(c, EMITTABLE_ALIGN), _size(size) 196 | { 197 | } 198 | 199 | EAlign::~EAlign() ASMJIT_NOTHROW 200 | { 201 | } 202 | 203 | void EAlign::emit(Assembler& a) ASMJIT_NOTHROW 204 | { 205 | a.align(_size); 206 | } 207 | 208 | int EAlign::getMaxSize() const ASMJIT_NOTHROW 209 | { 210 | return (_size > 0) ? (int)_size - 1 : 0; 211 | } 212 | 213 | // ============================================================================ 214 | // [AsmJit::ETarget] 215 | // ============================================================================ 216 | 217 | ETarget::ETarget(Compiler* c, const Label& label) ASMJIT_NOTHROW : 218 | Emittable(c, EMITTABLE_TARGET), 219 | _label(label), 220 | _from(NULL), 221 | _state(NULL), 222 | _jumpsCount(0) 223 | { 224 | } 225 | 226 | ETarget::~ETarget() ASMJIT_NOTHROW 227 | { 228 | } 229 | 230 | void ETarget::prepare(CompilerContext& cc) ASMJIT_NOTHROW 231 | { 232 | _offset = cc._currentOffset++; 233 | } 234 | 235 | Emittable* ETarget::translate(CompilerContext& cc) ASMJIT_NOTHROW 236 | { 237 | // If this ETarget was already translated, it's needed to change the current 238 | // state and return NULL to tell CompilerContext to process next untranslated 239 | // emittable. 240 | if (_translated) 241 | { 242 | cc._restoreState(_state); 243 | return NULL; 244 | } 245 | 246 | if (cc._unreachable) 247 | { 248 | cc._unreachable = 0; 249 | 250 | // Assign state to the compiler context. 251 | ASMJIT_ASSERT(_state != NULL); 252 | cc._assignState(_state); 253 | } 254 | else 255 | { 256 | _state = cc._saveState(); 257 | } 258 | 259 | return translated(); 260 | } 261 | 262 | void ETarget::emit(Assembler& a) ASMJIT_NOTHROW 263 | { 264 | a.bind(_label); 265 | } 266 | 267 | int ETarget::getMaxSize() const ASMJIT_NOTHROW 268 | { 269 | return 0; 270 | } 271 | 272 | } // AsmJit namespace 273 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Config.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is designed to be modifyable. Platform specific changes should 8 | // be applied to this file so it's guaranteed that never versions of AsmJit 9 | // library will never overwrite generated config files. 10 | // 11 | // So modify this file by your build system or by hand. 12 | 13 | // [Guard] 14 | #ifndef _ASMJIT_CONFIG_H 15 | #define _ASMJIT_CONFIG_H 16 | 17 | // ============================================================================ 18 | // [AsmJit - OS] 19 | // ============================================================================ 20 | 21 | // Provides definitions about your operating system. It's detected by default, 22 | // so override it if you have problems with automatic detection. 23 | // 24 | // #define ASMJIT_WINDOWS 1 25 | // #define ASMJIT_POSIX 2 26 | 27 | // ============================================================================ 28 | // [AsmJit - Architecture] 29 | // ============================================================================ 30 | 31 | // Provides definitions about your cpu architecture. It's detected by default, 32 | // so override it if you have problems with automatic detection. 33 | 34 | // #define ASMJIT_X86 35 | // #define ASMJIT_X64 36 | 37 | // ============================================================================ 38 | // [AsmJit - API] 39 | // ============================================================================ 40 | 41 | // If you are embedding AsmJit library into your project (statically), undef 42 | // ASMJIT_API macro. ASMJIT_HIDDEN macro can contain visibility (used by GCC) 43 | // to hide some AsmJit symbols that shouldn't be never exported. 44 | // 45 | // If you have problems with throw() in compilation time, undef ASMJIT_NOTHROW 46 | // to disable this feature. ASMJIT_NOTHROW marks functions that never throws 47 | // an exception. 48 | 49 | // #define ASMJIT_HIDDEN 50 | // #define ASMJIT_API 51 | // #define ASMJIT_NOTHROW 52 | 53 | 54 | // ============================================================================ 55 | // [AsmJit - Memory Management] 56 | // ============================================================================ 57 | 58 | // #define ASMJIT_MALLOC ::malloc 59 | // #define ASMJIT_REALLOC ::realloc 60 | // #define ASMJIT_FREE ::free 61 | 62 | // ============================================================================ 63 | // [AsmJit - Debug] 64 | // ============================================================================ 65 | 66 | // Turn debug on/off (to bypass autodetection) 67 | // #define ASMJIT_DEBUG 68 | // #define ASMJIT_NO_DEBUG 69 | 70 | // Setup custom assertion code. 71 | // #define ASMJIT_ASSERT(exp) do { if (!(exp)) ::AsmJit::assertionFailure(__FILE__, __LINE__, #exp); } while(0) 72 | 73 | // [Guard] 74 | #endif // _ASMJIT_CONFIG_H 75 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/CpuInfo.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include "CpuInfo.h" 9 | 10 | #if defined(ASMJIT_WINDOWS) 11 | # include 12 | #endif // ASMJIT_WINDOWS 13 | 14 | // 2009-02-05: Thanks to Mike Tajmajer for supporting VC7.1 compiler. This 15 | // shouldn't affect x64 compilation, because x64 compiler starts with 16 | // VS2005 (VC8.0). 17 | #if defined(_MSC_VER) 18 | # if _MSC_VER >= 1400 19 | # include 20 | # endif // _MSC_VER >= 1400 (>= VS2005) 21 | #endif // _MSC_VER 22 | 23 | #if defined(ASMJIT_POSIX) 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #endif // ASMJIT_POSIX 30 | 31 | // [Api-Begin] 32 | #include "ApiBegin.h" 33 | 34 | namespace AsmJit { 35 | 36 | // helpers 37 | static uint32_t detectNumberOfProcessors(void) 38 | { 39 | #if defined(ASMJIT_WINDOWS) 40 | SYSTEM_INFO info; 41 | GetSystemInfo(&info); 42 | return info.dwNumberOfProcessors; 43 | #elif defined(ASMJIT_POSIX) && defined(_SC_NPROCESSORS_ONLN) 44 | // It seems that sysconf returns the number of "logical" processors on both 45 | // mac and linux. So we get the number of "online logical" processors. 46 | long res = sysconf(_SC_NPROCESSORS_ONLN); 47 | if (res == -1) return 1; 48 | 49 | return static_cast(res); 50 | #else 51 | return 1; 52 | #endif 53 | } 54 | 55 | // This is messy, I know. cpuid is implemented as intrinsic in VS2005, but 56 | // we should support other compilers as well. Main problem is that MS compilers 57 | // in 64-bit mode not allows to use inline assembler, so we need intrinsic and 58 | // we need also asm version. 59 | 60 | // cpuid() and detectCpuInfo() for x86 and x64 platforms begins here. 61 | #if defined(ASMJIT_X86) || defined(ASMJIT_X64) 62 | void cpuid(uint32_t in, CpuId* out) ASMJIT_NOTHROW 63 | { 64 | #if defined(_MSC_VER) 65 | 66 | // 2009-02-05: Thanks to Mike Tajmajer for supporting VC7.1 compiler. 67 | // ASMJIT_X64 is here only for readibility, only VS2005 can compile 64-bit code. 68 | # if _MSC_VER >= 1400 || defined(ASMJIT_X64) 69 | // done by intrinsics 70 | __cpuid(reinterpret_cast(out->i), in); 71 | # else // _MSC_VER < 1400 72 | uint32_t cpuid_in = in; 73 | uint32_t* cpuid_out = out->i; 74 | 75 | __asm 76 | { 77 | mov eax, cpuid_in 78 | mov edi, cpuid_out 79 | cpuid 80 | mov dword ptr[edi + 0], eax 81 | mov dword ptr[edi + 4], ebx 82 | mov dword ptr[edi + 8], ecx 83 | mov dword ptr[edi + 12], edx 84 | } 85 | # endif // _MSC_VER < 1400 86 | 87 | #elif defined(__GNUC__) 88 | 89 | // Note, need to preserve ebx/rbx register! 90 | # if defined(ASMJIT_X86) 91 | # define __mycpuid(a, b, c, d, inp) \ 92 | asm ("mov %%ebx, %%edi\n" \ 93 | "cpuid\n" \ 94 | "xchg %%edi, %%ebx\n" \ 95 | : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp)) 96 | # else 97 | # define __mycpuid(a, b, c, d, inp) \ 98 | asm ("mov %%rbx, %%rdi\n" \ 99 | "cpuid\n" \ 100 | "xchg %%rdi, %%rbx\n" \ 101 | : "=a" (a), "=D" (b), "=c" (c), "=d" (d) : "a" (inp)) 102 | # endif 103 | __mycpuid(out->eax, out->ebx, out->ecx, out->edx, in); 104 | 105 | #endif // compiler 106 | } 107 | 108 | struct CpuVendorInfo 109 | { 110 | uint32_t id; 111 | char text[12]; 112 | }; 113 | 114 | static const CpuVendorInfo cpuVendorInfo[] = 115 | { 116 | { CPU_VENDOR_INTEL , { 'G', 'e', 'n', 'u', 'i', 'n', 'e', 'I', 'n', 't', 'e', 'l' } }, 117 | 118 | { CPU_VENDOR_AMD , { 'A', 'u', 't', 'h', 'e', 'n', 't', 'i', 'c', 'A', 'M', 'D' } }, 119 | { CPU_VENDOR_AMD , { 'A', 'M', 'D', 'i', 's', 'b', 'e', 't', 't', 'e', 'r', '!' } }, 120 | 121 | { CPU_VENDOR_NSM , { 'G', 'e', 'o', 'd', 'e', ' ', 'b', 'y', ' ', 'N', 'S', 'C' } }, 122 | { CPU_VENDOR_NSM , { 'C', 'y', 'r', 'i', 'x', 'I', 'n', 's', 't', 'e', 'a', 'd' } }, 123 | 124 | { CPU_VENDOR_TRANSMETA, { 'G', 'e', 'n', 'u', 'i', 'n', 'e', 'T', 'M', 'x', '8', '6' } }, 125 | { CPU_VENDOR_TRANSMETA, { 'T', 'r', 'a', 'n', 's', 'm', 'e', 't', 'a', 'C', 'P', 'U' } }, 126 | 127 | { CPU_VENDOR_VIA , { 'V', 'I', 'A', 0 , 'V', 'I', 'A', 0 , 'V', 'I', 'A', 0 } }, 128 | { CPU_VENDOR_VIA , { 'C', 'e', 'n', 't', 'a', 'u', 'r', 'H', 'a', 'u', 'l', 's' } } 129 | }; 130 | 131 | static inline bool cpuVencorEq(const CpuVendorInfo& info, const char* vendorString) 132 | { 133 | const uint32_t* a = reinterpret_cast(info.text); 134 | const uint32_t* b = reinterpret_cast(vendorString); 135 | 136 | return (a[0] == b[0]) & 137 | (a[1] == b[1]) & 138 | (a[2] == b[2]) ; 139 | } 140 | 141 | static inline void simplifyBrandString(char* s) 142 | { 143 | // Always clear the current character in the buffer. This ensures that there 144 | // is no garbage after the string NULL terminator. 145 | char* d = s; 146 | 147 | char prev = 0; 148 | char curr = s[0]; 149 | s[0] = '\0'; 150 | 151 | for (;;) 152 | { 153 | if (curr == 0) break; 154 | 155 | if (curr == ' ') 156 | { 157 | if (prev == '@') goto _Skip; 158 | if (s[1] == ' ' || s[1] == '@') goto _Skip; 159 | } 160 | 161 | d[0] = curr; 162 | d++; 163 | prev = curr; 164 | 165 | _Skip: 166 | curr = *++s; 167 | s[0] = '\0'; 168 | } 169 | 170 | d[0] = '\0'; 171 | } 172 | 173 | void detectCpuInfo(CpuInfo* i) ASMJIT_NOTHROW 174 | { 175 | uint32_t a; 176 | 177 | // First clear our struct 178 | memset(i, 0, sizeof(CpuInfo)); 179 | memcpy(i->vendor, "Unknown", 8); 180 | 181 | i->numberOfProcessors = detectNumberOfProcessors(); 182 | 183 | #if defined(ASMJIT_X86) || defined(ASMJIT_X64) 184 | CpuId out; 185 | 186 | // Get vendor string 187 | cpuid(0, &out); 188 | 189 | memcpy(i->vendor, &out.ebx, 4); 190 | memcpy(i->vendor + 4, &out.edx, 4); 191 | memcpy(i->vendor + 8, &out.ecx, 4); 192 | 193 | for (a = 0; a < 3; a++) 194 | { 195 | if (cpuVencorEq(cpuVendorInfo[a], i->vendor)) 196 | { 197 | i->vendorId = cpuVendorInfo[a].id; 198 | break; 199 | } 200 | } 201 | 202 | // get feature flags in ecx/edx, and family/model in eax 203 | cpuid(1, &out); 204 | 205 | // family and model fields 206 | i->family = (out.eax >> 8) & 0x0F; 207 | i->model = (out.eax >> 4) & 0x0F; 208 | i->stepping = (out.eax ) & 0x0F; 209 | 210 | // use extended family and model fields 211 | if (i->family == 0x0F) 212 | { 213 | i->family += ((out.eax >> 20) & 0xFF); 214 | i->model += ((out.eax >> 16) & 0x0F) << 4; 215 | } 216 | 217 | i->x86ExtendedInfo.processorType = ((out.eax >> 12) & 0x03); 218 | i->x86ExtendedInfo.brandIndex = ((out.ebx ) & 0xFF); 219 | i->x86ExtendedInfo.flushCacheLineSize = ((out.ebx >> 8) & 0xFF) * 8; 220 | i->x86ExtendedInfo.maxLogicalProcessors = ((out.ebx >> 16) & 0xFF); 221 | i->x86ExtendedInfo.apicPhysicalId = ((out.ebx >> 24) & 0xFF); 222 | 223 | if (out.ecx & 0x00000001U) i->features |= CPU_FEATURE_SSE3; 224 | if (out.ecx & 0x00000002U) i->features |= CPU_FEATURE_PCLMULDQ; 225 | if (out.ecx & 0x00000008U) i->features |= CPU_FEATURE_MONITOR_MWAIT; 226 | if (out.ecx & 0x00000200U) i->features |= CPU_FEATURE_SSSE3; 227 | if (out.ecx & 0x00002000U) i->features |= CPU_FEATURE_CMPXCHG16B; 228 | if (out.ecx & 0x00080000U) i->features |= CPU_FEATURE_SSE4_1; 229 | if (out.ecx & 0x00100000U) i->features |= CPU_FEATURE_SSE4_2; 230 | if (out.ecx & 0x00400000U) i->features |= CPU_FEATURE_MOVBE; 231 | if (out.ecx & 0x00800000U) i->features |= CPU_FEATURE_POPCNT; 232 | if (out.ecx & 0x10000000U) i->features |= CPU_FEATURE_AVX; 233 | 234 | if (out.edx & 0x00000010U) i->features |= CPU_FEATURE_RDTSC; 235 | if (out.edx & 0x00000100U) i->features |= CPU_FEATURE_CMPXCHG8B; 236 | if (out.edx & 0x00008000U) i->features |= CPU_FEATURE_CMOV; 237 | if (out.edx & 0x00800000U) i->features |= CPU_FEATURE_MMX; 238 | if (out.edx & 0x01000000U) i->features |= CPU_FEATURE_FXSR; 239 | if (out.edx & 0x02000000U) i->features |= CPU_FEATURE_SSE | CPU_FEATURE_MMX_EXT; 240 | if (out.edx & 0x04000000U) i->features |= CPU_FEATURE_SSE | CPU_FEATURE_SSE2; 241 | if (out.edx & 0x10000000U) i->features |= CPU_FEATURE_MULTI_THREADING; 242 | 243 | if (i->vendorId == CPU_VENDOR_AMD && (out.edx & 0x10000000U)) 244 | { 245 | // AMD sets Multithreading to ON if it has more cores. 246 | if (i->numberOfProcessors == 1) i->numberOfProcessors = 2; 247 | } 248 | 249 | // This comment comes from V8 and I think that its important: 250 | // 251 | // Opteron Rev E has a bug in which on very rare occasions a locked 252 | // instruction doesn't act as a read-acquire barrier if followed by a 253 | // non-locked read-modify-write instruction. Rev F has this bug in 254 | // pre-release versions, but not in versions released to customers, 255 | // so we test only for Rev E, which is family 15, model 32..63 inclusive. 256 | 257 | if (i->vendorId == CPU_VENDOR_AMD && i->family == 15 && i->model >= 32 && i->model <= 63) 258 | { 259 | i->bugs |= CPU_BUG_AMD_LOCK_MB; 260 | } 261 | 262 | // Calling cpuid with 0x80000000 as the in argument 263 | // gets the number of valid extended IDs. 264 | 265 | cpuid(0x80000000, &out); 266 | 267 | uint32_t exIds = out.eax; 268 | if (exIds > 0x80000004) exIds = 0x80000004; 269 | 270 | uint32_t* brand = reinterpret_cast(i->brand); 271 | 272 | for (a = 0x80000001; a <= exIds; a++) 273 | { 274 | cpuid(a, &out); 275 | 276 | switch (a) 277 | { 278 | case 0x80000001: 279 | if (out.ecx & 0x00000001U) i->features |= CPU_FEATURE_LAHF_SAHF; 280 | if (out.ecx & 0x00000020U) i->features |= CPU_FEATURE_LZCNT; 281 | if (out.ecx & 0x00000040U) i->features |= CPU_FEATURE_SSE4_A; 282 | if (out.ecx & 0x00000080U) i->features |= CPU_FEATURE_MSSE; 283 | if (out.ecx & 0x00000100U) i->features |= CPU_FEATURE_PREFETCH; 284 | 285 | if (out.edx & 0x00100000U) i->features |= CPU_FEATURE_EXECUTE_DISABLE_BIT; 286 | if (out.edx & 0x00200000U) i->features |= CPU_FEATURE_FFXSR; 287 | if (out.edx & 0x00400000U) i->features |= CPU_FEATURE_MMX_EXT; 288 | if (out.edx & 0x08000000U) i->features |= CPU_FEATURE_RDTSCP; 289 | if (out.edx & 0x20000000U) i->features |= CPU_FEATURE_64_BIT; 290 | if (out.edx & 0x40000000U) i->features |= CPU_FEATURE_3DNOW_EXT | CPU_FEATURE_MMX_EXT; 291 | if (out.edx & 0x80000000U) i->features |= CPU_FEATURE_3DNOW; 292 | break; 293 | 294 | case 0x80000002: 295 | case 0x80000003: 296 | case 0x80000004: 297 | *brand++ = out.eax; 298 | *brand++ = out.ebx; 299 | *brand++ = out.ecx; 300 | *brand++ = out.edx; 301 | break; 302 | 303 | default: 304 | // Additional features can be detected in the future. 305 | break; 306 | } 307 | } 308 | 309 | // Simplify the brand string (remove unnecessary spaces to make it printable). 310 | simplifyBrandString(i->brand); 311 | 312 | #endif // ASMJIT_X86 || ASMJIT_X64 313 | } 314 | #else 315 | void detectCpuInfo(CpuInfo* i) ASMJIT_NOTHROW 316 | { 317 | memset(i, 0, sizeof(CpuInfo)); 318 | } 319 | #endif 320 | 321 | struct ASMJIT_HIDDEN CpuInfoStatic 322 | { 323 | CpuInfoStatic() ASMJIT_NOTHROW { detectCpuInfo(&i); } 324 | 325 | CpuInfo i; 326 | }; 327 | 328 | CpuInfo* getCpuInfo() ASMJIT_NOTHROW 329 | { 330 | static CpuInfoStatic i; 331 | return &i.i; 332 | } 333 | 334 | } // AsmJit 335 | 336 | // [Api-End] 337 | #include "ApiEnd.h" 338 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/CpuInfo.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_CPUINFO_H 9 | #define _ASMJIT_CPUINFO_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | 14 | // [Api-Begin] 15 | #include "ApiBegin.h" 16 | 17 | namespace AsmJit { 18 | 19 | //! @addtogroup AsmJit_CpuInfo 20 | //! @{ 21 | 22 | // ============================================================================ 23 | // [AsmJit::CpuId] 24 | // ============================================================================ 25 | 26 | #if defined(ASMJIT_X86) || defined(ASMJIT_X64) 27 | //! @brief Structure (union) used by cpuid() function. 28 | union CpuId 29 | { 30 | //! @brief cpuid results array(eax, ebx, ecx and edx registers). 31 | uint32_t i[4]; 32 | 33 | struct 34 | { 35 | //! @brief cpuid result in eax register. 36 | uint32_t eax; 37 | //! @brief cpuid result in ebx register. 38 | uint32_t ebx; 39 | //! @brief cpuid result in ecx register. 40 | uint32_t ecx; 41 | //! @brief cpuid result in edx register. 42 | uint32_t edx; 43 | }; 44 | }; 45 | 46 | //! @brief Calls CPUID instruction with eax == @a in and returns result to @a out. 47 | //! 48 | //! @c cpuid() function has one input parameter that is passed to cpuid through 49 | //! eax register and results in four output values representing result of cpuid 50 | //! instruction (eax, ebx, ecx and edx registers). 51 | ASMJIT_API void cpuid(uint32_t in, CpuId* out) ASMJIT_NOTHROW; 52 | #endif // ASMJIT_X86 || ASMJIT_X64 53 | 54 | // ============================================================================ 55 | // [AsmJit::CPU_VENDOR] 56 | // ============================================================================ 57 | 58 | //! @brief Cpu vendor IDs. 59 | //! 60 | //! Cpu vendor IDs are specific for AsmJit library. Vendor ID is not directly 61 | //! read from cpuid result, instead it's based on CPU vendor string. 62 | enum CPU_VENDOR 63 | { 64 | //! @brief Unknown CPU vendor. 65 | CPU_VENDOR_UNKNOWN = 0, 66 | 67 | //! @brief Intel CPU vendor. 68 | CPU_VENDOR_INTEL = 1, 69 | //! @brief AMD CPU vendor. 70 | CPU_VENDOR_AMD = 2, 71 | //! @brief National Semiconductor CPU vendor (applies also to Cyrix processors). 72 | CPU_VENDOR_NSM = 3, 73 | //! @brief Transmeta CPU vendor. 74 | CPU_VENDOR_TRANSMETA = 4, 75 | //! @brief VIA CPU vendor. 76 | CPU_VENDOR_VIA = 5 77 | }; 78 | 79 | // ============================================================================ 80 | // [AsmJit::CPU_FEATURE] 81 | // ============================================================================ 82 | 83 | //! @brief X86/X64 CPU features. 84 | enum CPU_FEATURE 85 | { 86 | //! @brief Cpu has RDTSC instruction. 87 | CPU_FEATURE_RDTSC = 1U << 0, 88 | //! @brief Cpu has RDTSCP instruction. 89 | CPU_FEATURE_RDTSCP = 1U << 1, 90 | //! @brief Cpu has CMOV instruction (conditional move) 91 | CPU_FEATURE_CMOV = 1U << 2, 92 | //! @brief Cpu has CMPXCHG8B instruction 93 | CPU_FEATURE_CMPXCHG8B = 1U << 3, 94 | //! @brief Cpu has CMPXCHG16B instruction (64-bit processors) 95 | CPU_FEATURE_CMPXCHG16B = 1U << 4, 96 | //! @brief Cpu has CLFUSH instruction 97 | CPU_FEATURE_CLFLUSH = 1U << 5, 98 | //! @brief Cpu has PREFETCH instruction 99 | CPU_FEATURE_PREFETCH = 1U << 6, 100 | //! @brief Cpu supports LAHF and SAHF instrictions. 101 | CPU_FEATURE_LAHF_SAHF = 1U << 7, 102 | //! @brief Cpu supports FXSAVE and FXRSTOR instructions. 103 | CPU_FEATURE_FXSR = 1U << 8, 104 | //! @brief Cpu supports FXSAVE and FXRSTOR instruction optimizations (FFXSR). 105 | CPU_FEATURE_FFXSR = 1U << 9, 106 | //! @brief Cpu has MMX. 107 | CPU_FEATURE_MMX = 1U << 10, 108 | //! @brief Cpu has extended MMX. 109 | CPU_FEATURE_MMX_EXT = 1U << 11, 110 | //! @brief Cpu has 3dNow! 111 | CPU_FEATURE_3DNOW = 1U << 12, 112 | //! @brief Cpu has enchanced 3dNow! 113 | CPU_FEATURE_3DNOW_EXT = 1U << 13, 114 | //! @brief Cpu has SSE. 115 | CPU_FEATURE_SSE = 1U << 14, 116 | //! @brief Cpu has SSE2. 117 | CPU_FEATURE_SSE2 = 1U << 15, 118 | //! @brief Cpu has SSE3. 119 | CPU_FEATURE_SSE3 = 1U << 16, 120 | //! @brief Cpu has Supplemental SSE3 (SSSE3). 121 | CPU_FEATURE_SSSE3 = 1U << 17, 122 | //! @brief Cpu has SSE4.A. 123 | CPU_FEATURE_SSE4_A = 1U << 18, 124 | //! @brief Cpu has SSE4.1. 125 | CPU_FEATURE_SSE4_1 = 1U << 19, 126 | //! @brief Cpu has SSE4.2. 127 | CPU_FEATURE_SSE4_2 = 1U << 20, 128 | //! @brief Cpu has AVX. 129 | CPU_FEATURE_AVX = 1U << 22, 130 | //! @brief Cpu has Misaligned SSE (MSSE). 131 | CPU_FEATURE_MSSE = 1U << 23, 132 | //! @brief Cpu supports MONITOR and MWAIT instructions. 133 | CPU_FEATURE_MONITOR_MWAIT = 1U << 24, 134 | //! @brief Cpu supports MOVBE instruction. 135 | CPU_FEATURE_MOVBE = 1U << 25, 136 | //! @brief Cpu supports POPCNT instruction. 137 | CPU_FEATURE_POPCNT = 1U << 26, 138 | //! @brief Cpu supports LZCNT instruction. 139 | CPU_FEATURE_LZCNT = 1U << 27, 140 | //! @brief Cpu supports PCLMULDQ set of instructions. 141 | CPU_FEATURE_PCLMULDQ = 1U << 28, 142 | //! @brief Cpu supports multithreading. 143 | CPU_FEATURE_MULTI_THREADING = 1U << 29, 144 | //! @brief Cpu supports execute disable bit (execute protection). 145 | CPU_FEATURE_EXECUTE_DISABLE_BIT = 1U << 30, 146 | //! @brief 64-bit CPU. 147 | CPU_FEATURE_64_BIT = 1U << 31 148 | }; 149 | 150 | // ============================================================================ 151 | // [AsmJit::CPU_BUG] 152 | // ============================================================================ 153 | 154 | //! @brief X86/X64 CPU bugs. 155 | enum CPU_BUG 156 | { 157 | //! @brief Whether the processor contains bug seen in some 158 | //! AMD-Opteron processors. 159 | CPU_BUG_AMD_LOCK_MB = 1U << 0 160 | }; 161 | 162 | // ============================================================================ 163 | // [AsmJit::CpuInfo] 164 | // ============================================================================ 165 | 166 | //! @brief Informations about host cpu. 167 | struct ASMJIT_HIDDEN CpuInfo 168 | { 169 | //! @brief Cpu short vendor string. 170 | char vendor[16]; 171 | //! @brief Cpu long vendor string (brand). 172 | char brand[64]; 173 | //! @brief Cpu vendor id (see @c AsmJit::CpuInfo::VendorId enum). 174 | uint32_t vendorId; 175 | //! @brief Cpu family ID. 176 | uint32_t family; 177 | //! @brief Cpu model ID. 178 | uint32_t model; 179 | //! @brief Cpu stepping. 180 | uint32_t stepping; 181 | //! @brief Number of processors or cores. 182 | uint32_t numberOfProcessors; 183 | //! @brief Cpu features bitfield, see @c AsmJit::CpuInfo::Feature enum). 184 | uint32_t features; 185 | //! @brief Cpu bugs bitfield, see @c AsmJit::CpuInfo::Bug enum). 186 | uint32_t bugs; 187 | 188 | #if defined(ASMJIT_X86) || defined(ASMJIT_X64) 189 | //! @brief Extended information for x86/x64 compatible processors. 190 | struct X86ExtendedInfo 191 | { 192 | //! @brief Processor type. 193 | uint32_t processorType; 194 | //! @brief Brand index. 195 | uint32_t brandIndex; 196 | //! @brief Flush cache line size in bytes. 197 | uint32_t flushCacheLineSize; 198 | //! @brief Maximum number of addressable IDs for logical processors. 199 | uint32_t maxLogicalProcessors; 200 | //! @brief Initial APIC ID. 201 | uint32_t apicPhysicalId; 202 | }; 203 | //! @brief Extended information for x86/x64 compatible processors. 204 | X86ExtendedInfo x86ExtendedInfo; 205 | #endif // ASMJIT_X86 || ASMJIT_X64 206 | }; 207 | 208 | //! @brief Detect CPU features to CpuInfo structure @a i. 209 | //! 210 | //! @sa @c CpuInfo. 211 | ASMJIT_API void detectCpuInfo(CpuInfo* i) ASMJIT_NOTHROW; 212 | 213 | //! @brief Return CpuInfo (detection is done only once). 214 | //! 215 | //! @sa @c CpuInfo. 216 | ASMJIT_API CpuInfo* getCpuInfo() ASMJIT_NOTHROW; 217 | 218 | //! @} 219 | 220 | } // AsmJit namespace 221 | 222 | // [Api-End] 223 | #include "ApiEnd.h" 224 | 225 | // [Guard] 226 | #endif // _ASMJIT_CPUINFO_H 227 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Defs.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include "Defs.h" 9 | 10 | // [Api-Begin] 11 | #include "ApiBegin.h" 12 | 13 | namespace AsmJit { 14 | 15 | const char* getErrorString(uint32_t error) ASMJIT_NOTHROW 16 | { 17 | static const char* errorMessage[] = { 18 | "No error", 19 | 20 | "No heap memory", 21 | "No virtual memory", 22 | 23 | "Unknown instruction", 24 | "Illegal instruction", 25 | "Illegal addressing", 26 | "Illegal short jump", 27 | 28 | "No function defined", 29 | "Incomplete function", 30 | 31 | "Not enough registers", 32 | "Registers overlap", 33 | 34 | "Incompatible argument", 35 | "Incompatible return value", 36 | 37 | "Unknown error" 38 | }; 39 | 40 | // Saturate error code to be able to use errorMessage[]. 41 | if (error > _ERROR_COUNT) error = _ERROR_COUNT; 42 | 43 | return errorMessage[error]; 44 | } 45 | 46 | } // AsmJit 47 | 48 | // [Api-End] 49 | #include "ApiEnd.h" 50 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Logger.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // We are using sprintf() here. 8 | #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_WARNINGS) 9 | #define _CRT_SECURE_NO_WARNINGS 10 | #endif // _MSC_VER 11 | 12 | // [Dependencies] 13 | #include "Logger.h" 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | // [Api-Begin] 20 | #include "ApiBegin.h" 21 | 22 | namespace AsmJit { 23 | 24 | // ============================================================================ 25 | // [AsmJit::Logger] 26 | // ============================================================================ 27 | 28 | Logger::Logger() ASMJIT_NOTHROW : 29 | _enabled(true), 30 | _used(true), 31 | _logBinary(false) 32 | { 33 | } 34 | 35 | Logger::~Logger() ASMJIT_NOTHROW 36 | { 37 | } 38 | 39 | void Logger::logFormat(const char* fmt, ...) ASMJIT_NOTHROW 40 | { 41 | char buf[1024]; 42 | sysuint_t len; 43 | 44 | va_list ap; 45 | va_start(ap, fmt); 46 | len = vsnprintf(buf, 1023, fmt, ap); 47 | va_end(ap); 48 | 49 | logString(buf, len); 50 | } 51 | 52 | void Logger::setEnabled(bool enabled) ASMJIT_NOTHROW 53 | { 54 | _enabled = enabled; 55 | _used = enabled; 56 | } 57 | 58 | // ============================================================================ 59 | // [AsmJit::FileLogger] 60 | // ============================================================================ 61 | 62 | FileLogger::FileLogger(FILE* stream) ASMJIT_NOTHROW 63 | : _stream(NULL) 64 | { 65 | setStream(stream); 66 | } 67 | 68 | void FileLogger::logString(const char* buf, sysuint_t len) ASMJIT_NOTHROW 69 | { 70 | if (!_used) return; 71 | 72 | if (len == (sysuint_t)-1) len = strlen(buf); 73 | fwrite(buf, 1, len, _stream); 74 | } 75 | 76 | void FileLogger::setEnabled(bool enabled) ASMJIT_NOTHROW 77 | { 78 | _enabled = enabled; 79 | _used = (_enabled == true) & (_stream != NULL); 80 | } 81 | 82 | //! @brief Set file stream. 83 | void FileLogger::setStream(FILE* stream) ASMJIT_NOTHROW 84 | { 85 | _stream = stream; 86 | _used = (_enabled == true) & (_stream != NULL); 87 | } 88 | 89 | } // AsmJit namespace 90 | 91 | // [Api-End] 92 | #include "ApiEnd.h" 93 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Logger.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_LOGGER_H 9 | #define _ASMJIT_LOGGER_H 10 | 11 | // [Dependencies] 12 | #include "Defs.h" 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | // [Api-Begin] 19 | #include "ApiBegin.h" 20 | 21 | namespace AsmJit { 22 | 23 | //! @addtogroup AsmJit_Logging 24 | //! @{ 25 | 26 | //! @brief Abstract logging class. 27 | //! 28 | //! This class can be inherited and reimplemented to fit into your logging 29 | //! subsystem. When reimplementing use @c AsmJit::Logger::log() method to 30 | //! log into your stream. 31 | //! 32 | //! This class also contain @c _enabled member that can be used to enable 33 | //! or disable logging. 34 | struct ASMJIT_API Logger 35 | { 36 | // -------------------------------------------------------------------------- 37 | // [Construction / Destruction] 38 | // -------------------------------------------------------------------------- 39 | 40 | //! @brief Create logger. 41 | Logger() ASMJIT_NOTHROW; 42 | //! @brief Destroy logger. 43 | virtual ~Logger() ASMJIT_NOTHROW; 44 | 45 | // -------------------------------------------------------------------------- 46 | // [Logging] 47 | // -------------------------------------------------------------------------- 48 | 49 | //! @brief Abstract method to log output. 50 | //! 51 | //! Default implementation that is in @c AsmJit::Logger is to do nothing. 52 | //! It's virtual to fit to your logging system. 53 | virtual void logString(const char* buf, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW = 0; 54 | 55 | //! @brief Log formatter message (like sprintf) sending output to @c logString() method. 56 | virtual void logFormat(const char* fmt, ...) ASMJIT_NOTHROW; 57 | 58 | // -------------------------------------------------------------------------- 59 | // [Enabled] 60 | // -------------------------------------------------------------------------- 61 | 62 | //! @brief Return @c true if logging is enabled. 63 | inline bool isEnabled() const ASMJIT_NOTHROW { return _enabled; } 64 | 65 | //! @brief Set logging to enabled or disabled. 66 | virtual void setEnabled(bool enabled) ASMJIT_NOTHROW; 67 | 68 | // -------------------------------------------------------------------------- 69 | // [Used] 70 | // -------------------------------------------------------------------------- 71 | 72 | //! @brief Get whether the logger should be used. 73 | inline bool isUsed() const ASMJIT_NOTHROW { return _used; } 74 | 75 | // -------------------------------------------------------------------------- 76 | // [LogBinary] 77 | // -------------------------------------------------------------------------- 78 | 79 | //! @brief Get whether logging binary output. 80 | inline bool getLogBinary() const { return _logBinary; } 81 | //! @brief Get whether to log binary output. 82 | inline void setLogBinary(bool val) { _logBinary = val; } 83 | 84 | // -------------------------------------------------------------------------- 85 | // [Members] 86 | // -------------------------------------------------------------------------- 87 | 88 | protected: 89 | 90 | //! @brief Whether logger is enabled or disabled. 91 | //! 92 | //! Default @c true. 93 | bool _enabled; 94 | 95 | //! @brief Whether logger is enabled and can be used. 96 | //! 97 | //! This value can be set by inherited classes to inform @c Logger that 98 | //! assigned stream (or something that can log output) is invalid. If 99 | //! @c _used is false it means that there is no logging output and AsmJit 100 | //! shouldn't use this logger (because all messages will be lost). 101 | //! 102 | //! This is designed only to optimize cases that logger exists, but its 103 | //! configured not to output messages. The API inside Logging and AsmJit 104 | //! should only check this value when needed. The API outside AsmJit should 105 | //! check only whether logging is @c _enabled. 106 | //! 107 | //! Default @c true. 108 | bool _used; 109 | 110 | //! @brief Whether to log instruction in binary form. 111 | bool _logBinary; 112 | 113 | private: 114 | ASMJIT_DISABLE_COPY(Logger) 115 | }; 116 | 117 | //! @brief Logger that can log to standard C @c FILE* stream. 118 | struct ASMJIT_API FileLogger : public Logger 119 | { 120 | // -------------------------------------------------------------------------- 121 | // [Construction / Destruction] 122 | // -------------------------------------------------------------------------- 123 | 124 | //! @brief Create new @c FileLogger. 125 | //! @param stream FILE stream where logging will be sent (can be @c NULL 126 | //! to disable logging). 127 | FileLogger(FILE* stream = NULL) ASMJIT_NOTHROW; 128 | 129 | // -------------------------------------------------------------------------- 130 | // [Logging] 131 | // -------------------------------------------------------------------------- 132 | 133 | virtual void logString(const char* buf, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW; 134 | 135 | // -------------------------------------------------------------------------- 136 | // [Enabled] 137 | // -------------------------------------------------------------------------- 138 | 139 | virtual void setEnabled(bool enabled) ASMJIT_NOTHROW; 140 | 141 | // -------------------------------------------------------------------------- 142 | // [Stream] 143 | // -------------------------------------------------------------------------- 144 | 145 | //! @brief Get @c FILE* stream. 146 | //! 147 | //! @note Return value can be @c NULL. 148 | inline FILE* getStream() const ASMJIT_NOTHROW { return _stream; } 149 | 150 | //! @brief Set @c FILE* stream. 151 | //! 152 | //! @param stream @c FILE stream where to log output (can be @c NULL to 153 | //! disable logging). 154 | void setStream(FILE* stream) ASMJIT_NOTHROW; 155 | 156 | // -------------------------------------------------------------------------- 157 | // [Members] 158 | // -------------------------------------------------------------------------- 159 | 160 | protected: 161 | //! @brief C file stream. 162 | FILE* _stream; 163 | 164 | ASMJIT_DISABLE_COPY(FileLogger) 165 | }; 166 | 167 | //! @} 168 | 169 | } // AsmJit namespace 170 | 171 | // [Api-End] 172 | #include "ApiEnd.h" 173 | 174 | // [Guard] 175 | #endif // _ASMJIT_LOGGER_H 176 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/MemoryManager.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_MEMORYMANAGER_H 9 | #define _ASMJIT_MEMORYMANAGER_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | #include "Defs.h" 14 | 15 | // [Api-Begin] 16 | #include "ApiBegin.h" 17 | 18 | // [Debug] 19 | // #define ASMJIT_MEMORY_MANAGER_DUMP 20 | 21 | namespace AsmJit { 22 | 23 | //! @addtogroup AsmJit_MemoryManagement 24 | //! @{ 25 | 26 | // ============================================================================ 27 | // [AsmJit::MemoryManager] 28 | // ============================================================================ 29 | 30 | //! @brief Virtual memory manager interface. 31 | //! 32 | //! This class is pure virtual. You can get default virtual memory manager using 33 | //! @c getGlobal() method. If you want to create more memory managers with same 34 | //! functionality as global memory manager use @c VirtualMemoryManager class. 35 | struct ASMJIT_API MemoryManager 36 | { 37 | // -------------------------------------------------------------------------- 38 | // [Construction / Destruction] 39 | // -------------------------------------------------------------------------- 40 | 41 | //! @brief Create memory manager instance. 42 | MemoryManager() ASMJIT_NOTHROW; 43 | //! @brief Destroy memory manager instance, this means also to free all memory 44 | //! blocks. 45 | virtual ~MemoryManager() ASMJIT_NOTHROW; 46 | 47 | // -------------------------------------------------------------------------- 48 | // [Interface] 49 | // -------------------------------------------------------------------------- 50 | 51 | //! @brief Allocate a @a size bytes of virtual memory. 52 | //! 53 | //! Note that if you are implementing your own virtual memory manager then you 54 | //! can quitly ignore type of allocation. This is mainly for AsmJit to memory 55 | //! manager that allocated memory will be never freed. 56 | virtual void* alloc(sysuint_t size, uint32_t type = MEMORY_ALLOC_FREEABLE) ASMJIT_NOTHROW = 0; 57 | //! @brief Free previously allocated memory at a given @a address. 58 | virtual bool free(void* address) ASMJIT_NOTHROW = 0; 59 | //! @brief Free some tail memory. 60 | virtual bool shrink(void* address, sysuint_t used) ASMJIT_NOTHROW = 0; 61 | //! @brief Free all allocated memory. 62 | virtual void freeAll() ASMJIT_NOTHROW = 0; 63 | 64 | //! @brief Get how many bytes are currently used. 65 | virtual sysuint_t getUsedBytes() ASMJIT_NOTHROW = 0; 66 | //! @brief Get how many bytes are currently allocated. 67 | virtual sysuint_t getAllocatedBytes() ASMJIT_NOTHROW = 0; 68 | 69 | //! @brief Get global memory manager instance. 70 | //! 71 | //! Global instance is instance of @c VirtualMemoryManager class. Global memory 72 | //! manager is used by default by @ref Assembler::make() and @ref Compiler::make() 73 | //! methods. 74 | static MemoryManager* getGlobal() ASMJIT_NOTHROW; 75 | }; 76 | 77 | //! @brief Reference implementation of memory manager that uses 78 | //! @ref AsmJit::VirtualMemory class to allocate chunks of virtual memory 79 | //! and bit arrays to manage it. 80 | struct ASMJIT_API VirtualMemoryManager : public MemoryManager 81 | { 82 | // -------------------------------------------------------------------------- 83 | // [Construction / Destruction] 84 | // -------------------------------------------------------------------------- 85 | 86 | //! @brief Create a @c VirtualMemoryManager instance. 87 | VirtualMemoryManager() ASMJIT_NOTHROW; 88 | 89 | #if defined(ASMJIT_WINDOWS) 90 | //! @brief Create a @c VirtualMemoryManager instance for process @a hProcess. 91 | //! 92 | //! This is specialized version of constructor available only for windows and 93 | //! usable to alloc/free memory of different process. 94 | VirtualMemoryManager(HANDLE hProcess) ASMJIT_NOTHROW; 95 | #endif // ASMJIT_WINDOWS 96 | 97 | //! @brief Destroy the @c VirtualMemoryManager instance, this means also to 98 | //! free all blocks. 99 | virtual ~VirtualMemoryManager() ASMJIT_NOTHROW; 100 | 101 | // -------------------------------------------------------------------------- 102 | // [Interface] 103 | // -------------------------------------------------------------------------- 104 | 105 | virtual void* alloc(sysuint_t size, uint32_t type = MEMORY_ALLOC_FREEABLE) ASMJIT_NOTHROW; 106 | virtual bool free(void* address) ASMJIT_NOTHROW; 107 | virtual bool shrink(void* address, sysuint_t used) ASMJIT_NOTHROW; 108 | virtual void freeAll() ASMJIT_NOTHROW; 109 | 110 | virtual sysuint_t getUsedBytes() ASMJIT_NOTHROW; 111 | virtual sysuint_t getAllocatedBytes() ASMJIT_NOTHROW; 112 | 113 | // -------------------------------------------------------------------------- 114 | // [Virtual Memory Manager Specific] 115 | // -------------------------------------------------------------------------- 116 | 117 | //! @brief Get whether to keep allocated memory after memory manager is 118 | //! destroyed. 119 | //! 120 | //! @sa @c setKeepVirtualMemory(). 121 | bool getKeepVirtualMemory() const ASMJIT_NOTHROW; 122 | 123 | //! @brief Set whether to keep allocated memory after memory manager is 124 | //! destroyed. 125 | //! 126 | //! This method is usable when patching code of remote process. You need to 127 | //! allocate process memory, store generated assembler into it and patch the 128 | //! method you want to redirect (into your code). This method affects only 129 | //! VirtualMemoryManager destructor. After destruction all internal 130 | //! structures are freed, only the process virtual memory remains. 131 | //! 132 | //! @note Memory allocated with MEMORY_ALLOC_PERMANENT is always kept. 133 | //! 134 | //! @sa @c getKeepVirtualMemory(). 135 | void setKeepVirtualMemory(bool keepVirtualMemory) ASMJIT_NOTHROW; 136 | 137 | // -------------------------------------------------------------------------- 138 | // [Debug] 139 | // -------------------------------------------------------------------------- 140 | 141 | #if defined(ASMJIT_MEMORY_MANAGER_DUMP) 142 | //! @brief Dump memory manager tree into file. 143 | //! 144 | //! Generated output is using DOT language (from graphviz package). 145 | void dump(const char* fileName); 146 | #endif // ASMJIT_MEMORY_MANAGER_DUMP 147 | 148 | // -------------------------------------------------------------------------- 149 | // [Members] 150 | // -------------------------------------------------------------------------- 151 | 152 | protected: 153 | //! @brief Pointer to private data hidden from the public API. 154 | void* _d; 155 | }; 156 | 157 | //! @} 158 | 159 | } // AsmJit namespace 160 | 161 | // [Api-End] 162 | #include "ApiEnd.h" 163 | 164 | // [Guard] 165 | #endif // _ASMJIT_MEMORYMANAGER_H 166 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/MemoryMarker.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include "Build.h" 9 | #include "MemoryMarker.h" 10 | 11 | // [Api-Begin] 12 | #include "ApiBegin.h" 13 | 14 | namespace AsmJit { 15 | 16 | // ============================================================================ 17 | // [AsmJit::MemoryMarker] 18 | // ============================================================================ 19 | 20 | MemoryMarker::MemoryMarker() ASMJIT_NOTHROW {} 21 | MemoryMarker::~MemoryMarker() ASMJIT_NOTHROW {} 22 | 23 | } // AsmJit namespace 24 | 25 | // [Api-End] 26 | #include "ApiEnd.h" 27 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/MemoryMarker.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_MEMORYMARKER_H 9 | #define _ASMJIT_MEMORYMARKER_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | #include "Defs.h" 14 | 15 | // [Api-Begin] 16 | #include "ApiBegin.h" 17 | 18 | namespace AsmJit { 19 | 20 | //! @addtogroup AsmJit_MemoryManagement 21 | //! @{ 22 | 23 | // ============================================================================ 24 | // [AsmJit::MemoryMarker] 25 | // ============================================================================ 26 | 27 | //! @brief Virtual memory marker interface. 28 | struct ASMJIT_API MemoryMarker 29 | { 30 | // -------------------------------------------------------------------------- 31 | // [Construction / Destruction] 32 | // -------------------------------------------------------------------------- 33 | 34 | MemoryMarker() ASMJIT_NOTHROW; 35 | virtual ~MemoryMarker() ASMJIT_NOTHROW; 36 | 37 | // -------------------------------------------------------------------------- 38 | // [Interface] 39 | // -------------------------------------------------------------------------- 40 | 41 | virtual void mark(const void* ptr, sysuint_t size) ASMJIT_NOTHROW = 0; 42 | 43 | private: 44 | ASMJIT_DISABLE_COPY(MemoryMarker) 45 | }; 46 | 47 | //! @} 48 | 49 | } // AsmJit namespace 50 | 51 | // [Api-End] 52 | #include "ApiEnd.h" 53 | 54 | // [Guard] 55 | #endif // _ASMJIT_MEMORYMARKER_H 56 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Operand.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_OPERAND_H 9 | #define _ASMJIT_OPERAND_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | 14 | namespace AsmJit { 15 | 16 | //! @addtogroup AsmJit_Core 17 | //! @{ 18 | 19 | // There is currently no platform independent code. 20 | 21 | //! @} 22 | 23 | } // AsmJit namespace 24 | 25 | // ============================================================================ 26 | // [Platform Specific] 27 | // ============================================================================ 28 | 29 | #if defined(ASMJIT_X86) || defined(ASMJIT_X64) 30 | #include "OperandX86X64.h" 31 | #endif // ASMJIT_X86 || ASMJIT_X64 32 | 33 | // [Guard] 34 | #endif // _ASMJIT_OPERAND_H 35 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/OperandX86X64.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include "Defs.h" 9 | #include "Operand.h" 10 | 11 | // [Api-Begin] 12 | #include "ApiBegin.h" 13 | 14 | namespace AsmJit { 15 | 16 | // ============================================================================ 17 | // [AsmJit::Registers - no_reg] 18 | // ============================================================================ 19 | 20 | const GPReg no_reg(_Initialize(), INVALID_VALUE); 21 | 22 | // ============================================================================ 23 | // [AsmJit::Registers - 8-bit] 24 | // ============================================================================ 25 | 26 | const GPReg al(_Initialize(), REG_AL); 27 | const GPReg cl(_Initialize(), REG_CL); 28 | const GPReg dl(_Initialize(), REG_DL); 29 | const GPReg bl(_Initialize(), REG_BL); 30 | 31 | #if defined(ASMJIT_X64) 32 | const GPReg spl(_Initialize(), REG_SPL); 33 | const GPReg bpl(_Initialize(), REG_BPL); 34 | const GPReg sil(_Initialize(), REG_SIL); 35 | const GPReg dil(_Initialize(), REG_DIL); 36 | 37 | const GPReg r8b(_Initialize(), REG_R8B); 38 | const GPReg r9b(_Initialize(), REG_R9B); 39 | const GPReg r10b(_Initialize(), REG_R10B); 40 | const GPReg r11b(_Initialize(), REG_R11B); 41 | const GPReg r12b(_Initialize(), REG_R12B); 42 | const GPReg r13b(_Initialize(), REG_R13B); 43 | const GPReg r14b(_Initialize(), REG_R14B); 44 | const GPReg r15b(_Initialize(), REG_R15B); 45 | #endif // ASMJIT_X64 46 | 47 | const GPReg ah(_Initialize(), REG_AH); 48 | const GPReg ch(_Initialize(), REG_CH); 49 | const GPReg dh(_Initialize(), REG_DH); 50 | const GPReg bh(_Initialize(), REG_BH); 51 | 52 | // ============================================================================ 53 | // [AsmJit::Registers - 16-bit] 54 | // ============================================================================ 55 | 56 | const GPReg ax(_Initialize(), REG_AX); 57 | const GPReg cx(_Initialize(), REG_CX); 58 | const GPReg dx(_Initialize(), REG_DX); 59 | const GPReg bx(_Initialize(), REG_BX); 60 | const GPReg sp(_Initialize(), REG_SP); 61 | const GPReg bp(_Initialize(), REG_BP); 62 | const GPReg si(_Initialize(), REG_SI); 63 | const GPReg di(_Initialize(), REG_DI); 64 | 65 | #if defined(ASMJIT_X64) 66 | const GPReg r8w(_Initialize(), REG_R8W); 67 | const GPReg r9w(_Initialize(), REG_R9W); 68 | const GPReg r10w(_Initialize(), REG_R10W); 69 | const GPReg r11w(_Initialize(), REG_R11W); 70 | const GPReg r12w(_Initialize(), REG_R12W); 71 | const GPReg r13w(_Initialize(), REG_R13W); 72 | const GPReg r14w(_Initialize(), REG_R14W); 73 | const GPReg r15w(_Initialize(), REG_R15W); 74 | #endif // ASMJIT_X64 75 | 76 | // ============================================================================ 77 | // [AsmJit::Registers - 32-bit] 78 | // ============================================================================ 79 | 80 | const GPReg eax(_Initialize(), REG_EAX); 81 | const GPReg ecx(_Initialize(), REG_ECX); 82 | const GPReg edx(_Initialize(), REG_EDX); 83 | const GPReg ebx(_Initialize(), REG_EBX); 84 | const GPReg esp(_Initialize(), REG_ESP); 85 | const GPReg ebp(_Initialize(), REG_EBP); 86 | const GPReg esi(_Initialize(), REG_ESI); 87 | const GPReg edi(_Initialize(), REG_EDI); 88 | 89 | #if defined(ASMJIT_X64) 90 | const GPReg r8d(_Initialize(), REG_R8D); 91 | const GPReg r9d(_Initialize(), REG_R9D); 92 | const GPReg r10d(_Initialize(), REG_R10D); 93 | const GPReg r11d(_Initialize(), REG_R11D); 94 | const GPReg r12d(_Initialize(), REG_R12D); 95 | const GPReg r13d(_Initialize(), REG_R13D); 96 | const GPReg r14d(_Initialize(), REG_R14D); 97 | const GPReg r15d(_Initialize(), REG_R15D); 98 | #endif // ASMJIT_X64 99 | 100 | // ============================================================================ 101 | // [AsmJit::Registers - 64-bit] 102 | // ============================================================================ 103 | 104 | #if defined(ASMJIT_X64) 105 | const GPReg rax(_Initialize(), REG_RAX); 106 | const GPReg rcx(_Initialize(), REG_RCX); 107 | const GPReg rdx(_Initialize(), REG_RDX); 108 | const GPReg rbx(_Initialize(), REG_RBX); 109 | const GPReg rsp(_Initialize(), REG_RSP); 110 | const GPReg rbp(_Initialize(), REG_RBP); 111 | const GPReg rsi(_Initialize(), REG_RSI); 112 | const GPReg rdi(_Initialize(), REG_RDI); 113 | 114 | const GPReg r8(_Initialize(), REG_R8); 115 | const GPReg r9(_Initialize(), REG_R9); 116 | const GPReg r10(_Initialize(), REG_R10); 117 | const GPReg r11(_Initialize(), REG_R11); 118 | const GPReg r12(_Initialize(), REG_R12); 119 | const GPReg r13(_Initialize(), REG_R13); 120 | const GPReg r14(_Initialize(), REG_R14); 121 | const GPReg r15(_Initialize(), REG_R15); 122 | #endif // ASMJIT_X64 123 | 124 | // ============================================================================ 125 | // [AsmJit::Registers - Native (AsmJit extension)] 126 | // ============================================================================ 127 | 128 | const GPReg nax(_Initialize(), REG_NAX); 129 | const GPReg ncx(_Initialize(), REG_NCX); 130 | const GPReg ndx(_Initialize(), REG_NDX); 131 | const GPReg nbx(_Initialize(), REG_NBX); 132 | const GPReg nsp(_Initialize(), REG_NSP); 133 | const GPReg nbp(_Initialize(), REG_NBP); 134 | const GPReg nsi(_Initialize(), REG_NSI); 135 | const GPReg ndi(_Initialize(), REG_NDI); 136 | 137 | // ============================================================================ 138 | // [AsmJit::Registers - MM] 139 | // ============================================================================ 140 | 141 | const MMReg mm0(_Initialize(), REG_MM0); 142 | const MMReg mm1(_Initialize(), REG_MM1); 143 | const MMReg mm2(_Initialize(), REG_MM2); 144 | const MMReg mm3(_Initialize(), REG_MM3); 145 | const MMReg mm4(_Initialize(), REG_MM4); 146 | const MMReg mm5(_Initialize(), REG_MM5); 147 | const MMReg mm6(_Initialize(), REG_MM6); 148 | const MMReg mm7(_Initialize(), REG_MM7); 149 | 150 | // ============================================================================ 151 | // [AsmJit::Registers - XMM] 152 | // ============================================================================ 153 | 154 | const XMMReg xmm0(_Initialize(), REG_XMM0); 155 | const XMMReg xmm1(_Initialize(), REG_XMM1); 156 | const XMMReg xmm2(_Initialize(), REG_XMM2); 157 | const XMMReg xmm3(_Initialize(), REG_XMM3); 158 | const XMMReg xmm4(_Initialize(), REG_XMM4); 159 | const XMMReg xmm5(_Initialize(), REG_XMM5); 160 | const XMMReg xmm6(_Initialize(), REG_XMM6); 161 | const XMMReg xmm7(_Initialize(), REG_XMM7); 162 | 163 | #if defined(ASMJIT_X64) 164 | const XMMReg xmm8(_Initialize(), REG_XMM8); 165 | const XMMReg xmm9(_Initialize(), REG_XMM9); 166 | const XMMReg xmm10(_Initialize(), REG_XMM10); 167 | const XMMReg xmm11(_Initialize(), REG_XMM11); 168 | const XMMReg xmm12(_Initialize(), REG_XMM12); 169 | const XMMReg xmm13(_Initialize(), REG_XMM13); 170 | const XMMReg xmm14(_Initialize(), REG_XMM14); 171 | const XMMReg xmm15(_Initialize(), REG_XMM15); 172 | #endif // ASMJIT_X64 173 | 174 | // ============================================================================ 175 | // [AsmJit::Registers - Segment] 176 | // ============================================================================ 177 | 178 | const SegmentReg cs(_Initialize(), REG_CS); 179 | const SegmentReg ss(_Initialize(), REG_SS); 180 | const SegmentReg ds(_Initialize(), REG_DS); 181 | const SegmentReg es(_Initialize(), REG_ES); 182 | const SegmentReg fs(_Initialize(), REG_FS); 183 | const SegmentReg gs(_Initialize(), REG_GS); 184 | 185 | // ============================================================================ 186 | // [AsmJit::Immediate] 187 | // ============================================================================ 188 | 189 | //! @brief Create signed immediate value operand. 190 | Imm imm(sysint_t i) ASMJIT_NOTHROW 191 | { 192 | return Imm(i, false); 193 | } 194 | 195 | //! @brief Create unsigned immediate value operand. 196 | Imm uimm(sysuint_t i) ASMJIT_NOTHROW 197 | { 198 | return Imm((sysint_t)i, true); 199 | } 200 | 201 | // ============================================================================ 202 | // [AsmJit::BaseVar] 203 | // ============================================================================ 204 | 205 | Mem _BaseVarMem(const BaseVar& var, uint32_t ptrSize) ASMJIT_NOTHROW 206 | { 207 | Mem m; //(_DontInitialize()); 208 | 209 | m._mem.op = OPERAND_MEM; 210 | m._mem.size = (ptrSize == INVALID_VALUE) ? var.getSize() : (uint8_t)ptrSize; 211 | m._mem.type = OPERAND_MEM_NATIVE; 212 | m._mem.segmentPrefix = SEGMENT_NONE; 213 | m._mem.sizePrefix = 0; 214 | m._mem.shift = 0; 215 | 216 | m._mem.id = var.getId(); 217 | m._mem.base = INVALID_VALUE; 218 | m._mem.index = INVALID_VALUE; 219 | 220 | m._mem.target = NULL; 221 | m._mem.displacement = 0; 222 | 223 | return m; 224 | } 225 | 226 | 227 | Mem _BaseVarMem(const BaseVar& var, uint32_t ptrSize, sysint_t disp) ASMJIT_NOTHROW 228 | { 229 | Mem m; //(_DontInitialize()); 230 | 231 | m._mem.op = OPERAND_MEM; 232 | m._mem.size = (ptrSize == INVALID_VALUE) ? var.getSize() : (uint8_t)ptrSize; 233 | m._mem.type = OPERAND_MEM_NATIVE; 234 | m._mem.segmentPrefix = SEGMENT_NONE; 235 | m._mem.sizePrefix = 0; 236 | m._mem.shift = 0; 237 | 238 | m._mem.id = var.getId(); 239 | 240 | m._mem.base = INVALID_VALUE; 241 | m._mem.index = INVALID_VALUE; 242 | 243 | m._mem.target = NULL; 244 | m._mem.displacement = disp; 245 | 246 | return m; 247 | } 248 | 249 | Mem _BaseVarMem(const BaseVar& var, uint32_t ptrSize, const GPVar& index, uint32_t shift, sysint_t disp) ASMJIT_NOTHROW 250 | { 251 | Mem m; //(_DontInitialize()); 252 | 253 | m._mem.op = OPERAND_MEM; 254 | m._mem.size = (ptrSize == INVALID_VALUE) ? var.getSize() : (uint8_t)ptrSize; 255 | m._mem.type = OPERAND_MEM_NATIVE; 256 | m._mem.segmentPrefix = SEGMENT_NONE; 257 | m._mem.sizePrefix = 0; 258 | m._mem.shift = shift; 259 | 260 | m._mem.id = var.getId(); 261 | 262 | m._mem.base = INVALID_VALUE; 263 | m._mem.index = index.getId(); 264 | 265 | m._mem.target = NULL; 266 | m._mem.displacement = disp; 267 | 268 | return m; 269 | } 270 | 271 | // ============================================================================ 272 | // [AsmJit::Mem - ptr[]] 273 | // ============================================================================ 274 | 275 | Mem _MemPtrBuild( 276 | const Label& label, sysint_t disp, uint32_t ptrSize) 277 | ASMJIT_NOTHROW 278 | { 279 | return Mem(label, disp, ptrSize); 280 | } 281 | 282 | Mem _MemPtrBuild( 283 | const Label& label, 284 | const GPReg& index, uint32_t shift, sysint_t disp, uint32_t ptrSize) 285 | ASMJIT_NOTHROW 286 | { 287 | Mem m(label, disp, ptrSize); 288 | 289 | m._mem.index = index.getRegIndex(); 290 | m._mem.shift = shift; 291 | 292 | return m; 293 | } 294 | 295 | Mem _MemPtrBuild( 296 | const Label& label, 297 | const GPVar& index, uint32_t shift, sysint_t disp, uint32_t ptrSize) 298 | ASMJIT_NOTHROW 299 | { 300 | Mem m(label, disp, ptrSize); 301 | 302 | m._mem.index = index.getId(); 303 | m._mem.shift = shift; 304 | 305 | return m; 306 | } 307 | 308 | // ============================================================================ 309 | // [AsmJit::Mem - ptr[] - Absolute Addressing] 310 | // ============================================================================ 311 | 312 | ASMJIT_API Mem _MemPtrAbs( 313 | void* target, sysint_t disp, 314 | uint32_t segmentPrefix, uint32_t ptrSize) 315 | ASMJIT_NOTHROW 316 | { 317 | Mem m; 318 | 319 | m._mem.size = ptrSize; 320 | m._mem.type = OPERAND_MEM_ABSOLUTE; 321 | m._mem.segmentPrefix = segmentPrefix; 322 | 323 | m._mem.target = target; 324 | m._mem.displacement = disp; 325 | 326 | return m; 327 | } 328 | 329 | ASMJIT_API Mem _MemPtrAbs( 330 | void* target, 331 | const GPReg& index, uint32_t shift, sysint_t disp, 332 | uint32_t segmentPrefix, uint32_t ptrSize) 333 | ASMJIT_NOTHROW 334 | { 335 | Mem m;// (_DontInitialize()); 336 | 337 | m._mem.op = OPERAND_MEM; 338 | m._mem.size = ptrSize; 339 | m._mem.type = OPERAND_MEM_ABSOLUTE; 340 | m._mem.segmentPrefix = (uint8_t)segmentPrefix; 341 | 342 | #if defined(ASMJIT_X86) 343 | m._mem.sizePrefix = index.getSize() != 4; 344 | #else 345 | m._mem.sizePrefix = index.getSize() != 8; 346 | #endif 347 | 348 | m._mem.shift = shift; 349 | 350 | m._mem.id = INVALID_VALUE; 351 | m._mem.base = INVALID_VALUE; 352 | m._mem.index = index.getRegIndex(); 353 | 354 | m._mem.target = target; 355 | m._mem.displacement = disp; 356 | 357 | return m; 358 | } 359 | 360 | ASMJIT_API Mem _MemPtrAbs( 361 | void* target, 362 | const GPVar& index, uint32_t shift, sysint_t disp, 363 | uint32_t segmentPrefix, uint32_t ptrSize) 364 | ASMJIT_NOTHROW 365 | { 366 | Mem m;// (_DontInitialize()); 367 | 368 | m._mem.op = OPERAND_MEM; 369 | m._mem.size = ptrSize; 370 | m._mem.type = OPERAND_MEM_ABSOLUTE; 371 | m._mem.segmentPrefix = (uint8_t)segmentPrefix; 372 | 373 | #if defined(ASMJIT_X86) 374 | m._mem.sizePrefix = index.getSize() != 4; 375 | #else 376 | m._mem.sizePrefix = index.getSize() != 8; 377 | #endif 378 | 379 | m._mem.shift = shift; 380 | 381 | m._mem.id = INVALID_VALUE; 382 | m._mem.base = INVALID_VALUE; 383 | m._mem.index = index.getId(); 384 | 385 | m._mem.target = target; 386 | m._mem.displacement = disp; 387 | 388 | return m; 389 | } 390 | 391 | // ============================================================================ 392 | // [AsmJit::Mem - ptr[base + displacement]] 393 | // ============================================================================ 394 | 395 | Mem _MemPtrBuild( 396 | const GPReg& base, sysint_t disp, uint32_t ptrSize) 397 | ASMJIT_NOTHROW 398 | { 399 | return Mem(base, disp, ptrSize); 400 | } 401 | 402 | Mem _MemPtrBuild( 403 | const GPReg& base, 404 | const GPReg& index, uint32_t shift, sysint_t disp, uint32_t ptrSize) 405 | ASMJIT_NOTHROW 406 | { 407 | return Mem(base, index, shift, disp, ptrSize); 408 | } 409 | 410 | Mem _MemPtrBuild( 411 | const GPVar& base, sysint_t disp, uint32_t ptrSize) 412 | ASMJIT_NOTHROW 413 | { 414 | return Mem(base, disp, ptrSize); 415 | } 416 | 417 | Mem _MemPtrBuild( 418 | const GPVar& base, 419 | const GPVar& index, uint32_t shift, sysint_t disp, uint32_t ptrSize) 420 | ASMJIT_NOTHROW 421 | { 422 | return Mem(base, index, shift, disp, ptrSize); 423 | } 424 | 425 | } // AsmJit namespace 426 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Platform.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include 9 | 10 | #include "Platform.h" 11 | 12 | // [Api-Begin] 13 | #include "ApiBegin.h" 14 | 15 | // helpers 16 | namespace AsmJit { 17 | 18 | // ============================================================================ 19 | // [AsmJit::Assert] 20 | // ============================================================================ 21 | 22 | void assertionFailure(const char* file, int line, const char* exp) 23 | { 24 | fprintf(stderr, 25 | "*** ASSERTION FAILURE at %s (line %d)\n" 26 | "*** %s\n", file, line, exp); 27 | 28 | exit(1); 29 | } 30 | 31 | // ============================================================================ 32 | // [AsmJit::Helpers] 33 | // ============================================================================ 34 | 35 | static bool isAligned(sysuint_t base, sysuint_t alignment) 36 | { 37 | return base % alignment == 0; 38 | } 39 | 40 | static sysuint_t roundUp(sysuint_t base, sysuint_t pageSize) 41 | { 42 | sysuint_t over = base % pageSize; 43 | return base + (over > 0 ? pageSize - over : 0); 44 | } 45 | 46 | // Implementation is from "Hacker's Delight" by Henry S. Warren, Jr., 47 | // figure 3-3, page 48, where the function is called clp2. 48 | static sysuint_t roundUpToPowerOf2(sysuint_t base) 49 | { 50 | base -= 1; 51 | 52 | base = base | (base >> 1); 53 | base = base | (base >> 2); 54 | base = base | (base >> 4); 55 | base = base | (base >> 8); 56 | base = base | (base >> 16); 57 | 58 | // I'm trying to make this portable and MSVC strikes me the warning C4293: 59 | // "Shift count negative or too big, undefined behavior" 60 | // Fixing... 61 | #if _MSC_VER 62 | # pragma warning(disable: 4293) 63 | #endif // _MSC_VER 64 | 65 | if (sizeof(sysuint_t) >= 8) 66 | base = base | (base >> 32); 67 | 68 | return base + 1; 69 | } 70 | 71 | } // AsmJit namespace 72 | 73 | // ============================================================================ 74 | // [AsmJit::VirtualMemory::Windows] 75 | // ============================================================================ 76 | 77 | #if defined(ASMJIT_WINDOWS) 78 | 79 | #include 80 | 81 | namespace AsmJit { 82 | 83 | struct ASMJIT_HIDDEN VirtualMemoryLocal 84 | { 85 | VirtualMemoryLocal() ASMJIT_NOTHROW 86 | { 87 | SYSTEM_INFO info; 88 | GetSystemInfo(&info); 89 | 90 | alignment = info.dwAllocationGranularity; 91 | pageSize = roundUpToPowerOf2(info.dwPageSize); 92 | } 93 | 94 | sysuint_t alignment; 95 | sysuint_t pageSize; 96 | }; 97 | 98 | static VirtualMemoryLocal& vm() ASMJIT_NOTHROW 99 | { 100 | static VirtualMemoryLocal vm; 101 | return vm; 102 | }; 103 | 104 | void* VirtualMemory::alloc(sysuint_t length, sysuint_t* allocated, bool canExecute) 105 | ASMJIT_NOTHROW 106 | { 107 | return allocProcessMemory(GetCurrentProcess(), length, allocated, canExecute); 108 | } 109 | 110 | void VirtualMemory::free(void* addr, sysuint_t length) 111 | ASMJIT_NOTHROW 112 | { 113 | return freeProcessMemory(GetCurrentProcess(), addr, length); 114 | } 115 | 116 | void* VirtualMemory::allocProcessMemory(HANDLE hProcess, sysuint_t length, sysuint_t* allocated, bool canExecute) ASMJIT_NOTHROW 117 | { 118 | // VirtualAlloc rounds allocated size to page size automatically. 119 | sysuint_t msize = roundUp(length, vm().pageSize); 120 | 121 | // Windows XP SP2 / Vista allow Data Excution Prevention (DEP). 122 | WORD protect = canExecute ? PAGE_EXECUTE_READWRITE : PAGE_READWRITE; 123 | LPVOID mbase = VirtualAllocEx(hProcess, NULL, msize, MEM_COMMIT | MEM_RESERVE, protect); 124 | if (mbase == NULL) return NULL; 125 | 126 | ASMJIT_ASSERT(isAligned(reinterpret_cast(mbase), vm().alignment)); 127 | 128 | if (allocated) *allocated = msize; 129 | return mbase; 130 | } 131 | 132 | void VirtualMemory::freeProcessMemory(HANDLE hProcess, void* addr, sysuint_t /* length */) ASMJIT_NOTHROW 133 | { 134 | VirtualFreeEx(hProcess, addr, 0, MEM_RELEASE); 135 | } 136 | 137 | sysuint_t VirtualMemory::getAlignment() 138 | ASMJIT_NOTHROW 139 | { 140 | return vm().alignment; 141 | } 142 | 143 | sysuint_t VirtualMemory::getPageSize() 144 | ASMJIT_NOTHROW 145 | { 146 | return vm().pageSize; 147 | } 148 | 149 | } // AsmJit 150 | 151 | #endif // ASMJIT_WINDOWS 152 | 153 | // ============================================================================ 154 | // [AsmJit::VirtualMemory::Posix] 155 | // ============================================================================ 156 | 157 | #if defined(ASMJIT_POSIX) 158 | 159 | #include 160 | #include 161 | #include 162 | 163 | // MacOS uses MAP_ANON instead of MAP_ANONYMOUS 164 | #ifndef MAP_ANONYMOUS 165 | # define MAP_ANONYMOUS MAP_ANON 166 | #endif 167 | 168 | namespace AsmJit { 169 | 170 | struct ASMJIT_HIDDEN VirtualMemoryLocal 171 | { 172 | VirtualMemoryLocal() ASMJIT_NOTHROW 173 | { 174 | alignment = pageSize = getpagesize(); 175 | } 176 | 177 | sysuint_t alignment; 178 | sysuint_t pageSize; 179 | }; 180 | 181 | static VirtualMemoryLocal& vm() 182 | ASMJIT_NOTHROW 183 | { 184 | static VirtualMemoryLocal vm; 185 | return vm; 186 | } 187 | 188 | void* VirtualMemory::alloc(sysuint_t length, sysuint_t* allocated, bool canExecute) 189 | ASMJIT_NOTHROW 190 | { 191 | sysuint_t msize = roundUp(length, vm().pageSize); 192 | int protection = PROT_READ | PROT_WRITE | (canExecute ? PROT_EXEC : 0); 193 | void* mbase = mmap(NULL, msize, protection, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); 194 | if (mbase == MAP_FAILED) return NULL; 195 | if (allocated) *allocated = msize; 196 | return mbase; 197 | } 198 | 199 | void VirtualMemory::free(void* addr, sysuint_t length) 200 | ASMJIT_NOTHROW 201 | { 202 | munmap(addr, length); 203 | } 204 | 205 | sysuint_t VirtualMemory::getAlignment() 206 | ASMJIT_NOTHROW 207 | { 208 | return vm().alignment; 209 | } 210 | 211 | sysuint_t VirtualMemory::getPageSize() 212 | ASMJIT_NOTHROW 213 | { 214 | return vm().pageSize; 215 | } 216 | 217 | } // AsmJit 218 | 219 | #endif // ASMJIT_POSIX 220 | 221 | // [Api-End] 222 | #include "ApiEnd.h" 223 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Platform.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_PLATFORM_H 9 | #define _ASMJIT_PLATFORM_H 10 | 11 | // [Dependencies] 12 | #include "Build.h" 13 | 14 | #if defined(ASMJIT_WINDOWS) 15 | #include 16 | #endif // ASMJIT_WINDOWS 17 | 18 | #if defined(ASMJIT_POSIX) 19 | #include 20 | #endif // ASMJIT_POSIX 21 | 22 | // [Api-Begin] 23 | #include "ApiBegin.h" 24 | 25 | namespace AsmJit { 26 | 27 | //! @addtogroup AsmJit_Util 28 | //! @{ 29 | 30 | // ============================================================================ 31 | // [AsmJit::Assert] 32 | // ============================================================================ 33 | 34 | //! @brief Called in debug build on assertion failure. 35 | //! @param file Source file name where it happened. 36 | //! @param line Line in the source file. 37 | //! @param exp Expression what failed. 38 | //! 39 | //! If you have problems with assertions simply put a breakpoint into 40 | //! AsmJit::assertionFailure() method (see AsmJit/Platform.cpp file) and see 41 | //! call stack. 42 | ASMJIT_API void assertionFailure(const char* file, int line, const char* exp); 43 | 44 | // ============================================================================ 45 | // [AsmJit::Lock] 46 | // ============================================================================ 47 | 48 | //! @brief Lock - used in thread-safe code for locking. 49 | struct ASMJIT_HIDDEN Lock 50 | { 51 | #if defined(ASMJIT_WINDOWS) 52 | typedef CRITICAL_SECTION Handle; 53 | #endif // ASMJIT_WINDOWS 54 | #if defined(ASMJIT_POSIX) 55 | typedef pthread_mutex_t Handle; 56 | #endif // ASMJIT_POSIX 57 | 58 | //! @brief Create a new @ref Lock instance. 59 | inline Lock() ASMJIT_NOTHROW 60 | { 61 | #if defined(ASMJIT_WINDOWS) 62 | InitializeCriticalSection(&_handle); 63 | // InitializeLockAndSpinCount(&_handle, 2000); 64 | #endif // ASMJIT_WINDOWS 65 | #if defined(ASMJIT_POSIX) 66 | pthread_mutex_init(&_handle, NULL); 67 | #endif // ASMJIT_POSIX 68 | } 69 | 70 | //! @brief Destroy the @ref Lock instance. 71 | inline ~Lock() ASMJIT_NOTHROW 72 | { 73 | #if defined(ASMJIT_WINDOWS) 74 | DeleteCriticalSection(&_handle); 75 | #endif // ASMJIT_WINDOWS 76 | #if defined(ASMJIT_POSIX) 77 | pthread_mutex_destroy(&_handle); 78 | #endif // ASMJIT_POSIX 79 | } 80 | 81 | //! @brief Get handle. 82 | inline Handle& getHandle() ASMJIT_NOTHROW 83 | { 84 | return _handle; 85 | } 86 | 87 | //! @overload 88 | inline const Handle& getHandle() const ASMJIT_NOTHROW 89 | { 90 | return _handle; 91 | } 92 | 93 | //! @brief Lock. 94 | inline void lock() ASMJIT_NOTHROW 95 | { 96 | #if defined(ASMJIT_WINDOWS) 97 | EnterCriticalSection(&_handle); 98 | #endif // ASMJIT_WINDOWS 99 | #if defined(ASMJIT_POSIX) 100 | pthread_mutex_lock(&_handle); 101 | #endif // ASMJIT_POSIX 102 | } 103 | 104 | //! @brief Unlock. 105 | inline void unlock() ASMJIT_NOTHROW 106 | { 107 | #if defined(ASMJIT_WINDOWS) 108 | LeaveCriticalSection(&_handle); 109 | #endif // ASMJIT_WINDOWS 110 | #if defined(ASMJIT_POSIX) 111 | pthread_mutex_unlock(&_handle); 112 | #endif // ASMJIT_POSIX 113 | } 114 | 115 | private: 116 | //! @brief Handle. 117 | Handle _handle; 118 | 119 | // Disable copy. 120 | ASMJIT_DISABLE_COPY(Lock) 121 | }; 122 | 123 | // ============================================================================ 124 | // [AsmJit::AutoLock] 125 | // ============================================================================ 126 | 127 | //! @brief Scope auto locker. 128 | struct ASMJIT_HIDDEN AutoLock 129 | { 130 | //! @brief Locks @a target. 131 | inline AutoLock(Lock& target) ASMJIT_NOTHROW : _target(target) 132 | { 133 | _target.lock(); 134 | } 135 | 136 | //! @brief Unlocks target. 137 | inline ~AutoLock() ASMJIT_NOTHROW 138 | { 139 | _target.unlock(); 140 | } 141 | 142 | private: 143 | //! @brief Pointer to target (lock). 144 | Lock& _target; 145 | 146 | // Disable copy. 147 | ASMJIT_DISABLE_COPY(AutoLock) 148 | }; 149 | 150 | // ============================================================================ 151 | // [AsmJit::VirtualMemory] 152 | // ============================================================================ 153 | 154 | //! @brief Class that helps with allocating memory for executing code 155 | //! generated by JIT compiler. 156 | //! 157 | //! There are defined functions that provides facility to allocate and free 158 | //! memory where can be executed code. If processor and operating system 159 | //! supports execution protection then you can't run code from normally 160 | //! malloc()'ed memory. 161 | //! 162 | //! Functions are internally implemented by operating system dependent way. 163 | //! VirtualAlloc() function is used for Windows operating system and mmap() 164 | //! for posix ones. If you want to study or create your own functions, look 165 | //! at VirtualAlloc() or mmap() documentation (depends on you target OS). 166 | //! 167 | //! Under posix operating systems is also useable mprotect() function, that 168 | //! can enable execution protection to malloc()'ed memory block. 169 | struct ASMJIT_API VirtualMemory 170 | { 171 | //! @brief Allocate virtual memory. 172 | //! 173 | //! Pages are readable/writeable, but they are not guaranteed to be 174 | //! executable unless 'canExecute' is true. Returns the address of 175 | //! allocated memory, or NULL if failed. 176 | static void* alloc(sysuint_t length, sysuint_t* allocated, bool canExecute) ASMJIT_NOTHROW; 177 | 178 | //! @brief Free memory allocated by @c alloc() 179 | static void free(void* addr, sysuint_t length) ASMJIT_NOTHROW; 180 | 181 | #if defined(ASMJIT_WINDOWS) 182 | //! @brief Allocate virtual memory of @a hProcess. 183 | //! 184 | //! @note This function is windows specific and unportable. 185 | static void* allocProcessMemory(HANDLE hProcess, sysuint_t length, sysuint_t* allocated, bool canExecute) ASMJIT_NOTHROW; 186 | 187 | //! @brief Free virtual memory of @a hProcess. 188 | //! 189 | //! @note This function is windows specific and unportable. 190 | static void freeProcessMemory(HANDLE hProcess, void* addr, sysuint_t length) ASMJIT_NOTHROW; 191 | #endif // ASMJIT_WINDOWS 192 | 193 | //! @brief Get the alignment guaranteed by alloc(). 194 | static sysuint_t getAlignment() ASMJIT_NOTHROW; 195 | 196 | //! @brief Get size of single page. 197 | static sysuint_t getPageSize() ASMJIT_NOTHROW; 198 | }; 199 | 200 | //! @} 201 | 202 | } // AsmJit namespace 203 | 204 | // [Api-End] 205 | #include "ApiEnd.h" 206 | 207 | // [Guard] 208 | #endif // _ASMJIT_PLATFORM_H 209 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Regenerate.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # ============================================================================= 4 | # [Regenerate.py - Description] 5 | # 6 | # This Python script will regenerate instruction names in Assembler{$ARCH}.cpp 7 | # files. Idea is that there can be big instruction table and this script tries 8 | # to minimize runtime relocation data of AsmJit library. 9 | # ============================================================================= 10 | 11 | # ============================================================================= 12 | # [Configuration] 13 | # ============================================================================= 14 | 15 | # Files to process. 16 | FILES = [ 17 | "DefsX86X64.cpp" 18 | ] 19 | 20 | # ============================================================================= 21 | # [Imports] 22 | # ============================================================================= 23 | 24 | import os, re, string 25 | 26 | # ============================================================================= 27 | # [Helpers] 28 | # ============================================================================= 29 | 30 | def readFile(fileName): 31 | handle = open(fileName, "rb") 32 | data = handle.read() 33 | handle.close() 34 | return data 35 | 36 | def writeFile(fileName, data): 37 | handle = open(fileName, "wb") 38 | handle.truncate() 39 | handle.write(data) 40 | handle.close() 41 | 42 | # ============================================================================= 43 | # [Main] 44 | # ============================================================================= 45 | 46 | def processFile(fileName): 47 | data = readFile(fileName); 48 | 49 | din = data 50 | r = re.compile(r"instructionDescription\[\][\s]*=[\s]*{(?P[^}])*}") 51 | m = r.search(din) 52 | 53 | if not m: 54 | print "Cannot match instruction data in " + fileName 55 | exit(0) 56 | 57 | din = din[m.start():m.end()] 58 | dout = "" 59 | 60 | dinst = [] 61 | daddr = [] 62 | hinst = {} 63 | 64 | r = re.compile(r'\"(?P[A-Za-z0-9_ ]+)\"') 65 | dpos = 0 66 | for m in r.finditer(din): 67 | inst = m.group("INST") 68 | 69 | if not inst in hinst: 70 | dinst.append(inst) 71 | hinst[inst] = dpos 72 | 73 | daddr.append(dpos) 74 | dpos += len(inst) + 1 75 | 76 | dout += "const char instructionName[] =\n" 77 | for i in xrange(len(dinst)): 78 | dout += " \"" + dinst[i] + "\\0\"\n" 79 | dout += " ;\n" 80 | 81 | dout += "\n" 82 | 83 | for i in xrange(len(dinst)): 84 | dout += "#define INST_" + dinst[i].upper().replace(" ", "_") + "_INDEX" + " " + str(daddr[i]) + "\n" 85 | 86 | mb_string = "// ${INSTRUCTION_DATA_BEGIN}\n" 87 | me_string = "// ${INSTRUCTION_DATA_END}\n" 88 | 89 | mb = data.index(mb_string) 90 | me = data.index(me_string) 91 | 92 | data = data[:mb + len(mb_string)] + dout + data[me:] 93 | 94 | writeFile(fileName, data) 95 | 96 | for fileName in FILES: 97 | processFile(fileName) 98 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Util.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Dependencies] 8 | #include "Build.h" 9 | #include "Util_p.h" 10 | 11 | // [Api-Begin] 12 | #include "ApiBegin.h" 13 | 14 | namespace AsmJit { 15 | 16 | // ============================================================================ 17 | // [AsmJit::Util] 18 | // ============================================================================ 19 | 20 | static const char letters[] = "0123456789ABCDEF"; 21 | 22 | char* Util::mycpy(char* dst, const char* src, sysuint_t len) ASMJIT_NOTHROW 23 | { 24 | if (src == NULL) return dst; 25 | 26 | if (len == (sysuint_t)-1) 27 | { 28 | while (*src) *dst++ = *src++; 29 | } 30 | else 31 | { 32 | memcpy(dst, src, len); 33 | dst += len; 34 | } 35 | 36 | return dst; 37 | } 38 | 39 | char* Util::myfill(char* dst, const int c, sysuint_t len) ASMJIT_NOTHROW 40 | { 41 | memset(dst, c, len); 42 | return dst + len; 43 | } 44 | 45 | char* Util::myhex(char* dst, const uint8_t* src, sysuint_t len) ASMJIT_NOTHROW 46 | { 47 | for (sysuint_t i = len; i; i--, dst += 2, src += 1) 48 | { 49 | dst[0] = letters[(src[0] >> 4) & 0xF]; 50 | dst[1] = letters[(src[0] ) & 0xF]; 51 | } 52 | 53 | return dst; 54 | } 55 | 56 | // Not too efficient, but this is mainly for debugging:) 57 | char* Util::myutoa(char* dst, sysuint_t i, sysuint_t base) ASMJIT_NOTHROW 58 | { 59 | ASMJIT_ASSERT(base <= 16); 60 | 61 | char buf[128]; 62 | char* p = buf + 128; 63 | 64 | do { 65 | sysint_t b = i % base; 66 | *--p = letters[b]; 67 | i /= base; 68 | } while (i); 69 | 70 | return Util::mycpy(dst, p, (sysuint_t)(buf + 128 - p)); 71 | } 72 | 73 | char* Util::myitoa(char* dst, sysint_t i, sysuint_t base) ASMJIT_NOTHROW 74 | { 75 | if (i < 0) 76 | { 77 | *dst++ = '-'; 78 | i = -i; 79 | } 80 | 81 | return Util::myutoa(dst, (sysuint_t)i, base); 82 | } 83 | 84 | // ============================================================================ 85 | // [AsmJit::Buffer] 86 | // ============================================================================ 87 | 88 | void Buffer::emitData(const void* dataPtr, sysuint_t dataLen) ASMJIT_NOTHROW 89 | { 90 | sysint_t max = getCapacity() - getOffset(); 91 | if ((sysuint_t)max < dataLen) 92 | { 93 | if (!realloc(getOffset() + dataLen)) return; 94 | } 95 | 96 | memcpy(_cur, dataPtr, dataLen); 97 | _cur += dataLen; 98 | } 99 | 100 | bool Buffer::realloc(sysint_t to) ASMJIT_NOTHROW 101 | { 102 | if (getCapacity() < to) 103 | { 104 | sysint_t len = getOffset(); 105 | 106 | uint8_t *newdata; 107 | if (_data) 108 | newdata = (uint8_t*)ASMJIT_REALLOC(_data, to); 109 | else 110 | newdata = (uint8_t*)ASMJIT_MALLOC(to); 111 | if (!newdata) return false; 112 | 113 | _data = newdata; 114 | _cur = newdata + len; 115 | _max = newdata + to; 116 | _max -= (to >= _growThreshold) ? _growThreshold : to; 117 | 118 | _capacity = to; 119 | } 120 | 121 | return true; 122 | } 123 | 124 | bool Buffer::grow() ASMJIT_NOTHROW 125 | { 126 | sysint_t to = _capacity; 127 | 128 | if (to < 512) 129 | to = 1024; 130 | else if (to > 65536) 131 | to += 65536; 132 | else 133 | to <<= 1; 134 | 135 | return realloc(to); 136 | } 137 | 138 | void Buffer::clear() ASMJIT_NOTHROW 139 | { 140 | _cur = _data; 141 | } 142 | 143 | void Buffer::free() ASMJIT_NOTHROW 144 | { 145 | if (!_data) return; 146 | ASMJIT_FREE(_data); 147 | 148 | _data = NULL; 149 | _cur = NULL; 150 | _max = NULL; 151 | _capacity = 0; 152 | } 153 | 154 | uint8_t* Buffer::take() ASMJIT_NOTHROW 155 | { 156 | uint8_t* data = _data; 157 | 158 | _data = NULL; 159 | _cur = NULL; 160 | _max = NULL; 161 | _capacity = 0; 162 | 163 | return data; 164 | } 165 | 166 | // ============================================================================ 167 | // [AsmJit::Zone] 168 | // ============================================================================ 169 | 170 | Zone::Zone(sysuint_t chunkSize) ASMJIT_NOTHROW 171 | { 172 | _chunks = NULL; 173 | _total = 0; 174 | _chunkSize = chunkSize; 175 | } 176 | 177 | Zone::~Zone() ASMJIT_NOTHROW 178 | { 179 | freeAll(); 180 | } 181 | 182 | void* Zone::zalloc(sysuint_t size) ASMJIT_NOTHROW 183 | { 184 | // Align to 4 or 8 bytes. 185 | size = (size + sizeof(sysint_t)-1) & ~(sizeof(sysint_t)-1); 186 | 187 | Chunk* cur = _chunks; 188 | 189 | if (!cur || cur->getRemainingBytes() < size) 190 | { 191 | sysuint_t chSize = _chunkSize; 192 | if (chSize < size) chSize = size; 193 | 194 | cur = (Chunk*)ASMJIT_MALLOC(sizeof(Chunk) - sizeof(void*) + chSize); 195 | if (!cur) return NULL; 196 | 197 | cur->prev = _chunks; 198 | cur->pos = 0; 199 | cur->size = _chunkSize; 200 | _chunks = cur; 201 | } 202 | 203 | uint8_t* p = cur->data + cur->pos; 204 | cur->pos += size; 205 | _total += size; 206 | return (void*)p; 207 | } 208 | 209 | char* Zone::zstrdup(const char* str) ASMJIT_NOTHROW 210 | { 211 | if (str == NULL) return NULL; 212 | 213 | sysuint_t len = strlen(str); 214 | if (len == 0) return NULL; 215 | 216 | // Include NULL terminator. 217 | len++; 218 | 219 | // Limit string length. 220 | if (len > 256) len = 256; 221 | 222 | char* m = reinterpret_cast(zalloc((len + 15) & ~15)); 223 | if (!m) return NULL; 224 | 225 | memcpy(m, str, len); 226 | m[len-1] = '\0'; 227 | return m; 228 | } 229 | 230 | void Zone::clear() ASMJIT_NOTHROW 231 | { 232 | Chunk* cur = _chunks; 233 | if (!cur) return; 234 | 235 | _chunks->pos = 0; 236 | _chunks->prev = NULL; 237 | _total = 0; 238 | 239 | cur = cur->prev; 240 | while (cur) 241 | { 242 | Chunk* prev = cur->prev; 243 | ASMJIT_FREE(cur); 244 | cur = prev; 245 | } 246 | } 247 | 248 | void Zone::freeAll() ASMJIT_NOTHROW 249 | { 250 | Chunk* cur = _chunks; 251 | 252 | _chunks = NULL; 253 | _total = 0; 254 | 255 | while (cur) 256 | { 257 | Chunk* prev = cur->prev; 258 | ASMJIT_FREE(cur); 259 | cur = prev; 260 | } 261 | } 262 | 263 | } // AsmJit namespace 264 | 265 | // [Api-End] 266 | #include "ApiEnd.h" 267 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/AsmJit/Util_p.h: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // [Guard] 8 | #ifndef _ASMJIT_UTIL_P_H 9 | #define _ASMJIT_UTIL_P_H 10 | 11 | // [Dependencies] 12 | #include "Util.h" 13 | 14 | #include 15 | #include 16 | 17 | namespace AsmJit { 18 | 19 | //! @addtogroup AsmJit_Util 20 | //! @{ 21 | 22 | // ============================================================================ 23 | // [AsmJit::Util] 24 | // ============================================================================ 25 | 26 | namespace Util 27 | { 28 | // -------------------------------------------------------------------------- 29 | // [AsmJit::floatAsInt32, int32AsFloat] 30 | // -------------------------------------------------------------------------- 31 | 32 | //! @internal 33 | //! 34 | //! @brief used to cast from float to 32-bit integer and vica versa. 35 | union I32FPUnion 36 | { 37 | //! @brief 32-bit signed integer value. 38 | int32_t i; 39 | //! @brief 32-bit SP-FP value. 40 | float f; 41 | }; 42 | 43 | //! @internal 44 | //! 45 | //! @brief used to cast from double to 64-bit integer and vica versa. 46 | union I64FPUnion 47 | { 48 | //! @brief 64-bit signed integer value. 49 | int64_t i; 50 | //! @brief 64-bit DP-FP value. 51 | double f; 52 | }; 53 | 54 | //! @brief Binary cast from 32-bit integer to SP-FP value (@c float). 55 | static inline float int32AsFloat(int32_t i) ASMJIT_NOTHROW 56 | { 57 | I32FPUnion u; 58 | u.i = i; 59 | return u.f; 60 | } 61 | 62 | //! @brief Binary cast SP-FP value (@c float) to 32-bit integer. 63 | static inline int32_t floatAsInt32(float f) ASMJIT_NOTHROW 64 | { 65 | I32FPUnion u; 66 | u.f = f; 67 | return u.i; 68 | } 69 | 70 | //! @brief Binary cast from 64-bit integer to DP-FP value (@c double). 71 | static inline double int64AsDouble(int64_t i) ASMJIT_NOTHROW 72 | { 73 | I64FPUnion u; 74 | u.i = i; 75 | return u.f; 76 | } 77 | 78 | //! @brief Binary cast from DP-FP value (@c double) to 64-bit integer. 79 | static inline int64_t doubleAsInt64(double f) ASMJIT_NOTHROW 80 | { 81 | I64FPUnion u; 82 | u.f = f; 83 | return u.i; 84 | } 85 | 86 | // -------------------------------------------------------------------------- 87 | // [Str Utils] 88 | // -------------------------------------------------------------------------- 89 | 90 | ASMJIT_HIDDEN char* mycpy(char* dst, const char* src, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW; 91 | ASMJIT_HIDDEN char* myfill(char* dst, const int c, sysuint_t len) ASMJIT_NOTHROW; 92 | ASMJIT_HIDDEN char* myhex(char* dst, const uint8_t* src, sysuint_t len) ASMJIT_NOTHROW; 93 | ASMJIT_HIDDEN char* myutoa(char* dst, sysuint_t i, sysuint_t base = 10) ASMJIT_NOTHROW; 94 | ASMJIT_HIDDEN char* myitoa(char* dst, sysint_t i, sysuint_t base = 10) ASMJIT_NOTHROW; 95 | 96 | // -------------------------------------------------------------------------- 97 | // [Mem Utils] 98 | // -------------------------------------------------------------------------- 99 | 100 | static inline void memset32(uint32_t* p, uint32_t c, sysuint_t len) ASMJIT_NOTHROW 101 | { 102 | sysuint_t i; 103 | for (i = 0; i < len; i++) p[i] = c; 104 | } 105 | } // Util namespace 106 | 107 | //! @} 108 | 109 | } // AsmJit namespace 110 | 111 | #endif // _ASMJIT_UTIL_P_H 112 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/CMakeFiles/CMakeDirectoryInformation.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 2.8 3 | 4 | # Relative path conversion top directories. 5 | SET(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/rudd/dev/asmjit/AsmJit-1.0-beta4") 6 | SET(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build") 7 | 8 | # Force unix paths in dependencies. 9 | SET(CMAKE_FORCE_UNIX_PATHS 1) 10 | 11 | # The C and CXX include file search paths: 12 | SET(CMAKE_C_INCLUDE_PATH 13 | ) 14 | SET(CMAKE_CXX_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH}) 15 | SET(CMAKE_Fortran_INCLUDE_PATH ${CMAKE_C_INCLUDE_PATH}) 16 | 17 | # The C and CXX include file regular expressions for this directory. 18 | SET(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$") 19 | SET(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$") 20 | SET(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN}) 21 | SET(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN}) 22 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/CMakeFiles/Makefile.cmake: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 2.8 3 | 4 | # The generator used is: 5 | SET(CMAKE_DEPENDS_GENERATOR "Unix Makefiles") 6 | 7 | # The top level Makefile was generated from the following files: 8 | SET(CMAKE_MAKEFILE_DEPENDS 9 | "CMakeCache.txt" 10 | "../CMakeLists.txt" 11 | "/usr/share/cmake-2.8/Modules/CMakeCInformation.cmake" 12 | "/usr/share/cmake-2.8/Modules/CMakeCXXInformation.cmake" 13 | "/usr/share/cmake-2.8/Modules/CMakeDetermineCCompiler.cmake" 14 | "/usr/share/cmake-2.8/Modules/CMakeDetermineCXXCompiler.cmake" 15 | "/usr/share/cmake-2.8/Modules/CMakeDetermineSystem.cmake" 16 | "/usr/share/cmake-2.8/Modules/CMakeSystemSpecificInformation.cmake" 17 | "/usr/share/cmake-2.8/Modules/CMakeTestCCompiler.cmake" 18 | "/usr/share/cmake-2.8/Modules/CMakeTestCXXCompiler.cmake" 19 | "/usr/share/cmake-2.8/Modules/CMakeUnixFindMake.cmake" 20 | ) 21 | 22 | # The corresponding makefile is: 23 | SET(CMAKE_MAKEFILE_OUTPUTS 24 | "Makefile" 25 | "CMakeFiles/cmake.check_cache" 26 | ) 27 | 28 | # Byproducts of CMake generate step: 29 | SET(CMAKE_MAKEFILE_PRODUCTS 30 | "CMakeFiles/CMakeDirectoryInformation.cmake" 31 | ) 32 | 33 | # Dependency information for all targets: 34 | SET(CMAKE_DEPEND_INFO_FILES 35 | ) 36 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/CMakeFiles/Makefile2: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 2.8 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | .PHONY : default_target 7 | 8 | # The main recursive all target 9 | all: 10 | .PHONY : all 11 | 12 | # The main recursive preinstall target 13 | preinstall: 14 | .PHONY : preinstall 15 | 16 | #============================================================================= 17 | # Special targets provided by cmake. 18 | 19 | # Disable implicit rules so canoncical targets will work. 20 | .SUFFIXES: 21 | 22 | # Remove some rules from gmake that .SUFFIXES does not remove. 23 | SUFFIXES = 24 | 25 | .SUFFIXES: .hpux_make_needs_suffix_list 26 | 27 | # Suppress display of executed commands. 28 | $(VERBOSE).SILENT: 29 | 30 | # A target that is always out of date. 31 | cmake_force: 32 | .PHONY : cmake_force 33 | 34 | #============================================================================= 35 | # Set environment variables for the build. 36 | 37 | # The shell in which to execute make rules. 38 | SHELL = /bin/sh 39 | 40 | # The CMake executable. 41 | CMAKE_COMMAND = /usr/bin/cmake 42 | 43 | # The command to remove a file. 44 | RM = /usr/bin/cmake -E remove -f 45 | 46 | # The top-level source directory on which CMake was run. 47 | CMAKE_SOURCE_DIR = /home/rudd/dev/asmjit/AsmJit-1.0-beta4 48 | 49 | # The top-level build directory on which CMake was run. 50 | CMAKE_BINARY_DIR = /home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build 51 | 52 | #============================================================================= 53 | # Special targets to cleanup operation of make. 54 | 55 | # Special rule to run CMake to check the build system integrity. 56 | # No rule that depends on this can have commands that come from listfiles 57 | # because they might be regenerated. 58 | cmake_check_build_system: 59 | $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 60 | .PHONY : cmake_check_build_system 61 | 62 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/CMakeFiles/TargetDirectories.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Falaina/AsmJit-Python/66d72713c6bb365c0b812333d6985ca21da1d5b8/deps/AsmJit-1.0-beta4/Build/CMakeFiles/TargetDirectories.txt -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/CMakeFiles/progress.marks: -------------------------------------------------------------------------------- 1 | 0 2 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/Makefile: -------------------------------------------------------------------------------- 1 | # CMAKE generated file: DO NOT EDIT! 2 | # Generated by "Unix Makefiles" Generator, CMake Version 2.8 3 | 4 | # Default target executed when no arguments are given to make. 5 | default_target: all 6 | .PHONY : default_target 7 | 8 | #============================================================================= 9 | # Special targets provided by cmake. 10 | 11 | # Disable implicit rules so canoncical targets will work. 12 | .SUFFIXES: 13 | 14 | # Remove some rules from gmake that .SUFFIXES does not remove. 15 | SUFFIXES = 16 | 17 | .SUFFIXES: .hpux_make_needs_suffix_list 18 | 19 | # Suppress display of executed commands. 20 | $(VERBOSE).SILENT: 21 | 22 | # A target that is always out of date. 23 | cmake_force: 24 | .PHONY : cmake_force 25 | 26 | #============================================================================= 27 | # Set environment variables for the build. 28 | 29 | # The shell in which to execute make rules. 30 | SHELL = /bin/sh 31 | 32 | # The CMake executable. 33 | CMAKE_COMMAND = /usr/bin/cmake 34 | 35 | # The command to remove a file. 36 | RM = /usr/bin/cmake -E remove -f 37 | 38 | # The top-level source directory on which CMake was run. 39 | CMAKE_SOURCE_DIR = /home/rudd/dev/asmjit/AsmJit-1.0-beta4 40 | 41 | # The top-level build directory on which CMake was run. 42 | CMAKE_BINARY_DIR = /home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build 43 | 44 | #============================================================================= 45 | # Targets provided globally by CMake. 46 | 47 | # Special rule for the target edit_cache 48 | edit_cache: 49 | @echo "Running interactive CMake command-line interface..." 50 | /usr/bin/cmake -i . 51 | .PHONY : edit_cache 52 | 53 | # Special rule for the target edit_cache 54 | edit_cache/fast: edit_cache 55 | .PHONY : edit_cache/fast 56 | 57 | # Special rule for the target rebuild_cache 58 | rebuild_cache: 59 | @echo "Running CMake to regenerate build system..." 60 | /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 61 | .PHONY : rebuild_cache 62 | 63 | # Special rule for the target rebuild_cache 64 | rebuild_cache/fast: rebuild_cache 65 | .PHONY : rebuild_cache/fast 66 | 67 | # The main all target 68 | all: cmake_check_build_system 69 | $(CMAKE_COMMAND) -E cmake_progress_start /home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build/CMakeFiles /home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build/CMakeFiles/progress.marks 70 | $(MAKE) -f CMakeFiles/Makefile2 all 71 | $(CMAKE_COMMAND) -E cmake_progress_start /home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build/CMakeFiles 0 72 | .PHONY : all 73 | 74 | # The main clean target 75 | clean: 76 | $(MAKE) -f CMakeFiles/Makefile2 clean 77 | .PHONY : clean 78 | 79 | # The main clean target 80 | clean/fast: clean 81 | .PHONY : clean/fast 82 | 83 | # Prepare targets for installation. 84 | preinstall: all 85 | $(MAKE) -f CMakeFiles/Makefile2 preinstall 86 | .PHONY : preinstall 87 | 88 | # Prepare targets for installation. 89 | preinstall/fast: 90 | $(MAKE) -f CMakeFiles/Makefile2 preinstall 91 | .PHONY : preinstall/fast 92 | 93 | # clear depends 94 | depend: 95 | $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 96 | .PHONY : depend 97 | 98 | # Help Target 99 | help: 100 | @echo "The following are some of the valid targets for this Makefile:" 101 | @echo "... all (the default if no target is provided)" 102 | @echo "... clean" 103 | @echo "... depend" 104 | @echo "... edit_cache" 105 | @echo "... rebuild_cache" 106 | .PHONY : help 107 | 108 | 109 | 110 | #============================================================================= 111 | # Special targets to cleanup operation of make. 112 | 113 | # Special rule to run CMake to check the build system integrity. 114 | # No rule that depends on this can have commands that come from listfiles 115 | # because they might be regenerated. 116 | cmake_check_build_system: 117 | $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0 118 | .PHONY : cmake_check_build_system 119 | 120 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Build/cmake_install.cmake: -------------------------------------------------------------------------------- 1 | # Install script for directory: /home/rudd/dev/asmjit/AsmJit-1.0-beta4 2 | 3 | # Set the install prefix 4 | IF(NOT DEFINED CMAKE_INSTALL_PREFIX) 5 | SET(CMAKE_INSTALL_PREFIX "/usr/local") 6 | ENDIF(NOT DEFINED CMAKE_INSTALL_PREFIX) 7 | STRING(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") 8 | 9 | # Set the install configuration name. 10 | IF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 11 | IF(BUILD_TYPE) 12 | STRING(REGEX REPLACE "^[^A-Za-z0-9_]+" "" 13 | CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}") 14 | ELSE(BUILD_TYPE) 15 | SET(CMAKE_INSTALL_CONFIG_NAME "Release") 16 | ENDIF(BUILD_TYPE) 17 | MESSAGE(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"") 18 | ENDIF(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME) 19 | 20 | # Set the component getting installed. 21 | IF(NOT CMAKE_INSTALL_COMPONENT) 22 | IF(COMPONENT) 23 | MESSAGE(STATUS "Install component: \"${COMPONENT}\"") 24 | SET(CMAKE_INSTALL_COMPONENT "${COMPONENT}") 25 | ELSE(COMPONENT) 26 | SET(CMAKE_INSTALL_COMPONENT) 27 | ENDIF(COMPONENT) 28 | ENDIF(NOT CMAKE_INSTALL_COMPONENT) 29 | 30 | IF(CMAKE_INSTALL_COMPONENT) 31 | SET(CMAKE_INSTALL_MANIFEST "install_manifest_${CMAKE_INSTALL_COMPONENT}.txt") 32 | ELSE(CMAKE_INSTALL_COMPONENT) 33 | SET(CMAKE_INSTALL_MANIFEST "install_manifest.txt") 34 | ENDIF(CMAKE_INSTALL_COMPONENT) 35 | 36 | FILE(WRITE "/home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build/${CMAKE_INSTALL_MANIFEST}" "") 37 | FOREACH(file ${CMAKE_INSTALL_MANIFEST_FILES}) 38 | FILE(APPEND "/home/rudd/dev/asmjit/AsmJit-1.0-beta4/Build/${CMAKE_INSTALL_MANIFEST}" "${file}\n") 39 | ENDFOREACH(file) 40 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/CHANGELOG.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Falaina/AsmJit-Python/66d72713c6bb365c0b812333d6985ca21da1d5b8/deps/AsmJit-1.0-beta4/CHANGELOG.txt -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Reguire minimum version of CMake 2 | CMake_Minimum_Required(VERSION 2.6) 3 | 4 | # AsmJit project - Need to use both C and C++ 5 | Project(AsmJit C CXX) 6 | 7 | # If ASMJIT_DIR is not specified, assume that we are building it from here 8 | If(NOT ASMJIT_DIR) 9 | Set(ASMJIT_DIR ${CMAKE_CURRENT_SOURCE_DIR}) 10 | EndIf() 11 | 12 | # AsmJit C++ sources 13 | Set(ASMJIT_SOURCES 14 | AsmJit/AssemblerX86X64.cpp 15 | AsmJit/CodeGenerator.cpp 16 | AsmJit/Compiler.cpp 17 | AsmJit/CompilerX86X64.cpp 18 | AsmJit/CpuInfo.cpp 19 | AsmJit/Defs.cpp 20 | AsmJit/DefsX86X64.cpp 21 | AsmJit/Logger.cpp 22 | AsmJit/MemoryManager.cpp 23 | AsmJit/MemoryMarker.cpp 24 | AsmJit/OperandX86X64.cpp 25 | AsmJit/Platform.cpp 26 | AsmJit/Util.cpp 27 | ) 28 | 29 | # AsmJit C++ headers 30 | Set(ASMJIT_HEADERS 31 | AsmJit/ApiBegin.h 32 | AsmJit/ApiEnd.h 33 | AsmJit/AsmJit.h 34 | AsmJit/Assembler.h 35 | AsmJit/AssemblerX86X64.h 36 | AsmJit/Build.h 37 | AsmJit/CodeGenerator.h 38 | AsmJit/Compiler.h 39 | AsmJit/CompilerX86X64.h 40 | AsmJit/Config.h 41 | AsmJit/CpuInfo.h 42 | AsmJit/Defs.h 43 | AsmJit/DefsX86X64.h 44 | AsmJit/Logger.h 45 | AsmJit/MemoryManager.h 46 | AsmJit/MemoryMarker.h 47 | AsmJit/Operand.h 48 | AsmJit/OperandX86X64.h 49 | AsmJit/Platform.h 50 | AsmJit/Util.h 51 | AsmJit/Util_p.h 52 | ) 53 | 54 | # Include AsmJit to be able to use #include 55 | Include_Directories(${ASMJIT_DIR}) 56 | 57 | # pthread library is needed for non-windows OSes. 58 | If(NOT WIN32) 59 | Link_Libraries(pthread) 60 | EndIf() 61 | 62 | # Build-Type. 63 | If(${CMAKE_BUILD_TYPE}) 64 | If(${CMAKE_BUILD_TYPE} MATCHES "Debug") 65 | Add_Definitions(-DASMJIT_DEBUG) 66 | Else() 67 | Add_Definitions(-DASMJIT_NO_DEBUG) 68 | EndIf() 69 | EndIf() 70 | 71 | # Build AsmJit shared library? 72 | If(ASMJIT_BUILD_LIBRARY) 73 | Add_Library(AsmJit SHARED ${ASMJIT_SOURCES} ${ASMJIT_HEADERS}) 74 | Install(TARGETS AsmJit DESTINATION lib${LIB_SUFFIX}) 75 | 76 | # Install header files. 77 | ForEach(i ${ASMJIT_HEADERS}) 78 | Get_Filename_Component(path ${i} PATH) 79 | Install(FILES ${i} DESTINATION "include/${path}") 80 | EndForEach(i) 81 | EndIf() 82 | 83 | # Build AsmJit test executables? 84 | If(ASMJIT_BUILD_TEST) 85 | Set(ASMJIT_TEST_FILES 86 | testcorecpu 87 | testcoresize 88 | testdummy 89 | testfuncalign 90 | testfunccall1 91 | testfunccall2 92 | testfunccall3 93 | testfuncmanyargs 94 | testfuncmemcpy 95 | testfuncrecursive1 96 | testfuncret 97 | testjit 98 | testjump1 99 | testmem1 100 | testopcode 101 | testspecial1 102 | testspecial2 103 | testspecial3 104 | testspecial4 105 | testtrampoline 106 | testvar2 107 | testvar3 108 | testvar4 109 | testvar5 110 | ) 111 | 112 | ForEach(file ${ASMJIT_TEST_FILES}) 113 | Add_Executable(${file} Test/${file}.cpp) 114 | Target_Link_Libraries(${file} AsmJit) 115 | EndForEach(file) 116 | EndIf() 117 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/COPYING.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2008-2012, Petr Kobalicek 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Documentation/Doxygen.css: -------------------------------------------------------------------------------- 1 | body, table, div, p, dl { 2 | font-family: Lucida Grande, Verdana, Geneva, Arial, sans-serif; 3 | font-size: 12px; 4 | } 5 | 6 | /* @group Heading Levels */ 7 | 8 | h1 { 9 | text-align: center; 10 | font-size: 150%; 11 | } 12 | 13 | h2 { 14 | font-size: 120%; 15 | } 16 | 17 | h3 { 18 | font-size: 100%; 19 | } 20 | 21 | /* @end */ 22 | 23 | caption { 24 | font-weight: bold; 25 | } 26 | 27 | div.qindex, div.navtab{ 28 | background-color: #e8eef2; 29 | border: 1px solid #84b0c7; 30 | text-align: center; 31 | margin: 2px; 32 | padding: 2px; 33 | } 34 | 35 | div.qindex, div.navpath { 36 | width: 100%; 37 | line-height: 140%; 38 | } 39 | 40 | div.navtab { 41 | margin-right: 15px; 42 | } 43 | 44 | /* @group Link Styling */ 45 | 46 | a { 47 | color: #153788; 48 | font-weight: normal; 49 | text-decoration: none; 50 | } 51 | 52 | .contents a:visited { 53 | color: #1b77c5; 54 | } 55 | 56 | a:hover { 57 | text-decoration: underline; 58 | } 59 | 60 | a.qindex { 61 | font-weight: bold; 62 | } 63 | 64 | a.qindexHL { 65 | font-weight: bold; 66 | background-color: #6666cc; 67 | color: #ffffff; 68 | border: 1px double #9295C2; 69 | } 70 | 71 | .contents a.qindexHL:visited { 72 | color: #ffffff; 73 | } 74 | 75 | a.el { 76 | font-weight: bold; 77 | } 78 | 79 | a.elRef { 80 | } 81 | 82 | a.code { 83 | } 84 | 85 | a.codeRef { 86 | } 87 | 88 | /* @end */ 89 | 90 | dl.el { 91 | margin-left: -1cm; 92 | } 93 | 94 | .fragment { 95 | font-family: monospace, fixed; 96 | font-size: 105%; 97 | } 98 | 99 | pre.fragment { 100 | border: 1px dotted #CCCCFF; 101 | padding: 4px 6px; 102 | margin: 4px 8px 4px 2px; 103 | } 104 | 105 | div.ah { 106 | background-color: black; 107 | font-weight: bold; 108 | color: #ffffff; 109 | margin-bottom: 3px; 110 | margin-top: 3px 111 | } 112 | 113 | div.groupHeader { 114 | margin-left: 16px; 115 | margin-top: 12px; 116 | margin-bottom: 6px; 117 | font-weight: bold; 118 | } 119 | 120 | div.groupText { 121 | margin-left: 16px; 122 | font-style: italic; 123 | } 124 | 125 | body { 126 | background: white; 127 | color: black; 128 | margin-right: 20px; 129 | margin-left: 20px; 130 | } 131 | 132 | td.indexkey { 133 | background-color: #e8eef2; 134 | font-weight: bold; 135 | border: 1px solid #CCCCCC; 136 | margin: 2px 0px 2px 0; 137 | padding: 2px 10px; 138 | } 139 | 140 | td.indexvalue { 141 | background-color: #e8eef2; 142 | border: 1px solid #CCCCCC; 143 | padding: 2px 10px; 144 | margin: 2px 0px; 145 | } 146 | 147 | tr.memlist { 148 | background-color: #f0f0f0; 149 | } 150 | 151 | p.formulaDsp { 152 | text-align: center; 153 | } 154 | 155 | img.formulaDsp { 156 | 157 | } 158 | 159 | img.formulaInl { 160 | vertical-align: middle; 161 | } 162 | 163 | /* @group Code Colorization */ 164 | 165 | span.keyword { 166 | color: #008000 167 | } 168 | 169 | span.keywordtype { 170 | color: #604020 171 | } 172 | 173 | span.keywordflow { 174 | color: #e08000 175 | } 176 | 177 | span.comment { 178 | color: #800000 179 | } 180 | 181 | span.preprocessor { 182 | color: #806020 183 | } 184 | 185 | span.stringliteral { 186 | color: #002080 187 | } 188 | 189 | span.charliteral { 190 | color: #008080 191 | } 192 | 193 | /* @end */ 194 | 195 | td.tiny { 196 | font-size: 75%; 197 | } 198 | 199 | .dirtab { 200 | padding: 4px; 201 | border-collapse: collapse; 202 | border: 1px solid #84b0c7; 203 | } 204 | 205 | th.dirtab { 206 | background: #e8eef2; 207 | font-weight: bold; 208 | } 209 | 210 | hr { 211 | height: 0; 212 | border: none; 213 | border-top: 1px solid #666; 214 | } 215 | 216 | /* @group Member Descriptions */ 217 | 218 | .mdescLeft, .mdescRight, 219 | .memItemLeft, .memItemRight, 220 | .memTemplItemLeft, .memTemplItemRight, .memTemplParams { 221 | background-color: #FFFFFF; 222 | border: none; 223 | margin: 4px; 224 | padding: 1px 0 0 8px; 225 | } 226 | 227 | .mdescLeft, .mdescRight { 228 | padding: 0px 8px 4px 8px; 229 | color: #555; 230 | } 231 | 232 | .memItemLeft, .memItemRight { 233 | padding-top: 4px; 234 | padding-bottom: 4px; 235 | border-top: 1px solid #CCCCFF; 236 | } 237 | 238 | .mdescLeft, .mdescRight { 239 | } 240 | 241 | .memTemplParams { 242 | color: #606060; 243 | } 244 | 245 | /* @end */ 246 | 247 | /* @group Member Details */ 248 | 249 | /* Styles for detailed member documentation */ 250 | 251 | .memtemplate { 252 | margin-left: 3px; 253 | font-weight: normal; 254 | font-size: 80%; 255 | color: #606060; 256 | } 257 | 258 | .memnav { 259 | background-color: #e8eef2; 260 | border: 1px solid #84b0c7; 261 | text-align: center; 262 | margin: 2px; 263 | margin-right: 15px; 264 | padding: 2px; 265 | } 266 | 267 | .memitem { 268 | padding: 0; 269 | } 270 | 271 | .memname { 272 | white-space: nowrap; 273 | font-weight: bold; 274 | } 275 | 276 | .memproto, .memdoc { 277 | } 278 | 279 | .memproto { 280 | padding: 0; 281 | background-color: #EEEEFF; 282 | border: 1px solid #CCCCFF; 283 | } 284 | 285 | .memdoc { 286 | padding: 2px 5px; 287 | border-left: 1px solid #CCCCFF; 288 | border-right: 1px solid #CCCCFF; 289 | border-bottom: 1px solid #CCCCFF; 290 | } 291 | 292 | .paramkey { 293 | text-align: right; 294 | } 295 | 296 | .paramtype { 297 | white-space: nowrap; 298 | } 299 | 300 | .paramname { 301 | color: #606060; 302 | font-weight: normal; 303 | white-space: nowrap; 304 | } 305 | .paramname em { 306 | font-style: normal; 307 | } 308 | 309 | /* @end */ 310 | 311 | /* @group Directory (tree) */ 312 | 313 | /* for the tree view */ 314 | 315 | .ftvtree { 316 | font-family: sans-serif; 317 | margin: 0.5em; 318 | } 319 | 320 | /* these are for tree view when used as main index */ 321 | 322 | .directory { 323 | font-size: 9pt; 324 | font-weight: bold; 325 | } 326 | 327 | .directory h3 { 328 | margin: 0px; 329 | margin-top: 1em; 330 | font-size: 11pt; 331 | } 332 | 333 | /* 334 | The following two styles can be used to replace the root node title 335 | with an image of your choice. Simply uncomment the next two styles, 336 | specify the name of your image and be sure to set 'height' to the 337 | proper pixel height of your image. 338 | */ 339 | 340 | /* 341 | .directory h3.swap { 342 | height: 61px; 343 | background-repeat: no-repeat; 344 | background-image: url("yourimage.gif"); 345 | } 346 | .directory h3.swap span { 347 | display: none; 348 | } 349 | */ 350 | 351 | .directory > h3 { 352 | margin-top: 0; 353 | } 354 | 355 | .directory p { 356 | margin: 0px; 357 | white-space: nowrap; 358 | } 359 | 360 | .directory div { 361 | display: none; 362 | margin: 0px; 363 | } 364 | 365 | .directory img { 366 | vertical-align: -30%; 367 | } 368 | 369 | /* these are for tree view when not used as main index */ 370 | 371 | .directory-alt { 372 | font-size: 100%; 373 | font-weight: bold; 374 | } 375 | 376 | .directory-alt h3 { 377 | margin: 0px; 378 | margin-top: 1em; 379 | font-size: 11pt; 380 | } 381 | 382 | .directory-alt > h3 { 383 | margin-top: 0; 384 | } 385 | 386 | .directory-alt p { 387 | margin: 0px; 388 | white-space: nowrap; 389 | } 390 | 391 | .directory-alt div { 392 | display: none; 393 | margin: 0px; 394 | } 395 | 396 | .directory-alt img { 397 | vertical-align: -30%; 398 | } 399 | 400 | /* @end */ 401 | 402 | address { 403 | font-style: normal; 404 | color: #333; 405 | } 406 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/README.txt: -------------------------------------------------------------------------------- 1 | AsmJit - Complete x86/x64 JIT Assembler for C++ Language - V1.0-beta4 2 | ===================================================================== 3 | 4 | http://code.google.com/p/asmjit/ 5 | 6 | Introduction 7 | ============ 8 | 9 | AsmJit is complete x86/x64 JIT Assembler for C++ language. It supports FPU, 10 | MMX, 3dNow, SSE, SSE2, SSE3 and SSE4 intrinsics, powerful compiler that helps 11 | to write portable functions for 32-bit (x86) and 64-bit (x64) architectures. 12 | AsmJit can be used to create functions at runtime that can be called from 13 | existing (but also generated) C/C++ code. 14 | 15 | AsmJit is crossplatform library that supports various compilers and operating 16 | systems. Currently only limitation is x86 (32-bit) or x64 (64-bit) processor. 17 | Currently tested operating systems are Windows (32 bit and 64 bit), Linux (32 18 | bit and 64 bit) and MacOSX (32 bit). 19 | 20 | Assembler / Compiler 21 | ==================== 22 | 23 | AsmJit library contains two main classes for code generation with different 24 | goals. First main code generation class is called Assembler and contains low 25 | level API that can be used to generate JIT binary code. It directly emits 26 | binary stream that represents encoded x86/x64 assembler opcodes. Together 27 | with operands and labels it can be used to generate complete code. 28 | 29 | There is also class named Compiler that allows to develop crossplatform 30 | assembler code without worring about function calling conventions and 31 | registers allocation. It can be also used to write 32 bit and 64 bit portable 32 | code. Compiler is recommended class to use for high level code generation. 33 | 34 | Building & Configuring 35 | ====================== 36 | 37 | You have two choices when using AsmJit library: 38 | 39 | 1. Embed files into your project - This is simplest way how to use AsmJit 40 | library. If you want to do this, edit AsmJit/Config.h file and undefine 41 | "// #define ASMJIT_API" macro or define ASMJIT_API using your IDE or 42 | makefiles (for example gcc can accept -DASMJIT_API to define it). 43 | 44 | You will bypass shared library (dll) support by defining ASMJIT_API . 45 | 46 | 2. Build shared library and link your project to it. This is now default way 47 | for using AsmJit library, but can be easily changed. To build dynamically 48 | linked library use cmake (http://www.cmake.org/) that can generate 49 | makefiles and project files for your IDE (included is Visual Studio, 50 | Code::Blocks, Eclipse, KDevelop and more...). 51 | 52 | To build shared library use this cmake command (or use provided scripts): 53 | cmake {Replace this with AsmJit directory} DASMJIT_BUILD_LIBRARY=1 54 | 55 | Directory structure 56 | =================== 57 | 58 | AsmJit - Directory where are sources needed to compile AsmJit. This directory 59 | is designed to be embeddable to your application as easy as possible. There is 60 | also AsmJit/Config.h header where you can configure platform (if autodetection 61 | not works for you) and application specific features. Look at platform macros 62 | to change some backends to your preferences. 63 | 64 | Test - Directory with cmake project to test AsmJit library. It generates simple 65 | command line applications for testing AsmJit functionality. It's only here as a 66 | demonstration how easy this can be done. These applications are also examples 67 | how to use AsmJit API. For example look at testjit for simple code generation, 68 | testcpu for cpuid() and cpuInfo() demonstration, testcompiler for compiler 69 | example, etc... 70 | 71 | Supported compilers 72 | =================== 73 | 74 | AsmJit is successfully tested by following compilers: 75 | - MSVC (VC6.0, VC7.1, VC8.0) 76 | - GCC (3.4.X+ including MinGW and 4.1.X+, 4.3.X+, 4.4.X+) 77 | 78 | If you are using different compiler and you have troubles, please use AsmJit 79 | mailing list or create an Issue (see project home page). 80 | 81 | Supported platforms 82 | =================== 83 | 84 | Fully supported platforms at this time are X86 (32-bit) and X86_64/X64 (64-bit). 85 | Other platforms need volunteers. Also note that AsmJit is designed to generate 86 | assembler binary only for host CPU, don't try to generate 64-bit assembler in 87 | 32 bit mode and vica versa - this is not designed to work and will not work. 88 | 89 | Examples 90 | ======== 91 | 92 | Examples and tests can be found in these places: 93 | - AsmJit home page 94 | - AsmJit wiki 95 | - AsmJit Test directory (in this package) 96 | 97 | License 98 | ======= 99 | 100 | AsmJit can be distributed under zlib license: 101 | 102 | 103 | Google Groups and Mailing Lists 104 | =============================== 105 | 106 | AsmJit google group: 107 | * http://groups.google.com/group/asmjit-dev 108 | 109 | AsmJit mailing list: 110 | * asmjit-dev@googlegroups.com 111 | 112 | Contact Author/Maintainer 113 | ========================= 114 | 115 | Petr Kobalicek 116 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testcorecpu.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // this file is used to test cpu detection. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | using namespace AsmJit; 16 | 17 | struct BitDescription 18 | { 19 | uint32_t mask; 20 | const char* description; 21 | }; 22 | 23 | static const BitDescription cFeatures[] = 24 | { 25 | { CPU_FEATURE_RDTSC , "RDTSC" }, 26 | { CPU_FEATURE_RDTSCP , "RDTSCP" }, 27 | { CPU_FEATURE_CMOV , "CMOV" }, 28 | { CPU_FEATURE_CMPXCHG8B , "CMPXCHG8B" }, 29 | { CPU_FEATURE_CMPXCHG16B , "CMPXCHG16B" }, 30 | { CPU_FEATURE_CLFLUSH , "CLFLUSH" }, 31 | { CPU_FEATURE_PREFETCH , "PREFETCH" }, 32 | { CPU_FEATURE_LAHF_SAHF , "LAHF/SAHF" }, 33 | { CPU_FEATURE_FXSR , "FXSAVE/FXRSTOR" }, 34 | { CPU_FEATURE_FFXSR , "FXSAVE/FXRSTOR Optimizations" }, 35 | { CPU_FEATURE_MMX , "MMX" }, 36 | { CPU_FEATURE_MMX_EXT , "MMX Extensions" }, 37 | { CPU_FEATURE_3DNOW , "3dNow!" }, 38 | { CPU_FEATURE_3DNOW_EXT , "3dNow! Extensions" }, 39 | { CPU_FEATURE_SSE , "SSE" }, 40 | { CPU_FEATURE_SSE2 , "SSE2" }, 41 | { CPU_FEATURE_SSE3 , "SSE3" }, 42 | { CPU_FEATURE_SSSE3 , "Suplemental SSE3 (SSSE3)" }, 43 | { CPU_FEATURE_SSE4_A , "SSE4A" }, 44 | { CPU_FEATURE_SSE4_1 , "SSE4.1" }, 45 | { CPU_FEATURE_SSE4_2 , "SSE4.2" }, 46 | { CPU_FEATURE_AVX , "AVX" }, 47 | { CPU_FEATURE_MSSE , "Misaligned SSE" }, 48 | { CPU_FEATURE_MONITOR_MWAIT , "MONITOR/MWAIT" }, 49 | { CPU_FEATURE_MOVBE , "MOVBE" }, 50 | { CPU_FEATURE_POPCNT , "POPCNT" }, 51 | { CPU_FEATURE_LZCNT , "LZCNT" }, 52 | { CPU_FEATURE_PCLMULDQ , "PCLMULDQ" }, 53 | { CPU_FEATURE_MULTI_THREADING , "Multi-Threading" }, 54 | { CPU_FEATURE_EXECUTE_DISABLE_BIT , "Execute Disable Bit" }, 55 | { CPU_FEATURE_64_BIT , "64 Bit Processor" }, 56 | { 0, NULL } 57 | }; 58 | 59 | static void printBits(const char* msg, uint32_t mask, const BitDescription* d) 60 | { 61 | for (; d->mask; d++) 62 | { 63 | if (mask & d->mask) printf("%s%s\n", msg, d->description); 64 | } 65 | } 66 | 67 | int main(int argc, char* argv[]) 68 | { 69 | CpuInfo *i = getCpuInfo(); 70 | 71 | printf("CPUID Detection\n"); 72 | printf("===============\n"); 73 | 74 | printf("\nBasic info\n"); 75 | printf(" Vendor string : %s\n", i->vendor); 76 | printf(" Brand string : %s\n", i->brand); 77 | printf(" Family : %u\n", i->family); 78 | printf(" Model : %u\n", i->model); 79 | printf(" Stepping : %u\n", i->stepping); 80 | printf(" Number of Processors : %u\n", i->numberOfProcessors); 81 | printf(" Features : 0x%0.8X\n", i->features); 82 | printf(" Bugs : 0x%0.8X\n", i->bugs); 83 | 84 | printf("\nExtended Info (X86/X64):\n"); 85 | printf(" Processor Type : %u\n", i->x86ExtendedInfo.processorType); 86 | printf(" Brand Index : %u\n", i->x86ExtendedInfo.brandIndex); 87 | printf(" CL Flush Cache Line : %u\n", i->x86ExtendedInfo.flushCacheLineSize); 88 | printf(" Max logical Processors: %u\n", i->x86ExtendedInfo.maxLogicalProcessors); 89 | printf(" APIC Physical ID : %u\n", i->x86ExtendedInfo.apicPhysicalId); 90 | 91 | printf("\nCpu Features:\n"); 92 | printBits(" ", i->features, cFeatures); 93 | 94 | return 0; 95 | } 96 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testcoresize.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // this file is used to test cpu detection. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | using namespace AsmJit; 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | printf("AsmJit size test\n"); 20 | printf("================\n"); 21 | printf("\n"); 22 | 23 | printf("Variable sizes:\n"); 24 | printf(" uint8_t : %u\n", (uint32_t)sizeof(uint8_t)); 25 | printf(" uint16_t : %u\n", (uint32_t)sizeof(uint16_t)); 26 | printf(" uint32_t : %u\n", (uint32_t)sizeof(uint32_t)); 27 | printf(" uint64_t : %u\n", (uint32_t)sizeof(uint64_t)); 28 | printf(" sysuint_t : %u\n", (uint32_t)sizeof(sysuint_t)); 29 | printf(" void* : %u\n", (uint32_t)sizeof(void*)); 30 | printf("\n"); 31 | 32 | printf("Structure sizes:\n"); 33 | printf(" AsmJit::Operand : %u\n", (uint32_t)sizeof(Operand)); 34 | printf(" AsmJit::Operand::BaseData : %u\n", (uint32_t)sizeof(Operand::BaseData)); 35 | printf(" AsmJit::Operand::ImmData : %u\n", (uint32_t)sizeof(Operand::ImmData)); 36 | printf(" AsmJit::Operand::LblData : %u\n", (uint32_t)sizeof(Operand::LblData)); 37 | printf(" AsmJit::Operand::MemData : %u\n", (uint32_t)sizeof(Operand::MemData)); 38 | printf(" AsmJit::Operand::RegData : %u\n", (uint32_t)sizeof(Operand::RegData)); 39 | printf(" AsmJit::Operand::VarData : %u\n", (uint32_t)sizeof(Operand::VarData)); 40 | printf(" AsmJit::Operand::BinData : %u\n", (uint32_t)sizeof(Operand::BinData)); 41 | printf("\n"); 42 | 43 | printf(" AsmJit::Assembler : %u\n", (uint32_t)sizeof(Assembler)); 44 | printf(" AsmJit::Compiler : %u\n", (uint32_t)sizeof(Compiler)); 45 | printf(" AsmJit::FunctionDefinition: %u\n", (uint32_t)sizeof(FunctionDefinition)); 46 | printf("\n"); 47 | 48 | printf(" AsmJit::Emittable : %u\n", (uint32_t)sizeof(Emittable)); 49 | printf(" AsmJit::EAlign : %u\n", (uint32_t)sizeof(EAlign)); 50 | printf(" AsmJit::ECall : %u\n", (uint32_t)sizeof(ECall)); 51 | printf(" AsmJit::EComment : %u\n", (uint32_t)sizeof(EComment)); 52 | printf(" AsmJit::EData : %u\n", (uint32_t)sizeof(EData)); 53 | printf(" AsmJit::EEpilog : %u\n", (uint32_t)sizeof(EEpilog)); 54 | printf(" AsmJit::EFunction : %u\n", (uint32_t)sizeof(EFunction)); 55 | printf(" AsmJit::EFunctionEnd : %u\n", (uint32_t)sizeof(EFunctionEnd)); 56 | printf(" AsmJit::EInstruction : %u\n", (uint32_t)sizeof(EInstruction)); 57 | printf(" AsmJit::EJmp : %u\n", (uint32_t)sizeof(EJmp)); 58 | printf(" AsmJit::EProlog : %u\n", (uint32_t)sizeof(EProlog)); 59 | printf(" AsmJit::ERet : %u\n", (uint32_t)sizeof(ERet)); 60 | printf("\n"); 61 | 62 | printf(" AsmJit::VarData : %u\n", (uint32_t)sizeof(VarData)); 63 | printf(" AsmJit::VarAllocRecord : %u\n", (uint32_t)sizeof(VarAllocRecord)); 64 | printf(" AsmJit::StateData : %u\n", (uint32_t)sizeof(StateData)); 65 | printf("\n"); 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testdummy.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used as a dummy test. It's changed during development. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(void); 17 | 18 | static void dummyFunc(void) 19 | { 20 | 21 | } 22 | 23 | int main(int argc, char* argv[]) 24 | { 25 | using namespace AsmJit; 26 | 27 | // ========================================================================== 28 | // Log compiler output. 29 | FileLogger logger(stderr); 30 | logger.setLogBinary(true); 31 | 32 | // Create compiler. 33 | Compiler c; 34 | c.setLogger(&logger); 35 | 36 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0()); 37 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 38 | 39 | ECall* ctx = c.call((void*)dummyFunc); 40 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder0()); 41 | 42 | c.endFunction(); 43 | // ========================================================================== 44 | 45 | // ========================================================================== 46 | // Make the function. 47 | MyFn fn = function_cast(c.make()); 48 | 49 | // Call it. 50 | // printf("Result %llu\n", (unsigned long long)fn()); 51 | 52 | // Free the generated function if it's not needed anymore. 53 | MemoryManager::getGlobal()->free((void*)fn); 54 | // ========================================================================== 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfuncalign.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Test function variables alignment (for sse2 code, 16-byte xmm variables). 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | using namespace AsmJit; 16 | 17 | // Generated functions prototypes. 18 | typedef sysint_t (*MyFn0)(); 19 | typedef sysint_t (*MyFn1)(sysint_t); 20 | typedef sysint_t (*MyFn2)(sysint_t, sysint_t); 21 | typedef sysint_t (*MyFn3)(sysint_t, sysint_t, sysint_t); 22 | 23 | static void* compileFunction(int args, int vars, bool naked, bool pushPopSequence) 24 | { 25 | Compiler c; 26 | 27 | // Not enabled by default... 28 | // FileLogger logger(stderr); 29 | // c.setLogger(&logger); 30 | 31 | switch (args) 32 | { 33 | case 0: 34 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0()); 35 | break; 36 | case 1: 37 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder1()); 38 | break; 39 | case 2: 40 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder2()); 41 | break; 42 | case 3: 43 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder3()); 44 | break; 45 | } 46 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, naked); 47 | c.getFunction()->setHint(FUNCTION_HINT_PUSH_POP_SEQUENCE, pushPopSequence); 48 | 49 | GPVar gvar(c.newGP()); 50 | XMMVar xvar(c.newXMM(VARIABLE_TYPE_XMM)); 51 | 52 | // Alloc, use and spill preserved registers. 53 | if (vars) 54 | { 55 | int var = 0; 56 | uint32_t index = 0; 57 | uint32_t mask = 1; 58 | uint32_t preserved = c.getFunction()->getPrototype().getPreservedGP(); 59 | 60 | do { 61 | if ((preserved & mask) != 0 && (index != REG_INDEX_ESP && index != REG_INDEX_EBP)) 62 | { 63 | GPVar somevar(c.newGP(VARIABLE_TYPE_GPD)); 64 | c.alloc(somevar, index); 65 | c.mov(somevar, imm(0)); 66 | c.spill(somevar); 67 | var++; 68 | } 69 | 70 | index++; 71 | mask <<= 1; 72 | } while (var < vars && index < REG_NUM_GP); 73 | } 74 | 75 | c.alloc(gvar, nax); 76 | c.lea(gvar, xvar.m()); 77 | c.and_(gvar, imm(15)); 78 | c.ret(gvar); 79 | c.endFunction(); 80 | 81 | return c.make(); 82 | } 83 | 84 | static bool testFunction(int args, int vars, bool naked, bool pushPopSequence) 85 | { 86 | void* fn = compileFunction(args, vars, naked, pushPopSequence); 87 | sysint_t result = 0; 88 | 89 | printf("Function (args=%d, vars=%d, naked=%d, pushPop=%d):", args, vars, naked, pushPopSequence); 90 | 91 | switch (args) 92 | { 93 | case 0: 94 | result = AsmJit::function_cast(fn)(); 95 | break; 96 | case 1: 97 | result = AsmJit::function_cast(fn)(1); 98 | break; 99 | case 2: 100 | result = AsmJit::function_cast(fn)(1, 2); 101 | break; 102 | case 3: 103 | result = AsmJit::function_cast(fn)(1, 2, 3); 104 | break; 105 | } 106 | 107 | printf(" result=%d (expected 0)\n", (int)result); 108 | 109 | MemoryManager::getGlobal()->free(fn); 110 | return result == 0; 111 | } 112 | 113 | #define TEST_FN(naked, pushPop) \ 114 | { \ 115 | for (int _args = 0; _args < 4; _args++) \ 116 | { \ 117 | for (int _vars = 0; _vars < 4; _vars++) \ 118 | { \ 119 | testFunction(_args, _vars, naked, pushPop); \ 120 | } \ 121 | } \ 122 | } 123 | 124 | int main(int argc, char* argv[]) 125 | { 126 | TEST_FN(false, false) 127 | TEST_FN(false, true ) 128 | 129 | if (CompilerUtil::isStack16ByteAligned()) 130 | { 131 | // If stack is 16-byte aligned by the operating system. 132 | TEST_FN(true , false) 133 | TEST_FN(true , true ) 134 | } 135 | 136 | return 0; 137 | } 138 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfunccall1.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used as a function call test (calling functions inside 8 | // the generated code). 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // Type of generated function. 17 | typedef int (*MyFn)(int, int, int); 18 | 19 | // Function that is called inside the generated one. 20 | static int calledFn(int a, int b, int c) { return (a + b) * c; } 21 | 22 | int main(int argc, char* argv[]) 23 | { 24 | using namespace AsmJit; 25 | 26 | // ========================================================================== 27 | // Create compiler. 28 | Compiler c; 29 | 30 | // Log compiler output. 31 | FileLogger logger(stderr); 32 | c.setLogger(&logger); 33 | 34 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder3()); 35 | 36 | GPVar v0(c.argGP(0)); 37 | GPVar v1(c.argGP(1)); 38 | GPVar v2(c.argGP(2)); 39 | 40 | // Just do something;) 41 | c.shl(v0, imm(1)); 42 | c.shl(v1, imm(1)); 43 | c.shl(v2, imm(1)); 44 | 45 | // Call function. 46 | GPVar address(c.newGP()); 47 | c.mov(address, imm((sysint_t)(void*)calledFn)); 48 | 49 | ECall* ctx = c.call(address); 50 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder3()); 51 | ctx->setArgument(0, v2); 52 | ctx->setArgument(1, v1); 53 | ctx->setArgument(2, v0); 54 | 55 | //ctx->setReturn(v0); 56 | //c.ret(v0); 57 | 58 | c.endFunction(); 59 | // ========================================================================== 60 | 61 | // ========================================================================== 62 | // Make the function. 63 | MyFn fn = function_cast(c.make()); 64 | 65 | uint result = fn(3, 2, 1); 66 | bool success = result == 36; 67 | 68 | printf("Result %u (expected 36)\n", result); 69 | printf("Status: %s\n", success ? "Success" : "Failure"); 70 | 71 | // Free the generated function if it's not needed anymore. 72 | MemoryManager::getGlobal()->free((void*)fn); 73 | // ========================================================================== 74 | 75 | return 0; 76 | } 77 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfunccall2.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used as a function call test (calling functions inside 8 | // the generated code). 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // Type of generated function. 17 | typedef void (*MyFn)(void); 18 | 19 | // Function that is called inside the generated one. Because this test is 20 | // mainly about register arguments, we need to use the fastcall calling 21 | // convention under 32-bit mode. 22 | static void ASMJIT_FASTCALL simpleFn(int a) {} 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | using namespace AsmJit; 27 | 28 | // ========================================================================== 29 | // Create compiler. 30 | Compiler c; 31 | 32 | // Log compiler output. 33 | FileLogger logger(stderr); 34 | c.setLogger(&logger); 35 | 36 | ECall* ctx; 37 | 38 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0()); 39 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 40 | 41 | // Call a function. 42 | GPVar address(c.newGP()); 43 | GPVar argument(c.newGP(VARIABLE_TYPE_GPD)); 44 | 45 | c.mov(address, imm((sysint_t)(void*)simpleFn)); 46 | 47 | c.mov(argument, imm(1)); 48 | ctx = c.call(address); 49 | ctx->setPrototype(CALL_CONV_COMPAT_FASTCALL, FunctionBuilder1()); 50 | ctx->setArgument(0, argument); 51 | c.unuse(argument); 52 | 53 | c.mov(argument, imm(2)); 54 | ctx = c.call(address); 55 | ctx->setPrototype(CALL_CONV_COMPAT_FASTCALL, FunctionBuilder1()); 56 | ctx->setArgument(0, argument); 57 | 58 | c.endFunction(); 59 | // ========================================================================== 60 | 61 | // ========================================================================== 62 | // Make the function. 63 | MyFn fn = function_cast(c.make()); 64 | 65 | fn(); 66 | 67 | // Free the generated function if it's not needed anymore. 68 | MemoryManager::getGlobal()->free((void*)fn); 69 | // ========================================================================== 70 | 71 | return 0; 72 | } 73 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfunccall3.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used as a function call test (calling functions inside 8 | // the generated code). 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // Type of generated function. 17 | typedef int (*MyFn)(void); 18 | 19 | // Function that is called inside the generated one. Because this test is 20 | // mainly about register arguments, we need to use the fastcall calling 21 | // convention under 32-bit mode. 22 | static int oneFunc(void) { return 1; } 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | using namespace AsmJit; 27 | 28 | // ========================================================================== 29 | // Create compiler. 30 | Compiler c; 31 | 32 | // Log compiler output. 33 | FileLogger logger(stderr); 34 | c.setLogger(&logger); 35 | 36 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder1()); 37 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 38 | Label L0(c.newLabel()); 39 | Label L1(c.newLabel()); 40 | GPVar x(c.newGP()); 41 | GPVar y(c.newGP()); 42 | c.mov(x, 0); 43 | c.jnz(L0); 44 | c.mov(y, c.argGP(0)); 45 | c.jmp(L1); 46 | c.bind(L0); 47 | ECall *ctx = c.call((void*)oneFunc); 48 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder1()); 49 | ctx->setArgument(0, c.argGP(0)); 50 | ctx->setReturn(y); 51 | c.bind(L1); 52 | c.add(x, y); 53 | c.endFunction(); 54 | 55 | // TODO: Remove 56 | #if 0 57 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0()); 58 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 59 | GPVar x(c.newGP()); 60 | GPVar y(c.newGP()); 61 | ECall *ctx = c.call((void*)oneFunc); 62 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder0()); 63 | ctx->setReturn(y); 64 | c.mov(x, 0); 65 | c.add(x, y); 66 | c.ret(x); 67 | c.endFunction(); 68 | #endif 69 | // ========================================================================== 70 | 71 | // ========================================================================== 72 | // Make the function. 73 | MyFn fn = function_cast(c.make()); 74 | 75 | //uint result = fn(); 76 | //bool success = result == 1; 77 | 78 | //printf("Result %u (expected 1)\n", result); 79 | //printf("Status: %s\n", success ? "Success" : "Failure"); 80 | 81 | // Free the generated function if it's not needed anymore. 82 | MemoryManager::getGlobal()->free((void*)fn); 83 | // ========================================================================== 84 | 85 | return 0; 86 | } 87 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfuncmanyargs.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test function with many arguments. Bug originally 8 | // reported by Tilo Nitzsche for X64W and X64U calling conventions. 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // This is type of function we will generate 17 | typedef void (*MyFn)(void*, void*, void*, void*, void*, void*, void*, void*); 18 | 19 | int main(int argc, char* argv[]) 20 | { 21 | using namespace AsmJit; 22 | 23 | // ========================================================================== 24 | // Create compiler. 25 | Compiler c; 26 | 27 | // Log compiler output. 28 | FileLogger logger(stderr); 29 | c.setLogger(&logger); 30 | 31 | c.newFunction(CALL_CONV_DEFAULT, 32 | FunctionBuilder8()); 33 | 34 | GPVar p1(c.argGP(0)); 35 | GPVar p2(c.argGP(1)); 36 | GPVar p3(c.argGP(2)); 37 | GPVar p4(c.argGP(3)); 38 | GPVar p5(c.argGP(4)); 39 | GPVar p6(c.argGP(5)); 40 | GPVar p7(c.argGP(6)); 41 | GPVar p8(c.argGP(7)); 42 | 43 | c.add(p1, 1); 44 | c.add(p2, 2); 45 | c.add(p3, 3); 46 | c.add(p4, 4); 47 | c.add(p5, 5); 48 | c.add(p6, 6); 49 | c.add(p7, 7); 50 | c.add(p8, 8); 51 | 52 | // Move some data into buffer provided by arguments so we can verify if it 53 | // really works without looking into assembler output. 54 | c.add(byte_ptr(p1), imm(1)); 55 | c.add(byte_ptr(p2), imm(2)); 56 | c.add(byte_ptr(p3), imm(3)); 57 | c.add(byte_ptr(p4), imm(4)); 58 | c.add(byte_ptr(p5), imm(5)); 59 | c.add(byte_ptr(p6), imm(6)); 60 | c.add(byte_ptr(p7), imm(7)); 61 | c.add(byte_ptr(p8), imm(8)); 62 | 63 | c.endFunction(); 64 | // ========================================================================== 65 | 66 | // ========================================================================== 67 | // Make the function. 68 | uint8_t var[9] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 69 | 70 | MyFn fn = function_cast(c.make()); 71 | fn(var, var, var, var, var, var, var, var); 72 | 73 | printf("Results: %d, %d, %d, %d, %d, %d, %d, %d, %d\n", 74 | var[0], var[1], var[2], var[3], 75 | var[4], var[5], var[6], var[7], 76 | var[8]); 77 | 78 | bool success = 79 | var[0] == 0 && var[1] == 1 && var[2] == 2 && var[3] == 3 && 80 | var[4] == 4 && var[5] == 5 && var[6] == 6 && var[7] == 7 && 81 | var[8] == 8; 82 | printf("Status: %s\n", success ? "Success" : "Failure"); 83 | 84 | // Free the generated function if it's not needed anymore. 85 | MemoryManager::getGlobal()->free((void*)fn); 86 | // ========================================================================== 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfuncmemcpy.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Create simple DWORD memory copy function for 32/64-bit x86 platform, this 8 | // is enchanced version that's using Compiler class: 9 | // 10 | // void memcpy32(uint32_t* dst, const uint32_t* src, sysuint_t len); 11 | 12 | // AsmJit library 13 | #include 14 | 15 | // C library - printf 16 | #include 17 | 18 | // It isn't needed to include namespace here, but when generating assembly it's 19 | // easier to use directly eax, rax, ... instead of AsmJit::eax, AsmJit::rax, ... 20 | using namespace AsmJit; 21 | 22 | // This is type of function we will generate. 23 | typedef void (*MemCpy32Fn)(uint32_t*, const uint32_t*, sysuint_t); 24 | 25 | int main(int argc, char* argv[]) 26 | { 27 | // ========================================================================== 28 | // Part 1: 29 | 30 | // Create Compiler. 31 | Compiler c; 32 | 33 | FileLogger logger(stderr); 34 | c.setLogger(&logger); 35 | 36 | // Tell compiler the function prototype we want. It allocates variables representing 37 | // function arguments that can be accessed through Compiler or Function instance. 38 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder3()); 39 | 40 | // Try to generate function without prolog/epilog code: 41 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 42 | 43 | // Create labels. 44 | Label L_Loop = c.newLabel(); 45 | Label L_Exit = c.newLabel(); 46 | 47 | // Function arguments. 48 | GPVar dst(c.argGP(0)); 49 | GPVar src(c.argGP(1)); 50 | GPVar cnt(c.argGP(2)); 51 | 52 | // Allocate loop variables registers (if they are not allocated already). 53 | c.alloc(dst); 54 | c.alloc(src); 55 | c.alloc(cnt); 56 | 57 | // Exit if length is zero. 58 | c.test(cnt, cnt); 59 | c.jz(L_Exit); 60 | 61 | // Loop. 62 | c.bind(L_Loop); 63 | 64 | // Copy DWORD (4 bytes). 65 | GPVar tmp(c.newGP(VARIABLE_TYPE_GPD)); 66 | c.mov(tmp, dword_ptr(src)); 67 | c.mov(dword_ptr(dst), tmp); 68 | 69 | // Increment dst/src pointers. 70 | c.add(src, 4); 71 | c.add(dst, 4); 72 | 73 | // Loop until cnt is not zero. 74 | c.dec(cnt); 75 | c.jnz(L_Loop); 76 | 77 | // Exit. 78 | c.bind(L_Exit); 79 | 80 | // Finish. 81 | c.endFunction(); 82 | // ========================================================================== 83 | 84 | // ========================================================================== 85 | // Part 2: 86 | 87 | // Make JIT function. 88 | MemCpy32Fn fn = function_cast(c.make()); 89 | 90 | // Ensure that everything is ok. 91 | if (!fn) 92 | { 93 | printf("Error making jit function (%u).\n", c.getError()); 94 | return 1; 95 | } 96 | 97 | // Create some data. 98 | uint32_t dstBuffer[128]; 99 | uint32_t srcBuffer[128]; 100 | 101 | // Call the JIT function. 102 | fn(dstBuffer, srcBuffer, 128); 103 | 104 | // Free the JIT function if it's not needed anymore. 105 | MemoryManager::getGlobal()->free((void*)fn); 106 | // ========================================================================== 107 | 108 | return 0; 109 | } 110 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfuncrecursive1.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Recursive function call test. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // Type of generated function. 16 | typedef int (*MyFn)(int); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | ECall* ctx; 31 | Label skip(c.newLabel()); 32 | 33 | EFunction* func = c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder1()); 34 | func->setHint(FUNCTION_HINT_NAKED, true); 35 | 36 | GPVar var(c.argGP(0)); 37 | c.cmp(var, imm(1)); 38 | c.jle(skip); 39 | 40 | GPVar tmp(c.newGP(VARIABLE_TYPE_INT32)); 41 | c.mov(tmp, var); 42 | c.dec(tmp); 43 | 44 | ctx = c.call(func->getEntryLabel()); 45 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder1()); 46 | ctx->setArgument(0, tmp); 47 | ctx->setReturn(tmp); 48 | c.mul(c.newGP(VARIABLE_TYPE_INT32), var, tmp); 49 | 50 | c.bind(skip); 51 | c.ret(var); 52 | c.endFunction(); 53 | // ========================================================================== 54 | 55 | // ========================================================================== 56 | // Make the function. 57 | MyFn fn = function_cast(c.make()); 58 | 59 | printf("Factorial 5 == %d\n", fn(5)); 60 | 61 | // Free the generated function if it's not needed anymore. 62 | MemoryManager::getGlobal()->free((void*)fn); 63 | // ========================================================================== 64 | 65 | return 0; 66 | } 67 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testfuncret.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test function with many arguments. Bug originally 8 | // reported by Tilo Nitzsche for X64W and X64U calling conventions. 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | // This is type of function we will generate. 16 | typedef int (*MyFn)(int, int, int); 17 | 18 | static int FuncA(int x, int y) { return x + y; } 19 | static int FuncB(int x, int y) { return x * y; } 20 | 21 | int main(int argc, char* argv[]) 22 | { 23 | using namespace AsmJit; 24 | 25 | // ========================================================================== 26 | // Create compiler. 27 | Compiler c; 28 | 29 | // Log compiler output. 30 | FileLogger logger(stderr); 31 | c.setLogger(&logger); 32 | 33 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder3()); 34 | { 35 | GPVar x(c.argGP(0)); 36 | GPVar y(c.argGP(1)); 37 | GPVar op(c.argGP(2)); 38 | 39 | Label opAdd(c.newLabel()); 40 | Label opMul(c.newLabel()); 41 | 42 | c.cmp(op, 0); 43 | c.jz(opAdd); 44 | 45 | c.cmp(op, 1); 46 | c.jz(opMul); 47 | 48 | { 49 | GPVar result(c.newGP()); 50 | c.mov(result, imm(0)); 51 | c.ret(result); 52 | } 53 | 54 | { 55 | c.bind(opAdd); 56 | 57 | GPVar result(c.newGP()); 58 | ECall* ctx = c.call((void*)FuncA); 59 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder2()); 60 | ctx->setArgument(0, x); 61 | ctx->setArgument(1, y); 62 | ctx->setReturn(result); 63 | c.ret(result); 64 | } 65 | 66 | { 67 | c.bind(opMul); 68 | 69 | GPVar result(c.newGP()); 70 | ECall* ctx = c.call((void*)FuncB); 71 | ctx->setPrototype(CALL_CONV_DEFAULT, FunctionBuilder2()); 72 | ctx->setArgument(0, x); 73 | ctx->setArgument(1, y); 74 | ctx->setReturn(result); 75 | c.ret(result); 76 | } 77 | } 78 | c.endFunction(); 79 | // ========================================================================== 80 | 81 | // ========================================================================== 82 | // Make the function. 83 | MyFn fn = function_cast(c.make()); 84 | int result = fn(4, 8, 1); 85 | 86 | printf("Result from JIT function: %d (Expected 32) \n", result); 87 | printf("Status: %s\n", result == 32 ? "Success" : "Failure"); 88 | 89 | // Free the generated function if it's not needed anymore. 90 | MemoryManager::getGlobal()->free((void*)fn); 91 | // ========================================================================== 92 | 93 | return 0; 94 | } 95 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testjit.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is only included as an example and simple test if jit 8 | // compiler works. 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // This is type of function we will generate 17 | typedef int (*MyFn)(); 18 | 19 | int main(int argc, char* argv[]) 20 | { 21 | using namespace AsmJit; 22 | 23 | // ========================================================================== 24 | // Create assembler. 25 | Assembler a; 26 | 27 | // Log assembler output. 28 | FileLogger logger(stderr); 29 | a.setLogger(&logger); 30 | 31 | // Prolog. 32 | a.push(nbp); 33 | a.mov(nbp, nsp); 34 | 35 | // Mov 1024 to EAX/RAX, EAX/RAX is also return value. 36 | a.mov(nax, 1024); 37 | 38 | // Epilog. 39 | a.mov(nsp, nbp); 40 | a.pop(nbp); 41 | a.ret(); 42 | // ========================================================================== 43 | 44 | // NOTE: 45 | // This function can be also completely rewritten to this form: 46 | // a.mov(nax, 1024); 47 | // a.ret(); 48 | // If you are interested in removing prolog and epilog, please 49 | // study calling conventions and check register preservations. 50 | 51 | // ========================================================================== 52 | // Make the function. 53 | MyFn fn = function_cast(a.make()); 54 | 55 | // Call it. 56 | int result = fn(); 57 | printf("Result from jit function: %d\n", result); 58 | printf("Status: %s\n", result == 1024 ? "Success" : "Failure"); 59 | 60 | // Free the generated function if it's not needed anymore. 61 | MemoryManager::getGlobal()->free((void*)fn); 62 | // ========================================================================== 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testjump1.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test crossed jumps. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | using namespace AsmJit; 16 | typedef void (*VoidFn)(); 17 | 18 | int main(int, char**) 19 | { 20 | Compiler c; 21 | 22 | FileLogger logger(stderr); 23 | c.setLogger(&logger); 24 | 25 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0()); 26 | 27 | Label L_A = c.newLabel(); 28 | Label L_B = c.newLabel(); 29 | Label L_C = c.newLabel(); 30 | 31 | c.jmp(L_B); 32 | 33 | c.bind(L_A); 34 | c.jmp(L_C); 35 | 36 | c.bind(L_B); 37 | c.jmp(L_A); 38 | 39 | c.bind(L_C); 40 | 41 | c.ret(); 42 | c.endFunction(); 43 | 44 | VoidFn fn = function_cast(c.make()); 45 | 46 | // Ensure that everything is ok. 47 | if (!fn) 48 | { 49 | printf("Error making jit function (%u).\n", c.getError()); 50 | return 1; 51 | } 52 | 53 | // Free the JIT function if it's not needed anymore. 54 | MemoryManager::getGlobal()->free((void*)fn); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testmem1.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test AsmJit memory manager. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | static int problems = 0; 16 | 17 | static void gen(void* a, void* b, int i) 18 | { 19 | int pattern = rand() % 256; 20 | *(int *)a = i; 21 | *(int *)b = i; 22 | memset((char*)a + sizeof(int), pattern, i - sizeof(int)); 23 | memset((char*)b + sizeof(int), pattern, i - sizeof(int)); 24 | } 25 | 26 | static void verify(void* a, void* b) 27 | { 28 | int ai = *(int*)a; 29 | int bi = *(int*)b; 30 | if (ai != bi || memcmp(a, b, ai) != 0) 31 | { 32 | printf("Failed to verify %p\n", a); 33 | problems++; 34 | } 35 | } 36 | 37 | static void die() 38 | { 39 | printf("Couldn't allocate virtual memory, this test needs at least 100MB of free virtual memory.\n"); 40 | exit(1); 41 | } 42 | 43 | static void stats(const char* dumpFile) 44 | { 45 | AsmJit::MemoryManager* memmgr = AsmJit::MemoryManager::getGlobal(); 46 | 47 | printf("-- Used: %d\n", (int)memmgr->getUsedBytes()); 48 | printf("-- Allocated: %d\n", (int)memmgr->getAllocatedBytes()); 49 | 50 | #if defined(ASMJIT_MEMORY_MANAGER_DUMP) 51 | reinterpret_cast(memmgr)->dump(dumpFile); 52 | #endif // ASMJIT_MEMORY_MANAGER_DUMP 53 | } 54 | 55 | static void shuffle(void **a, void **b, sysuint_t count) 56 | { 57 | for (sysuint_t i = 0; i < count; ++i) 58 | { 59 | sysuint_t si = (sysuint_t)rand() % count; 60 | 61 | void *ta = a[i]; 62 | void *tb = b[i]; 63 | 64 | a[i] = a[si]; 65 | b[i] = b[si]; 66 | 67 | a[si] = ta; 68 | b[si] = tb; 69 | } 70 | } 71 | 72 | int main(int argc, char* argv[]) 73 | { 74 | AsmJit::MemoryManager* memmgr = AsmJit::MemoryManager::getGlobal(); 75 | 76 | sysuint_t i; 77 | sysuint_t count = 200000; 78 | 79 | printf("Memory alloc/free test - %d allocations\n\n", (int)count); 80 | 81 | void** a = (void**)malloc(sizeof(void*) * count); 82 | void** b = (void**)malloc(sizeof(void*) * count); 83 | if (!a || !b) die(); 84 | 85 | srand(100); 86 | printf("Allocating virtual memory..."); 87 | 88 | for (i = 0; i < count; i++) 89 | { 90 | int r = (rand() % 1000) + 4; 91 | 92 | a[i] = memmgr->alloc(r); 93 | if (a[i] == NULL) die(); 94 | 95 | memset(a[i], 0, r); 96 | } 97 | 98 | printf("done\n"); 99 | stats("dump0.dot"); 100 | 101 | printf("\n"); 102 | printf("Freeing virtual memory..."); 103 | 104 | for (i = 0; i < count; i++) 105 | { 106 | if (!memmgr->free(a[i])) 107 | { 108 | printf("Failed to free %p\n", b[i]); 109 | problems++; 110 | } 111 | } 112 | 113 | printf("done\n"); 114 | stats("dump1.dot"); 115 | 116 | printf("\n"); 117 | printf("Verified alloc/free test - %d allocations\n\n", (int)count); 118 | 119 | printf("Alloc..."); 120 | for (i = 0; i < count; i++) 121 | { 122 | int r = (rand() % 1000) + 4; 123 | 124 | a[i] = memmgr->alloc(r); 125 | b[i] = malloc(r); 126 | if (a[i] == NULL || b[i] == NULL) die(); 127 | 128 | gen(a[i], b[i], r); 129 | } 130 | printf("done\n"); 131 | stats("dump2.dot"); 132 | 133 | printf("\n"); 134 | printf("Shuffling..."); 135 | shuffle(a, b, count); 136 | printf("done\n"); 137 | 138 | printf("\n"); 139 | printf("Verify and free..."); 140 | for (i = 0; i < count/2; i++) 141 | { 142 | verify(a[i], b[i]); 143 | if (!memmgr->free(a[i])) 144 | { 145 | printf("Failed to free %p\n", b[i]); 146 | problems++; 147 | } 148 | free(b[i]); 149 | } 150 | printf("done\n"); 151 | stats("dump3.dot"); 152 | 153 | printf("\n"); 154 | printf("Alloc..."); 155 | for (i = 0; i < count/2; i++) 156 | { 157 | int r = (rand() % 1000) + 4; 158 | 159 | a[i] = memmgr->alloc(r); 160 | b[i] = malloc(r); 161 | if (a[i] == NULL || b[i] == NULL) die(); 162 | 163 | gen(a[i], b[i], r); 164 | } 165 | printf("done\n"); 166 | stats("dump4.dot"); 167 | 168 | printf("\n"); 169 | printf("Verify and free..."); 170 | for (i = 0; i < count; i++) 171 | { 172 | verify(a[i], b[i]); 173 | if (!memmgr->free(a[i])) 174 | { 175 | printf("Failed to free %p\n", b[i]); 176 | problems++; 177 | } 178 | free(b[i]); 179 | } 180 | printf("done\n"); 181 | stats("dump5.dot"); 182 | 183 | printf("\n"); 184 | if (problems) 185 | printf("Status: Failure: %d problems found\n", problems); 186 | else 187 | printf("Status: Success\n"); 188 | 189 | free(a); 190 | free(b); 191 | 192 | return 0; 193 | } 194 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testspecial1.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Test special instruction generation. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(int32_t*, int32_t*, int32_t, int32_t); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | { 31 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder4()); 32 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 33 | 34 | GPVar dst0_hi(c.argGP(0)); 35 | GPVar dst0_lo(c.argGP(1)); 36 | 37 | GPVar v0_hi(c.newGP(VARIABLE_TYPE_GPD)); 38 | GPVar v0_lo(c.argGP(2)); 39 | 40 | GPVar src0(c.argGP(3)); 41 | c.imul(v0_hi, v0_lo, src0); 42 | 43 | c.mov(dword_ptr(dst0_hi), v0_hi); 44 | c.mov(dword_ptr(dst0_lo), v0_lo); 45 | c.endFunction(); 46 | } 47 | // ========================================================================== 48 | 49 | // ========================================================================== 50 | // Make the function. 51 | MyFn fn = function_cast(c.make()); 52 | 53 | { 54 | int32_t out_hi; 55 | int32_t out_lo; 56 | 57 | int32_t v0 = 4; 58 | int32_t v1 = 4; 59 | 60 | int32_t expected_hi = 0; 61 | int32_t expected_lo = v0 * v1; 62 | 63 | fn(&out_hi, &out_lo, v0, v1); 64 | 65 | printf("out_hi=%d (expected %d)\n", out_hi, expected_hi); 66 | printf("out_lo=%d (expected %d)\n", out_lo, expected_lo); 67 | 68 | printf("Status: %s\n", (out_hi == expected_hi && out_lo == expected_lo) 69 | ? "Success" 70 | : "Failure"); 71 | } 72 | 73 | // Free the generated function if it's not needed anymore. 74 | MemoryManager::getGlobal()->free((void*)fn); 75 | // ========================================================================== 76 | 77 | return 0; 78 | } 79 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testspecial2.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Test special instruction generation. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(int32_t*, int32_t, int32_t, int32_t); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | { 31 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder4()); 32 | 33 | GPVar dst0(c.argGP(0)); 34 | GPVar v0(c.argGP(1)); 35 | 36 | c.shl(v0, c.argGP(2)); 37 | c.ror(v0, c.argGP(3)); 38 | 39 | c.mov(dword_ptr(dst0), v0); 40 | c.endFunction(); 41 | } 42 | // ========================================================================== 43 | 44 | // ========================================================================== 45 | // Make the function. 46 | MyFn fn = function_cast(c.make()); 47 | 48 | { 49 | int32_t out; 50 | int32_t v0 = 0x000000FF; 51 | int32_t expected = 0x0000FF00; 52 | 53 | fn(&out, v0, 16, 8); 54 | 55 | printf("out=%d (expected %d)\n", out, expected); 56 | printf("Status: %s\n", (out == expected) ? "Success" : "Failure"); 57 | } 58 | 59 | // Free the generated function if it's not needed anymore. 60 | MemoryManager::getGlobal()->free((void*)fn); 61 | // ========================================================================== 62 | 63 | return 0; 64 | } 65 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testspecial3.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used as rep-test. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MemCopy)(void* a, void* b, sysuint_t size); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | { 31 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder3()); 32 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 33 | 34 | GPVar dst(c.argGP(0)); 35 | GPVar src(c.argGP(1)); 36 | GPVar cnt(c.argGP(2)); 37 | 38 | c.rep_movsb(dst, src, cnt); 39 | c.endFunction(); 40 | } 41 | // ========================================================================== 42 | 43 | // ========================================================================== 44 | { 45 | MemCopy copy = function_cast(c.make()); 46 | 47 | char src[20] = "Hello AsmJit"; 48 | char dst[20]; 49 | 50 | copy(dst, src, strlen(src) + 1); 51 | printf("src=%s\n", src); 52 | printf("dst=%s\n", dst); 53 | printf("Status: %s\n", strcmp(src, dst) == 0 ? "Success" : "Failure"); 54 | 55 | MemoryManager::getGlobal()->free((void*)copy); 56 | } 57 | // ========================================================================== 58 | 59 | return 0; 60 | } 61 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testspecial4.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test setcc instruction generation. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(int, int, char*); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder3()); 31 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, true); 32 | 33 | GPVar src0(c.argGP(0)); 34 | GPVar src1(c.argGP(1)); 35 | GPVar dst0(c.argGP(2)); 36 | 37 | c.cmp(src0, src1); 38 | c.setz(byte_ptr(dst0)); 39 | 40 | // Finish. 41 | c.endFunction(); 42 | // ========================================================================== 43 | 44 | // ========================================================================== 45 | // Make the function. 46 | MyFn fn = function_cast(c.make()); 47 | 48 | // Results storage. 49 | char r[4]; 50 | 51 | // Call it 52 | fn(0, 0, &r[0]); // We are expecting 1 (0 == 0). 53 | fn(0, 1, &r[1]); // We are expecting 0 (0 != 1). 54 | fn(1, 0, &r[2]); // We are expecting 0 (1 != 0). 55 | fn(1, 1, &r[3]); // We are expecting 1 (1 == 1). 56 | 57 | printf("Result from JIT function: %d %d %d %d\n", r[0], r[1], r[2], r[3]); 58 | printf("Status: %s\n", (r[0] == 1 && r[1] == 0 && r[2] == 0 && r[3] == 1) ? "Success" : "Failure"); 59 | 60 | // Free the generated function if it's not needed anymore. 61 | MemoryManager::getGlobal()->free((void*)fn); 62 | // ========================================================================== 63 | 64 | return 0; 65 | } 66 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testtrampoline.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test trampoline generation (absolute addressing 8 | // in 64-bit mode). 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | #if defined(ASMJIT_X86) 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | printf("Trampoline test can be only used in x64 mode.\n"); 21 | printf("Status: %s\n", "Success"); 22 | 23 | return 0; 24 | } 25 | 26 | #else 27 | 28 | // This is type of function we will generate 29 | typedef void (*MyFn)(void); 30 | 31 | static int i = 0; 32 | 33 | // Function that is called from JIT code. 34 | static void calledfn(void) 35 | { 36 | i++; 37 | } 38 | 39 | int main(int argc, char* argv[]) 40 | { 41 | using namespace AsmJit; 42 | 43 | // ========================================================================== 44 | // Create assembler. 45 | Assembler a; 46 | 47 | // Log compiler output. 48 | FileLogger logger(stderr); 49 | a.setLogger(&logger); 50 | 51 | a.call(imm((sysint_t)calledfn)); // First trampoline - call. 52 | a.jmp(imm((sysint_t)calledfn)); // Second trampoline - jump, will return. 53 | MyFn fn0 = function_cast(a.make()); 54 | 55 | a.clear(); // Purge assembler, we will reuse it. 56 | a.jmp(imm((sysint_t)fn0)); 57 | MyFn fn1 = function_cast(a.make()); 58 | 59 | // ========================================================================== 60 | 61 | // ========================================================================== 62 | fn0(); 63 | fn1(); 64 | 65 | printf("Status: %s\n", (i == 4) ? "Success" : "Failure"); 66 | 67 | // If functions are not needed again they should be freed. 68 | MemoryManager::getGlobal()->free((void*)fn0); 69 | MemoryManager::getGlobal()->free((void*)fn1); 70 | // ========================================================================== 71 | 72 | return 0; 73 | } 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testvar2.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test function with many arguments. Bug originally 8 | // reported by Tilo Nitzsche for X64W and X64U calling conventions. 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | // This is type of function we will generate 17 | typedef sysint_t (*MyFn)(); 18 | 19 | int main(int argc, char* argv[]) 20 | { 21 | using namespace AsmJit; 22 | 23 | // ========================================================================== 24 | // Create compiler. 25 | Compiler c; 26 | 27 | // Log compiler output. 28 | FileLogger logger(stderr); 29 | c.setLogger(&logger); 30 | 31 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder0()); 32 | 33 | GPVar v0(c.newGP()); 34 | GPVar v1(c.newGP()); 35 | GPVar v2(c.newGP()); 36 | GPVar v3(c.newGP()); 37 | GPVar v4(c.newGP()); 38 | 39 | c.xor_(v0, v0); 40 | 41 | c.mov(v1, 1); 42 | c.mov(v2, 2); 43 | c.mov(v3, 3); 44 | c.mov(v4, 4); 45 | 46 | c.add(v0, v1); 47 | c.add(v0, v2); 48 | c.add(v0, v3); 49 | c.add(v0, v4); 50 | 51 | c.ret(v0); 52 | c.endFunction(); 53 | // ========================================================================== 54 | 55 | // ========================================================================== 56 | // Make the function. 57 | MyFn fn = function_cast(c.make()); 58 | int result = (int)fn(); 59 | 60 | printf("Result from JIT function: %d\n", result); 61 | printf("Status: %s\n", result == 10 ? "Success" : "Failure"); 62 | 63 | // Free the generated function if it's not needed anymore. 64 | MemoryManager::getGlobal()->free((void*)fn); 65 | // ========================================================================== 66 | 67 | return 0; 68 | } 69 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testvar3.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // This file is used to test AsmJit register allocator. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(int*, int*); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log assembler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder2()); 31 | 32 | // Function arguments. 33 | GPVar a1(c.argGP(0)); 34 | GPVar a2(c.argGP(1)); 35 | 36 | // Create some variables. 37 | GPVar x1(c.newGP(VARIABLE_TYPE_GPD)); 38 | GPVar x2(c.newGP(VARIABLE_TYPE_GPD)); 39 | GPVar x3(c.newGP(VARIABLE_TYPE_GPD)); 40 | GPVar x4(c.newGP(VARIABLE_TYPE_GPD)); 41 | GPVar x5(c.newGP(VARIABLE_TYPE_GPD)); 42 | GPVar x6(c.newGP(VARIABLE_TYPE_GPD)); 43 | GPVar x7(c.newGP(VARIABLE_TYPE_GPD)); 44 | GPVar x8(c.newGP(VARIABLE_TYPE_GPD)); 45 | 46 | GPVar t(c.newGP(VARIABLE_TYPE_GPD)); 47 | 48 | // Setup variables (use mov with reg/imm to se if register allocator works). 49 | c.mov(x1, 1); 50 | c.mov(x2, 2); 51 | c.mov(x3, 3); 52 | c.mov(x4, 4); 53 | c.mov(x5, 5); 54 | c.mov(x6, 6); 55 | c.mov(x7, 7); 56 | c.mov(x8, 8); 57 | 58 | // Make sum (addition) 59 | c.xor_(t, t); 60 | c.add(t, x1); 61 | c.add(t, x2); 62 | c.add(t, x3); 63 | c.add(t, x4); 64 | c.add(t, x5); 65 | c.add(t, x6); 66 | c.add(t, x7); 67 | c.add(t, x8); 68 | 69 | // Store result to a given pointer in first argument. 70 | c.mov(dword_ptr(a1), t); 71 | 72 | // Make sum (subtraction). 73 | c.xor_(t, t); 74 | c.sub(t, x1); 75 | c.sub(t, x2); 76 | c.sub(t, x3); 77 | c.sub(t, x4); 78 | c.sub(t, x5); 79 | c.sub(t, x6); 80 | c.sub(t, x7); 81 | c.sub(t, x8); 82 | 83 | // Store result to a given pointer in second argument. 84 | c.mov(dword_ptr(a2), t); 85 | 86 | // End of function. 87 | c.endFunction(); 88 | // ========================================================================== 89 | 90 | // ========================================================================== 91 | // Make the function. 92 | MyFn fn = function_cast(c.make()); 93 | 94 | // Call it. 95 | int x; 96 | int y; 97 | fn(&x, &y); 98 | 99 | printf("\nResults from JIT function: %d %d\n", x, y); 100 | printf("Status: %s\n", (x == 36 && y == -36) ? "Success" : "Failure"); 101 | 102 | // Free the generated function if it's not needed anymore. 103 | MemoryManager::getGlobal()->free((void*)fn); 104 | // ========================================================================== 105 | 106 | return 0; 107 | } 108 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testvar4.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Test variable scope detection in loop. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(uint32_t*); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | { 31 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder1()); 32 | 33 | GPVar var[32]; 34 | int i; 35 | 36 | for (i = 0; i < ASMJIT_ARRAY_SIZE(var); i++) 37 | { 38 | var[i] = c.newGP(VARIABLE_TYPE_GPD); 39 | c.xor_(var[i], var[i]); 40 | } 41 | 42 | GPVar v0(c.newGP(VARIABLE_TYPE_GPD)); 43 | Label L(c.newLabel()); 44 | 45 | c.mov(v0, imm(32)); 46 | c.bind(L); 47 | 48 | for (i = 0; i < ASMJIT_ARRAY_SIZE(var); i++) 49 | { 50 | c.add(var[i], imm(i)); 51 | } 52 | 53 | c.dec(v0); 54 | c.jnz(L); 55 | 56 | GPVar a0(c.argGP(0)); 57 | for (i = 0; i < ASMJIT_ARRAY_SIZE(var); i++) 58 | { 59 | c.mov(dword_ptr(a0, i * 4), var[i]); 60 | } 61 | c.endFunction(); 62 | } 63 | // ========================================================================== 64 | 65 | // ========================================================================== 66 | // Make the function. 67 | MyFn fn = function_cast(c.make()); 68 | 69 | { 70 | uint32_t out[32]; 71 | int i; 72 | bool success = true; 73 | 74 | fn(out); 75 | 76 | for (i = 0; i < ASMJIT_ARRAY_SIZE(out); i++) 77 | { 78 | printf("out[%d]=%u (expected %d)\n", i, out[i], i * 32); 79 | if (out[i] != i * 32) success = false; 80 | } 81 | 82 | printf("Status: %s\n", (success) ? "Success" : "Failure"); 83 | } 84 | 85 | // Free the generated function if it's not needed anymore. 86 | MemoryManager::getGlobal()->free((void*)fn); 87 | // ========================================================================== 88 | 89 | return 0; 90 | } 91 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Test/testvar5.cpp: -------------------------------------------------------------------------------- 1 | // [AsmJit] 2 | // Complete JIT Assembler for C++ Language. 3 | // 4 | // [License] 5 | // Zlib - See COPYING file in this package. 6 | 7 | // Test variable scope detection in loop. 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | 15 | // This is type of function we will generate 16 | typedef void (*MyFn)(uint32_t*); 17 | 18 | int main(int argc, char* argv[]) 19 | { 20 | using namespace AsmJit; 21 | 22 | // ========================================================================== 23 | // Create compiler. 24 | Compiler c; 25 | 26 | // Log compiler output. 27 | FileLogger logger(stderr); 28 | c.setLogger(&logger); 29 | 30 | { 31 | c.newFunction(CALL_CONV_DEFAULT, FunctionBuilder1()); 32 | c.getFunction()->setHint(FUNCTION_HINT_NAKED, false); 33 | 34 | GPVar v0(c.newGP(VARIABLE_TYPE_GPD)); 35 | GPVar v1(c.newGP(VARIABLE_TYPE_GPD)); 36 | GPVar cnt(c.newGP(VARIABLE_TYPE_GPD)); 37 | 38 | c.xor_(v0, v0); 39 | c.xor_(v1, v1); 40 | c.spill(v0); 41 | c.spill(v1); 42 | 43 | Label L(c.newLabel()); 44 | c.mov(cnt, imm(32)); 45 | c.bind(L); 46 | 47 | c.inc(v1); 48 | c.add(v0, v1); 49 | 50 | c.dec(cnt); 51 | c.jnz(L); 52 | 53 | GPVar a0(c.argGP(0)); 54 | c.mov(dword_ptr(a0), v0); 55 | c.endFunction(); 56 | } 57 | // ========================================================================== 58 | 59 | // ========================================================================== 60 | // Make the function. 61 | MyFn fn = function_cast(c.make()); 62 | 63 | { 64 | uint32_t out; 65 | uint32_t expected = 0+ 1+ 2+ 3+ 4+ 5+ 6+ 7+ 8+ 9+ 66 | 10+11+12+13+14+15+16+17+18+19+ 67 | 20+21+22+23+24+25+26+27+28+29+ 68 | 30+31+32; 69 | 70 | fn(&out); 71 | 72 | printf("out=%u (should be %u)\n", out, expected); 73 | printf("Status: %s\n", (out == expected) ? "Success" : "Failure"); 74 | } 75 | 76 | // Free the generated function if it's not needed anymore. 77 | MemoryManager::getGlobal()->free((void*)fn); 78 | // ========================================================================== 79 | 80 | return 0; 81 | } 82 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/code-fix.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | # This script will convert all TABs to SPACEs in the AsmJit root directory 4 | # and all sub-directories (recursive). 5 | # 6 | # Converted sequences: 7 | # - The \r\n sequence is converted to \n (To UNIX line-ending). 8 | # - The \t (TAB) sequence is converted to TAB_REPLACEMENT which should 9 | # be two spaces. 10 | # 11 | # Affected files: 12 | # - *.cmake 13 | # - *.cpp 14 | # - *.h 15 | 16 | import os 17 | 18 | TAB_REPLACEMENT = " " 19 | 20 | for root, dirs, files in os.walk("../"): 21 | for f in files: 22 | if f.lower().endswith(".cpp") or f.lower().endswith(".h") or f.lower().endswith(".cmake") or f.lower().endswith(".txt"): 23 | path = os.path.join(root, f) 24 | 25 | fh = open(path, "rb") 26 | data = fh.read() 27 | fh.close() 28 | 29 | fixed = False 30 | 31 | if "\r" in data: 32 | print "Fixing \\r\\n in: " + path 33 | data = data.replace("\r", "") 34 | fixed = True 35 | 36 | if "\t" in data: 37 | print "Fixing TABs in: " + path 38 | data = data.replace("\t", TAB_REPLACEMENT) 39 | fixed = True 40 | 41 | if fixed: 42 | fh = open(path, "wb") 43 | fh.truncate() 44 | fh.write(data) 45 | fh.close() 46 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-borland-dbg.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Borland Makefiles" -DCMAKE_BUILD_TYPE=Debug -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-borland-rel.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Borland Makefiles" -DCMAKE_BUILD_TYPE=Release -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-mac-xcode.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir ../Build 3 | cd ../Build 4 | cmake .. -G"Xcode" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 5 | cd ../Util 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-unix-makefiles-dbg.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir ../Build 3 | cd ../Build 4 | cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 5 | cd ../Util 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-unix-makefiles-rel.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | mkdir ../Build 3 | cd ../Build 4 | cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 5 | cd ../Util 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-mingw-dbg.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-mingw-rel.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-msvc6.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 6" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-vs2005-x64.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 8 2005 Win64" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | pause 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-vs2005-x86.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 8 2005" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | pause 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-vs2008-x64.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 9 2008 Win64" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | pause 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-vs2008-x86.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 9 2008" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | pause 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-vs2010-x64.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 10 Win64" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | pause 6 | -------------------------------------------------------------------------------- /deps/AsmJit-1.0-beta4/Util/configure-windows-vs2010-x86.bat: -------------------------------------------------------------------------------- 1 | mkdir ..\Build 2 | cd ..\Build 3 | cmake .. -G"Visual Studio 10" -DASMJIT_BUILD_LIBRARY=1 -DASMJIT_BUILD_TEST=1 4 | cd ..\Util 5 | pause 6 | -------------------------------------------------------------------------------- /scripts/clean_preprocessed.pl: -------------------------------------------------------------------------------- 1 | unless(/(^\s*$|^\#.*$|^\n)/g){print "$_"} 2 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [nosetests] 2 | verbosity=3 3 | tests=tests/compilertests.py,tests/jittests.py,tests/extensiontests.py 4 | -------------------------------------------------------------------------------- /tests/compilertests.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from asmjit import * 3 | import ctypes 4 | import array 5 | 6 | class TestCompiler(unittest.TestCase): 7 | def testBasicCompiler(self): 8 | c = Compiler() 9 | c.newFunction(CALL_CONV_DEFAULT, UIntFunctionBuilder0()); 10 | 11 | c.nop() 12 | c.nop() 13 | c.nop() 14 | 15 | address = GPVar(c.newGP()) 16 | c.mov(address, imm(432)) 17 | c.ret(address) 18 | c.endFunction() 19 | 20 | raw_ptr = int(c.make()) 21 | var = GPVar() 22 | print 'Generated function at %x' % (raw_ptr,) 23 | 24 | restype = ctypes.c_uint 25 | argtypes = [] 26 | functype = ctypes.CFUNCTYPE(restype, *argtypes) 27 | func = functype(raw_ptr) 28 | ret = func() 29 | self.assertEqual(ret, 432, 'Compiler function did not return 432') 30 | 31 | -------------------------------------------------------------------------------- /tests/extensiontests.py: -------------------------------------------------------------------------------- 1 | # Test for python-specific extensions to asmjit 2 | import sys 3 | import ctypes 4 | import array 5 | from binascii import hexlify 6 | from functools import wraps 7 | import logging 8 | import unittest 9 | log = logging.getLogger('tests.extensions') 10 | 11 | try: 12 | sys.path.append('.') 13 | from asmjit import * 14 | except ImportError: 15 | # Maybe we're being called directly from our own dir 16 | # append .. and give it one more shot 17 | sys.path.append('..') 18 | from asmjit import * 19 | 20 | TYPE_JUMP = 0x25 21 | TYPE_CALL = 0x15 22 | 23 | class TestExtensions(unittest.TestCase): 24 | 25 | def assertEqual(self, actual, expected): 26 | try: 27 | super(TestExtensions, self).assertEqual(actual, expected) 28 | except AssertionError: 29 | raise AssertionError('0x%x != 0x%x' % (actual, expected)) 30 | 31 | def _jmp_or_call(self, type_): 32 | assert type_ in [TYPE_JUMP, TYPE_CALL], 'Unknown type %s' %(type_,) 33 | a = Assembler() 34 | a.mov(eax, uimm(0xCCCCCCCC)) 35 | a.ret() 36 | fn0_ptr = int(a.make()) 37 | 38 | a.clear() 39 | [a.nop() for _ in range(10)] 40 | a.mov(eax, uimm(0xBAF)) 41 | a.ret() 42 | 43 | a.clear() 44 | if type_ == TYPE_JUMP: 45 | a.py_jmp(fn0_ptr) 46 | else: 47 | raise NotImplementedError 48 | fn1_ptr = int(a.make()) 49 | log.info('Generated %s' % (hexlify((ctypes.c_char * 12).from_address(fn1_ptr)),)) 50 | fn1 = MakeFunction(fn1_ptr) 51 | ret = fn1() 52 | self.assertEqual(ret, 0xCCCCCCCC) 53 | 54 | def testAbsJmp(self): 55 | """ 56 | Test the emission of an Indirect Absolute Jump 57 | (currently is unsupported for x86 in asmjit) 58 | """ 59 | self._jmp_or_call(TYPE_JUMP) 60 | 61 | def testCpy(self): 62 | """ 63 | Test the copy of instructions from the assembler code buffer 64 | to an arbitrary location of memory 65 | """ 66 | goal = 0xABCDEF00 67 | 68 | a = Assembler() 69 | a.mov(eax, uimm(goal)) 70 | a.ret() 71 | 72 | code_sz = a.getCodeSize() 73 | dest = ctypes.create_string_buffer(code_sz) 74 | log.info('Allocated code buffer of size %d at %x' % 75 | (code_sz, ctypes.addressof(dest))) 76 | 77 | ctypes.memmove(dest, a.py_make(), code_sz) 78 | 79 | fn = a.py_make_cfunc() 80 | ret = fn() 81 | self.assertEqual(ret, goal) 82 | 83 | if __name__ == '__main__': 84 | unittest.main() 85 | 86 | 87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /tests/jittests.py: -------------------------------------------------------------------------------- 1 | from asmjit import * 2 | import ctypes 3 | import array 4 | 5 | def testAbsJmp(): 6 | a = Assembler() 7 | ptr = AbsPtr(0xFFEE) 8 | a.jmp(ptr) 9 | goal = array.array('B', [0xFF, 0x25, 0xEE, 0xFF, 0x00, 0x00]) 10 | assert a.toarray() == goal, ('Absolute Jump assembly does not match expected (%s vs %s)' % 11 | (a.toarray(), goal)) 12 | 13 | # Converted from testjit.cpp 14 | def testFunction(): 15 | a = Assembler() 16 | 17 | # Prologue 18 | a.push(ebp) 19 | a.mov(ebp, esp) 20 | 21 | # return 1024 22 | a.mov(eax, imm(1024)) 23 | 24 | # Epilogue 25 | a.mov(esp, ebp) 26 | a.pop(ebp) 27 | a.ret() 28 | 29 | raw_ptr = int(a.make()) 30 | 31 | print 'Generated function at %x' % (raw_ptr,), hex(a) 32 | 33 | restype = ctypes.c_int 34 | argtypes = [] 35 | functype = ctypes.CFUNCTYPE(restype, *argtypes) 36 | func = functype(raw_ptr) 37 | ret = func() 38 | assert ret == 1024, 'JIT function did not return 1024 [actual: %d]' % (ret,) 39 | 40 | testAbsJmp() 41 | testFunction() 42 | 43 | print "HI" 44 | --------------------------------------------------------------------------------