2 Copyright (C) 2001-2009, Parrot Foundation.
3 This program is free software. It is subject to the same license as
9 src/packdump.c - Functions for dumping packfile structures
13 This is only used by the PBC dumper C<pbc_dump>.
23 #include "parrot/parrot.h"
24 #include "parrot/packfile.h"
25 #include "pmc/pmc_sub.h"
26 #include "pmc/pmc_key.h"
28 /* HEADERIZER HFILE: include/parrot/packfile.h */
30 /* HEADERIZER BEGIN: static */
31 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
33 static void PackFile_Constant_dump(PARROT_INTERP
,
34 ARGIN(const PackFile_ConstTable
*ct
),
35 ARGIN(const PackFile_Constant
*self
))
36 __attribute__nonnull__(1)
37 __attribute__nonnull__(2)
38 __attribute__nonnull__(3);
40 static void pobj_flag_dump(PARROT_INTERP
, long flags
)
41 __attribute__nonnull__(1);
43 #define ASSERT_ARGS_PackFile_Constant_dump __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
44 PARROT_ASSERT_ARG(interp) \
45 , PARROT_ASSERT_ARG(ct) \
46 , PARROT_ASSERT_ARG(self))
47 #define ASSERT_ARGS_pobj_flag_dump __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
48 PARROT_ASSERT_ARG(interp))
49 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
50 /* HEADERIZER END: static */
55 =item C<void PackFile_ConstTable_dump(PARROT_INTERP, const PackFile_ConstTable
58 Dumps the constant table C<self>.
66 PackFile_ConstTable_dump(PARROT_INTERP
, ARGIN(const PackFile_ConstTable
*self
))
68 ASSERT_ARGS(PackFile_ConstTable_dump
)
71 for (i
= 0; i
< self
->const_count
; i
++) {
72 Parrot_io_printf(interp
, " # %ld:\n", (long)i
);
73 PackFile_Constant_dump(interp
, self
, self
->constants
[i
]);
79 =item C<static void PackFile_Constant_dump(PARROT_INTERP, const
80 PackFile_ConstTable *ct, const PackFile_Constant *self)>
82 Dumps the constant C<self>.
88 /* [this desperately needs better abstraction, so we're not duplicating the enum
89 * PObj_enum definition in the include/parrot/pobj.h file. -- rgr, 1-Mar-08.]
91 PARROT_OBSERVER
static const char * const flag_bit_names
[] =
126 =item C<static void pobj_flag_dump(PARROT_INTERP, long flags)>
128 Given a word of flags, generate a dump line of the whole word in hex,
129 followed by individual bits.
136 pobj_flag_dump(PARROT_INTERP
, long flags
)
138 ASSERT_ARGS(pobj_flag_dump
)
140 int printed_flag_p
= 0;
142 Parrot_io_printf(interp
, "\tFLAGS => 0x%04lx (", flags
);
146 Parrot_io_printf(interp
, ",");
147 Parrot_io_printf(interp
, "%s", flag_bit_names
[idx
]);
153 Parrot_io_printf(interp
, ")\n");
157 PackFile_Constant_dump(PARROT_INTERP
, ARGIN(const PackFile_ConstTable
*ct
),
158 ARGIN(const PackFile_Constant
*self
))
160 ASSERT_ARGS(PackFile_Constant_dump
)
164 switch (self
->type
) {
167 Parrot_io_printf(interp
, " [ 'PFC_NUMBER', %g ],\n", self
->u
.number
);
171 Parrot_io_printf(interp
, " [ 'PFC_STRING', {\n");
172 pobj_flag_dump(interp
, (long)PObj_get_FLAGS(self
->u
.string
));
173 Parrot_io_printf(interp
, " CHARSET => %ld,\n",
174 self
->u
.string
->charset
);
175 i
= self
->u
.string
->bufused
;
176 Parrot_io_printf(interp
, " SIZE => %ld,\n",
179 Parrot_io_printf(interp
, " DATA => \"%Ss\"\n",
180 Parrot_str_escape(interp
, self
->u
.string
));
181 Parrot_io_printf(interp
, " } ],\n");
185 for (i
= 0, key
= self
->u
.key
; key
; i
++) {
186 GETATTR_Key_next_key(interp
, key
, key
);
188 /* number of key components */
189 Parrot_io_printf(interp
, " [ 'PFC_KEY' (%ld items)\n", i
);
190 /* and now type / value per component */
191 for (key
= self
->u
.key
; key
;) {
192 opcode_t type
= PObj_get_FLAGS(key
);
194 Parrot_io_printf(interp
, " {\n");
196 type
&= KEY_type_FLAGS
;
197 pobj_flag_dump(interp
, (long)PObj_get_FLAGS(key
));
199 case KEY_integer_FLAG
:
200 Parrot_io_printf(interp
, " TYPE => INTEGER\n");
201 Parrot_io_printf(interp
, " DATA => %ld\n",
202 VTABLE_get_integer(interp
, key
));
203 Parrot_io_printf(interp
, " },\n");
205 case KEY_number_FLAG
:
207 const PackFile_Constant
*detail
;
210 Parrot_io_printf(interp
, " TYPE => NUMBER\n");
211 ct_index
= PackFile_find_in_const(interp
, ct
, key
, PFC_NUMBER
);
212 Parrot_io_printf(interp
, " PFC_OFFSET => %ld\n", ct_index
);
213 detail
= ct
->constants
[ct_index
];
214 Parrot_io_printf(interp
, " DATA => %ld\n", detail
->u
.number
);
215 Parrot_io_printf(interp
, " },\n");
218 case KEY_string_FLAG
:
220 const PackFile_Constant
*detail
;
223 Parrot_io_printf(interp
, " TYPE => STRING\n");
224 ct_index
= PackFile_find_in_const(interp
, ct
, key
, PFC_STRING
);
225 Parrot_io_printf(interp
, " PFC_OFFSET => %ld\n", ct_index
);
226 detail
= ct
->constants
[ct_index
];
227 Parrot_io_printf(interp
, " DATA => '%Ss'\n",
229 Parrot_io_printf(interp
, " },\n");
232 case KEY_integer_FLAG
| KEY_register_FLAG
:
233 Parrot_io_printf(interp
, " TYPE => I REGISTER\n");
234 Parrot_io_printf(interp
, " DATA => %ld\n",
235 VTABLE_get_integer(interp
, key
));
236 Parrot_io_printf(interp
, " },\n");
238 case KEY_number_FLAG
| KEY_register_FLAG
:
239 Parrot_io_printf(interp
, " TYPE => N REGISTER\n");
240 Parrot_io_printf(interp
, " DATA => %ld\n",
241 VTABLE_get_integer(interp
, key
));
242 Parrot_io_printf(interp
, " },\n");
244 case KEY_string_FLAG
| KEY_register_FLAG
:
245 Parrot_io_printf(interp
, " TYPE => S REGISTER\n");
246 Parrot_io_printf(interp
, " DATA => %ld\n",
247 VTABLE_get_integer(interp
, key
));
248 Parrot_io_printf(interp
, " },\n");
250 case KEY_pmc_FLAG
| KEY_register_FLAG
:
251 Parrot_io_printf(interp
, " TYPE => P REGISTER\n");
252 Parrot_io_printf(interp
, " DATA => %ld\n",
253 VTABLE_get_integer(interp
, key
));
254 Parrot_io_printf(interp
, " },\n");
257 Parrot_io_eprintf(NULL
, "PackFile_Constant_pack: "
258 "unsupported constant type\n");
259 Parrot_exit(interp
, 1);
261 GETATTR_Key_next_key(interp
, key
, key
);
263 Parrot_io_printf(interp
, " ],\n");
266 Parrot_io_printf(interp
, " [ 'PFC_PMC', {\n");
268 PMC
* const pmc
= self
->u
.key
;
269 Parrot_Sub_attributes
*sub
;
270 STRING
* const null
= Parrot_str_new_constant(interp
, "(null)");
271 STRING
*namespace_description
;
273 pobj_flag_dump(interp
, (long)PObj_get_FLAGS(pmc
));
274 switch (pmc
->vtable
->base_type
) {
275 case enum_class_FixedBooleanArray
:
276 case enum_class_FixedFloatArray
:
277 case enum_class_FixedPMCArray
:
278 case enum_class_FixedStringArray
:
279 case enum_class_ResizableBooleanArray
:
280 case enum_class_ResizableIntegerArray
:
281 case enum_class_ResizableFloatArray
:
282 case enum_class_ResizablePMCArray
:
283 case enum_class_ResizableStringArray
:
285 const int n
= VTABLE_get_integer(interp
, pmc
);
286 STRING
* const out_buffer
= VTABLE_get_repr(interp
, pmc
);
287 Parrot_io_printf(interp
,
289 "\telement count => %d,\n"
290 "\telements => %Ss,\n",
297 case enum_class_Coroutine
:
298 PMC_get_sub(interp
, pmc
, sub
);
299 if (sub
->namespace_name
) {
300 switch (sub
->namespace_name
->vtable
->base_type
) {
301 case enum_class_String
:
302 namespace_description
= Parrot_str_new(interp
, "'", 1);
303 namespace_description
= Parrot_str_append(interp
,
304 namespace_description
,
305 VTABLE_get_string(interp
, sub
->namespace_name
));
306 namespace_description
= Parrot_str_append(interp
,
307 namespace_description
,
308 Parrot_str_new(interp
, "'", 1));
311 namespace_description
=
312 key_set_to_string(interp
, sub
->namespace_name
);
315 namespace_description
= sub
->namespace_name
->vtable
->whoami
;
319 namespace_description
= null
;
321 Parrot_io_printf(interp
,
323 "\tstart_offs => %d,\n"
324 "\tend_offs => %d,\n"
326 "\tsubid => '%Ss',\n"
327 "\tmethod => '%Ss',\n"
328 "\tnsentry => '%Ss',\n"
329 "\tnamespace => %Ss\n"
338 namespace_description
,
341 case enum_class_FixedIntegerArray
:
342 Parrot_io_printf(interp
,
346 VTABLE_get_repr(interp
, pmc
));
349 Parrot_io_printf(interp
, "\tno dump info for PMC %ld %Ss\n",
350 pmc
->vtable
->base_type
, pmc
->vtable
->whoami
);
351 Parrot_io_printf(interp
, "\tclass => %Ss,\n", pmc
->vtable
->whoami
);
354 Parrot_io_printf(interp
, " } ],\n");
357 Parrot_io_printf(interp
, " [ 'PFC_\?\?\?', type '0x%x' ],\n",
365 =item C<void PackFile_Fixup_dump(PARROT_INTERP, const PackFile_FixupTable *ft)>
367 Dumps the fix-up table C<ft>.
375 PackFile_Fixup_dump(PARROT_INTERP
, ARGIN(const PackFile_FixupTable
*ft
))
377 ASSERT_ARGS(PackFile_Fixup_dump
)
380 for (i
= 0; i
< ft
->fixup_count
; i
++) {
381 Parrot_io_printf(interp
, "\t#%d\n", (int) i
);
382 switch (ft
->fixups
[i
]->type
) {
383 case enum_fixup_label
:
385 Parrot_io_printf(interp
,
386 "\ttype => %d offs => %8d name => '%s',\n",
387 (int)ft
->fixups
[i
]->type
,
388 (int)ft
->fixups
[i
]->offset
,
389 ft
->fixups
[i
]->name
);
392 Parrot_io_printf(interp
, "\ttype => %d ???,\n",
393 (int) ft
->fixups
[i
]->type
);
414 * c-file-style: "parrot"
416 * vim: expandtab shiftwidth=4: