#ifndef JITCode_h
#define JITCode_h
#if ENABLE(JIT)
#include "CallFrame.h"
#include "JSValue.h"
#include "MacroAssemblerCodeRef.h"
#include "Profiler.h"
namespace JSC {
class JSGlobalData;
class RegisterFile;
class JITCode {
typedef MacroAssemblerCodeRef CodeRef;
typedef MacroAssemblerCodePtr CodePtr;
public:
enum JITType { HostCallThunk, BaselineJIT, DFGJIT };
JITCode()
{
}
JITCode(const CodeRef ref, JITType jitType)
: m_ref(ref)
, m_jitType(jitType)
{
}
bool operator !() const
{
return !m_ref.m_code.executableAddress();
}
CodePtr addressForCall()
{
return m_ref.m_code;
}
unsigned offsetOf(void* pointerIntoCode)
{
intptr_t result = reinterpret_cast<intptr_t>(pointerIntoCode) - reinterpret_cast<intptr_t>(m_ref.m_code.executableAddress());
ASSERT(static_cast<intptr_t>(static_cast<unsigned>(result)) == result);
return static_cast<unsigned>(result);
}
inline JSValue execute(RegisterFile* registerFile, CallFrame* callFrame, JSGlobalData* globalData)
{
JSValue result = JSValue::decode(ctiTrampoline(m_ref.m_code.executableAddress(), registerFile, callFrame, 0, Profiler::enabledProfilerReference(), globalData));
return globalData->exception ? jsNull() : result;
}
void* start()
{
return m_ref.m_code.dataLocation();
}
size_t size()
{
ASSERT(m_ref.m_code.executableAddress());
return m_ref.m_size;
}
ExecutablePool* getExecutablePool()
{
return m_ref.m_executablePool.get();
}
JITType jitType()
{
return m_jitType;
}
static JITCode HostFunction(CodePtr code)
{
return JITCode(code.dataLocation(), 0, 0, HostCallThunk);
}
void clear()
{
m_ref.~CodeRef();
new (&m_ref) CodeRef();
}
private:
JITCode(void* code, PassRefPtr<ExecutablePool> executablePool, size_t size, JITType jitType)
: m_ref(code, executablePool, size)
, m_jitType(jitType)
{
}
CodeRef m_ref;
JITType m_jitType;
};
};
#endif
#endif