+static inline void dump_decl_type(int fd, decl_type *t) {
+ const char *pre;
+
+ switch (t->type) {
+ case PSI_T_STRUCT:
+ pre = "struct ";
+ break;
+ default:
+ pre = "";
+ }
+ dprintf(fd, "%s%s", pre, t->name);
+}
+static inline void dump_decl_var(int fd, decl_var *v) {
+ dprintf(fd, "%.*s%s", v->pointer_level-!!v->array_size, "**********", v->name);
+ if (v->array_size) {
+ dprintf(fd, "[%u]", v->array_size);
+ }
+}
+static inline void dump_decl_arg(int fd, decl_arg *a) {
+ dump_decl_type(fd, a->type);
+ dprintf(fd, " ");
+ dump_decl_var(fd, a->var);
+}
+void PSI_ContextDump(PSI_Context *C, int fd)
+{
+ size_t i, j;
+
+#ifdef HAVE_LIBJIT
+ if (C->ops == PSI_Libjit()) {
+ dprintf(fd, "#PSI(libjit)\n");
+ }
+#endif
+#ifdef HAVE_LIBFFI
+ if (C->ops == PSI_Libffi()) {
+ dprintf(fd, "#PSI(libffi)\n");
+ }
+#endif
+
+ if (C->defs) for (i = 0; i < C->defs->count; ++i) {
+ decl_typedef *tdef = C->defs->list[i];
+
+ dprintf(fd, "typedef ");
+ dump_decl_type(fd, tdef->type);
+ dprintf(fd, " %s;\n", tdef->alias);
+ }
+ if (C->structs) for (i = 0; i < C->structs->count; ++i) {
+ decl_struct *strct = C->structs->list[i];
+ decl_arg *sarg = NULL;
+
+ dprintf(fd, "struct %s::(%zu) {\n", strct->name, strct->size);
+ for (j = 0; j < strct->args->count; ++j) {
+ sarg = strct->args->args[j];
+ dprintf(fd, "\t");
+ dump_decl_arg(fd, sarg);
+ dprintf(fd, "::(%zu, %zu);\n", sarg->layout->pos, sarg->layout->len);
+ }
+ dprintf(fd, "}\n");
+ }
+
+ dprintf(fd, "\n");
+}
+