2 Copyright (C) 2001-2009, Parrot Foundation.
7 pbc_disassemble - Parrot disassembler
11 pbc_disassemble [-bdh?] [-o outfile] [file.pbc]
15 This uses the C<Parrot_disassemble()> function from F<src/embed.c>,
16 which in turn uses the C<PDB_disassemble()> function from
19 Without non-option arguments it reads the pbc from STDIN.
29 #include <parrot/parrot.h>
30 #include "parrot/embed.h"
35 static void do_dis(Parrot_Interp
, const char *, int);
39 =item C<static void help(void)>
41 Print out the user help info.
47 static void help(void)
49 printf("pbc_disassemble - dump or convert parrot bytecode (PBC) files\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");
56 printf("\t-D<1-7> --debug debug output\n");
57 printf("\t 1 general info\n");
58 printf("\t 2 alignment\n");
59 printf("\t 4 values\n");
61 printf(" -o filename\t ... output to filename\n");
65 static struct longopt_opt_decl options
[] = {
66 { 'h', 'h', OPTION_optional_FLAG
, { "--header-only" } },
67 { '?', '?', OPTION_optional_FLAG
, { "--help" } },
68 { 'b', 'b', OPTION_optional_FLAG
, { "--bare" } },
70 { 'D', 'D', OPTION_required_FLAG
, { "--debug" } },
72 { 'o', 'o', OPTION_required_FLAG
, { "--output" } }
77 =item C<int main(int argc, const char *argv[])>
79 The run-loop. Starts up an interpreter, loads the bytecode from the
80 command-line and disassembles it.
87 main(int argc
, const char *argv
[])
91 const char *outfile
= NULL
;
93 int debug
= PFOPT_UTILS
;
94 struct longopt_opt_info opt
= LONGOPT_OPT_INFO_INIT
;
97 interp
= Parrot_new(NULL
);
101 /* init and set top of stack */
102 Parrot_init_stacktop(interp
, &status
);
103 while ((status
= longopt_get(interp
,
104 argc
, argv
, options
, &opt
)) > 0) {
105 switch (opt
.opt_id
) {
107 option
+= enum_DIS_HEADER
;
110 option
+= enum_DIS_BARE
;
113 outfile
= opt
.opt_arg
;
117 debug
+= atoi(opt
.opt_arg
) << 2;
129 argc
-= opt
.opt_index
;
130 argv
+= opt
.opt_index
;
132 pf
= Parrot_pbc_read(interp
, argc
? *argv
: "-", debug
);
135 printf("Can't read PBC\n");
139 Parrot_pbc_load(interp
, pf
);
141 do_dis(interp
, outfile
, option
);
143 Parrot_exit(interp
, 0);
148 =item C<static void do_dis(PARROT_INTERP, const char *outfile, int options)>
150 Do the disassembling.
152 C<option> is currently used to pass debugging flags to the packfile reader.
159 do_dis(PARROT_INTERP
, const char *outfile
, int options
)
161 Parrot_disassemble(interp
, outfile
, (Parrot_disassemble_options
) options
);
170 F<src/embed.c> and F<src/debug.c>.
174 Initial version by Daniel Grunblatt on 2002.5.26.
176 Florian Ragwitz: Moved POD documentation that's not necessary to know how to
177 actually run the disassembler to normal C comments (Wed, 16 Nov 2005).
179 Reini Urban: Renamed from disassemble to pbc_disassemble (2008-07-03).
180 Add options: help, -h, -o, --debug, --bare (2009-01-29)
181 Force option 1 for passing version check (2009-03-07)
190 * c-file-style: "parrot"
192 * vim: expandtab shiftwidth=4: