Ticket #258: tt258-pbc_disassemble-options.patch
File tt258-pbc_disassemble-options.patch, 8.0 KB (added by rurban, 13 years ago) |
---|
-
include/parrot/embed.h
old new 22 22 23 23 typedef int Parrot_warnclass; 24 24 25 typedef enum { 26 enum_DIS_BARE = 1, 27 enum_DIS_HEADER = 2 28 } Parrot_disassemble_options; 29 25 30 PARROT_EXPORT Parrot_Interp Parrot_new(Parrot_Interp parent); 26 31 27 32 PARROT_EXPORT void Parrot_init_stacktop(Parrot_Interp, void *); … … 58 63 59 64 PARROT_EXPORT Parrot_Opcode * Parrot_debug(Parrot_Interp, Parrot_Interp, Parrot_Opcode *pc); 60 65 61 PARROT_EXPORT void Parrot_disassemble(Parrot_Interp );66 PARROT_EXPORT void Parrot_disassemble(Parrot_Interp, char *outfile, Parrot_disassemble_options options); 62 67 63 68 PARROT_EXPORT 64 69 PARROT_DOES_NOT_RETURN -
src/embed.c
old new 1040 1040 INTVAL i; 1041 1041 1042 1042 /* TODO: would be nice to print the name of the file as well */ 1043 Parrot_io_printf(interp, " Constant-table\n");1043 Parrot_io_printf(interp, "=head1 Constant-table\n\n"); 1044 1044 1045 1045 for (i = 0; i < numconstants; ++i) { 1046 1046 PackFile_Constant *c = interp->code->const_table->constants[i]; … … 1110 1110 } 1111 1111 } 1112 1112 1113 Parrot_io_printf(interp, "\n ");1113 Parrot_io_printf(interp, "\n=cut\n\n"); 1114 1114 } 1115 1115 1116 1116 … … 1128 1128 1129 1129 PARROT_EXPORT 1130 1130 void 1131 Parrot_disassemble(PARROT_INTERP )1131 Parrot_disassemble(PARROT_INTERP, char *outfile, Parrot_disassemble_options options) 1132 1132 { 1133 1133 PDB_line_t *line; 1134 1134 PDB_t *pdb = mem_allocate_zeroed_typed(PDB_t); … … 1146 1146 debugs = (interp->code->debugs != NULL); 1147 1147 1148 1148 print_constant_table(interp); 1149 if (options & enum_DIS_HEADER) 1150 return; 1149 1151 1150 Parrot_io_printf(interp, "%12s-%12s", "Seq_Op_Num", "Relative-PC"); 1152 if (!(options & enum_DIS_BARE)) 1153 Parrot_io_printf(interp, "# %12s-%12s", "Seq_Op_Num", "Relative-PC"); 1151 1154 1152 1155 if (debugs) { 1153 Parrot_io_printf(interp, " %6s:\n", "SrcLn#"); 1156 if (!(options & enum_DIS_BARE)) 1157 Parrot_io_printf(interp, " %6s:\n", "SrcLn#"); 1154 1158 num_mappings = interp->code->debugs->num_mappings; 1155 1159 } 1156 1160 else { … … 1168 1172 if (op_code_seq_num == interp->code->debugs->mappings[curr_mapping]->offset) { 1169 1173 const int filename_const_offset = 1170 1174 interp->code->debugs->mappings[curr_mapping]->filename; 1171 Parrot_io_printf(interp, " Current Source Filename %Ss\n",1175 Parrot_io_printf(interp, "# Current Source Filename '%Ss'\n", 1172 1176 interp->code->const_table->constants[filename_const_offset]->u.string); 1173 1177 curr_mapping++; 1174 1178 } 1175 1179 } 1176 1180 1177 Parrot_io_printf(interp, "%012i-%012i", 1178 op_code_seq_num, line->opcode - interp->code->base.data); 1181 if (!(options & enum_DIS_BARE)) 1182 Parrot_io_printf(interp, "%012i-%012i", 1183 op_code_seq_num, line->opcode - interp->code->base.data); 1179 1184 1180 if (debugs )1185 if (debugs && !(options & enum_DIS_BARE)) 1181 1186 Parrot_io_printf(interp, " %06i: ", 1182 1187 interp->code->debugs->base.data[op_code_seq_num]); 1183 1188 -
src/pbc_disassemble.c
old new 8 8 9 9 =head1 SYNOPSIS 10 10 11 pbc_disassemble file.pbc11 pbc_disassemble [-bh?] [-o outfile] [file.pbc] 12 12 13 13 =head1 DESCRIPTION 14 14 … … 16 16 which in turn uses the C<PDB_disassemble()> function from 17 17 F<src/debug.c>. 18 18 19 Without non-option arguments it reads the pbc from STDIN. 20 19 21 =head2 Functions 20 22 21 23 =over 4 … … 30 32 #include <stdlib.h> 31 33 #include <ctype.h> 32 34 33 static void do_dis(Parrot_Interp); 35 static void do_dis(Parrot_Interp, char *, Parrot_disassemble_options); 36 37 /* 38 39 =item C<static void help(void)> 40 41 Print out the user help info. 42 43 =cut 44 45 */ 46 47 static void help(void) 48 { 49 printf("pbc_disassemble - dump or convert parrot bytecode (PBC) files\n"); 50 printf("usage:\n"); 51 printf("pbc_disassemble [-bh] [--bare|--header-only] [file.pbc]\n"); 52 printf("pbc_disassemble -o converted.pasm file.pbc\n\n"); 53 printf(" -b\t\t ... bare .pasm without header and left column\n"); 54 printf(" -h\t\t ... dump Constant-table header only\n"); 55 printf(" -o filename\t ... output to filename\n"); 56 exit(EXIT_SUCCESS); 57 } 58 59 static struct longopt_opt_decl options[] = { 60 { 'h', 'h', OPTION_optional_FLAG, { "--header-only" } }, 61 { '?', '?', OPTION_optional_FLAG, { "--help" } }, 62 { 'b', 'b', OPTION_optional_FLAG, { "--bare" } }, 63 { 'o', 'o', OPTION_required_FLAG, { "--output" } } 64 }; 34 65 35 66 /* 36 67 … … 46 77 int 47 78 main(int argc, char *argv[]) 48 79 { 49 Parrot_Interp interp;50 char *filename;51 80 Parrot_PackFile pf; 81 Parrot_Interp interp; 82 char *outfile = NULL; 83 int option = 0; 84 struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT; 85 int status; 52 86 53 87 interp = Parrot_new(NULL); 54 55 88 if (!interp) { 56 89 return 1; 57 90 } 58 59 /* set the top of the stack so GC can trace it for GC-able pointers 60 * see trace_system_areas() in src/cpu_dep.c */ 61 interp->lo_var_ptr = &interp; 62 63 if (argc != 2) { 64 fprintf(stderr, "Usage: pbc_disassemble programfile \n"); 65 Parrot_exit(interp, 1); 91 /* init and set top of stack */ 92 Parrot_init_stacktop(interp, &status); 93 while ((status = longopt_get(interp, 94 argc, argv, options, &opt)) > 0) { 95 switch (opt.opt_id) { 96 case 'h': 97 option += enum_DIS_HEADER; 98 break; 99 case 'b': 100 option += enum_DIS_BARE; 101 break; 102 case 'o': 103 outfile = opt.opt_arg; 104 break; 105 case '?': 106 default: 107 help(); 108 break; 109 } 66 110 } 111 if (status == -1) { 112 help(); 113 } 114 argc -= opt.opt_index; 115 argv += opt.opt_index; 67 116 68 filename = argv[1]; 69 70 pf = Parrot_readbc(interp, filename); 117 pf = Parrot_readbc(interp, argc ? *argv : "-"); 71 118 72 119 if (!pf) { 120 printf("Can't read PBC\n"); 73 121 return 1; 74 122 } 75 123 76 124 Parrot_loadbc(interp, pf); 77 125 78 do_dis(interp );126 do_dis(interp, outfile, option); 79 127 80 128 Parrot_exit(interp, 0); 81 129 } 82 130 83 131 /* 84 132 85 =item C<static void do_dis(PARROT_INTERP )>133 =item C<static void do_dis(PARROT_INTERP, outfile, options)> 86 134 87 135 Do the disassembling. 88 136 … … 91 139 */ 92 140 93 141 static void 94 do_dis(PARROT_INTERP )142 do_dis(PARROT_INTERP, char *outfile, Parrot_disassemble_options options) 95 143 { 96 Parrot_disassemble(interp );144 Parrot_disassemble(interp, outfile, options); 97 145 } 98 146 99 147 /* … … 112 160 actually run the disassembler to normal C comments (Wed, 16 Nov 2005). 113 161 114 162 Reini Urban: Renamed from disassemble to pbc_disassemble (2008-07-03). 163 add options: help, -h, -o, bare (2009-01-29) 115 164 116 165 =cut 117 166 -
tools/util/dump_pbc.pl
old new 70 70 my %cache; 71 71 72 72 foreach (@dis) { 73 if (/^Current Source Filename (.*)/) { 74 if ($cur_file ne $1) { 75 $cur_file = $1; 73 if (/^(?:# )?Current Source Filename (.*)/) { 74 my $found = $1; 75 $found =~ s/^'//; 76 $found =~ s/'$//; 77 if ($cur_file ne $found) { 78 $cur_file = $found; 76 79 $cache{$cur_file} ||= slurp_file($cur_file); 77 80 $cur_line = -1; 78 81