static void dump_list_literal(struct list_literal *literal) { struct literal *part; int length; int i; length = 0; for (part = literal->first; part != NULL; part = part->next) length++; part = literal->first; while (length > 255+9) { dump_op(fop_DOTTED_LISTN); dump_byte(255); for (i = 0; i < 255+9; i++) { dump_literal(part); part = part->next; } length -= 255+9; } if (literal->tail) switch (length) { case 0: lose("Zero element dotted list?\n"); case 1: dump_op(fop_DOTTED_LIST1); break; case 2: dump_op(fop_DOTTED_LIST2); break; case 3: dump_op(fop_DOTTED_LIST3); break; case 4: dump_op(fop_DOTTED_LIST4); break; case 5: dump_op(fop_DOTTED_LIST5); break; case 6: dump_op(fop_DOTTED_LIST6); break; case 7: dump_op(fop_DOTTED_LIST7); break; case 8: dump_op(fop_DOTTED_LIST8); break; default: dump_op(fop_DOTTED_LISTN); dump_byte(length - 9); break; } else switch (length) { case 0: dump_op(fop_NIL); break; case 1: dump_op(fop_LIST1); break; case 2: dump_op(fop_LIST2); break; case 3: dump_op(fop_LIST3); break; case 4: dump_op(fop_LIST4); break; case 5: dump_op(fop_LIST5); break; case 6: dump_op(fop_LIST6); break; case 7: dump_op(fop_LIST7); break; case 8: dump_op(fop_LIST8); break; default: dump_op(fop_LISTN); dump_byte(length - 9); break; } while (part != NULL) { dump_literal(part); part = part->next; } if (literal->tail) dump_literal(literal->tail); }
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_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_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); }
int main(int argc, char* argv[]) { int fd, opt=-1, byte_mode=0; unsigned long kaddr = 0; unsigned long size = 0; char *va = NULL; while ((opt = getopt(argc, argv, "b:s:Bh")) != -1) { switch (opt) { case 'h': show_help(); return 0; case 'b': kaddr = (unsigned long)strtoll(optarg, NULL, 16); break; case 's': size = (unsigned long)strtoll(optarg, NULL, 16); break; case 'B': byte_mode = 1; break; default: show_help(); return 0; } } fd = open(DEVKMEM, O_RDONLY); if (fd == -1) { perror("open"); return -1; } printf("addr=%x, size=%x\n", kaddr, size); va = mmap(0, size, PROT_READ, MAP_SHARED, fd, kaddr); if (va == MAP_FAILED) { perror("mmap"); return -1; } printf("va:%p\n", va); if (byte_mode) dump_byte(kaddr, va, size); else dump_word(kaddr, va, size); close(fd); munmap(va, size); return 0; }
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_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_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); }
static void dump_character_literal(struct character_literal *literal) { dump_op(fop_CHAR); dump_byte(literal->value); }
void recorder_t::output () { merge_and_sort(); dump_byte(); if (text_mode) dump_text(); }