$(PHP_PSI_SRCDIR)/src/parser.c: $(PHP_PSI_SRCDIR)/src/parser.re
$(RE2C) -o $@ $<
-$(PHP_PSI_SRCDIR)/src/types/decl.c: $(PHP_PSI_SRCDIR)/php_psi_macros.h $(PHP_PSI_SRCDIR)/php_psi_redirs.h
-$(PHP_PSI_SRCDIR)/src/context.c: $(PHP_PSI_SRCDIR)/php_psi_consts.h $(PHP_PSI_SRCDIR)/php_psi_decls.h $(PHP_PSI_SRCDIR)/php_psi_fn_decls.h $(PHP_PSI_SRCDIR)/php_psi_structs.h $(PHP_PSI_SRCDIR)/php_psi_types.h $(PHP_PSI_SRCDIR)/php_psi_unions.h $(PHP_PSI_SRCDIR)/php_psi_va_decls.h
-
# -- deps
-PHP_PSI_DEPEND = $(PHP_PSI_BUILDDIR)/php_psi.dep $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep))
+PHP_PSI_DEPEND = $(patsubst $(PHP_PSI_SRCDIR)/%,$(PHP_PSI_BUILDDIR)/%,$(PHP_PSI_SOURCES:.c=.dep))
.PHONY: psi-clean-depend
psi-clean-depend:
$(CPPFLAGS) $(DEFS) $(INCLUDES) $< \
|| touch $@
+php_psi_stdinc.h:
+
ifneq ($(findstring clean,$(MAKECMDGOALS)),clean)
ifneq ($(PSI_DEPS),)
-include $(PHP_PSI_DEPEND)
[psi/psi_const.m4],
[psi/psi_decl.m4],
[psi/psi_macro.m4],
- [psi/psi_struct.m4],
+ [psi/psi_composite.m4],
[posix/errno.m4],
[posix/fcntl.m4],
[posix/glob.m4],
AC_DEFINE_UNQUOTED(PHP_PSI_SHLIB_SUFFIX, ["$SHLIB_SUFFIX_NAME"], DL suffix)
- AC_DEFINE_UNQUOTED([PSI_STDINC], ["$PSI_STDINC"], [Standard includes])
- AC_DEFINE_UNQUOTED([PSI_TYPES], ["$PSI_TYPES"], [Predefined types])
- AC_DEFINE_UNQUOTED([PSI_STRUCTS], ["$PSI_STRUCTS"], [Predefined structs])
- AC_DEFINE_UNQUOTED([PSI_UNIONS], ["$PSI_UNIONS"], [Predefined structs])
- AC_DEFINE_UNQUOTED([PSI_CONSTS], ["$PSI_CONSTS"], [Predefined constants])
- AC_DEFINE_UNQUOTED([PSI_MACROS], ["$PSI_MACROS"], [Redirected Macros])
- AC_DEFINE_UNQUOTED([PSI_REDIRS], ["$PSI_REDIRS"], [Redirected functions])
- AC_DEFINE_UNQUOTED([PSI_DECLS], ["$PSI_DECLS"], [Predefined functions])
- AC_DEFINE_UNQUOTED([PSI_VA_DECLS], ["$PSI_VA_DECLS"], [Predefined vararg functions])
-
PHP_ADD_INCLUDE($PHP_PSI_SRCDIR)
PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src)
PHP_ADD_INCLUDE($PHP_PSI_SRCDIR/src/types)
+ PHP_ADD_INCLUDE($PHP_PSI_BUILDDIR)
PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src)
PHP_ADD_BUILD_DIR($PHP_PSI_BUILDDIR/src/types)
-dnl Generated headers with pre-defined types, structs, consts and decls.
-PSI_STDINC=$PHP_PSI_SRCDIR/php_psi_stdinc.h
-PSI_STDTYPES=$PHP_PSI_SRCDIR/php_psi_stdtypes.h
-PSI_TYPES=$PHP_PSI_SRCDIR/php_psi_types.h
-PSI_STRUCTS=$PHP_PSI_SRCDIR/php_psi_structs.h
-PSI_UNIONS=$PHP_PSI_SRCDIR/php_psi_unions.h
-PSI_CONSTS=$PHP_PSI_SRCDIR/php_psi_consts.h
-PSI_REDIRS=$PHP_PSI_SRCDIR/php_psi_redirs.h
-PSI_MACROS=$PHP_PSI_SRCDIR/php_psi_macros.h
-PSI_DECLS=$PHP_PSI_SRCDIR/php_psi_decls.h
-PSI_VA_DECLS=$PHP_PSI_SRCDIR/php_psi_va_decls.h
-PSI_FN_DECLS=$PHP_PSI_SRCDIR/php_psi_fn_decls.h
dnl PSI_CONFIG_INIT()
dnl Creates stubs of the headers with pre-defined types etc.
fi
fi
- cat >$PHP_PSI_BUILDDIR/php_psi.dep <<EOF
-\$(PHP_PSI_SRCDIR)/php_psi.h:
-php_psi.h:
-\$(PHP_PSI_SRCDIR)/php_psi_stdinc.h:
-php_psi_stdinc.h:
-EOF
- for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_MACROS $PSI_DECLS $PSI_VA_DECLS $PSI_FN_DECLS; do
- cat >>$PHP_PSI_BUILDDIR/php_psi.dep <<EOF
-$i:
-$(basename $i):
-EOF
- cat >$i <<EOF
-/* generated by configure */
-#include "php_psi_stdinc.h"
-EOF
- done
- cat >>$PSI_STDTYPES <<EOF
-static struct psi_std_type {
- token_t type_tag;
- const char *type_name;
- const char *alias;
-} psi_std_types@<:@@:>@ = {
- {PSI_T_INT8, "int8_t", NULL},
- {PSI_T_INT16, "int16_t", NULL},
- {PSI_T_INT32, "int32_t", NULL},
- {PSI_T_INT64, "int64_t", NULL},
- {PSI_T_UINT8, "uint8_t", NULL},
- {PSI_T_UINT16, "uint16_t", NULL},
- {PSI_T_UINT32, "uint32_t", NULL},
- {PSI_T_UINT64, "uint64_t", NULL},
-EOF
- cat >>$PSI_TYPES <<EOF
-static struct psi_predef_type {
- token_t type_tag;
- const char *type_name;
- const char *alias;
-} psi_predef_types@<:@@:>@ = {
-EOF
- cat >>$PSI_STRUCTS <<EOF
-static struct psi_predef_struct {
- token_t type_tag;
- const char *type_name;
- const char *var_name;
- size_t offset;
- size_t size;
- size_t pointer_level;
- size_t array_size;
-} psi_predef_structs@<:@@:>@ = {
-EOF
- cat >>$PSI_UNIONS <<EOF
-static struct psi_predef_union {
- token_t type_tag;
- const char *type_name;
- const char *var_name;
- size_t offset;
- size_t size;
- size_t pointer_level;
- size_t array_size;
-} psi_predef_unions@<:@@:>@ = {
-EOF
- cat >>$PSI_CONSTS <<EOF
-static struct psi_predef_const {
- token_t type_tag;
- const char *type_name;
- const char *var_name;
- const char *val_text;
- token_t val_type_tag;
-} psi_predef_consts@<:@@:>@ = {
-EOF
- cat >>$PSI_REDIRS <<EOF
-typedef void (*psi_func_ptr)();
-static struct psi_func_redir {
- const char *name;
- psi_func_ptr func;
-} psi_func_redirs@<:@@:>@ = {
-EOF
- cat >>$PSI_MACROS <<EOF
-EOF
- cat >>$PSI_DECLS <<EOF
-static struct psi_predef_decl {
- token_t type_tag;
- const char *type_name;
- const char *var_name;
- size_t pointer_level;
- size_t array_size;
-} psi_predef_decls@<:@@:>@ = {
-EOF
- cat >>$PSI_VA_DECLS <<EOF
-static struct psi_predef_decl psi_predef_vararg_decls@<:@@:>@ = {
-EOF
- cat >>$PSI_FN_DECLS <<EOF
-static struct psi_predef_decl psi_predef_functor_decls@<:@@:>@ = {
-EOF
+ PSI_STDTYPES=
+ PSI_TYPES=
+ PSI_COMPOSITES=
+ PSI_CONSTS=
+ PSI_REDIRS=
+ PSI_MACROS=
+ PSI_DECLS=
+
+ AC_CONFIG_FILES(
+ [$PHP_PSI_BUILDDIR/php_psi_stdinc.h:$PHP_PSI_SRCDIR/php_psi_stdinc.h.in]
+ [$PHP_PSI_BUILDDIR/php_psi_posix.h:$PHP_PSI_SRCDIR/php_psi_posix.h.in]
+ )
+
])
dnl PSI_CONFIG_DONE()
dnl Finish the headers with the pre-defined types etc.
AC_DEFUN(PSI_CONFIG_DONE, [
-
- wait
-
if $PSI_FAST_CONFIG; then
+ wait
for conf_env in $PSI_CONFIG_TMP/*/conf.env; do
source $conf_env
done
LIBS=$psi_save_LIBS
PHP_EVAL_LIBLINE($psi_eval_LIBS, PSI_SHARED_LIBADD)
- cat >$PSI_STDINC <<EOF
-/* generated by configure */
-#ifndef PSI_STDINC_H
-#define PSI_STDINC_H
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#else
-# include "php_config.h"
-#endif
-
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE
-#endif
-#ifndef _REENTRANT
-# define _REENTRANT
-#endif
-
-PSI_INCLUDES
-#endif
-EOF
- for i in $PSI_STDTYPES $PSI_TYPES $PSI_STRUCTS $PSI_UNIONS $PSI_CONSTS $PSI_REDIRS $PSI_DECLS $PSI_VA_DECLS $PSI_FN_DECLS; do
- cat >>$i <<EOF
- {0}
-};
-EOF
- done
+ [PSI_INCLUDES]="PSI_INCLUDES"
+ AC_SUBST([PSI_INCLUDES])
+ AC_SUBST([PSI_STDTYPES])
+ AC_SUBST([PSI_TYPES])
+ AC_SUBST([PSI_COMPOSITES])
+ AC_SUBST([PSI_CONSTS])
+ AC_SUBST([PSI_REDIRS])
+ AC_SUBST([PSI_MACROS])
+ AC_SUBST([PSI_DECLS])
])
dnl PSI_SH_CONFIG_POSIX_ENABLED(section)
cd $PSI_CONFIG_TMP/AS_TR_SH([$1])
dnl run checks
+ PSI_TYPES=
+ PSI_CONSTS=
+ PSI_COMPOSITES=
+ PSI_REDIRS=
+ PSI_MACROS=
+ PSI_DECLS=
AS_TR_CPP([PSI_CHECK_$1])
- dnl save libs
+ dnl save env
cat >$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
LIBS="$LIBS \$LIBS"
EOF
+ for env in TYPES CONSTS COMPOSITES MACROS REDIRS DECLS; do
+ eval var=\$PSI_$env
+ if test -n "$var"; then
+ cat >>$PSI_CONFIG_TMP/AS_TR_SH([$1])/conf.env <<EOF
+PSI_$env='$var'"
+\$PSI_$env"
+EOF
+ fi
+ done
+
dnl done
printf "%s " "$1" >&66
) &
dnl PSI_CHECK_SIZEOF(type, special-includes)
dnl AC_CHECK_SIZEOF wrapper with PSI_INCLUDES
-dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS.
+dnl Defines psi\\SIZEOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
AC_DEFUN(PSI_CHECK_SIZEOF, [
AC_CHECK_SIZEOF($1, [], PSI_INCLUDES
$2)
dnl PSI_CHECK_ALIGNOF(type, special-includes)
dnl AC_CHECK_ALIGNOF wrapper with PSI_INCLUDES
-dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS.
+dnl Defines psi\\ALIGNOF_<TYPE> pre-defined constant in $PSI_CONSTS_H.
AC_DEFUN(PSI_CHECK_ALIGNOF, [
AC_CHECK_ALIGNOF($1, PSI_INCLUDES
$2)
--- /dev/null
+# psi_add_composite(composite members)
+# Add a pre-defined composite (struct or union)
+psi_add_composite() {
+ PSI_COMPOSITES="$PSI_COMPOSITES
+ $1, {0},"
+}
+
+dnl PSI_COMPOSITE_MEMBER(composite name, decl member)
+dnl INTERNAL: build $psi_composite_members
+AC_DEFUN(PSI_COMPOSITE_MEMBER, [
+ m4_define([member_name], PSI_VAR_NAME($2))
+ m4_define([member_type], PSI_VAR_TYPE($2))
+ PSI_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name,
+ [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_name
+ )
+ if PSI_SH_TEST_SIZEOF($1 member_name); then
+ PSI_CHECK_OFFSETOF($1, member_name)
+ PSI_TYPE_INDIRECTION($2, [PSI_SH_SIZEOF([$1 member_name])], pl, as)
+
+ psi_member_sizeof=PSI_SH_SIZEOF($1 member_name)
+ psi_member_offsetof=PSI_SH_OFFSETOF($1 member_name)
+
+ if test $pl -gt 0 && test $as -eq 0; then
+ check_size=PSI_SH_SIZEOF(void *)
+ elif test $pl -eq 1 && test $as -gt 0; then
+ check_size=`expr PSI_SH_SIZEOF(member_type) \* $as`
+ else
+ check_size=PSI_SH_SIZEOF(member_type)
+ fi
+ if test $psi_member_sizeof != "$check_size"; then
+ psi_member_basic_type=PSI_SH_BASIC_TYPE(member_type)
+ psi_member_type_pair="`psi_type_pair $psi_member_basic_type $psi_member_sizeof`"
+ psi_composite_members="$psi_composite_members, {$psi_member_type_pair, \"[]member_name[]\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}"
+ AC_MSG_WARN(pre-defined size $check_size of $2 in $1 does not match computed size $psi_member_sizeof; adjusting to $psi_member_type_pair)
+ else
+ psi_composite_members="[$psi_composite_members, {]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}]"
+ fi
+ fi
+])
+
+dnl PSI_STRUCT(struct name, struct members)
+dnl Check a struct and its members and add a pre-defined struct and possibly a
+dnl pre-defined type for this struct.
+dnl Calls PSI_CHECK_SIZEOF and PSI_CHECK_ALIGNOF for the struct.
+dnl Calls PSI_CHECK_SIZEOF, PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member.
+AC_DEFUN(PSI_STRUCT, [
+ PSI_CHECK_SIZEOF($1)
+ if PSI_SH_TEST_SIZEOF($1); then
+ PSI_CHECK_ALIGNOF($1)
+ psi_composite_name=m4_bregexp([$1], [^\(struct \)?\(\w+\)], [\2])
+ psi_composite_members="{PSI_T_STRUCT, \"struct\", \"$psi_composite_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}"
+ ifelse([$2],,,[m4_map_args_sep([PSI_COMPOSITE_MEMBER($1, m4_normalize(], [))], [], $2)])
+ psi_add_composite "$psi_composite_members"
+ if test "$1" = "$psi_composite_name"; then
+ psi_add_type "{PSI_T_STRUCT, \"$1\", \"$1\"}"
+ fi
+ fi
+])
+
+dnl PSI_UNION(union name, union/struct members)
+dnl Check a union and its members and add a pre-defined union and possibly a
+dnl pre-defined type for this union.
+dnl Calls PSI_CHECK_SIZEOF for the union and each member.
+dnl Calls PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member.
+AC_DEFUN(PSI_UNION, [
+ PSI_CHECK_SIZEOF($1)
+ if PSI_SH_TEST_SIZEOF($1); then
+ PSI_CHECK_ALIGNOF($1)
+ psi_composite_name=m4_bregexp([$1], [^\(union \)?\(\w+\)], [\2])
+ psi_composite_members="{PSI_T_UNION, \"union\", \"$psi_composite_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}"
+ ifelse([$2],,,[m4_map_args_sep([PSI_COMPOSITE_MEMBER($1, m4_normalize(], [))], [], $2)])
+ psi_add_composite "$psi_composite_members"
+ if test "$1" = "$psi_composite_name"; then
+ psi_add_type "{PSI_T_UNION, \"$1\", \"$1\"}"
+ fi
+ fi
+])
# psi_add_str_const(name, value)
-# Add a pre-defined string constant to $PSI_CONSTS
+# Add a pre-defined string constant to $PSI_CONSTS_H
psi_add_str_const() {
- grep -Fq "\"psi\\\\$1\"" $PSI_CONSTS \
- || cat >>$PSI_CONSTS <<EOF
- {PSI_T_STRING, "string", "psi\\\\$1", $2, PSI_T_QUOTED_STRING},
-EOF
+ PSI_CONSTS="$PSI_CONSTS
+ {PSI_T_STRING, \"string\", \"psi\\\\$1\", $2, PSI_T_QUOTED_STRING},"
}
# psi_add_int_const(name, value)
-# Add a pre-defined int constant to $PSI_CONSTS
+# Add a pre-defined int constant to $PSI_CONSTS_H
psi_add_int_const() {
- grep -Fq "\"psi\\\\$1\"" $PSI_CONSTS \
- || cat >>$PSI_CONSTS <<EOF
- {PSI_T_INT, "int", "psi\\\\$1", "$2", PSI_T_NUMBER},
-EOF
+ PSI_CONSTS="$PSI_CONSTS
+ {PSI_T_INT, \"int\", \"psi\\\\$1\", \"$2\", PSI_T_NUMBER},
+"
}
dnl PSI_CONST(const name, type)
# psi_add_redir(name, symbol)
-# Add a function redirection to $PSI_REDIRS.
+# Add a function redirection to $PSI_REDIRS_H.
psi_add_redir() {
- cat >>$PSI_REDIRS <<EOF
- {"$1", (psi_func_ptr) $2},
-EOF
+ PSI_REDIRS="$PSI_REDIRS
+ {\"$1\", (psi_func_ptr) $2},"
}
# psi_add_decl(decl, options)
-# Add a pre-defined decl to $PSI_VA_DECLS/$PSI_DECLS.
+# Add a pre-defined decl to $PSI_VA_DECLS_H/$PSI_DECLS_H.
psi_add_decl() {
- case "$2" in
- *functor*)
- cat >>$PSI_FN_DECLS <<EOF
- $1, {0},
-EOF
- ;;
- *vararg*)
- cat >>$PSI_VA_DECLS <<EOF
- $1, {0},
-EOF
- ;;
- *)
- cat >>$PSI_DECLS <<EOF
- $1, {0},
-EOF
- ;;
- esac
+ PSI_DECLS="$PSI_DECLS
+ $1, {0},"
}
dnl PSI_DECL_TYPE(type functor_name, args)
-dnl Adds a pre-defined functor decl to $PSI_FN_DECLS.
+dnl Adds a pre-defined functor decl to $PSI_FN_DECLS_H.
AC_DEFUN(PSI_DECL_TYPE, [
- PSI_DECL_ARGS($1, $2)
- psi_add_decl "$psi_decl_args" functor
+ PSI_DECL_ARGS($1, $2, functor)
+ psi_add_decl "$psi_decl_args"
])
dnl PSI_REDIR(name, custom symbol)
dnl Create a function redirection to an optional custom symbol.
])
])
-dnl PSI_DECL_ARGS(decl args)
+dnl PSI_DECL_ARGS(decl func, decl args, options)
dnl INTERNAL: build psi_decl_args
AC_DEFUN(PSI_DECL_ARGS, [
psi_decl_args=
- PSI_DECL_ARG($1)
+ PSI_DECL_ARG([$1], [$3])
m4_case([$2],
[(void)], [],
[()], [],
[], [],
- [m4_map_args_sep([PSI_DECL_ARG(m4_normalize(], [))], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
+ [m4_map_args_sep(
+ [PSI_DECL_ARG(m4_normalize(],
+ [), [0])], [], m4_bregexp([$2], [(\(.*\))], [\1]))])
])
-dnl PSI_DECL_ARG(decl arg)
+dnl PSI_DECL_ARG(decl arg, options)
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))
+ m4_define([member_name], PSI_VAR_NAME([$1]))
+ m4_define([member_type], PSI_VAR_TYPE([$1]))
PSI_TYPE_INDIRECTION([$1],, pl, as)
if test -n "$psi_decl_args"; then
psi_decl_args="$psi_decl_args, "
fi
- psi_decl_args="[$psi_decl_args{]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
+ psi_decl_args="[$psi_decl_args{]ifelse([$2],,DECL_KIND_STD,[ifelse([$2],0,0,AS_TR_CPP([DECL_KIND_$2]))])[, ]PSI_TYPE_PAIR(member_type)[, \"]member_name[\",] $pl, $as[}]"
])
dnl PSI_DECL(type func, args, flags, libs)
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 Adds a pre-defined (vararg) decl to $PSI_VA_DECLS_H/$PSI_DECLS_H.
dnl Calls PSI_MACRO if PSI_FUNC fails.
AC_DEFUN(PSI_DECL, [
AC_REQUIRE([PSI_FUNC_LIBC_MAIN])dnl
- PSI_DECL_ARGS($1, $2)
+ PSI_DECL_ARGS($1, $2, $3)
psi_symbol="PSI_VAR_NAME($1)"
AC_CACHE_CHECK(for PSI_VAR_NAME($1), [psi_cv_fn_]PSI_VAR_NAME($1), [
then
PSI_REDIR($psi_symbol)
fi
- psi_add_decl "$psi_decl_args" $3
+ psi_add_decl "$psi_decl_args"
;;
esac
;;
;;
*)
PSI_REDIR($psi_symbol)
- psi_add_decl "$psi_decl_args" $3
+ psi_add_decl "$psi_decl_args"
;;
esac
])
# psi_add_macro(macro)
-# Add a pre-defined macro function to $PSI_MACROS.
+# Add a pre-defined macro function to $PSI_MACROS_H.
psi_add_macro() {
- cat >>$PSI_MACROS <<EOF
-$1
-EOF
+ PSI_MACROS="$PSI_MACROS
+$1"
}
dnl PSI_MACRO(macro, decl args, action-if-true)
psi_add_decl "$psi_decl_args"
dnl explicit getter
PSI_REDIR([${macro_name}_get], [_psi_get_$macro_name])
- PSI_DECL_ARGS([PSI_VAR_TYPE_RETURN($1) PSI_VAR_NAME($1)_get])
+ PSI_DECL_ARGS(PSI_VAR_TYPE_RETURN([$1]) PSI_VAR_NAME([$1])_get)
psi_add_decl "$psi_decl_args"
dnl setter
psi_add_macro "void _psi_set_${macro_name}($macro_type value$macro_array) { memcpy(&$macro_name, &value, sizeof($macro_type$macro_array)); }"
PSI_REDIR([${macro_name}_set], [_psi_set_${macro_name}])
- PSI_DECL_ARGS([void PSI_VAR_NAME($1)_set], [($1)])
+ PSI_DECL_ARGS([void ]PSI_VAR_NAME([$1])[_set], [($1)])
psi_add_decl "$psi_decl_args"
])
])
+++ /dev/null
-# psi_add_struct(struct members)
-# Add a pre-defined struct to $PSI_STRUCTS.
-psi_add_struct() {
- cat >>$PSI_STRUCTS <<EOF
- $1, {0},
-EOF
-}
-
-# psi_add_union(union/struct members)
-# Add a pre-defined union to $PSI_UNIONS.
-psi_add_union() {
- cat >>$PSI_UNIONS <<EOF
- $1, {0},
-EOF
-}
-
-dnl PSI_STRUCT_MEMBER(struct name, decl member)
-dnl INTERNAL: build $psi_struct_members
-AC_DEFUN(PSI_STRUCT_MEMBER, [
- m4_define([member_name], PSI_VAR_NAME($2))
- m4_define([member_type], PSI_VAR_TYPE($2))
- PSI_CHECK_SIZEOF(AS_TR_SH($1)[_]member_name,
- [#define ]AS_TR_SH($1)[_]member_name (($1 *)0)->member_name
- )
- if PSI_SH_TEST_SIZEOF($1 member_name); then
- PSI_CHECK_OFFSETOF($1, member_name)
- PSI_TYPE_INDIRECTION($2, [PSI_SH_SIZEOF([$1 member_name])], pl, as)
-
- psi_member_sizeof=PSI_SH_SIZEOF($1 member_name)
- psi_member_offsetof=PSI_SH_OFFSETOF($1 member_name)
-
- if test $pl -gt 0 && test $as -eq 0; then
- check_size=PSI_SH_SIZEOF(void *)
- elif test $pl -eq 1 && test $as -gt 0; then
- check_size=`expr PSI_SH_SIZEOF(member_type) \* $as`
- else
- check_size=PSI_SH_SIZEOF(member_type)
- fi
- if test $psi_member_sizeof != "$check_size"; then
- psi_member_basic_type=PSI_SH_BASIC_TYPE(member_type)
- psi_member_type_pair="`psi_type_pair $psi_member_basic_type $psi_member_sizeof`"
- psi_struct_members="$psi_struct_members, {$psi_member_type_pair, \"[]member_name[]\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}"
- AC_MSG_WARN(pre-defined size $check_size of $2 in $1 does not match computed size $psi_member_sizeof; adjusting to $psi_member_type_pair)
- else
- psi_struct_members="[$psi_struct_members, {]PSI_TYPE_PAIR(member_type)[, \"]member_name[\", $psi_member_offsetof, $psi_member_sizeof, $pl, $as}]"
- fi
- fi
-])
-
-dnl PSI_STRUCT(struct name, struct members)
-dnl Check a struct and its members and add a pre-defined struct and possibly a
-dnl pre-defined type for this struct.
-dnl Calls PSI_CHECK_SIZEOF and PSI_CHECK_ALIGNOF for the struct.
-dnl Calls PSI_CHECK_SIZEOF, PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member.
-AC_DEFUN(PSI_STRUCT, [
- PSI_CHECK_SIZEOF($1)
- if PSI_SH_TEST_SIZEOF($1); then
- PSI_CHECK_ALIGNOF($1)
- psi_struct_name=m4_bregexp([$1], [^\(struct \)?\(\w+\)], [\2])
- psi_struct_members="{PSI_T_STRUCT, \"struct\", \"$psi_struct_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}"
- ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1, m4_normalize(], [))], [], $2)])
- psi_add_struct "$psi_struct_members"
- if test "$1" = "$psi_struct_name"; then
- psi_add_type "{PSI_T_STRUCT, \"$1\", \"$1\"}"
- fi
- fi
-])
-
-dnl PSI_UNION(union name, union/struct members)
-dnl Check a union and its members and add a pre-defined union and possibly a
-dnl pre-defined type for this union.
-dnl Calls PSI_CHECK_SIZEOF for the union and each member.
-dnl Calls PSI_CHECK_OFFSETOF and PSI_TYPE_INDIRECTON for each member.
-AC_DEFUN(PSI_UNION, [
- PSI_CHECK_SIZEOF($1)
- if PSI_SH_TEST_SIZEOF($1); then
- PSI_CHECK_ALIGNOF($1)
- psi_struct_name=m4_bregexp([$1], [^\(union \)?\(\w+\)], [\2])
- psi_struct_members="{PSI_T_UNION, \"union\", \"$psi_struct_name\", PSI_SH_ALIGNOF($1), PSI_SH_SIZEOF($1), 0, 0}"
- ifelse([$2],,,[m4_map_args_sep([PSI_STRUCT_MEMBER($1, m4_normalize(], [))], [], $2)])
- psi_add_union "$psi_struct_members"
- if test "$1" = "$psi_struct_name"; then
- psi_add_type "{PSI_T_UNION, \"$1\", \"$1\"}"
- fi
- fi
-])
# psi_add_type(type triplet)
-# Add a pre-defined type to $PSI_TYPES.
+# Add a pre-defined type to $PSI_TYPES_H.
psi_add_type() {
- cat >>$PSI_TYPES <<EOF
- $1,
-EOF
+ PSI_TYPES="$PSI_TYPES
+ $1,"
}
psi_add_stdtype() {
- cat >>$PSI_STDTYPES <<EOF
- $1,
-EOF
+ PSI_STDTYPES="$PSI_STDTYPES
+ $1,"
}
# psi_type_pair(type, size)
dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
dnl If the basic type is just specified as "int" (in contrast to "sint" or
dnl "uint"), AX_CHECK_SIGN is used to discover signedness of the type.
-dnl Defines a pre-defined type in $PSI_TYPES.
+dnl Defines a pre-defined type in $PSI_TYPES_H.
AC_DEFUN(PSI_TYPE, [
ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
PSI_CHECK_SIZEOF($1)
dnl PSI_OPAQUE_TYPE(type name)
dnl Checks a type for being a scalar, a struct or a pointer type.
dnl Calls AC_TYPE_<TYPE> (if defined) and PSI_CHECK_SIZEOF.
-dnl Defines a pre-defined type in $PSI_TYPES and a pre-defined struct in
+dnl Defines a pre-defined type in $PSI_TYPES_H and a pre-defined struct in
dnl $PSI_STRUCTS if the type is a struct.
AC_DEFUN(PSI_OPAQUE_TYPE, [
ifdef(AS_TR_CPP(AC_TYPE_$1), AS_TR_CPP(AC_TYPE_$1))
--- /dev/null
+/* generated by configure */
+#ifndef PSI_POSIX_H
+#define PSI_POSIX_H
+
+#include "php_psi_stdinc.h"
+
+#ifdef PSI_STD_TYPES
+static struct psi_std_type {
+ token_t type_tag;
+ const char *type_name;
+ const char *alias;
+} psi_std_types[] = {
+ {PSI_T_INT8, "int8_t", NULL},
+ {PSI_T_INT16, "int16_t", NULL},
+ {PSI_T_INT32, "int32_t", NULL},
+ {PSI_T_INT64, "int64_t", NULL},
+ {PSI_T_UINT8, "uint8_t", NULL},
+ {PSI_T_UINT16, "uint16_t", NULL},
+ {PSI_T_UINT32, "uint32_t", NULL},
+ {PSI_T_UINT64, "uint64_t", NULL},
+@PSI_STDTYPES@
+ {0}
+};
+#endif
+
+#ifdef PSI_PREDEF_TYPES
+static struct psi_predef_type {
+ token_t type_tag;
+ const char *type_name;
+ const char *alias;
+} psi_predef_types[] = {
+@PSI_TYPES@
+ {0}
+};
+#endif
+
+#ifdef PSI_PREDEF_COMPOSITES
+static struct psi_predef_composite {
+ token_t type_tag;
+ const char *type_name;
+ const char *var_name;
+ size_t offset;
+ size_t size;
+ size_t pointer_level;
+ size_t array_size;
+} psi_predef_composites[] = {
+@PSI_COMPOSITES@
+ {0}
+};
+#endif
+
+#ifdef PSI_PREDEF_CONSTS
+static struct psi_predef_const {
+ token_t type_tag;
+ const char *type_name;
+ const char *var_name;
+ const char *val_text;
+ token_t val_type_tag;
+} psi_predef_consts[] = {
+@PSI_CONSTS@
+ {0}
+};
+#endif
+
+#ifdef PSI_PREDEF_DECLS
+static struct psi_predef_decl {
+ enum {
+ DECL_KIND_STD,
+ DECL_KIND_VARARG,
+ DECL_KIND_FUNCTOR
+ } kind;
+ token_t type_tag;
+ const char *type_name;
+ const char *var_name;
+ size_t pointer_level;
+ size_t array_size;
+} psi_predef_decls[] = {
+@PSI_DECLS@
+ {0}
+};
+#endif
+
+#ifdef PSI_FUNC_REDIRS
+@PSI_MACROS@
+
+typedef void (*psi_func_ptr)();
+static struct psi_func_redir {
+ const char *name;
+ psi_func_ptr func;
+} psi_func_redirs[] = {
+@PSI_REDIRS@
+ {0}
+};
+#endif
+
+#endif
--- /dev/null
+/* generated by configure */
+#ifndef PSI_STDINC_H
+#define PSI_STDINC_H
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#else
+# include "php_config.h"
+#endif
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+#ifndef _REENTRANT
+# define _REENTRANT
+#endif
+
+@PSI_INCLUDES@
+
+#endif
\ No newline at end of file
#include "token.h"
#include "parser.h"
-#include "php_psi_types.h"
-#include "php_psi_consts.h"
-#include "php_psi_decls.h"
-#include "php_psi_va_decls.h"
-#include "php_psi_fn_decls.h"
-#include "php_psi_structs.h"
-#include "php_psi_unions.h"
+#define PSI_PREDEF_TYPES
+#define PSI_PREDEF_CONSTS
+#define PSI_PREDEF_COMPOSITES
+#define PSI_PREDEF_DECLS
+#include "php_psi_posix.h"
struct psi_context *psi_context_init(struct psi_context *C, struct psi_context_ops *ops, psi_error_cb error, unsigned flags)
{
struct psi_data T;
struct psi_predef_type *predef_type;
struct psi_predef_const *predef_const;
- struct psi_predef_struct *predef_struct;
- struct psi_predef_union *predef_union;
+ struct psi_predef_composite *predef_composite;
struct psi_predef_decl *predef_decl;
if (!C) {
T.consts = psi_plist_add(T.consts, &constant);
}
- for (predef_struct = &psi_predef_structs[0]; predef_struct->type_tag; ++predef_struct) {
- struct psi_predef_struct *member;
+ for (predef_composite = &psi_predef_composites[0]; predef_composite->type_tag; ++predef_composite) {
+ struct psi_predef_composite *member;
+ struct psi_decl_struct *dstruct;
+ struct psi_decl_union *dunion;
struct psi_plist *dargs = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
- struct psi_decl_struct *dstruct = psi_decl_struct_init(predef_struct->var_name, dargs);
- dstruct->size = predef_struct->size;
- dstruct->align = predef_struct->offset;
- for (member = &predef_struct[1]; member->type_tag; ++member) {
- struct psi_decl_type *type;
- struct psi_decl_var *dvar;
- struct psi_decl_arg *darg;
-
- type = psi_decl_type_init(member->type_tag, member->type_name);
- dvar = psi_decl_var_init(member->var_name, member->pointer_level, member->array_size);
- darg = psi_decl_arg_init(type, dvar);
- darg->layout = psi_layout_init(member->offset, member->size);
- dstruct->args = psi_plist_add(dstruct->args, &darg);
+ switch (predef_composite->type_tag) {
+ case PSI_T_STRUCT:
+ dstruct = psi_decl_struct_init(predef_composite->var_name, dargs);
+ dstruct->size = predef_composite->size;
+ dstruct->align = predef_composite->offset;
+ break;
+ case PSI_T_UNION:
+ dunion = psi_decl_union_init(predef_composite->var_name, dargs);
+ dunion->size = predef_composite->size;
+ dunion->align = predef_composite->offset;
+ break;
+ default:
+ assert(0);
}
-
- T.structs = psi_plist_add(T.structs, &dstruct);
- predef_struct = member;
- }
- for (predef_union = &psi_predef_unions[0]; predef_union->type_tag; ++predef_union) {
- struct psi_predef_union *member;
- struct psi_plist *dargs = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
- struct psi_decl_union *dunion = psi_decl_union_init(predef_union->var_name, dargs);
-
- dunion->size = predef_union->size;
- dunion->align = predef_union->offset;
- for (member = &predef_union[1]; member->type_tag; ++member) {
+ for (member = &predef_composite[1]; member->type_tag; ++member) {
struct psi_decl_type *type;
struct psi_decl_var *dvar;
struct psi_decl_arg *darg;
dvar = psi_decl_var_init(member->var_name, member->pointer_level, member->array_size);
darg = psi_decl_arg_init(type, dvar);
darg->layout = psi_layout_init(member->offset, member->size);
- dunion->args = psi_plist_add(dunion->args, &darg);
- }
- T.unions = psi_plist_add(T.unions, &dunion);
- predef_union = member;
- }
- for (predef_decl = &psi_predef_decls[0]; predef_decl->type_tag; ++predef_decl) {
- struct psi_predef_decl *farg;
- struct psi_decl_type *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name);
- struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size);
- struct psi_decl_arg *func = psi_decl_arg_init(ftype, fname);
- struct psi_plist *args = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
- struct psi_decl *decl = psi_decl_init(psi_decl_abi_init("default"), func, args);
-
- for (farg = &predef_decl[1]; farg->type_tag; ++farg) {
- struct psi_decl_type *arg_type = psi_decl_type_init(farg->type_tag, farg->type_name);
- struct psi_decl_var *arg_var = psi_decl_var_init(farg->var_name, farg->pointer_level, farg->array_size);
- struct psi_decl_arg *darg = psi_decl_arg_init(arg_type, arg_var);
- decl->args = psi_plist_add(decl->args, &darg);
+ switch (predef_composite->type_tag) {
+ case PSI_T_STRUCT:
+ dstruct->args = psi_plist_add(dstruct->args, &darg);
+ break;
+ case PSI_T_UNION:
+ dunion->args = psi_plist_add(dunion->args, &darg);
+ break;
+ default:
+ assert(0);
+ }
}
-
- T.decls = psi_plist_add(T.decls, &decl);
- predef_decl = farg;
- }
-
- for (predef_decl = &psi_predef_vararg_decls[0]; predef_decl->type_tag; ++predef_decl) {
- struct psi_predef_decl *farg;
- struct psi_decl_type *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name);
- struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size);
- struct psi_decl_arg *func = psi_decl_arg_init(ftype, fname);
- struct psi_plist *args = psi_plist_init((psi_plist_dtor) psi_decl_arg_free);
- struct psi_decl *decl = psi_decl_init(psi_decl_abi_init("default"), func, args);
-
- for (farg = &predef_decl[1]; farg->type_tag; ++farg) {
- struct psi_decl_type *arg_type = psi_decl_type_init(farg->type_tag, farg->type_name);
- struct psi_decl_var *arg_var = psi_decl_var_init(farg->var_name, farg->pointer_level, farg->array_size);
- struct psi_decl_arg *darg = psi_decl_arg_init(arg_type, arg_var);
- decl->args = psi_plist_add(decl->args, &darg);
+ switch (predef_composite->type_tag) {
+ case PSI_T_STRUCT:
+ T.structs = psi_plist_add(T.structs, &dstruct);
+ break;
+ case PSI_T_UNION:
+ T.unions = psi_plist_add(T.unions, &dunion);
+ break;
+ default:
+ assert(0);
}
- decl->varargs = 1;
- T.decls = psi_plist_add(T.decls, &decl);
- predef_decl = farg;
+ predef_composite = member;
}
-
- for (predef_decl = &psi_predef_functor_decls[0]; predef_decl->type_tag; ++predef_decl) {
+ for (predef_decl = &psi_predef_decls[0]; predef_decl->type_tag; ++predef_decl) {
struct psi_predef_decl *farg;
struct psi_decl_type *dtype, *ftype = psi_decl_type_init(predef_decl->type_tag, predef_decl->type_name);
struct psi_decl_var *fname = psi_decl_var_init(predef_decl->var_name, predef_decl->pointer_level, predef_decl->array_size);
decl->args = psi_plist_add(decl->args, &darg);
}
- dtype = psi_decl_type_init(PSI_T_FUNCTION, fname->name);
- dtype->real.func = decl;
- tdef = psi_decl_arg_init(dtype, psi_decl_var_copy(fname));
- T.types = psi_plist_add(T.types, &tdef);
+ switch (predef_decl->kind) {
+ case DECL_KIND_VARARG:
+ decl->varargs = 1;
+ /* no break */
+ case DECL_KIND_STD:
+ T.decls = psi_plist_add(T.decls, &decl);
+ break;
+ case DECL_KIND_FUNCTOR:
+ dtype = psi_decl_type_init(PSI_T_FUNCTION, fname->name);
+ dtype->real.func = decl;
+ tdef = psi_decl_arg_init(dtype, psi_decl_var_copy(fname));
+ T.types = psi_plist_add(T.types, &tdef);
+ break;
+ default:
+ assert(0);
+ }
predef_decl = farg;
}
while (psi_plist_get(C->consts, i++, &c)) {
zc.name = zend_string_init(c->name + (c->name[0] == '\\'), strlen(c->name) - (c->name[0] == '\\'), 1);
+
+ if (zend_get_constant(zc.name)) {
+ zend_string_release(zc.name);
+ continue;
+ }
+
ZVAL_NEW_STR(&zc.value, zend_string_init(c->val->text, strlen(c->val->text), 1));
switch (c->type->type) {
#include "php_psi_stdinc.h"
-#if __GNUC__ >= 5
-# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
-#endif
-#include "php_psi_macros.h"
-#include "php_psi_redirs.h"
-#if __GNUC__ >= 5
-# pragma GCC diagnostic pop
-#endif
-
#include <dlfcn.h>
-
#include "data.h"
+#define PSI_FUNC_REDIRS
+#include "php_psi_posix.h"
+
struct psi_decl *psi_decl_init(struct psi_decl_abi *abi,
struct psi_decl_arg *func, struct psi_plist *args)
{
#include "php_psi_stdinc.h"
#include "token.h"
-#include "php_psi_stdtypes.h"
#include "data.h"
+#define PSI_STD_TYPES
+#include "php_psi_posix.h"
+
struct psi_decl_type *psi_decl_type_init(token_t type, const char *name)
{
struct psi_decl_type *t = calloc(1, sizeof(*t));