2012-05-23 21:26:15 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
gbx_jit.c
|
|
|
|
|
|
|
|
(c) 2012 Emil Lenngren <emil.lenngren [at] gmail.com>
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
|
|
|
MA 02110-1301, USA.
|
|
|
|
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#define __GBX_JIT_C
|
|
|
|
|
|
|
|
#include "gbx_jit.h"
|
|
|
|
#include "gbx_api.h"
|
|
|
|
#include "gbx_event.h"
|
|
|
|
|
|
|
|
JIT_INTERFACE JIT;
|
|
|
|
|
2012-05-24 01:39:02 +02:00
|
|
|
bool JIT_load()
|
|
|
|
{
|
2012-05-23 21:26:15 +02:00
|
|
|
static bool loaded = FALSE;
|
|
|
|
static bool available = TRUE;
|
|
|
|
|
2012-05-26 00:24:13 +02:00
|
|
|
COMPONENT *comp;
|
|
|
|
|
2012-05-23 21:26:15 +02:00
|
|
|
if (loaded)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!available)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
TRY
|
|
|
|
{
|
2012-05-26 00:24:13 +02:00
|
|
|
comp = COMPONENT_create("gb.jit");
|
|
|
|
//comp->preload = TRUE; // Prevent from being unloaded before exit() is called
|
|
|
|
|
|
|
|
COMPONENT_load(comp);
|
|
|
|
|
2012-05-23 21:26:15 +02:00
|
|
|
LIBRARY_get_interface_by_name("gb.jit", JIT_INTERFACE_VERSION, &JIT);
|
|
|
|
|
2012-07-03 00:38:29 +02:00
|
|
|
if (EXEC_debug)
|
|
|
|
GAMBAS_JitApi[offsetof(GB_JIT_INTERFACE, F_DEBUG_Profile_Add) / sizeof(void *)] = DEBUG.Profile.Add;
|
|
|
|
|
|
|
|
JIT.Init((GB_JIT_INTERFACE *)(void *)GAMBAS_JitApi, &EXEC_current, &SP, &TEMP, &RET,
|
|
|
|
&GAMBAS_StopEvent, (char **)&EXEC_enum, &EXEC, &EXEC_unknown_name, &EXEC_profile,
|
|
|
|
&EXEC_profile_instr, &EVENT_Last, &ERROR_current, &ERROR_handler, &STRING_char_string[0]);
|
2012-05-23 21:26:15 +02:00
|
|
|
|
|
|
|
loaded = TRUE;
|
|
|
|
}
|
|
|
|
CATCH
|
|
|
|
{
|
2012-06-01 02:18:38 +02:00
|
|
|
char *env = getenv("GB_JIT");
|
2012-05-23 21:26:15 +02:00
|
|
|
available = FALSE;
|
2012-06-01 02:18:38 +02:00
|
|
|
|
|
|
|
if (env && *env)
|
|
|
|
ERROR_warning("JIT compiler not available");
|
2012-05-23 21:26:15 +02:00
|
|
|
}
|
|
|
|
END_TRY
|
|
|
|
|
|
|
|
return loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
void JIT_default_jit_function()
|
|
|
|
{
|
|
|
|
JIT.CompileAndExecute();
|
|
|
|
}
|