[svn:parrot] r45774 - in trunk: include/parrot src
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Sun Apr 18 07:24:50 UTC 2010
Author: chromatic
Date: Sun Apr 18 07:24:50 2010
New Revision: 45774
URL: https://trac.parrot.org/parrot/changeset/45774
Log:
[pbc_dump] Tidied code; no functional changes.
Modified:
trunk/include/parrot/call.h
trunk/src/pbc_dump.c
Modified: trunk/include/parrot/call.h
==============================================================================
--- trunk/include/parrot/call.h Sun Apr 18 07:24:45 2010 (r45773)
+++ trunk/include/parrot/call.h Sun Apr 18 07:24:50 2010 (r45774)
@@ -319,10 +319,10 @@
/* XXX Remove interp from this */
#define ADD_OP_VAR_PART(interp, seg, pc, n) do { \
- if (*(pc) == PARROT_OP_set_args_pc || \
- *(pc) == PARROT_OP_get_results_pc || \
- *(pc) == PARROT_OP_get_params_pc || \
- *(pc) == PARROT_OP_set_returns_pc) { \
+ if (*(pc) == PARROT_OP_set_args_pc \
+ || *(pc) == PARROT_OP_get_results_pc \
+ || *(pc) == PARROT_OP_get_params_pc \
+ || *(pc) == PARROT_OP_set_returns_pc) { \
PMC * const sig = (seg)->const_table->constants[(pc)[1]]->u.key; \
(n) += VTABLE_elements((interp), sig); \
} \
Modified: trunk/src/pbc_dump.c
==============================================================================
--- trunk/src/pbc_dump.c Sun Apr 18 07:24:45 2010 (r45773)
+++ trunk/src/pbc_dump.c Sun Apr 18 07:24:50 2010 (r45774)
@@ -1,5 +1,5 @@
/*
-Copyright (C) 2001-2009, Parrot Foundation.
+Copyright (C) 2001-2010, Parrot Foundation.
$Id$
=head1 NAME
@@ -78,6 +78,7 @@
Parrot_io_printf(interp, "],\n");
}
+
/*
=item C<static void fixup_dump(PARROT_INTERP, const PackFile_Segment *segp)>
@@ -96,6 +97,7 @@
Parrot_io_printf(interp, "],\n");
}
+
/*
=item C<static void disas_dump(PARROT_INTERP, const PackFile_Segment *self)>
@@ -109,28 +111,36 @@
static void
disas_dump(PARROT_INTERP, const PackFile_Segment *self)
{
- opcode_t *pc;
- size_t i, n;
+ opcode_t *pc = self->data;
+
Parrot_io_printf(interp, "%Ss => [ # %d ops at offs 0x%x\n",
self->name, (int)self->size, (int)self->file_offset + 4);
- pc = self->data;
+
while (pc < self->data + self->size) {
+ /* n can't be const; the ADD_OP_VAR_PART macro increments it */
+ size_t n = (size_t)interp->op_info_table[*pc].op_count;
+ size_t i;
+
/* trace_op_dump(interp, self->pf->src, pc); */
- Parrot_io_printf(interp, " %04x: ", (int) (pc - self->data));
- n = (size_t)interp->op_info_table[*pc].op_count;
+ Parrot_io_printf(interp, " %04x: ", (int)(pc - self->data));
+
for (i = 0; i < 6; i++)
if (i < n)
- Parrot_io_printf(interp, "%08lx ", (unsigned long) pc[i]);
+ Parrot_io_printf(interp, "%08lx ", (unsigned long)pc[i]);
else
Parrot_io_printf(interp, " ");
+
Parrot_io_printf(interp, "%s\n",
interp->op_info_table[*pc].full_name);
+
ADD_OP_VAR_PART(interp, interp->code, pc, n);
pc += n;
}
+
Parrot_io_printf(interp, "]\n");
}
+
/*
=item C<static void PackFile_header_dump(PARROT_INTERP, PackFile *pf)>
@@ -152,24 +162,30 @@
Parrot_io_printf(interp, "\t(interpreter's byteorder = %d)\n",
PARROT_BIGENDIAN);
Parrot_io_printf(interp, "\tfloattype = %d", pf->header->floattype);
- Parrot_io_printf(interp, "\t(interpreter's NUMVAL_SIZE = %d)\n", NUMVAL_SIZE);
- Parrot_io_printf(interp, "\tparrot-version %d.%d.%d, bytecode-version %d.%d\n",
- pf->header->major, pf->header->minor, pf->header->patch,
- pf->header->bc_major, pf->header->bc_minor);
+ Parrot_io_printf(interp, "\t(interpreter's NUMVAL_SIZE = %d)\n",
+ NUMVAL_SIZE);
+ Parrot_io_printf(interp, "\tparrot-version %d.%d.%d, "
+ "bytecode-version %d.%d\n",
+ pf->header->major, pf->header->minor, pf->header->patch,
+ pf->header->bc_major, pf->header->bc_minor);
Parrot_io_printf(interp, "\tUUID: type = %d, size = %d",
- pf->header->uuid_type, pf->header->uuid_size);
+ pf->header->uuid_type, pf->header->uuid_size);
+
if (pf->header->uuid_size)
Parrot_io_printf(interp, ", '%s'\n", pf->header->uuid_data);
else
Parrot_io_printf(interp, "\n");
+
Parrot_io_printf(interp, "\t%s endianize, %s opcode, %s numval transform\n",
pf->need_endianize ? "**need**" : "no",
- pf->need_wordsize ? "**need**" : "no",
- pf->fetch_nv ? "**need**" : "no");
+ pf->need_wordsize ? "**need**" : "no",
+ pf->fetch_nv ? "**need**" : "no");
+
Parrot_io_printf(interp, "\tdirformat = %d\n", pf->header->dir_format);
Parrot_io_printf(interp, "]\n");
}
+
/*
=item C<static void help(void)>
@@ -189,12 +205,14 @@
printf("\t-d ... disassemble bytecode segments\n");
printf("\t-h ... dump header only\n");
printf("\t-t ... terse output\n");
+
#if TRACE_PACKFILE
printf("\t-D<1-7> --debug debug output\n");
printf("\t 1 general info\n");
printf("\t 2 alignment\n");
printf("\t 4 values\n");
#endif
+
printf("\t-o converted.pbc ... repacks a PBC file into "
"the platform's native\n");
printf("\t binary format for better efficiency on reading "
@@ -204,15 +222,17 @@
static struct longopt_opt_decl opt_options[] = {
{ 'h', 'h', OPTION_optional_FLAG, { "--header-only" } },
- { '?', '?', OPTION_optional_FLAG, { "--help" } },
- { 't', 't', OPTION_optional_FLAG, { "--terse" } },
+ { '?', '?', OPTION_optional_FLAG, { "--help" } },
+ { 't', 't', OPTION_optional_FLAG, { "--terse" } },
{ 'd', 'd', OPTION_optional_FLAG, { "--disassemble" } },
+ { 'o', 'o', OPTION_required_FLAG, { "--output" } }
+
#if TRACE_PACKFILE
- { 'D', 'D', OPTION_required_FLAG, { "--debug" } },
+ { 'D', 'D', OPTION_required_FLAG, { "--debug" } },
#endif
- { 'o', 'o', OPTION_required_FLAG, { "--output" } }
};
+
/*
=item C<int main(int argc, const char **argv)>
@@ -226,25 +246,34 @@
int
main(int argc, const char **argv)
{
- PackFile *pf;
- Interp *interp;
- int terse = 0;
- int disas = 0;
- int convert = 0;
- int options = PFOPT_UTILS;
- const char *file = NULL;
+ PackFile *pf;
+ Interp *interp;
+
+ const char *file = NULL;
+ int terse = 0;
+ int disas = 0;
+ int convert = 0;
+ int options = PFOPT_UTILS;
+
struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
- int status;
- if (argc < 2) {
+ int status;
+
+ if (argc < 2)
help();
- }
+
interp = Parrot_new(NULL);
+
/* init and set top of stack */
Parrot_init_stacktop(interp, &status);
- while ((status = longopt_get(interp,
- argc, argv, opt_options, &opt)) > 0) {
+
+ while ((status = longopt_get(interp, argc, argv, opt_options, &opt)) > 0) {
switch (opt.opt_id) {
+#if TRACE_PACKFILE
+ case 'D':
+ options += atoi(opt.opt_arg) << 2;
+ break;
+#endif
case 'h':
options += PFOPT_HEADERONLY;
break;
@@ -254,13 +283,8 @@
case 'd':
disas = 1;
break;
-#if TRACE_PACKFILE
- case 'D':
- options += atoi(opt.opt_arg) << 2;
- break;
-#endif
case 'o':
- file = opt.opt_arg;
+ file = opt.opt_arg;
convert = 1;
break;
case '?':
@@ -269,33 +293,36 @@
break;
}
}
- if (status == -1) {
+
+ if (status == -1)
help();
- }
+
argc -= opt.opt_index;
argv += opt.opt_index;
-
pf = Parrot_pbc_read(interp, *argv, options);
if (!pf) {
printf("Can't read PBC\n");
return 1;
}
+
Parrot_pbc_load(interp, pf);
+
if (convert) {
- size_t size;
- opcode_t *pack;
+ size_t size = PackFile_pack_size(interp,
+ interp->code->base.pf) * sizeof (opcode_t);
+ opcode_t *pack = (opcode_t *)Parrot_gc_allocate_memory_chunk(interp,
+ size);
FILE *fp;
- size = PackFile_pack_size(interp,
- interp->code->base.pf) * sizeof (opcode_t);
- pack = (opcode_t*) Parrot_gc_allocate_memory_chunk(interp, size);
if (!pack) {
printf("out of mem\n");
exit(EXIT_FAILURE);
}
+
PackFile_pack(interp, interp->code->base.pf, pack);
+
if (STREQ(file, "-"))
fp = stdout;
else if ((fp = fopen(file, "wb")) == 0) {
@@ -307,28 +334,33 @@
printf("Couldn't write %s\n", file);
exit(EXIT_FAILURE);
}
+
fclose(fp);
Parrot_gc_free_memory_chunk(interp, pack);
Parrot_exit(interp, 0);
}
PackFile_header_dump(interp, pf);
- if (options & PFOPT_HEADERONLY) {
+
+ if (options & PFOPT_HEADERONLY)
Parrot_exit(interp, 0);
- }
+
/* install a dumper function */
if (!terse) {
pf->PackFuncs[PF_CONST_SEG].dump = const_dump;
pf->PackFuncs[PF_FIXUP_SEG].dump = fixup_dump;
}
+
if (disas)
pf->PackFuncs[PF_BYTEC_SEG].dump = disas_dump;
+
/* do a directory dump, which dumps segs then */
PackFile_Segment_dump(interp, &pf->directory.base);
Parrot_exit(interp, 0);
}
+
/*
=back
More information about the parrot-commits
mailing list