size_t psi_t_alignment(token_t t)
{
size_t align;
-# define PSI_TAS_D(T) struct TAS_ ##T { \
+#define PSI_TAS_D(T) struct PSI_TAS_ ##T { \
char c; \
- ##T x; \
+ T x; \
}
-# define PSI_TAS_C(T) align = offsetof(struct TAS_ ##T, x)
-# define PSI_TAS_CASE(T) { \
+#define PSI_TAS_P(T) struct PSI_TAS_ ## T ## _pointer { \
+ char c; \
+ T *x; \
+}
+#define PSI_TAS_C(T) align = offsetof(struct PSI_TAS_ ##T, x)
+#define PSI_TAS_CASE(T) { \
PSI_TAS_D(T); \
PSI_TAS_C(T); \
}
case PSI_T_DOUBLE:
PSI_TAS_CASE(double);
break;
+ case PSI_T_SIZE_T:
+ PSI_TAS_CASE(size_t);
+ break;
+ case PSI_T_POINTER:
+ {
+ PSI_TAS_P(char);
+ PSI_TAS_C(char_pointer);
+ }
+ break;
EMPTY_SWITCH_DEFAULT_CASE();
}
+
+ return align;
}
size_t psi_t_size(token_t t)
case PSI_T_DOUBLE:
size = sizeof(double);
break;
+ case PSI_T_SIZE_T:
+ size = sizeof(size_t);
+ break;
+ case PSI_T_POINTER:
+ size = sizeof(char *);
+ break;
EMPTY_SWITCH_DEFAULT_CASE();
}
return size;
#define PSI_T_SHORT 25
#define PSI_T_LONG 26
#define PSI_T_DOUBLE 27
-#define PSI_T_SINT8 28
-#define PSI_T_UINT8 29
-#define PSI_T_SINT16 30
-#define PSI_T_UINT16 31
-#define PSI_T_SINT32 32
-#define PSI_T_UINT32 33
-#define PSI_T_SINT64 34
-#define PSI_T_UINT64 35
-#define PSI_T_FUNCTION 36
-#define PSI_T_COLON 37
-#define PSI_T_REFERENCE 38
-#define PSI_T_NULL 39
-#define PSI_T_TRUE 40
-#define PSI_T_FALSE 41
-#define PSI_T_DOLLAR 42
-#define PSI_T_LET 43
-#define PSI_T_CALLOC 44
-#define PSI_T_STRLEN 45
-#define PSI_T_STRVAL 46
-#define PSI_T_INTVAL 47
-#define PSI_T_FLOATVAL 48
-#define PSI_T_BOOLVAL 49
-#define PSI_T_SET 50
-#define PSI_T_TO_ARRAY 51
-#define PSI_T_TO_STRING 52
-#define PSI_T_TO_INT 53
-#define PSI_T_TO_FLOAT 54
-#define PSI_T_TO_BOOL 55
-#define PSI_T_RETURN 56
-#define PSI_T_FREE 57
-#define PSI_T_MIXED 58
-#define PSI_T_ARRAY 59
-#define PSI_T_POINTER 60
+#define PSI_T_SIZE_T 28
+#define PSI_T_SINT8 29
+#define PSI_T_UINT8 30
+#define PSI_T_SINT16 31
+#define PSI_T_UINT16 32
+#define PSI_T_SINT32 33
+#define PSI_T_UINT32 34
+#define PSI_T_SINT64 35
+#define PSI_T_UINT64 36
+#define PSI_T_FUNCTION 37
+#define PSI_T_COLON 38
+#define PSI_T_REFERENCE 39
+#define PSI_T_NULL 40
+#define PSI_T_TRUE 41
+#define PSI_T_FALSE 42
+#define PSI_T_DOLLAR 43
+#define PSI_T_LET 44
+#define PSI_T_CALLOC 45
+#define PSI_T_STRLEN 46
+#define PSI_T_STRVAL 47
+#define PSI_T_INTVAL 48
+#define PSI_T_FLOATVAL 49
+#define PSI_T_BOOLVAL 50
+#define PSI_T_SET 51
+#define PSI_T_TO_ARRAY 52
+#define PSI_T_TO_STRING 53
+#define PSI_T_TO_INT 54
+#define PSI_T_TO_FLOAT 55
+#define PSI_T_TO_BOOL 56
+#define PSI_T_RETURN 57
+#define PSI_T_FREE 58
+#define PSI_T_MIXED 59
+#define PSI_T_ARRAY 60
+#define PSI_T_POINTER 61
}
block ::= decl_typedef(def). {
P->defs = add_decl_typedef(P->defs, def);
+ if (def->type->strct) {
+ P->structs = add_decl_struct(P->structs, def->type->strct);
+ }
}
block ::= constant(constant). {
P->consts = add_constant(P->consts, constant);
free(S);
free(N);
}
+decl_typedef(def) ::= TYPEDEF decl_struct(s) NAME(ALIAS) EOS. {
+ def = init_decl_typedef(ALIAS->text, init_decl_type(PSI_T_STRUCT, s->name));
+ def->type->strct = s;
+ free(ALIAS);
+}
%type decl {decl*}
decl(decl) ::= decl_abi(abi) decl_arg(func) LPAREN decl_args(args) RPAREN EOS. {
type_ = init_decl_type(T->type, T->text);
free(T);
}
+decl_type(type_) ::= SIZE_T(T). {
+ type_ = init_decl_type(T->type, T->text);
+ free(T);
+}
decl_type(type_) ::= SINT8(T). {
type_ = init_decl_type(T->type, T->text);
free(T);
#include <jit/jit.h>
+#include "php.h"
+#include "php_psi.h"
#include "validator.h"
PSI_Validator *PSI_ValidatorInit(PSI_Validator *V, PSI_Parser *P)
if (!validate_decl_type(V, func, func->type)) {
return 0;
}
-
+#ifndef RTLD_NEXT
+# define RTLD_NEXT ((void *) -1l)
+#endif
decl->dlptr = dlsym(V->dlopened ?: RTLD_NEXT, func->var->name);
if (!decl->dlptr) {
V->error(PSI_WARNING, "Failed to located symbol '%s': %s",
s->layout = calloc(s->args->count, sizeof(*s->layout));
for (i = 0; i < s->args->count; ++i) {
- decl_type *t = real_decl_type(s->args->args[i]->type);
+ decl_arg *darg = s->args->args[i];
+ decl_type *type = real_decl_type(darg->type);
+ token_t t = darg->var->pointer_level ? PSI_T_POINTER : type->type;
if (i) {
decl_struct_layout *l = &s->layout[i-1];
- s->layout[i].pos = psi_t_align(t->type, l->pos + l->size);
+ s->layout[i].pos = psi_t_align(t, l->pos + l->len);
} else {
s->layout[i].pos = 0;
}
- s->layout[i].len = psi_t_size(t->type);
+ s->layout[i].len = psi_t_size(t);
}
return 1;
}
size_t i;
for (i = 0; i < V->structs->count; ++i) {
- if (!validate_struct(V->structs->list[i])) {
+ if (!validate_struct(V, V->structs->list[i])) {
return 0;
}
}
if (stmts->ret.count != 1) {
if (stmts->ret.count > 1) {
V->error(PSI_WARNING, "Too many `ret` statements for implmentation %s;"
- "found %zu, exactly one is needed",
+ " found %zu, exactly one is needed",
impl->func->name, stmts->ret.count);
} else {
V->error(PSI_WARNING, "Missing `ret` statement for implementation %s",
}
/* check that we have a let stmt for every decl arg */
- for (i = 0; i < decl->args->count; ++i) {
+ if (decl->args) for (i = 0; i < decl->args->count; ++i) {
decl_arg *darg = decl->args->args[i];
int check = 0;
}
if (!check) {
V->error(PSI_WARNING, "Missing `let` statement for arg '%s %.*s%s'"
- "of declaration '%s' for implementation '%s'",
+ " of declaration '%s' for implementation '%s'",
darg->type->name, (int) darg->var->pointer_level, "*****",
darg->var->name, decl->func->var->name, impl->func->name);
return 0;
int check = 0;
if (let->val && let->val->var) {
- for (j = 0; j < impl->func->args->count; ++j) {
+ if (impl->func->args) for (j = 0; j < impl->func->args->count; ++j) {
impl_arg *iarg = impl->func->args->args[j];
if (!strcmp(let->val->var->name, iarg->var->name)) {
set_stmt *set = stmts->set.list[i];
int check = 0;
- for (j = 0; j < impl->func->args->count; ++j) {
+ if (impl->func->args) for (j = 0; j < impl->func->args->count; ++j) {
impl_arg *iarg = impl->func->args->args[j];
if (!strcmp(set->var->name, iarg->var->name)) {
decl_var *set_var = set->val->vars->vars[j];
check = 0;
- for (k = 0; k < decl->args->count; ++k) {
+ if (decl->args) for (k = 0; k < decl->args->count; ++k) {
decl_arg *set_arg = decl->args->args[k];
if (!strcmp(set_var->name, set_arg->var->name)) {
if (!strcmp(free_var->name, decl->func->var->name)) {
continue;
}
- for (k = 0; k < decl->args->count; ++k) {
+ if (decl->args) for (k = 0; k < decl->args->count; ++k) {
decl_arg *free_arg = decl->args->args[k];
if (!strcmp(free_var->name, free_arg->var->name)) {