Author: tewk
Date: Fri Jan 5 21:31:27 2007
New Revision: 16429
Modified:
trunk/include/parrot/key.h
trunk/include/parrot/packfile.h
trunk/src/key.c
trunk/src/packdump.c
trunk/src/packout.c
Log:
Added detailed output to pdump
Modified: trunk/include/parrot/key.h
==============================================================================
--- trunk/include/parrot/key.h (original)
+++ trunk/include/parrot/key.h Fri Jan 5 21:31:27 2007
@@ -61,6 +61,8 @@
PARROT_API void key_mark(Interp *interp, PMC *key);
+PARROT_API STRING *key_set_to_string(Interp *interpreter, PMC *key);
+
#endif /* PARROT_KEY_H_GUARD */
/*
Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h (original)
+++ trunk/include/parrot/packfile.h Fri Jan 5 21:31:27 2007
@@ -254,7 +254,8 @@
PBC_LOADED = 2,
PBC_PBC = 4,
PBC_IMMEDIATE = 8,
- PBC_POSTCOMP = 16
+ PBC_POSTCOMP = 16,
+ PBC_INIT = 32
} pbc_action_enum_t;
PARROT_API void PackFile_fixup_subs(Interp *, pbc_action_enum_t, PMC
*eval_pmc);
@@ -375,7 +376,7 @@
PARROT_API size_t PackFile_Constant_pack_size(Interp *, struct
PackFile_Constant * self);
-PARROT_API opcode_t * PackFile_Constant_pack(Interp *, struct
PackFile_Constant *, opcode_t *);
+PARROT_API opcode_t * PackFile_Constant_pack(Interp *, struct
PackFile_ConstTable *ct, struct PackFile_Constant *, opcode_t *);
PARROT_API void PackFile_Constant_destroy(Interp *, struct PackFile_Constant *
self);
@@ -388,6 +389,9 @@
PARROT_API opcode_t * PackFile_Constant_unpack_pmc(Interp *interp,
struct PackFile_ConstTable *, struct PackFile_Constant *, opcode_t *);
+PARROT_API int PackFile_find_in_const(Interp *interpreter, struct
PackFile_ConstTable *ct,
+ PMC *key, int type);
+
/*
* pf_items low level Parrot items fetch routines
*/
Modified: trunk/src/key.c
==============================================================================
--- trunk/src/key.c (original)
+++ trunk/src/key.c Fri Jan 5 21:31:27 2007
@@ -481,6 +481,60 @@
/*
+=item C<STRING *
+key_set_to_string(Interp *interpreter, PMC *key)>
+
+=cut
+
+*/
+
+STRING *
+key_set_to_string(Interp *interp, PMC *key)
+{
+ PMC *reg;
+ STRING *semicolon = string_from_cstring(interp, " ; ", 3);
+ STRING *quote = string_from_cstring(interp, "'", 1);
+ STRING *value = string_from_cstring(interp, "[ ", 2);
+
+ for (; key; key = PMC_data(key)) {
+ switch (PObj_get_FLAGS(key) & KEY_type_FLAGS) {
+ case KEY_integer_FLAG:
+ string_append(interp, value, string_from_int(interp,
PMC_int_val(key)));
+ break;
+ case KEY_string_FLAG:
+ string_append(interp, value, quote);
+ string_append(interp, value, PMC_str_val(key));
+ string_append(interp, value, quote);
+ break;
+ case KEY_pmc_FLAG:
+ string_append(interp, value, VTABLE_get_string(interp, key));
+ break;
+ case KEY_integer_FLAG | KEY_register_FLAG:
+ string_append(interp, value, string_from_int(interp,
REG_INT(PMC_int_val(key))));
+ break;
+ case KEY_string_FLAG | KEY_register_FLAG:
+ string_append(interp, value, quote);
+ string_append(interp, value, REG_STR(PMC_int_val(key)));
+ string_append(interp, value, quote);
+ break;
+ case KEY_pmc_FLAG | KEY_register_FLAG:
+ reg = REG_PMC(PMC_int_val(key));
+ string_append(interp, value, VTABLE_get_string(interp, reg));
+ break;
+ default:
+ string_append(interp, value, string_from_cstring(interp, "Key
type unknown", 0));
+ break;
+ }
+
+ if (PMC_data(key))
+ string_append(interp, value, semicolon);
+ }
+ string_append(interp, value, string_from_cstring(interp, " ]", 2));
+ return value;
+}
+
+/*
+
=back
=head1 SEE ALSO
Modified: trunk/src/packdump.c
==============================================================================
--- trunk/src/packdump.c (original)
+++ trunk/src/packdump.c Fri Jan 5 21:31:27 2007
@@ -30,7 +30,7 @@
void PackFile_ConstTable_dump(Interp *,
struct PackFile_ConstTable *);
-static void PackFile_Constant_dump(Interp *,
+static void PackFile_Constant_dump(Interp *, struct PackFile_ConstTable *ct,
struct PackFile_Constant *);
void PackFile_Fixup_dump(Interp *,
struct PackFile_FixupTable *ft);
@@ -55,14 +55,14 @@
for (i = 0; i < self->const_count; i++) {
PIO_printf(interp, " # %ld:\n", (long)i);
- PackFile_Constant_dump(interp, self->constants[i]);
+ PackFile_Constant_dump(interp, self, self->constants[i]);
}
}
/*
=item C<void
-PackFile_Constant_dump(Interp *interp,
+PackFile_Constant_dump(Interp *interp, struct PackFile_ConstTable *ct
struct PackFile_Constant *self)>
Dumps the constant C<self>.
@@ -72,9 +72,15 @@
*/
void
-PackFile_Constant_dump(Interp *interp,
+PackFile_Constant_dump(Interp *interp, struct PackFile_ConstTable *ct,
struct PackFile_Constant *self)
{
+ struct PMC *key;
+ size_t i;
+ size_t ct_index;
+ opcode_t slice_bits;
+ struct PackFile_Constant *detail;
+
switch (self->type) {
case PFC_NUMBER:
@@ -97,9 +103,83 @@
break;
case PFC_KEY:
- PIO_printf(interp, " [ 'PFC_KEY', {\n");
- PIO_printf(interp, " ??? TODO \n");
- PIO_printf(interp, " } ],\n");
+ PIO_printf(interp, " [ 'PFC_KEY");
+ for (i = 0, key = self->u.key; key; key = PMC_data(key), i++)
+ ;
+ /* number of key components */
+ PIO_printf(interp, " %ld items\n", i);
+ /* and now type / value per component */
+ for (key = self->u.key; key; key = PMC_data(key)) {
+ PIO_printf(interp, " {\n");
+ opcode_t type = PObj_get_FLAGS(key);
+ slice_bits = 0;
+ if ((type & (KEY_start_slice_FLAG|KEY_inf_slice_FLAG)) ==
+ (KEY_start_slice_FLAG|KEY_inf_slice_FLAG))
+ PIO_printf(interp, " SLICE_BITS => PF_VT_END_INF\n");
+ if ((type & (KEY_end_slice_FLAG|KEY_inf_slice_FLAG)) ==
+ (KEY_end_slice_FLAG|KEY_inf_slice_FLAG))
+ slice_bits |= PF_VT_START_ZERO;
+ PIO_printf(interp, " SLICE_BITS =>
PF_VT_START_ZERO\n");
+ if (type & KEY_start_slice_FLAG)
+ slice_bits |= PF_VT_START_SLICE;
+ PIO_printf(interp, " SLICE_BITS =>
PF_VT_START_SLICE\n");
+ if (type & KEY_end_slice_FLAG)
+ slice_bits |= PF_VT_END_SLICE;
+ PIO_printf(interp, " SLICE_BITS => PF_VT_END_SLICE\n");
+
+ type &= KEY_type_FLAGS;
+ PIO_printf(interp, " FLAGS => 0x%04lx,\n",
(long)PObj_get_FLAGS(key));
+ switch (type) {
+ case KEY_integer_FLAG:
+ PIO_printf(interp, " TYPE => INTEGER\n");
+ PIO_printf(interp, " DATA => %ld\n",
PMC_int_val(key));
+ PIO_printf(interp, " },\n");
+ break;
+ case KEY_number_FLAG:
+ PIO_printf(interp, " TYPE => NUMBER\n");
+ ct_index = PackFile_find_in_const(interp, ct, key,
PFC_NUMBER);
+ PIO_printf(interp, " PFC_OFFSET => %ld\n",
ct_index);
+ detail = ct->constants[ct_index];
+ PIO_printf(interp, " DATA => %ld\n",
detail->u.number);
+ PIO_printf(interp, " },\n");
+ break;
+ case KEY_string_FLAG:
+ PIO_printf(interp, " TYPE => STRING\n");
+ ct_index = PackFile_find_in_const(interp, ct, key,
PFC_STRING);
+ PIO_printf(interp, " PFC_OFFSET => %ld\n",
ct_index);
+ detail = ct->constants[ct_index];
+ PIO_printf(interp, " DATA => '%.*s'\n",
+ (int)detail->u.string->bufused,
+ (char *)detail->u.string->strstart);
+ PIO_printf(interp, " },\n");
+ break;
+ case KEY_integer_FLAG | KEY_register_FLAG:
+ PIO_printf(interp, " TYPE => I REGISTER\n");
+ PIO_printf(interp, " DATA => %ld\n",
PMC_int_val(key));
+ PIO_printf(interp, " },\n");
+ break;
+ case KEY_number_FLAG | KEY_register_FLAG:
+ PIO_printf(interp, " TYPE => N REGISTER\n");
+ PIO_printf(interp, " DATA => %ld\n",
PMC_int_val(key));
+ PIO_printf(interp, " },\n");
+ break;
+ case KEY_string_FLAG | KEY_register_FLAG:
+ PIO_printf(interp, " TYPE => S REGISTER\n");
+ PIO_printf(interp, " DATA => %ld\n",
PMC_int_val(key));
+ PIO_printf(interp, " },\n");
+ break;
+ case KEY_pmc_FLAG | KEY_register_FLAG:
+ PIO_printf(interp, " TYPE => P REGISTER\n");
+ PIO_printf(interp, " DATA => %ld\n",
PMC_int_val(key));
+ PIO_printf(interp, " },\n");
+ break;
+ default:
+ PIO_eprintf(NULL, "PackFile_Constant_pack: "
+ "unsupported constant type\n");
+ Parrot_exit(interp, 1);
+ }
+ }
+ PIO_printf(interp, " ],\n");
break;
case PFC_PMC:
PIO_printf(interp, " [ 'PFC_PMC', {\n");
@@ -108,27 +188,65 @@
parrot_sub_t sub;
STRING *a_key = const_string(interp, "(keyed)");
STRING *null = const_string(interp, "(null)");
+ STRING *namespace_description;
opcode_t *code_start =
interp->code->base.data;
switch (pmc->vtable->base_type) {
+ case enum_class_FixedBooleanArray:
+ case enum_class_FixedFloatArray:
+ case enum_class_FixedPMCArray:
+ case enum_class_FixedStringArray:
+ case enum_class_ResizableBooleanArray:
+ case enum_class_ResizableIntegerArray:
+ case enum_class_ResizableFloatArray:
+ case enum_class_ResizablePMCArray:
+ case enum_class_ResizableStringArray:
+ {
+ int i;
+ int n = VTABLE_get_integer(interp, pmc);
+ STRING* out_buffer = VTABLE_get_repr(interp, pmc);
+ PIO_printf(interp,
+ "\tclass => %Ss,\n"
+ "\telement count => %d,\n"
+ "\telements => %Ss,\n",
+ pmc->vtable->whoami,
+ n,
+ out_buffer
+ );
+ }
+ break;
case enum_class_Sub:
case enum_class_Coroutine:
sub = PMC_sub(pmc);
+ if (sub->namespace) {
+ switch (sub->namespace->vtable->base_type) {
+ case enum_class_String:
+ namespace_description =
string_from_cstring(interp, "'", 1);
+ namespace_description = string_append(interp,
namespace_description, PMC_str_val(sub->namespace));
+ namespace_description = string_append(interp,
namespace_description, string_from_cstring(interp, "'", 1));
+ break;
+ case enum_class_Key:
+ namespace_description =
key_set_to_string(interp, sub->namespace);
+ break;
+ default:
+ namespace_description =
sub->namespace->vtable->whoami;
+ }
+ } else {
+ namespace_description = null;
+ }
PIO_printf(interp,
"\tclass => %Ss,\n"
"\tstart_offs => %d,\n"
"\tend_offs => %d,\n"
"\tname => '%Ss',\n"
- "\tnamespace => '%Ss'\n",
+ "\tnamespace => %Ss\n"
+ "\tHLL_id => %d,\n",
pmc->vtable->whoami,
sub->start_offs,
sub->end_offs,
sub->name,
- sub->namespace ?
- (sub->namespace->vtable->base_type ==
- enum_class_String ?
- PMC_str_val(sub->namespace) : a_key) :
- null
+ namespace_description,
+ sub->HLL_id
);
break;
case enum_class_FixedIntegerArray:
@@ -140,7 +258,7 @@
);
break;
default:
- PIO_printf(interp, "\tunknown PMC\n");
+ PIO_printf(interp, "\tno dump info for PMC %ld %Ss\n",
pmc->vtable->base_type, pmc->vtable->whoami);
PIO_printf(interp, "\tclass => %Ss,\n",
pmc->vtable->whoami);
}
}
Modified: trunk/src/packout.c
==============================================================================
--- trunk/src/packout.c (original)
+++ trunk/src/packout.c Fri Jan 5 21:31:27 2007
@@ -151,8 +151,6 @@
*/
-static struct PackFile_ConstTable *ct;
-
opcode_t *
PackFile_ConstTable_pack(Interp *interp,
struct PackFile_Segment *seg, opcode_t *cursor)
@@ -160,14 +158,10 @@
struct PackFile_ConstTable * const self = (struct PackFile_ConstTable
*)seg;
opcode_t i;
- /* remember const_table for find_in_const */
- ct = self;
-
*cursor++ = self->const_count;
for (i = 0; i < self->const_count; i++) {
- cursor = PackFile_Constant_pack(interp,
- self->constants[i], cursor);
+ cursor = PackFile_Constant_pack(interp, self, self->constants[i],
cursor);
}
return cursor;
@@ -185,8 +179,8 @@
*/
-static int
-find_in_const(Interp *interp, PMC *key, int type)
+int
+PackFile_find_in_const(Interp *interp, struct PackFile_ConstTable *ct, PMC
*key, int type)
{
int i;
for (i = 0; i < ct->const_count; i++)
@@ -204,8 +198,8 @@
/*
=item C<opcode_t *
-PackFile_Constant_pack(Interp*, struct PackFile_Constant *self,
- opcode_t *cursor)>
+PackFile_Constant_pack(Interp*, struct PackFile_ConstTable * const_table,
+ struct PackFile_Constant *self, opcode_t *cursor)>
Pack a PackFile Constant into a contiguous region of memory.
@@ -223,7 +217,7 @@
*/
opcode_t *
-PackFile_Constant_pack(Interp* interp,
+PackFile_Constant_pack(Interp* interp, struct PackFile_ConstTable *
const_table,
struct PackFile_Constant *self, opcode_t *cursor)
{
struct PMC *key;
@@ -278,12 +272,12 @@
case KEY_number_FLAG:
*cursor++ = PARROT_ARG_NC | slice_bits;
/* Argh */
- *cursor++ = find_in_const(interp, key, PFC_NUMBER);
+ *cursor++ = PackFile_find_in_const(interp, const_table,
key, PFC_NUMBER);
break;
case KEY_string_FLAG:
*cursor++ = PARROT_ARG_SC | slice_bits;
/* Argh */
- *cursor++ = find_in_const(interp, key, PFC_STRING);
+ *cursor++ = PackFile_find_in_const(interp, const_table,
key, PFC_STRING);
break;
case KEY_integer_FLAG | KEY_register_FLAG: