From a748a5d3822aad83a7caeab63208a3c9c24e7327 Mon Sep 17 00:00:00 2001 From: Klaus Treichel Date: Sun, 17 Dec 2006 21:06:26 +0000 Subject: [PATCH] 2006-12-17 Klaus Treichel * include/jit/jit-function.h, jit/jit-function.c: Add the function jit_function_from_vtable_pointer to convert a vtable pointer back to the jit_function_t. --- ChangeLog | 6 ++++++ include/jit/jit-function.h | 2 ++ jit/jit-function.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/ChangeLog b/ChangeLog index c6b1335..f446534 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-12-17 Klaus Treichel + + * include/jit/jit-function.h, jit/jit-function.c: Add the function + jit_function_from_vtable_pointer to convert a vtable pointer back to the + jit_function_t. + 2006-11-29 Aleksey Demakov * jit/jit-reg-alloc.c (save_value): fix bug freeing stack register diff --git a/include/jit/jit-function.h b/include/jit/jit-function.h index cd5e5d6..7e5e7a9 100644 --- a/include/jit/jit-function.h +++ b/include/jit/jit-function.h @@ -59,6 +59,8 @@ jit_function_t jit_function_from_closure jit_function_t jit_function_from_pc (jit_context_t context, void *pc, void **handler) JIT_NOTHROW; void *jit_function_to_vtable_pointer(jit_function_t func) JIT_NOTHROW; +jit_function_t jit_function_from_vtable_pointer + (jit_context_t context, void *vtable_pointer) JIT_NOTHROW; void jit_function_set_on_demand_compiler (jit_function_t func, jit_on_demand_func on_demand) JIT_NOTHROW; int jit_function_apply diff --git a/jit/jit-function.c b/jit/jit-function.c index 4f618fd..d922294 100644 --- a/jit/jit-function.c +++ b/jit/jit-function.c @@ -1138,6 +1138,34 @@ void *jit_function_to_vtable_pointer(jit_function_t func) #endif } +/*@ + * @deftypefun jit_function_t jit_function_from_vtable_pointer (jit_context_t context, {void *} vtable_pointer) + * Convert a vtable_pointer back into a function. Returns NULL if the + * vtable_pointer does not correspond to a function in the specified context. + * @end deftypefun +@*/ +jit_function_t jit_function_from_vtable_pointer(jit_context_t context, void *vtable_pointer) +{ +#ifdef JIT_BACKEND_INTERP + /* In the interpreted version, the function pointer is used in vtables */ + jit_function_t func = (jit_function_t)vtable_pinter; + + if(func && func->context == context) + { + return func; + } + return 0; +#else + void *cookie; + if(!context || !(context->cache)) + { + return 0; + } + return (jit_function_t)_jit_cache_get_method + (context->cache, vtable_pointer, &cookie); +#endif +} + /*@ * @deftypefun void jit_function_set_on_demand_compiler (jit_function_t func, jit_on_demand_func on_demand) * Specify the C function to be called when @code{func} needs to be -- 2.47.3