From 43f9e142088705cc003bb021a32ecd4d4d3b3d2b Mon Sep 17 00:00:00 2001 From: Michael Wallner Date: Fri, 1 Jan 2016 19:02:21 +0100 Subject: [PATCH] prepare varargs calls --- src/context.c | 4 ++-- src/context.h | 4 ++-- src/libffi.c | 8 +++++--- src/libjit.c | 10 ++++++---- src/module.c | 5 ++--- src/parser.h | 14 +++++++++----- 6 files changed, 26 insertions(+), 19 deletions(-) diff --git a/src/context.c b/src/context.c index ba9fabb..ba58720 100644 --- a/src/context.c +++ b/src/context.c @@ -1214,9 +1214,9 @@ zend_function_entry *PSI_ContextCompile(PSI_Context *C) } -void PSI_ContextCall(PSI_Context *C, impl_val *ret_val, decl *decl) +void PSI_ContextCall(PSI_Context *C, decl_callinfo *decl_call) { - C->ops->call(C, ret_val, decl); + C->ops->call(C, decl_call); } static inline void dump_decl_type(int fd, decl_type *t) { diff --git a/src/context.h b/src/context.h index e68eddf..6611a4a 100644 --- a/src/context.h +++ b/src/context.h @@ -14,7 +14,7 @@ struct PSI_ContextOps { void (*init)(PSI_Context *C); void (*dtor)(PSI_Context *C); zend_function_entry *(*compile)(PSI_Context *C); - void (*call)(PSI_Context *C, impl_val *ret_val, decl *decl); + void (*call)(PSI_Context *C, decl *decl); }; struct PSI_Context { @@ -30,7 +30,7 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr void PSI_ContextBuild(PSI_Context *C, const char *path); int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P); zend_function_entry *PSI_ContextCompile(PSI_Context *C); -void PSI_ContextCall(PSI_Context *C, impl_val *ret_val, decl *decl); +void PSI_ContextCall(PSI_Context *C, decl_callinfo *decl_call); void PSI_ContextDump(PSI_Context *C, int fd); void PSI_ContextDtor(PSI_Context *C); void PSI_ContextFree(PSI_Context **C); diff --git a/src/libffi.c b/src/libffi.c index ee077af..257fb48 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -127,6 +127,8 @@ static inline PSI_LibffiCall *PSI_LibffiCallAlloc(PSI_Context *C, decl *decl) { call->params[c] = NULL; decl->call.info = call; + decl->call.rval = decl->func->ptr; + decl->call.argc = c; decl->call.args = (void **) &call->params[c+1]; rc = ffi_prep_cif(&call->signature, psi_ffi_abi(decl->abi->convention), @@ -250,10 +252,10 @@ static zend_function_entry *psi_ffi_compile(PSI_Context *C) return zfe; } -static void psi_ffi_call(PSI_Context *C, impl_val *ret_val, decl *decl) { - PSI_LibffiCall *call = decl->call.info; +static void psi_ffi_call(PSI_Context *C, decl_callinfo *decl_call) { + PSI_LibffiCall *call = decl_call->info; - ffi_call(&call->signature, FFI_FN(decl->call.sym), ret_val, decl->call.args); + ffi_call(&call->signature, FFI_FN(decl_call->sym), decl_call->rval, decl_call->args); } static PSI_ContextOps ops = { diff --git a/src/libjit.c b/src/libjit.c index 45ee8e7..13c0aa4 100644 --- a/src/libjit.c +++ b/src/libjit.c @@ -87,6 +87,8 @@ static inline PSI_LibjitCall *PSI_LibjitCallAlloc(PSI_Context *C, decl *decl) { call->params[c] = NULL; decl->call.info = call; + decl->call.rval = decl->func->ptr; + decl->call.argc = c; decl->call.args = (void **) &call->params[c+1]; call->signature = jit_type_create_signature( @@ -208,11 +210,11 @@ static zend_function_entry *psi_jit_compile(PSI_Context *C) return zfe; } -static void psi_jit_call(PSI_Context *C, impl_val *ret_val, decl *decl) { - PSI_LibjitCall *call = decl->call.info; +static void psi_jit_call(PSI_Context *C, decl_callinfo *decl_call) { + PSI_LibjitCall *call = decl_call->info; - jit_apply(call->signature, decl->call.sym, decl->call.args, - decl->args->count, ret_val); + jit_apply(call->signature, decl_call->sym, decl_call->args, + decl_call->argc, decl_call->rval); } static PSI_ContextOps ops = { diff --git a/src/module.c b/src/module.c index c820f4f..ba3e4d5 100644 --- a/src/module.c +++ b/src/module.c @@ -703,7 +703,6 @@ static inline void psi_do_return(zval *return_value, return_stmt *ret) static inline void psi_do_free(free_stmt *fre) { size_t i, j; - impl_val dummy; for (i = 0; i < fre->calls->count; ++i) { free_call *f = fre->calls->list[i]; @@ -716,7 +715,7 @@ static inline void psi_do_free(free_stmt *fre) } /* FIXME: check in validate_* that free functions return scalar */ - PSI_ContextCall(&PSI_G(context), &dummy, f->decl); + PSI_ContextCall(&PSI_G(context), &f->decl->call); } } @@ -1007,7 +1006,7 @@ void psi_call(zend_execute_data *execute_data, zval *return_value, impl *impl) impl->decl->call.args[i] = impl->decl->args->args[i]->let->ptr; } - PSI_ContextCall(&PSI_G(context), var->arg->ptr, impl->decl); + PSI_ContextCall(&PSI_G(context), &impl->decl->call); psi_do_return(return_value, ret); for (i = 0; i < impl->stmts->set.count; ++i) { diff --git a/src/parser.h b/src/parser.h index 55f4f9d..7faa43b 100644 --- a/src/parser.h +++ b/src/parser.h @@ -262,16 +262,20 @@ static inline void free_decl_abi(decl_abi *abi) { free(abi); } +typedef struct decl_callinfo { + void *sym; + void *info; + size_t argc; + void **args; + void *rval; +} decl_callinfo; + typedef struct decl { decl_abi *abi; decl_arg *func; decl_args *args; struct impl *impl; - struct { - void *sym; - void *info; - void **args; - } call; + decl_callinfo call; } decl; static inline decl* init_decl(decl_abi *abi, decl_arg *func, decl_args *args) { -- 2.30.2