2018-06-09 22:42:35 +02:00
|
|
|
/***************************************************************************
|
|
|
|
|
|
|
|
jit.c
|
|
|
|
|
|
|
|
(c) 2000-2018 Benoît Minisini <g4mba5@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 __JIT_C
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "gb_str.h"
|
|
|
|
#include "jit.h"
|
|
|
|
|
|
|
|
typedef
|
|
|
|
struct {
|
|
|
|
const char *name;
|
|
|
|
char type;
|
|
|
|
}
|
|
|
|
CLASS_TYPE;
|
|
|
|
|
|
|
|
CLASS *JIT_class;
|
|
|
|
char *JIT_prefix;
|
|
|
|
bool JIT_last_print_is_label;
|
|
|
|
|
|
|
|
static char *_buffer = NULL;
|
2018-06-19 00:26:25 +02:00
|
|
|
static char *_buffer_decl = NULL;
|
|
|
|
static char *_buffer_body = NULL;
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2019-04-04 22:58:06 +02:00
|
|
|
static bool _decl_null_string = FALSE;
|
|
|
|
static bool _decl_null_date = FALSE;
|
|
|
|
static bool _decl_null_object = FALSE;
|
2018-11-26 01:20:09 +01:00
|
|
|
static bool _decl_null_variant = FALSE;
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
/*static const CLASS_TYPE _class_type[] = {
|
|
|
|
{ "Boolean[]", T_BOOLEAN },
|
|
|
|
{ "Byte[]", T_BYTE },
|
|
|
|
{ "Short[]", T_SHORT },
|
|
|
|
{ "Integer[]", T_INTEGER },
|
|
|
|
{ "Long[]", T_LONG },
|
|
|
|
{ "Single[]", T_SINGLE },
|
|
|
|
{ "Float[]", T_FLOAT },
|
|
|
|
{ "Date[]", T_DATE },
|
|
|
|
{ "String[]", T_STRING },
|
|
|
|
{ "Pointer[]", T_POINTER },
|
|
|
|
{ "Object[]", T_OBJECT },
|
|
|
|
{ "Variant[]", T_VARIANT },
|
|
|
|
{ NULL, 0 }
|
|
|
|
};*/
|
|
|
|
|
|
|
|
static const char *_type_name[] =
|
|
|
|
{
|
|
|
|
"V" , "b", "c", "h", "i", "l", "g", "f",
|
|
|
|
"d", "s", "t", "p", "v", "F", "C", "n",
|
|
|
|
"o", "u"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *_gtype_name[] =
|
|
|
|
{
|
|
|
|
"GB_T_VOID" , "GB_T_BOOLEAN", "GB_T_BYTE", "GB_T_SHORT", "GB_T_INTEGER", "GB_T_LONG", "GB_T_SINGLE", "GB_T_FLOAT",
|
2018-07-02 19:37:37 +02:00
|
|
|
"GB_T_DATE", "GB_T_STRING", "GB_T_CSTRING", "GB_T_POINTER", "GB_T_VARIANT", "?", "GB_T_CLASS", "?",
|
2018-06-09 22:42:35 +02:00
|
|
|
"GB_T_OBJECT"
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *_ctype_name[] =
|
|
|
|
{
|
|
|
|
"void" , "bool", "uchar", "short", "int", "int64_t", "float", "double",
|
2018-07-02 19:37:37 +02:00
|
|
|
"GB_DATE", "GB_STRING", "GB_STRING", "intptr_t", "GB_VARIANT", "?", "void *", "?",
|
2018-06-09 22:42:35 +02:00
|
|
|
"GB_OBJECT", "GB_VALUE", "?"
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *JIT_get_type(TYPE type)
|
|
|
|
{
|
|
|
|
return _type_name[TYPEID(type)];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *JIT_get_gtype(TYPE type)
|
|
|
|
{
|
|
|
|
return _gtype_name[TYPEID(type)];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *JIT_get_ctype(TYPE type)
|
|
|
|
{
|
|
|
|
return _ctype_name[TYPEID(type)];
|
|
|
|
}
|
|
|
|
|
2018-07-08 08:24:31 +02:00
|
|
|
TYPE JIT_ctype_to_type(CLASS *class, CTYPE ctype)
|
2018-06-09 22:42:35 +02:00
|
|
|
{
|
|
|
|
if (ctype.id == T_OBJECT && ctype.value >= 0)
|
2018-07-08 08:24:31 +02:00
|
|
|
return (TYPE)(class->load->class_ref[ctype.value]);
|
2018-06-09 22:42:35 +02:00
|
|
|
else if (ctype.id == TC_ARRAY)
|
2018-07-07 14:54:23 +02:00
|
|
|
{
|
2018-07-08 08:24:31 +02:00
|
|
|
CLASS_ARRAY *desc = class->load->array[ctype.value];
|
|
|
|
return (TYPE)JIT.get_array_class(class, *(JIT_CTYPE *)&desc->ctype);
|
2018-07-07 14:54:23 +02:00
|
|
|
}
|
2018-06-09 22:42:35 +02:00
|
|
|
else if (ctype.id == TC_STRUCT)
|
2018-07-08 08:24:31 +02:00
|
|
|
return (TYPE)(class->load->class_ref[ctype.value]);
|
2018-06-09 22:42:35 +02:00
|
|
|
else
|
|
|
|
return (TYPE)(ctype.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void JIT_begin(void)
|
|
|
|
{
|
|
|
|
JIT_prefix = STR_lower(JIT_class->name);
|
|
|
|
_buffer = NULL;
|
2018-06-19 00:26:25 +02:00
|
|
|
_buffer_decl = NULL;
|
2018-06-09 22:42:35 +02:00
|
|
|
JIT_print("\n//////// %s\n\n", JIT_class->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *JIT_end(void)
|
|
|
|
{
|
|
|
|
char *result = _buffer;
|
|
|
|
|
|
|
|
STR_free(JIT_prefix);
|
|
|
|
_buffer = NULL;
|
|
|
|
|
|
|
|
GB.FreeStringLater(result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void declare_implementation(FUNCTION *func, int index)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
int nopt;
|
|
|
|
int opt;
|
2018-07-05 07:05:53 +02:00
|
|
|
const char *vol = func->error ? "volatile " : "";
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
JIT_print("static %s jit_%s_%d_(", JIT_get_ctype(func->type), JIT_prefix, index);
|
|
|
|
|
|
|
|
for (i = 0; i < func->npmin; i++)
|
|
|
|
{
|
2018-06-11 18:52:39 +02:00
|
|
|
if (i) JIT_print(",");
|
2018-07-05 07:05:53 +02:00
|
|
|
JIT_print("%s%s p%d", vol, JIT_get_ctype(func->param[i].type), i);
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i < func->n_param)
|
|
|
|
{
|
|
|
|
opt = nopt = 0;
|
|
|
|
|
|
|
|
for (; i < func->n_param; i++)
|
|
|
|
{
|
2018-06-11 18:52:39 +02:00
|
|
|
if (i) JIT_print(",");
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
if (nopt == 0)
|
|
|
|
{
|
2018-06-11 18:52:39 +02:00
|
|
|
JIT_print("uchar o%d,", opt);
|
2018-06-09 22:42:35 +02:00
|
|
|
opt++;
|
|
|
|
}
|
|
|
|
|
2018-07-05 07:05:53 +02:00
|
|
|
JIT_print("%s%s p%d", vol, JIT_get_ctype(func->param[i].type), i);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
nopt++;
|
|
|
|
if (nopt >= 8)
|
|
|
|
nopt = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-02 19:37:37 +02:00
|
|
|
if (func->vararg)
|
2018-11-24 21:33:18 +01:00
|
|
|
{
|
|
|
|
if (func->n_param)
|
|
|
|
JIT_print(",");
|
|
|
|
JIT_print("uchar nv,GB_VALUE *v");
|
|
|
|
}
|
2018-07-02 19:37:37 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
JIT_print(")");
|
|
|
|
}
|
|
|
|
|
2018-06-14 16:42:47 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
void JIT_declare_func(FUNCTION *func, int index)
|
|
|
|
{
|
|
|
|
JIT_print("void jit_%s_%d(uchar n);\n", JIT_prefix, index);
|
|
|
|
|
|
|
|
declare_implementation(func, index);
|
|
|
|
JIT_print(";\n");
|
|
|
|
}
|
|
|
|
|
2018-06-14 16:42:47 +02:00
|
|
|
|
2018-06-11 18:52:39 +02:00
|
|
|
const char *JIT_get_default_value(TYPE type)
|
|
|
|
{
|
|
|
|
switch(TYPEID(type))
|
|
|
|
{
|
2019-04-04 22:58:06 +02:00
|
|
|
case T_DATE:
|
|
|
|
|
|
|
|
if (!_decl_null_date)
|
|
|
|
{
|
|
|
|
JIT_print_decl(" const GB_DATE null_date = {GB_T_DATE};\n");
|
|
|
|
_decl_null_date = TRUE;
|
|
|
|
}
|
|
|
|
return "null_date";
|
|
|
|
|
|
|
|
case T_STRING:
|
|
|
|
|
|
|
|
if (!_decl_null_string)
|
|
|
|
{
|
|
|
|
JIT_print_decl(" const GB_STRING null_string = {GB_T_STRING};\n");
|
|
|
|
_decl_null_string = TRUE;
|
|
|
|
}
|
|
|
|
return "null_string";
|
|
|
|
|
|
|
|
case T_OBJECT:
|
|
|
|
|
|
|
|
if (!_decl_null_object)
|
|
|
|
{
|
|
|
|
JIT_print_decl(" const GB_OBJECT null_object = {GB_T_NULL};\n");
|
|
|
|
_decl_null_object = TRUE;
|
|
|
|
}
|
|
|
|
return "null_object";
|
|
|
|
|
2018-11-24 20:00:45 +01:00
|
|
|
case T_VARIANT:
|
|
|
|
if (!_decl_null_variant)
|
|
|
|
{
|
2019-04-04 22:58:06 +02:00
|
|
|
JIT_print_decl(" const GB_VARIANT null_variant = {GB_T_VARIANT,{GB_T_NULL}};\n");
|
2018-11-24 20:00:45 +01:00
|
|
|
_decl_null_variant = TRUE;
|
|
|
|
}
|
|
|
|
return "null_variant";
|
2019-04-04 22:58:06 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
return "0";
|
2018-06-11 18:52:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-14 16:42:47 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
static bool JIT_translate_func(FUNCTION *func, int index)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
TYPE type;
|
|
|
|
int nopt;
|
2018-11-24 20:00:45 +01:00
|
|
|
const char *def;
|
2018-07-05 07:05:53 +02:00
|
|
|
const char *vol = func->error ? "volatile " : "";
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
if (func->debug)
|
|
|
|
JIT_section(func->debug->name);
|
|
|
|
|
|
|
|
JIT_print("void jit_%s_%d(uchar n)\n{\n", JIT_prefix, index);
|
|
|
|
|
2018-11-24 21:33:18 +01:00
|
|
|
if (func->n_param || func->vararg)
|
2018-06-09 22:42:35 +02:00
|
|
|
JIT_print(" VALUE *sp = *((VALUE **)%p);\n", JIT.sp);
|
|
|
|
|
|
|
|
JIT_print(" ");
|
|
|
|
|
|
|
|
if (!TYPE_is_void(func->type))
|
|
|
|
JIT_print("RETURN_%s(", JIT_get_type(func->type));
|
|
|
|
|
|
|
|
JIT_print("jit_%s_%d_(", JIT_prefix, index);
|
|
|
|
|
|
|
|
for (i = 0; i < func->npmin; i++)
|
|
|
|
{
|
2018-06-11 18:52:39 +02:00
|
|
|
if (i) JIT_print(",");
|
2018-06-13 00:38:18 +02:00
|
|
|
type = func->param[i].type;
|
|
|
|
if (TYPE_is_pure_object(type))
|
|
|
|
JIT_print("PARAM_O(%d, CLASS(%p))", i, type);
|
|
|
|
else
|
|
|
|
JIT_print("PARAM_%s(%d)", JIT_get_type(type), i);
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i < func->n_param)
|
|
|
|
{
|
|
|
|
nopt = 0;
|
|
|
|
|
|
|
|
for (; i < func->n_param; i++)
|
|
|
|
{
|
2018-06-11 18:52:39 +02:00
|
|
|
if (i) JIT_print(",");
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
if (nopt == 0)
|
2018-06-11 18:52:39 +02:00
|
|
|
JIT_print("OPT(%d,%d),", i, Min(func->n_param, i + 8) - i);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2018-06-13 00:38:18 +02:00
|
|
|
type = func->param[i].type;
|
|
|
|
if (TYPE_is_pure_object(type))
|
|
|
|
JIT_print("PARAM_OPT_O(%d, CLASS(%p))", i, type);
|
|
|
|
else
|
|
|
|
JIT_print("PARAM_OPT_%s(%d)", JIT_get_type(type), i);
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
nopt++;
|
|
|
|
if (nopt >= 8)
|
2018-06-11 18:52:39 +02:00
|
|
|
nopt = 0;
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (func->vararg)
|
2018-11-24 21:33:18 +01:00
|
|
|
{
|
|
|
|
if (func->n_param)
|
|
|
|
JIT_print(",");
|
|
|
|
JIT_print("n - %d,&sp[-n+%d]", i, i);
|
|
|
|
}
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
if (!TYPE_is_void(func->type))
|
|
|
|
JIT_print(")");
|
|
|
|
|
|
|
|
JIT_print(");\n");
|
|
|
|
JIT_print("}\n\n");
|
|
|
|
|
|
|
|
declare_implementation(func, index);
|
|
|
|
JIT_print("\n{\n");
|
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
_buffer_decl = NULL;
|
|
|
|
_buffer_body = NULL;
|
2019-04-04 22:58:06 +02:00
|
|
|
_decl_null_date = FALSE;
|
|
|
|
_decl_null_string = FALSE;
|
|
|
|
_decl_null_object = FALSE;
|
2018-11-26 01:20:09 +01:00
|
|
|
_decl_null_variant = FALSE;
|
2018-06-19 00:26:25 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
for (i = -1; i < func->n_local; i++)
|
|
|
|
{
|
|
|
|
if (i < 0)
|
|
|
|
{
|
|
|
|
if (TYPE_is_void(func->type))
|
|
|
|
continue;
|
|
|
|
type = func->type;
|
2018-11-24 20:00:45 +01:00
|
|
|
def = JIT_get_default_value(type);
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_print_decl(" %s r = ", JIT_get_ctype(type));
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-08 08:24:31 +02:00
|
|
|
type = JIT_ctype_to_type(JIT_class, func->local[i].type);
|
2018-11-24 20:00:45 +01:00
|
|
|
def = JIT_get_default_value(type);
|
2018-07-05 07:05:53 +02:00
|
|
|
JIT_print_decl(" %s%s l%d = ", vol, JIT_get_ctype(type), i);
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
|
2018-11-24 20:00:45 +01:00
|
|
|
JIT_print_decl(def);
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_print_decl(";\n");
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
|
2018-06-13 00:38:18 +02:00
|
|
|
for (i = 0; i < func->n_param; i++)
|
|
|
|
{
|
|
|
|
type = func->param[i].type;
|
|
|
|
switch(TYPEID(type))
|
|
|
|
{
|
|
|
|
case T_STRING: case T_OBJECT: case T_VARIANT:
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_print_body(" BORROW_%s(p%d);\n", JIT_get_type(type), i);
|
2018-06-13 00:38:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
if (JIT_translate_body(func, index))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (!TYPE_is_void(func->type))
|
|
|
|
{
|
|
|
|
switch(TYPEID(func->type))
|
|
|
|
{
|
|
|
|
case T_STRING:
|
|
|
|
case T_OBJECT:
|
|
|
|
case T_VARIANT:
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_print_body(" JIT.unborrow((GB_VALUE *)&r);\n");
|
2018-06-09 22:42:35 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_print_body(" return r;\n");
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
|
|
|
else
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_print_body(" return;\n");
|
|
|
|
|
|
|
|
_buffer = GB.AddString(_buffer, _buffer_decl, GB.StringLength(_buffer_decl));
|
|
|
|
JIT_print("\n");
|
|
|
|
_buffer = GB.AddString(_buffer, _buffer_body, GB.StringLength(_buffer_body));
|
|
|
|
|
|
|
|
GB.FreeString(&_buffer_decl);
|
|
|
|
GB.FreeString(&_buffer_body);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
JIT_print("}\n");
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
|
|
|
|
void JIT_vprint(char **buffer, const char *fmt, va_list args)
|
2018-06-09 22:42:35 +02:00
|
|
|
{
|
|
|
|
int len, add;
|
2018-06-13 00:38:18 +02:00
|
|
|
va_list copy;
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
va_copy(copy, args);
|
2018-06-13 00:38:18 +02:00
|
|
|
add = vsnprintf(NULL, 0, fmt, copy);
|
|
|
|
va_end(copy);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
len = GB.StringLength(*buffer);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
*buffer = GB.ExtendString(*buffer, len + add);
|
2018-06-13 00:38:18 +02:00
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
vsprintf(*buffer + len, fmt, args);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
|
|
|
JIT_last_print_is_label = (strncmp(fmt, "__L", 3) == 0);
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
void JIT_print(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
2018-06-19 00:26:25 +02:00
|
|
|
JIT_vprint(&_buffer, fmt, args);
|
2018-06-09 22:42:35 +02:00
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
|
|
|
|
void JIT_print_decl(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
JIT_vprint(&_buffer_decl, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void JIT_print_body(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
va_start(args, fmt);
|
|
|
|
JIT_vprint(&_buffer_body, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
void JIT_section(const char *str)
|
|
|
|
{
|
|
|
|
JIT_print("\n// %s\n\n", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-19 00:26:25 +02:00
|
|
|
void JIT_declare(TYPE type, const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
2018-11-24 20:00:45 +01:00
|
|
|
const char *def;
|
|
|
|
|
|
|
|
def = JIT_get_default_value(type);
|
2018-06-19 00:26:25 +02:00
|
|
|
|
|
|
|
JIT_print_decl(" %s ", JIT_get_ctype(type));
|
|
|
|
|
|
|
|
va_start(args, fmt);
|
|
|
|
JIT_vprint(&_buffer_decl, fmt, args);
|
|
|
|
va_end(args);
|
|
|
|
|
|
|
|
switch (TYPEID(type))
|
|
|
|
{
|
|
|
|
case T_STRING:
|
|
|
|
case T_OBJECT:
|
|
|
|
case T_VARIANT:
|
2018-11-24 20:00:45 +01:00
|
|
|
JIT_print_decl(" = %s", def);
|
2018-06-19 00:26:25 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
JIT_print_decl(";\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
char *JIT_translate(const char *name, const char *from)
|
|
|
|
{
|
|
|
|
CLASS *class;
|
|
|
|
int i;
|
|
|
|
FUNCTION *func;
|
|
|
|
|
|
|
|
JIT_class = class = (CLASS *)GB.LoadClassFrom(name, from);
|
|
|
|
|
|
|
|
JIT_begin();
|
|
|
|
|
|
|
|
for (i = 0; i < class->load->n_func; i++)
|
|
|
|
{
|
|
|
|
func = &class->load->func[i];
|
|
|
|
if (!func->fast)
|
|
|
|
continue;
|
|
|
|
JIT_declare_func(func, i);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < class->load->n_func; i++)
|
|
|
|
{
|
|
|
|
func = &class->load->func[i];
|
|
|
|
if (!func->fast)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
JIT_last_print_is_label = FALSE;
|
|
|
|
if (JIT_translate_func(func, i))
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return JIT_end();
|
|
|
|
}
|
|
|
|
|
|
|
|
void JIT_panic(const char *fmt, ...)
|
|
|
|
{
|
|
|
|
va_list args;
|
|
|
|
fprintf(stderr, "gb.jit: panic: ");
|
|
|
|
va_start(args, fmt);
|
|
|
|
vfprintf(stderr, fmt, args);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
va_end(args);
|
|
|
|
fputc('\n', stderr);
|
|
|
|
fputs(_buffer, stderr);
|
2019-04-04 22:58:06 +02:00
|
|
|
if (_buffer_decl) fputs(_buffer_decl, stderr);
|
|
|
|
if (_buffer_body) fputs(_buffer_body, stderr);
|
2018-06-09 22:42:35 +02:00
|
|
|
fputc('\n', stderr);
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
|
|
|
|
int JIT_get_code_size(FUNCTION *func)
|
|
|
|
{
|
|
|
|
void *code = func->code;
|
|
|
|
int size = ((int *)code)[-1] / sizeof(ushort);
|
|
|
|
|
|
|
|
if (func->code[size - 1] == 0)
|
|
|
|
size--;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-08-18 15:28:19 +02:00
|
|
|
void JIT_load_class_without_init(CLASS *class)
|
2018-06-09 22:42:35 +02:00
|
|
|
{
|
|
|
|
void *save_cp;
|
|
|
|
|
2018-08-16 01:50:45 +02:00
|
|
|
if (class->loaded)
|
2018-08-14 16:46:55 +02:00
|
|
|
return;
|
|
|
|
|
2018-06-09 22:42:35 +02:00
|
|
|
if (class->ready || class->in_load)
|
|
|
|
return;
|
|
|
|
|
2018-07-02 19:37:37 +02:00
|
|
|
save_cp = JIT.exec->cp;
|
|
|
|
JIT.exec->cp = JIT_class;
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2018-06-11 18:52:39 +02:00
|
|
|
//fprintf(stderr, "gb.jit: load class: %s (%p)\n", class->name, class);
|
2018-08-16 01:50:45 +02:00
|
|
|
JIT.load_class_without_init(class);
|
2018-06-09 22:42:35 +02:00
|
|
|
|
2018-07-02 19:37:37 +02:00
|
|
|
JIT.exec->cp = save_cp;
|
2018-06-09 22:42:35 +02:00
|
|
|
}
|
2018-08-10 13:26:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
int JIT_find_symbol(CLASS *class, const char *name)
|
|
|
|
{
|
2018-08-18 15:28:19 +02:00
|
|
|
JIT_load_class_without_init(class);
|
2019-06-11 22:32:12 +02:00
|
|
|
if (class->loaded)
|
|
|
|
return JIT.find_symbol(class->table, class->sort, class->n_desc, sizeof(CLASS_DESC_SYMBOL), TF_IGNORE_CASE, name, strlen(name), NULL);
|
|
|
|
else
|
|
|
|
return NO_SYMBOL;
|
2018-08-10 13:26:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|