static void dump_vars(struct scope_info *scope) { struct var_info *var_info; if (scope->handle != -1) dump_ref(scope->handle); else { scope->handle = dump_store(); if (scope->outer) dump_op(fop_DOTTED_LIST1); else dump_op(fop_LIST1); dump_vector_header(scope->nvars); for (var_info=scope->vars; var_info != NULL; var_info=var_info->next) { int loc_info = var_info->offset << 2; if (var_info->indirect) loc_info |= 2; if (var_info->argument) loc_info |= 1; dump_op(fop_VECTOR2); dump_symbol(var_info->var->symbol); dump_integer(loc_info); } if (scope->outer) dump_vars(scope->outer); } }
static void dump_vector_header(int length) { switch (length) { case 0: dump_op(fop_VECTOR0); break; case 1: dump_op(fop_VECTOR1); break; case 2: dump_op(fop_VECTOR2); break; case 3: dump_op(fop_VECTOR3); break; case 4: dump_op(fop_VECTOR4); break; case 5: dump_op(fop_VECTOR5); break; case 6: dump_op(fop_VECTOR6); break; case 7: dump_op(fop_VECTOR7); break; case 8: dump_op(fop_VECTOR8); break; default: dump_op(fop_VECTORN); if (length-9 < 254) dump_byte(length-9); else if (length-9-254 <= USHRT_MAX) { dump_byte(254); dump_short((short)(length-9-254)); } else { dump_byte(255); dump_int(length-9-254-USHRT_MAX-1); } break; } }
static void dump_ref(int handle) { if (handle <= USHRT_MAX) { dump_op(fop_SHORT_REF); dump_short((short)handle); } else { dump_op(fop_REF); dump_int(handle); } }
void dump_top_level_form(struct component *c) { if (!ModuleDumped) { dump_op(fop_IN_MODULE); dump_symbol(ModuleName); ModuleDumped = true; } dump_op(fop_TOP_LEVEL_FORM); dump_component(c); }
void dump_defgeneric(struct id *name, struct component *tlf) { if (!ModuleDumped) { dump_op(fop_IN_MODULE); dump_symbol(ModuleName); ModuleDumped = true; } dump_op(fop_DEFINE_GENERIC); dump_symbol(name->symbol); dump_component(tlf); }
static void dump_string_guts(int short_op, int long_op, char *str, int length) { if (length < 256) { dump_op(short_op); dump_byte(length); } else { dump_op(long_op); dump_int(length); } dump_bytes(str, length); }
void dump_defvar(struct param_list *params, struct component *initializer) { if (!ModuleDumped) { dump_op(fop_IN_MODULE); dump_symbol(ModuleName); ModuleDumped = true; } dump_op(fop_DEFINE_VARIABLE); dump_defconst_or_var(params); dump_component(initializer); }
void dump_defmethod(struct id *name, struct component *c) { if (!ModuleDumped) { dump_op(fop_IN_MODULE); dump_symbol(ModuleName); ModuleDumped = true; } dump_op(fop_DEFINE_METHOD); dump_symbol(name->symbol); dump_component(c); }
void dump::dump_op(node* n) { if (n->type == NT_IF) { dump_op(*n, "IF "); return; } switch(n->subtype) { case NST_ALU_INST: dump_alu(static_cast<alu_node*>(n)); break; case NST_FETCH_INST: dump_op(*n, static_cast<fetch_node*>(n)->bc.op_ptr->name); break; case NST_CF_INST: case NST_ALU_CLAUSE: case NST_TEX_CLAUSE: case NST_VTX_CLAUSE: dump_op(*n, static_cast<cf_node*>(n)->bc.op_ptr->name); break; case NST_ALU_PACKED_INST: dump_op(*n, static_cast<alu_packed_node*>(n)->op_ptr()->name); break; case NST_PHI: dump_op(*n, "PHI"); break; case NST_PSI: dump_op(*n, "PSI"); break; case NST_COPY: dump_op(*n, "COPY"); break; default: dump_op(*n, "??unknown_op"); } }
static void dump_method(struct method *method) { struct param_list *params = method->params; struct keyword_param *k; int param_info, nkeys; int nclosure_vars; struct closes_over *over; if (params->rest_param) param_info = 1; else param_info = 0; if (params->all_keys) param_info |= 2; if (params->allow_keys) { nkeys = 0; for (k = params->keyword_params; k != NULL; k = k->next) nkeys++; param_info = param_info | (nkeys+1)<<2; } nclosure_vars = 0; for (over = method->closes_over; over != NULL; over = over->next) nclosure_vars++; if (param_info < 256 && nclosure_vars < 256) { dump_op(fop_SHORT_METHOD); dump_byte(param_info); dump_byte(nclosure_vars); } else { dump_op(fop_METHOD); dump_int(param_info); dump_int(nclosure_vars); } for (k = params->keyword_params; k != NULL; k = k->next) { struct literal_expr *def = (struct literal_expr *)k->def; dump_symbol(k->keyword); if (def) { if (def->kind != expr_LITERAL) lose("non-literal keyword default made it though expand?"); dump_literal(def->lit); } else dump_op(fop_FALSE); } dump_component(method->component); }
static void dump_debug_info(struct component *c) { struct debug_info *info; dump_vector_header(c->ndebug_infos); for (info = c->debug_info; info != NULL; info = info->next) { dump_op(fop_VECTOR3); dump_integer(info->line); dump_integer(info->bytes); if (info->scope) dump_vars(info->scope); else dump_op(fop_NIL); } }
bool dump::visit(cf_node& n, bool enter) { if (enter) { indent(); dump_flags(n); dump_op(n, n.bc.op_ptr->name); if (n.bc.op_ptr->flags & CF_BRANCH) { sblog << " @" << (n.bc.addr << 1); } dump_common(n); sblog << "\n"; if (!n.empty()) { indent(); sblog << "< "; dump_live_values(n, true); } ++level; } else { --level; if (!n.empty()) { indent(); sblog << "> "; dump_live_values(n, false); } } return true; }
static void dump_if_expr(struct if_expr *expr) { dump_op(fop_IF_EXPR); dump_expr(expr->cond); dump_body(expr->consequent); dump_body(expr->alternate); }
static void dump_block_expr(struct block_expr *expr) { dump_op(fop_BLOCK_EXPR); if (expr->exit_fun) dump_id(expr->exit_fun); else dump_op(fop_FALSE); dump_body(expr->body); if (expr->inner) lose("Dumping a block that still has exception clauses?"); if (expr->cleanup) dump_body(expr->cleanup); else dump_op(fop_FALSE); if (expr->outer) lose("Dumping a block that still has exception clauses?"); }
static void dump_defgeneric_constituent(struct defgeneric_constituent *c) { dump_op(fop_DEFINE_GENERIC); dump_id(c->name); dump_param_list(c->params); dump_rettypes(c->rettypes); dump_plist(c->plist); }
void dump_all() { PerlIO_setlinebuf(Perl_debug_log); if (main_root) dump_op(main_root); dump_packsubs(defstash); }
void dump_setup_output(char *source, FILE *file) { struct stat buf; time_t tv; int statres; File = file; #if ! NO_SHARP_BANG fprintf(File, "#! /usr/bin/env mindy -x\n"); #endif fprintf(File, "# %s (%d.%d) of %s\n", "compilation", file_MajorVersion, file_MinorVersion, source); statres = stat(source, &buf); if (statres >= 0) fprintf(File, "# last modified on %s", ctime(&buf.st_mtime)); fprintf(File, "# produced with the %s version of mindycomp\n", Version); time(&tv); fprintf(File, "# at %s", ctime(&tv)); dump_op(fop_HEADER); dump_byte(file_MajorVersion); dump_byte(file_MinorVersion); dump_byte(sizeof(short)); dump_byte(sizeof(int)); dump_byte(sizeof(long)); dump_byte(sizeof(float)); dump_byte(sizeof(double)); dump_byte(sizeof(long double)); dump_short(1); dump_int(dbc_MagicNumber); dump_op(fop_IN_LIBRARY); if (LibraryName) dump_symbol(LibraryName); else dump_symbol(sym_DylanUser); if (source != NULL) { dump_op(fop_SOURCE_FILE); if (statres >= 0) dump_integer(buf.st_mtime); else dump_integer(0); dump_string_guts(fop_SHORT_STRING, fop_STRING, source, strlen(source)); } }
static void dump_method_parse(struct method *method) { if (method->name) dump_id(method->name); else dump_op(fop_FALSE); dump_param_list(method->params); dump_rettypes(method->rettypes); dump_body(method->body); }
static void dump_integer(long value) { if (SCHAR_MIN <= value && value <= SCHAR_MAX) { dump_op(fop_SIGNED_BYTE); dump_byte(value); } else if (SHRT_MIN <= value && value <= SHRT_MAX) { dump_op(fop_SIGNED_SHORT); dump_short((short)value); } else if (INT_MIN <= value && value <= INT_MAX) { dump_op(fop_SIGNED_INT); dump_int(value); } else { dump_op(fop_SIGNED_LONG); dump_long(value); } }
static void dump_varref(struct id *id, bool written) { if (id->line) { dump_op(fop_NOTE_REFERENCE); dump_int(id->line); } if (id->internal) if (written) dump_op(fop_BUILTIN_WRITABLE_VALUE_CELL); else dump_op(fop_BUILTIN_VALUE_CELL); else if (written) dump_op(fop_WRITABLE_VALUE_CELL); else dump_op(fop_VALUE_CELL); dump_symbol(id->symbol); }
static void dump_call_expr(struct call_expr *expr) { struct argument *args; int nargs = 0; dump_op(fop_CALL_EXPR); dump_expr(expr->func); for (args = expr->args; args != NULL; args = args->next) nargs++; dump_integer(nargs); for (args = expr->args; args != NULL; args = args->next) dump_expr(args->expr); }
static void dump_rettypes(struct return_type_list *rettypes) { struct return_type *r; int nreq = 0; if (rettypes != NULL) { for (r = rettypes->req_types; r != NULL; r = r->next) nreq++; dump_integer(nreq); for (r = rettypes->req_types; r != NULL; r = r->next) if (r->type) dump_expr(r->type); else dump_op(fop_FALSE); if (rettypes->rest_type) dump_expr(r->type); else dump_op(fop_FALSE); } else dump_op(fop_FALSE); }
void dump_defclass(struct id *name, struct slot_spec *slots, struct component *tlf1, struct component *tlf2) { struct slot_spec *slot; if (!ModuleDumped) { dump_op(fop_IN_MODULE); dump_symbol(ModuleName); ModuleDumped = true; } dump_op(fop_DEFINE_CLASS); dump_symbol(name->symbol); for (slot = slots; slot != NULL; slot = slot->next) { dump_symbol(slot->getter->symbol); if (slot->setter) dump_symbol(slot->setter->symbol); } dump_op(fop_FALSE); dump_component(tlf1); dump_component(tlf2); }
static void dump_local_constituent(struct local_constituent *c) { struct method *m; int nlocals = 0; dump_op(fop_LOCAL_CONSTITUENT); for (m = c->methods; m != NULL; m = m->next_local) nlocals++; dump_integer(nlocals); for (m = c->methods; m != NULL; m = m->next_local) dump_method_parse(m); dump_body(c->body); }
bool dump::visit(fetch_node& n, bool enter) { if (enter) { indent(); dump_flags(n); dump_op(n, n.bc.op_ptr->name); sblog << "\n"; ++level; } else { --level; } return true; }
static void dump_component(struct component *c) { struct constant *constant; struct block *block; int bytes; if (c->nconstants <= UCHAR_MAX && c->bytes <= USHRT_MAX) { dump_op(fop_SHORT_COMPONENT); dump_byte(c->nconstants); dump_short((short)(c->bytes)); } else { dump_op(fop_COMPONENT); dump_int(c->nconstants); dump_int(c->bytes); } if (c->debug_name) dump_literal(c->debug_name); else dump_op(fop_FALSE); dump_integer(c->frame_size); dump_debug_info(c); for (constant = c->constants; constant != NULL; constant = constant->next) dump_constant(constant); bytes = 0; for (block = c->blocks; block != NULL; block = block->next) { int count = block->end - block->bytes; dump_bytes(block->bytes, count); bytes += count; } if (bytes != c->bytes) lose("Planned on writing %d bytes, but ended up writing %d instead.", c->bytes, bytes); }
bool dump::visit(node& n, bool enter) { if (enter) { indent(); dump_flags(n); switch (n.subtype) { case NST_PHI: dump_op(n, "* phi"); break; case NST_PSI: dump_op(n, "* psi"); break; case NST_COPY: dump_op(n, "* copy"); break; default: assert(!"invalid node subtype"); break; } sblog << "\n"; } return false; }
static void dump_defnamespace(struct defnamespace_constituent *c, bool dump_creates) { struct use_clause *use; dump_literal(c->name); for (use = c->use_clauses; use != NULL; use = use->next) { dump_literal(use->name); dump_literal(use->import); dump_literal(use->exclude); dump_literal(use->prefix); dump_literal(use->rename); dump_literal(use->export); } dump_op(fop_FALSE); dump_literal(c->exported_literal); if (dump_creates) dump_literal(c->created_literal); }
void dump_op_array(zend_op_array *op_array){ if(op_array) { /* @TODO format output ... >_< */ int i; char *buf; char *top; memset(memset((buf=malloc(116))+115, 0, 1)-115, '-', 115); memset(memset((top=malloc(116))+115, 0, 1)-115, '-', 115); printf("%s\n",top); printf("%6s|%6s|%25s|%45s|%10s|%10s|%6s|\n", "opnum", "line", "opcode", "op_handler", "op1", "op2", "result"); printf("%.6s|%.6s|%.25s|%.45s|%.10s|%.10s|%.6s|\n", buf, buf, buf, buf, buf, buf, buf); for(i = 0; i < op_array->last; i++) { dump_op(&op_array->opcodes[i], i); } printf("%s\n",top); free(buf); free(top); } }
static void dump_param_list(struct param_list *params) { struct param *p; int nparams = 0; for (p = params->required_params; p != NULL; p = p->next) nparams++; dump_integer(nparams); for (p = params->required_params; p != NULL; p = p->next) { dump_id(p->id); if (p->type) dump_expr(p->type); else dump_op(fop_FALSE); } if (params->next_param) dump_id(params->next_param); else dump_op(fop_FALSE); if (params->rest_param) dump_id(params->rest_param); else dump_op(fop_FALSE); if (params->allow_keys) { struct keyword_param *k; int nkeys = 0; for (k = params->keyword_params; k != NULL; k = k->next) nkeys++; dump_integer(nkeys); for (k = params->keyword_params; k != NULL; k = k->next) { dump_symbol(k->keyword); dump_id(k->id); if (k->type) dump_expr(k->type); else dump_op(fop_FALSE); if (k->def) dump_expr(k->def); else dump_op(fop_FALSE); } } else dump_op(fop_FALSE); }