Created
March 3, 2016 17:37
-
-
Save feliwir/770695ca7cdfe8b67d9b 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); | |
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: | |
asBC_DWORD arg = asBC_DWORDARG(op); | |
| mov eax , arg | |
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]; | |
} | |
// 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