浏览代码

started jit wrapper func

Nicolas Cannasse 9 年之前
父节点
当前提交
288fbd47a8
共有 7 个文件被更改,包括 25 次插入4 次删除
  1. 1 0
      src/hl.h
  2. 0 1
      src/hlc.h
  3. 1 1
      src/hlc_main.c
  4. 1 0
      src/hlmodule.h
  5. 12 0
      src/jit.c
  6. 9 1
      src/module.c
  7. 1 1
      src/std/fun.c

+ 1 - 0
src/hl.h

@@ -581,6 +581,7 @@ typedef struct {
 HL_API void *hl_fatal_error( const char *msg, const char *file, int line );
 HL_API void hl_fatal_fmt( const char *file, int line, const char *fmt, ...);
 HL_API void hl_sys_init(void **args, int nargs);
+HL_API void hl_setup_callbacks(void *sc, void *gw);
 
 #include <setjmp.h>
 typedef struct _hl_trap_ctx hl_trap_ctx;

+ 0 - 1
src/hlc.h

@@ -119,7 +119,6 @@ static vdynamic *hlc_dyn_call_obj( vdynamic *o, int hfield, vdynamic **args, int
 
 extern void *hlc_static_call(void *fun, hl_type *t, void **args, vdynamic *out);
 extern void *hlc_get_wrapper(hl_type *t);
-HL_API void hlc_setup(void *sc, void *gw);
 extern void hl_entry_point();
 
 #endif

+ 1 - 1
src/hlc_main.c

@@ -37,7 +37,7 @@ int main(int argc, char *argv[]) {
 	hl_trap_ctx ctx;
 	vdynamic *exc;
 	hl_global_init(&ctx);
-	hlc_setup(hlc_static_call, hlc_get_wrapper);
+	hl_setup_callbacks(hlc_static_call, hlc_get_wrapper);
 	hl_sys_init(argv + 1,argc - 1);
 #	ifdef _DEBUG
 //	disable crt debug since it will prevent reusing our address space

+ 1 - 0
src/hlmodule.h

@@ -97,6 +97,7 @@ jit_ctx *hl_jit_alloc();
 void hl_jit_free( jit_ctx *ctx );
 void hl_jit_init( jit_ctx *ctx, hl_module *m );
 int hl_jit_init_callback( jit_ctx *ctx );
+int hl_jit_init_get_wrapper( jit_ctx *ctx );
 int hl_jit_function( jit_ctx *ctx, hl_module *m, hl_function *f );
 void *hl_jit_code( jit_ctx *ctx, hl_module *m, int *codesize );
 

+ 12 - 0
src/jit.c

@@ -1589,6 +1589,18 @@ int hl_jit_init_callback( jit_ctx *ctx ) {
 	return pos;
 }
 
+int hl_jit_init_get_wrapper( jit_ctx *ctx ) {
+	int pos = BUF_POS();
+	jit_buf(ctx);
+	
+	BREAK();
+	jit_buf(ctx);
+	while( BUF_POS() & 15 )
+		op32(ctx, NOP, UNUSED, UNUSED);
+
+	return pos;
+}
+
 static void *get_dyncast( hl_type *t ) {
 	switch( t->kind ) {
 	case HF32:

+ 9 - 1
src/module.c

@@ -123,8 +123,13 @@ static void append_type( char **p, hl_type *t ) {
 	}
 }
 
+static void *module_wrapper_func;
+static void *module_get_wrapper( hl_type * t ) {
+	return module_wrapper_func;
+}
+
 int hl_module_init( hl_module *m ) {
-	int i, entry;
+	int i, entry, wrapper;
 	jit_ctx *ctx;
 	// RESET globals
 	for(i=0;i<m->code->nglobals;i++) {
@@ -199,6 +204,7 @@ int hl_module_init( hl_module *m ) {
 		return 0;
 	hl_jit_init(ctx, m);
 	entry = hl_jit_init_callback(ctx);
+	wrapper = hl_jit_init_get_wrapper(ctx);
 	for(i=0;i<m->code->nfunctions;i++) {
 		hl_function *f = m->code->functions + i;
 		int fpos = hl_jit_function(ctx, m, f);
@@ -213,7 +219,9 @@ int hl_module_init( hl_module *m ) {
 		hl_function *f = m->code->functions + i;
 		m->functions_ptrs[f->findex] = ((unsigned char*)m->jit_code) + ((int_val)m->functions_ptrs[f->findex]);
 	}
+	module_wrapper_func = ((unsigned char*)m->jit_code) + wrapper;
 	hl_callback_init(((unsigned char*)m->jit_code) + entry);
+	hl_setup_callbacks(NULL, module_get_wrapper);
 	hl_jit_free(ctx);
 	return 1;
 }

+ 1 - 1
src/std/fun.c

@@ -99,7 +99,7 @@ typedef void *(*fptr_get_wrapper)(hl_type *t);
 static fptr_static_call hlc_static_call = NULL;
 static fptr_get_wrapper hlc_get_wrapper = NULL;
 
-HL_PRIM void hlc_setup( void *c, void *w ) {
+HL_PRIM void hl_setup_callbacks( void *c, void *w ) {
 	hlc_static_call = (fptr_static_call)c;
 	hlc_get_wrapper = (fptr_get_wrapper)w;
 }