X-Git-Url: https://git.m6w6.name/?p=m6w6%2Fext-psi;a=blobdiff_plain;f=m4%2Fpsi_decl.m4;h=6a0ef809916b256dd99e8f7e8cfeedd93c7d2014;hp=c331bbecc658fa4aa8a6f3e7655323cc6e15962d;hb=03100f9c2f83b42bee97e4adcfba5d8821c4ac22;hpb=b1720af16e5d7765e2effcd16e23f351c2f82e54 diff --git a/m4/psi_decl.m4 b/m4/psi_decl.m4 index c331bbe..6a0ef80 100644 --- a/m4/psi_decl.m4 +++ b/m4/psi_decl.m4 @@ -1,45 +1,60 @@ -AC_DEFUN(PSI_REDIR, [psi_symbol=ifelse([$2],[],[$1],[$2]) - cat >>$PSI_REDIRS <<<" {\"$1\", (void(*)(void))$psi_symbol}, "]) +# psi_add_redir(name, symbol) +# Add a function redirection to $PSI_REDIRS. +psi_add_redir() { + cat >>$PSI_REDIRS <>$PSI_VA_DECLS <>$PSI_DECLS <@@:>@+U / {print$[]3; exit}'` + psi_libc_main=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'` ]) psi_cv_libc_main=$psi_libc_main ]) ]) -dnl PSI_FUNC(fn, action-if-yes, action-if-no) -AC_DEFUN(PSI_FUNC, [ - AC_REQUIRE([PSI_FUNC_LIBC_MAIN]) - psi_symbol=$1 - AC_CACHE_CHECK(for $1, psi_cv_fn_$1, [ - psi_symbol_redirect= - AC_TRY_LINK(PSI_INCLUDES, [ - void (*fn)(void) = (void (*)(void)) $psi_symbol; - ], [ - psi_symbol_redirect=`$NM -g conftest$ac_exeext | $AWK -F" *|@" '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'` - ]) - psi_cv_fn_$1=$psi_symbol_redirect - ]) - case "$psi_cv_fn_$1" in - "") - $3 - ;; - "$psi_symbol"|"_$psi_symbol") - $2 - ;; - *) - $2 - PSI_REDIR($1) - ;; - esac +dnl PSI_DECL_ARGS(decl args) +dnl INTERNAL: build psi_decl_args +AC_DEFUN(PSI_DECL_ARGS, [ + psi_decl_args= + PSI_DECL_ARG($1) + m4_case([$2], + [(void)], [], + [()], [], + [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))]) ]) +dnl PSI_DECL_ARG(decl arg) +dnl INTERNAL: build psi_decl_args AC_DEFUN(PSI_DECL_ARG, [ m4_define([member_name], PSI_VAR_NAME($1)) m4_define([member_type], PSI_VAR_TYPE($1)) @@ -52,23 +67,38 @@ AC_DEFUN(PSI_DECL_ARG, [ ]) dnl PSI_DECL(type func, args, flags) +dnl Check for a function or macro declaration and a possible asm redirection. +dnl Adds a pre-defined (vararg) decl to $PSI_VA_DECLS/$PSI_DECLS. +dnl Calls PSI_MACRO if PSI_FUNC fails. AC_DEFUN(PSI_DECL, [ - psi_decl_args= - PSI_DECL_ARG($1) - m4_case([$2], - [(void)], [], - [()], [], - [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))]) - PSI_FUNC(PSI_VAR_NAME($1), [ - ifelse([$3], vararg, [ - cat >>$PSI_VA_DECLS <<<" $psi_decl_args, {0}, " + AC_REQUIRE([PSI_FUNC_LIBC_MAIN]) + PSI_DECL_ARGS($1, $2) + + psi_symbol="PSI_VAR_NAME($1)" + AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [ + psi_symbol_redirect= + AC_TRY_LINK(PSI_INCLUDES, [ + void (*fn)(void) = (void (*)(void)) $psi_symbol; (*fn)() ], [ - cat >>$PSI_DECLS <<<" $psi_decl_args, {0}, " - ]) - ], [ - PSI_MACRO($1, $2, [ - ifelse([$3], vararg, AC_MSG_ERROR(varargs macro support is not implemented),[]) - cat >>$PSI_DECLS <<<" $psi_decl_args, {0}, " + psi_symbol_redirect=`nm -g conftest$ac_exeext | $AWK -F ' *|@' '/^@<:@@<:@:space:@:>@@:>@+U '$psi_cv_libc_main'/ {next} /^@<:@@<:@:space:@:>@@:>@+U / {print$[]3; exit}'` ]) + [psi_cv_fn_]PSI_VAR_NAME($1)=$psi_symbol_redirect ]) + case "$[psi_cv_fn_]PSI_VAR_NAME($1)" in + "$psi_symbol"|"_$psi_symbol") + psi_add_decl "$psi_decl_args" $3 + ;; + "") + ifelse([$3], vararg, [ + AC_MSG_ERROR(varargs macro support is not implemented) + ],[ + PSI_MACRO($1, $2, [ + psi_add_decl "$psi_decl_args" + ]) + ]) + ;; + "*") + PSI_REDIR($psi_symbol, $psi_symbol_redirect) + ;; + esac ])