-
-
Save feliwir/a2bdb81f9b62cb281dd3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // / DynASM directives. | |
| |.arch x86 | |
| |.actionlist actions | |
| // This define affects "|" DynASM lines. "Dst" must | |
| // resolve to a dasm_State** that points to a dasm_State*. | |
| #define Dst &state | |
| #include "jit_util.hpp" | |
| void* translateFunc(asDWORD* byteCode, asDWORD* end) | |
| { | |
| dasm_State *state; | |
| asjit::initjit(&state, actions); | |
| | push esi | |
| | push edi | |
| | push ebx | |
| | push ebp | |
| | push esp | |
| //the actual code of the function | |
| while (byteCode < end) | |
| { | |
| // Determine the instruction | |
| asEBCInstr op = asEBCInstr(*(asBYTE*)byteCode); | |
| switch (op) | |
| { | |
| // Translate each byte code instruction into native code. | |
| // The codes that cannot be translated should return the control | |
| // to the VM, so that it can continue the processing. When | |
| // the VM encounters the next JitEntry instruction it will | |
| // transfer the control back to the JIT function. | |
| case asBC_SetV4: | |
| | mov eax , 4 | |
| break; | |
| case asBC_JitEntry: | |
| // Update the argument for the JitEntry instruction with | |
| // the argument that should be sent to the jit function. | |
| // Remember that 0 means that the VM should not pass | |
| // control to the JIT function. | |
| asBC_PTRARG(byteCode) = 1; | |
| break; | |
| } | |
| // Move to next instruction | |
| byteCode += asBCTypeSize[asBCInfo[op].type]; | |
| } | |
| | pop esi | |
| | pop edi | |
| | pop ebx | |
| | pop ebp | |
| | pop esp | |
| | ret | |
| // Link the code and write it to executable memory. | |
| void* fptr = asjit::jitcode(&state); | |
| return fptr; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment