From: Michael Wallner Date: Mon, 1 Feb 2016 15:44:04 +0000 (+0100) Subject: flush X-Git-Url: https://git.m6w6.name/?a=commitdiff_plain;h=d3171526ab7658114cac4ebe1098af4b038e576e;p=m6w6%2Fext-psi flush --- diff --git a/m4/unistd.m4 b/m4/unistd.m4 index a5a4ff6..2126500 100644 --- a/m4/unistd.m4 +++ b/m4/unistd.m4 @@ -310,7 +310,7 @@ PSI_CHECK_UNISTD() { PSI_DECL(int execvp, [(const char *file, char **argv)]) PSI_DECL(int faccessat, [(int fd, const char *path, int amode, int flag)]) PSI_DECL(int fchdir, [(int fildes)]) - PSI_DECL(int fchown, [(int fildes, uid_t owner, gid_tgroup)]) + PSI_DECL(int fchown, [(int fildes, uid_t owner, gid_t group)]) PSI_DECL(int fchownat, [(int fd, const char *path, uid_t owner, gid_t group, int flag)]) PSI_DECL(int fdatasync, [(int fildes)]) PSI_DECL(int fexecve, [(int fd, char **argv, char **envp)]) @@ -343,7 +343,7 @@ PSI_CHECK_UNISTD() { PSI_DECL(int nice, [(int incr)]) PSI_DECL(long pathconf, [(const char *path, int name)]) PSI_DECL(int pause, [(void)]) - PSI_DECL(int pipe, [(int fildes@<:@2:>@)]) + PSI_DECL(int pipe, [(int fildes@<:@2@:>@)]) PSI_DECL(ssize_t pread, [(int fildes, void *buf, size_t nbyte, off_t offset)]) PSI_DECL(ssize_t pwrite, [(int fildes, const void *buf, size_t nbyte, off_t offset)]) PSI_DECL(ssize_t read, [(int fd, void *buf, size_t count)]) diff --git a/src/context.c b/src/context.c index 17699a4..218da24 100644 --- a/src/context.c +++ b/src/context.c @@ -108,7 +108,7 @@ PSI_Context *PSI_ContextInit(PSI_Context *C, PSI_ContextOps *ops, PSI_ContextErr decl_union *dunion = init_decl_union(predef_union->var_name, dargs); dunion->size = predef_union->size; - dunion->align = dunion->offset; + dunion->align = predef_union->offset; for (member = &predef_union[1]; member->type_tag; ++member) { decl_type *type; decl_var *dvar; diff --git a/src/context_dump.c b/src/context_dump.c index c62ebf2..b778525 100644 --- a/src/context_dump.c +++ b/src/context_dump.c @@ -167,7 +167,7 @@ static inline void dump_typedefs(int fd, decl_typedefs *defs) { static inline void dump_struct(int fd, decl_struct *strct) { size_t j; - dprintf(fd, "struct %s::(%zu)", strct->name, strct->size); + dprintf(fd, "struct %s::(%zu, %zu)", strct->name, strct->align, strct->size); if (strct->args && strct->args->count) { dprintf(fd, " {\n"); for (j = 0; j < strct->args->count; ++j) { @@ -189,12 +189,36 @@ static inline void dump_structs(int fd, decl_structs *structs) { for (i = 0; i < structs->count; ++i) { decl_struct *strct = structs->list[i]; - dump_struct(fd, strct); dprintf(fd, "\n"); } } +static inline void dump_union(int fd, decl_union *unn) { + size_t j; + + dprintf(fd, "union %s::(%zu, %zu) {\n", unn->name, unn->align, unn->size); + for (j = 0; j < unn->args->count; ++j) { + decl_arg *uarg = unn->args->args[j]; + + dprintf(fd, "\t"); + dump_decl_arg(fd, uarg); + dprintf(fd, "::(%zu, %zu);\n", uarg->layout->pos, uarg->layout->len); + } + dprintf(fd, "}"); +} + +static inline void dump_unions(int fd, decl_unions *unions) { + size_t i; + + for (i = 0; i < unions->count; ++i) { + decl_union *unn = unions->list[i]; + + dump_union(fd, unn); + dprintf(fd, "\n"); + } +} + static inline void dump_enum(int fd, decl_enum *e) { size_t j; @@ -440,7 +464,10 @@ void PSI_ContextDump(PSI_Context *C, int fd) dump_typedefs(fd, C->defs); dprintf(fd, "\n"); } - + if (C->unions) { + dump_unions(fd, C->unions); + dprintf(fd, "\n"); + } if (C->structs) { dump_structs(fd, C->structs); dprintf(fd, "\n"); diff --git a/src/context_validate.c b/src/context_validate.c index 826a6b3..cf0695f 100644 --- a/src/context_validate.c +++ b/src/context_validate.c @@ -1,4 +1,4 @@ - #ifdef HAVE_CONFIG_H +#ifdef HAVE_CONFIG_H # include "config.h" #endif @@ -207,17 +207,26 @@ static inline int validate_decl_struct_darg(PSI_Data *data, decl_arg *darg, void /* pre-validate any structs/unions/enums */ switch (real->type) { case PSI_T_STRUCT: - if ((current && current == real->strct) || !validate_decl_struct(data, real->strct)) { + if (current && current == real->strct) { + return 1; + } + if (!validate_decl_struct(data, real->strct)) { return 0; } break; case PSI_T_UNION: - if ((current && current == real->unn) || !validate_decl_union(data, real->unn)) { + if (current && current == real->unn) { + return 1; + } + if (!validate_decl_union(data, real->unn)) { return 0; } break; case PSI_T_ENUM: - if ((current && current == real->enm) || !validate_decl_enum(data, real->enm)) { + if (current && current == real->enm) { + return 1; + } + if (!validate_decl_enum(data, real->enm)) { return 0; } break; @@ -1167,6 +1176,7 @@ int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P) size_t i, count = C->count++, check_round, check_count; decl_typedefs *check_defs = P->defs; decl_structs *check_structs = P->structs; + decl_unions *check_unions = P->unions; decl_enums *check_enums = P->enums; unsigned silent = C->flags & PSI_PARSER_SILENT; @@ -1190,6 +1200,7 @@ int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P) for (check_round = 0, check_count = 0; CHECK_TOTAL && check_count != CHECK_TOTAL; ++check_round) { decl_typedefs *recheck_defs = NULL; decl_structs *recheck_structs = NULL; + decl_unions *recheck_unions = NULL; decl_enums *recheck_enums = NULL; check_count = CHECK_TOTAL; @@ -1208,6 +1219,13 @@ int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P) recheck_structs = add_decl_struct(recheck_structs, check_structs->list[i]); } } + for (i = 0; i < CHECK_COUNT(unions); ++i) { + if (validate_decl_union(PSI_DATA(C), check_unions->list[i])) { + C->unions = add_decl_union(C->unions, check_unions->list[i]); + } else { + recheck_unions = add_decl_union(recheck_unions, check_unions->list[i]); + } + } for (i = 0; i < CHECK_COUNT(enums); ++i) { if (validate_decl_enum(PSI_DATA(C), check_enums->list[i])) { C->enums = add_decl_enum(C->enums, check_enums->list[i]); @@ -1218,6 +1236,7 @@ int PSI_ContextValidate(PSI_Context *C, PSI_Parser *P) REVALIDATE(defs); REVALIDATE(structs); + REVALIDATE(unions); REVALIDATE(enums); if (check_round == 0 && !silent) { diff --git a/src/libffi.c b/src/libffi.c index 369fe33..301995e 100644 --- a/src/libffi.c +++ b/src/libffi.c @@ -192,7 +192,8 @@ static ffi_type **psi_ffi_struct_type_elements(decl_struct *strct) { static inline ffi_type *psi_ffi_decl_type(decl_type *type) { decl_type *real = real_decl_type(type); - if (real->type == PSI_T_STRUCT) { + switch (real->type) { + case PSI_T_STRUCT: if (!real->strct->engine.type) { ffi_type *strct = calloc(1, sizeof(ffi_type)); @@ -205,8 +206,13 @@ static inline ffi_type *psi_ffi_decl_type(decl_type *type) { } return real->strct->engine.type; + + case PSI_T_UNION: + return psi_ffi_decl_arg_type(real->unn->args->args[0]); + + default: + return psi_ffi_token_type(real->type); } - return psi_ffi_token_type(real->type); } static inline ffi_type *psi_ffi_decl_arg_type(decl_arg *darg) { if (darg->var->pointer_level) { diff --git a/src/parser_proc.y b/src/parser_proc.y index 56938cf..b75ac67 100644 --- a/src/parser_proc.y +++ b/src/parser_proc.y @@ -164,26 +164,31 @@ decl_struct_args(args_) ::= EOS. { %type decl_struct {decl_struct*} %destructor decl_struct {free_decl_struct($$);} -decl_struct(strct) ::= STRUCT NAME(N) struct_size(size_) decl_struct_args(args). { +decl_struct(strct) ::= STRUCT NAME(N) align_and_size(as) decl_struct_args(args). { strct = init_decl_struct(N->text, args); - strct->size = size_; + strct->align = as.a; + strct->size = as.s; strct->token = N; } -%type struct_size {size_t} -struct_size(size) ::= . { - size = 0; +%type align_and_size { struct {size_t a; size_t s; } } +align_and_size(as) ::= . { + as.a = 0; + as.s = 0; } -struct_size(size) ::= COLON COLON LPAREN NUMBER(SIZ) RPAREN. { - size = atol(SIZ->text); - free(SIZ); +align_and_size(as) ::= COLON COLON LPAREN NUMBER(A) COMMA NUMBER(S) RPAREN. { + as.a = atol(A->text); + as.s = atol(S->text); + free(A); + free(S); } %type decl_union {decl_union*} %destructor decl_union {free_decl_union($$);} -decl_union(u) ::= UNION NAME(N) struct_size(size_) decl_struct_args(args). { +decl_union(u) ::= UNION NAME(N) align_and_size(as) decl_struct_args(args). { u = init_decl_union(N->text, args); - u->size = size_; + u->align = as.a; + u->size = as.s; u->token = N; } @@ -234,19 +239,21 @@ decl_typedef(def) ::= TYPEDEF(T) decl_typedef_body(def_) EOS. { free_decl($$->type->func); } } -decl_typedef_body_ex(def) ::= struct_name(N) struct_size(size_) decl_struct_args_block(args) decl_var(var). { +decl_typedef_body_ex(def) ::= struct_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). { def = init_decl_arg(init_decl_type(PSI_T_STRUCT, N->text), var); def->type->token = PSI_TokenCopy(N); def->type->strct = init_decl_struct(N->text, args); def->type->strct->token = N; - def->type->strct->size = size_; + def->type->strct->align = as.a; + def->type->strct->size = as.s; } -decl_typedef_body_ex(def) ::= union_name(N) struct_size(size_) decl_struct_args_block(args) decl_var(var). { +decl_typedef_body_ex(def) ::= union_name(N) align_and_size(as) decl_struct_args_block(args) decl_var(var). { def = init_decl_arg(init_decl_type(PSI_T_UNION, N->text), var); def->type->token = PSI_TokenCopy(N); def->type->unn = init_decl_union(N->text, args); def->type->unn->token = N; - def->type->unn->size = size_; + def->type->unn->align = as.a; + def->type->unn->size = as.s; } decl_typedef_body_ex(def) ::= decl_enum(e) NAME(ALIAS). { def = init_decl_arg(init_decl_type(PSI_T_ENUM, e->name), init_decl_var(ALIAS->text, 0, 0)); diff --git a/tests/pipe/pipe.psi b/tests/pipe/pipe.psi index fd7e3ff..6fc9e89 100644 --- a/tests/pipe/pipe.psi +++ b/tests/pipe/pipe.psi @@ -1,8 +1,8 @@ -extern int pipe(int fds[2]); +//extern int pipe(int fildes[2]); function \pipe(array &$fds = null) : int { return to_int(pipe); - let fds = calloc(2, psi\SIZEOF_INT); - set $fds = to_array(fds[2]); + let fildes = calloc(2, psi\SIZEOF_INT); + set $fds = to_array(fildes[2]); }