flush
[m6w6/ext-psi] / src / context_dump.c
index 93b8f325d4006a05b73ded6aaae7d8974b907ec9..b778525c93a4f4aa76bf9df59a2240933da73036 100644 (file)
@@ -4,15 +4,46 @@
 #include "libjit.h"
 #include "libffi.h"
 
 #include "libjit.h"
 #include "libffi.h"
 
+static inline void dump_decl_arg(int fd, decl_arg *darg);
+
 static inline void dump_decl_type(int fd, decl_type *t) {
        const char *pre;
 static inline void dump_decl_type(int fd, decl_type *t) {
        const char *pre;
+       size_t j;
 
        switch (t->type) {
 
        switch (t->type) {
+       case PSI_T_POINTER:
+               dprintf(fd, "%s *", t->name);
+               return;
+
+       case PSI_T_FUNCTION:
+               dump_decl_arg(fd, t->func->func);
+               dprintf(fd, "(");
+               if (t->func->args) {
+                       for (j = 0; j < t->func->args->count; ++j) {
+                               if (j) {
+                                       dprintf(fd, ", ");
+                               }
+                               dump_decl_arg(fd, t->func->args->args[j]);
+                       }
+                       if (t->func->args->varargs) {
+                               dprintf(fd, ", ...");
+                       }
+               }
+               dprintf(fd, ")");
+               return;
+
        case PSI_T_STRUCT:
                pre = "struct ";
                break;
        case PSI_T_STRUCT:
                pre = "struct ";
                break;
+       case PSI_T_ENUM:
+               pre = "enum ";
+               break;
+       case PSI_T_UNION:
+               pre = "union ";
+               break;
        default:
                pre = "";
        default:
                pre = "";
+               break;
        }
        dprintf(fd, "%s%s", pre, t->name);
 }
        }
        dprintf(fd, "%s%s", pre, t->name);
 }
@@ -46,6 +77,9 @@ static inline void dump_num_exp(int fd, num_exp *exp) {
                case PSI_T_NAME:
                        dump_decl_var(fd, exp->u.dvar);
                        break;
                case PSI_T_NAME:
                        dump_decl_var(fd, exp->u.dvar);
                        break;
+               case PSI_T_ENUM:
+                       dprintf(fd, "%s", exp->u.enm->name);
+                       break;
                EMPTY_SWITCH_DEFAULT_CASE();
                }
                if (exp->operand) {
                EMPTY_SWITCH_DEFAULT_CASE();
                }
                if (exp->operand) {
@@ -108,18 +142,22 @@ static inline void dump_impl_set_value(int fd, set_value *set, unsigned level, i
        }
 }
 
        }
 }
 
-static inline void dump_typedef(int fd, decl_typedef *tdef) {
+static inline void dump_typedef(int fd, decl_arg *tdef) {
        dprintf(fd, "typedef ");
        dprintf(fd, "typedef ");
+       dump_decl_arg(fd, tdef);
+       dprintf(fd, ";");
+       /*
        dump_decl_type(fd, tdef->type);
        dprintf(fd, " %s%s;", tdef->type->type == PSI_T_POINTER ? "*":"",
                        tdef->alias);
        dump_decl_type(fd, tdef->type);
        dprintf(fd, " %s%s;", tdef->type->type == PSI_T_POINTER ? "*":"",
                        tdef->alias);
+       */
 }
 
 static inline void dump_typedefs(int fd, decl_typedefs *defs) {
        size_t i;
 
        for (i = 0; i < defs->count; ++i) {
 }
 
 static inline void dump_typedefs(int fd, decl_typedefs *defs) {
        size_t i;
 
        for (i = 0; i < defs->count; ++i) {
-               decl_typedef *tdef = defs->list[i];
+               decl_arg *tdef = defs->list[i];
 
                dump_typedef(fd, tdef);
                dprintf(fd, "\n");
 
                dump_typedef(fd, tdef);
                dprintf(fd, "\n");
@@ -129,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;
 
 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) {
        if (strct->args && strct->args->count) {
                dprintf(fd, " {\n");
                for (j = 0; j < strct->args->count; ++j) {
@@ -144,6 +182,7 @@ static inline void dump_struct(int fd, decl_struct *strct) {
                dprintf(fd, ";");
        }
 }
                dprintf(fd, ";");
        }
 }
+
 static inline void dump_structs(int fd, decl_structs *structs) {
        size_t i;
 
 static inline void dump_structs(int fd, decl_structs *structs) {
        size_t i;
 
@@ -155,6 +194,60 @@ static inline void dump_structs(int fd, decl_structs *structs) {
        }
 }
 
        }
 }
 
+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;
+
+       dprintf(fd, "enum %s {\n", e->name);
+       for (j = 0; j < e->items->count; ++j) {
+               decl_enum_item *i = e->items->list[j];
+
+               if (j) {
+                       dprintf(fd, ",\n");
+               }
+               dprintf(fd, "\t%s", i->name);
+               if (i->num && i->num != &i->inc) {
+                       dprintf(fd, " = ");
+                       dump_num_exp(fd, i->num);
+               }
+       }
+       dprintf(fd, "\n}");
+}
+
+static inline void dump_enums(int fd, decl_enums *enums) {
+       size_t i;
+
+       for (i = 0; i < enums->count; ++i) {
+               decl_enum *e = enums->list[i];
+
+               dump_enum(fd, e);
+               dprintf(fd, "\n");
+       }
+}
 static inline void dump_constant(int fd, constant *cnst) {
        dprintf(fd, "const %s %s = ", cnst->type->name, cnst->name);
        if (cnst->val->type == PSI_T_QUOTED_STRING) {
 static inline void dump_constant(int fd, constant *cnst) {
        dprintf(fd, "const %s %s = ", cnst->type->name, cnst->name);
        if (cnst->val->type == PSI_T_QUOTED_STRING) {
@@ -371,11 +464,18 @@ void PSI_ContextDump(PSI_Context *C, int fd)
                dump_typedefs(fd, C->defs);
                dprintf(fd, "\n");
        }
                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");
        }
        if (C->structs) {
                dump_structs(fd, C->structs);
                dprintf(fd, "\n");
        }
+       if (C->enums) {
+               dump_enums(fd, C->enums);
+               dprintf(fd, "\n");
+       }
        if (C->consts) {
                dump_constants(fd, C->consts);
                dprintf(fd, "\n");
        if (C->consts) {
                dump_constants(fd, C->consts);
                dprintf(fd, "\n");