internal
| 1587 | |
| 1588 | // internal |
| 1589 | void asCScriptFunction::JITCompile() |
| 1590 | { |
| 1591 | if( funcType != asFUNC_SCRIPT ) |
| 1592 | return; |
| 1593 | |
| 1594 | asASSERT( scriptData ); |
| 1595 | |
| 1596 | if( !engine->jitCompiler ) |
| 1597 | return; |
| 1598 | |
| 1599 | // Make sure the function has been compiled with JitEntry instructions |
| 1600 | // For functions that has JitEntry this will be a quick test |
| 1601 | asUINT length; |
| 1602 | asDWORD *byteCode = GetByteCode(&length); |
| 1603 | asDWORD *end = byteCode + length; |
| 1604 | bool foundJitEntry = false; |
| 1605 | while( byteCode < end ) |
| 1606 | { |
| 1607 | // Determine the instruction |
| 1608 | asEBCInstr op = asEBCInstr(*(asBYTE*)byteCode); |
| 1609 | if( op == asBC_JitEntry ) |
| 1610 | { |
| 1611 | foundJitEntry = true; |
| 1612 | break; |
| 1613 | } |
| 1614 | |
| 1615 | // Move to next instruction |
| 1616 | byteCode += asBCTypeSize[asBCInfo[op].type]; |
| 1617 | } |
| 1618 | |
| 1619 | if( !foundJitEntry ) |
| 1620 | { |
| 1621 | asCString msg; |
| 1622 | msg.Format(TXT_NO_JIT_IN_FUNC_s, GetDeclaration()); |
| 1623 | engine->WriteMessage("", 0, 0, asMSGTYPE_WARNING, msg.AddressOf()); |
| 1624 | } |
| 1625 | |
| 1626 | // Release the previous function, if any |
| 1627 | if( scriptData->jitFunction ) |
| 1628 | { |
| 1629 | if (engine->ep.jitInterfaceVersion == 1) |
| 1630 | static_cast<asIJITCompiler*>(engine->jitCompiler)->ReleaseJITFunction(scriptData->jitFunction); |
| 1631 | else if (engine->ep.jitInterfaceVersion == 2) |
| 1632 | static_cast<asIJITCompilerV2*>(engine->jitCompiler)->CleanFunction(this, scriptData->jitFunction); |
| 1633 | scriptData->jitFunction = 0; |
| 1634 | } |
| 1635 | |
| 1636 | if (engine->ep.jitInterfaceVersion == 1) |
| 1637 | { |
| 1638 | // Compile for native system. If the JIT compiler decides to compile the function it |
| 1639 | // must do so now, as it is not allowed to do it later. |
| 1640 | int r = static_cast<asIJITCompiler*>(engine->jitCompiler)->CompileFunction(this, &scriptData->jitFunction); |
| 1641 | if (r < 0) |
| 1642 | asASSERT(scriptData->jitFunction == 0); |
| 1643 | } |
| 1644 | else if (engine->ep.jitInterfaceVersion == 2) |
| 1645 | { |
| 1646 | // Notify the JIT compiler about the new function, it may do JIT compilation now, or later, or not at all. |
nothing calls this directly
no test coverage detected