[svn:parrot] r49216 - branches/typesafe_consttable/src
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Wed Sep 22 00:41:37 UTC 2010
Author: plobsing
Date: Wed Sep 22 00:41:36 2010
New Revision: 49216
URL: https://trac.parrot.org/parrot/changeset/49216
Log:
fix pbc_merge, pbc_dump, and pbc_disassemble
Modified:
branches/typesafe_consttable/src/embed.c
branches/typesafe_consttable/src/packdump.c
branches/typesafe_consttable/src/pbc_merge.c
Modified: branches/typesafe_consttable/src/embed.c
==============================================================================
--- branches/typesafe_consttable/src/embed.c Tue Sep 21 23:07:16 2010 (r49215)
+++ branches/typesafe_consttable/src/embed.c Wed Sep 22 00:41:36 2010 (r49216)
@@ -928,7 +928,6 @@
}
Parrot_io_fprintf(interp, output, "\n");
- break;
}
Parrot_io_fprintf(interp, output, "\n=cut\n\n");
Modified: branches/typesafe_consttable/src/packdump.c
==============================================================================
--- branches/typesafe_consttable/src/packdump.c Tue Sep 21 23:07:16 2010 (r49215)
+++ branches/typesafe_consttable/src/packdump.c Wed Sep 22 00:41:36 2010 (r49216)
@@ -29,9 +29,16 @@
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-static void PackFile_Constant_dump(PARROT_INTERP,
+static void PackFile_Constant_dump_pmc(PARROT_INTERP,
ARGIN(const PackFile_ConstTable *ct),
- ARGIN(const PackFile_Constant *self))
+ ARGIN(PMC *self))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
+static void PackFile_Constant_dump_str(PARROT_INTERP,
+ ARGIN(const PackFile_ConstTable *ct),
+ ARGIN(const STRING *self))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
__attribute__nonnull__(3);
@@ -39,7 +46,11 @@
static void pobj_flag_dump(PARROT_INTERP, long flags)
__attribute__nonnull__(1);
-#define ASSERT_ARGS_PackFile_Constant_dump __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+#define ASSERT_ARGS_PackFile_Constant_dump_pmc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(ct) \
+ , PARROT_ASSERT_ARG(self))
+#define ASSERT_ARGS_PackFile_Constant_dump_str __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(ct) \
, PARROT_ASSERT_ARG(self))
@@ -67,9 +78,19 @@
ASSERT_ARGS(PackFile_ConstTable_dump)
opcode_t i;
- for (i = 0; i < self->const_count; ++i) {
+ for (i = 0; i < self->num.const_count; i++) {
+ Parrot_io_printf(interp, " # %x:\n", (long)i);
+ Parrot_io_printf(interp, " [ 'PFC_NUMBER', %g ],\n", self->num.constants[i]);
+ }
+
+ for (i = 0; i < self->str.const_count; i++) {
+ Parrot_io_printf(interp, " # %x:\n", (long)i);
+ PackFile_Constant_dump_str(interp, self, self->str.constants[i]);
+ }
+
+ for (i = 0; i < self->pmc.const_count; i++) {
Parrot_io_printf(interp, " # %x:\n", (long)i);
- PackFile_Constant_dump(interp, self, &self->constants[i]);
+ PackFile_Constant_dump_pmc(interp, self, self->pmc.constants[i]);
}
}
@@ -153,41 +174,36 @@
}
static void
-PackFile_Constant_dump(PARROT_INTERP, ARGIN(const PackFile_ConstTable *ct),
- ARGIN(const PackFile_Constant *self))
+PackFile_Constant_dump_str(PARROT_INTERP, ARGIN(const PackFile_ConstTable *ct),
+ ARGIN(const STRING *self))
{
- ASSERT_ARGS(PackFile_Constant_dump)
- PMC *key;
- size_t i;
-
- switch (self->type) {
-
- case PFC_NUMBER:
- Parrot_io_printf(interp, " [ 'PFC_NUMBER', %g ],\n", self->u.number);
- break;
-
- case PFC_STRING:
- Parrot_io_printf(interp, " [ 'PFC_STRING', {\n");
- pobj_flag_dump(interp, (long)PObj_get_FLAGS(self->u.string));
- Parrot_io_printf(interp, " ENCODING => %ld,\n",
- self->u.string->encoding);
- i = self->u.string->bufused;
- Parrot_io_printf(interp, " SIZE => %ld,\n",
- (long)i);
+ ASSERT_ARGS(PackFile_Constant_dump_str)
- Parrot_io_printf(interp, " DATA => \"%Ss\"\n",
- Parrot_str_escape(interp, self->u.string));
- Parrot_io_printf(interp, " } ],\n");
- break;
+ Parrot_io_printf(interp, " [ 'PFC_STRING', {\n");
+ pobj_flag_dump(interp, (long)PObj_get_FLAGS(self));
+ Parrot_io_printf(interp, " ENCODING => %ld,\n", self->encoding);
+ Parrot_io_printf(interp, " SIZE => %ld,\n", self->bufused);
+ Parrot_io_printf(interp, " DATA => \"%Ss\"\n",
+ Parrot_str_escape(interp, self));
+ Parrot_io_printf(interp, " } ],\n");
+}
+
+static void
+PackFile_Constant_dump_pmc(PARROT_INTERP, ARGIN(const PackFile_ConstTable *ct),
+ ARGIN(PMC *self))
+{
+ ASSERT_ARGS(PackFile_Constant_dump_pmc)
- case PFC_KEY:
- for (i = 0, key = self->u.key; key; ++i) {
+ if (self->vtable->base_type == enum_class_Key) {
+ size_t i;
+ PMC *key;
+ for (i = 0, key = self; key; i++) {
GETATTR_Key_next_key(interp, key, key);
}
/* number of key components */
Parrot_io_printf(interp, " [ 'PFC_KEY' (%ld items)\n", i);
/* and now type / value per component */
- for (key = self->u.key; key;) {
+ for (key = self; key;) {
opcode_t type = PObj_get_FLAGS(key);
Parrot_io_printf(interp, " {\n");
@@ -203,28 +219,25 @@
break;
case KEY_number_FLAG:
{
- const PackFile_Constant *detail;
size_t ct_index;
Parrot_io_printf(interp, " TYPE => NUMBER\n");
ct_index = PackFile_find_in_const(interp, ct, key, PFC_NUMBER);
Parrot_io_printf(interp, " PFC_OFFSET => %ld\n", ct_index);
- detail = &ct->constants[ct_index];
- Parrot_io_printf(interp, " DATA => %ld\n", detail->u.number);
+ Parrot_io_printf(interp, " DATA => %ld\n",
+ ct->num.constants[ct_index]);
Parrot_io_printf(interp, " },\n");
}
break;
case KEY_string_FLAG:
{
- const PackFile_Constant *detail;
size_t ct_index;
Parrot_io_printf(interp, " TYPE => STRING\n");
ct_index = PackFile_find_in_const(interp, ct, key, PFC_STRING);
Parrot_io_printf(interp, " PFC_OFFSET => %ld\n", ct_index);
- detail = &ct->constants[ct_index];
Parrot_io_printf(interp, " DATA => '%Ss'\n",
- detail->u.string);
+ ct->str.constants[ct_index]);
Parrot_io_printf(interp, " },\n");
}
break;
@@ -260,109 +273,102 @@
GETATTR_Key_next_key(interp, key, key);
}
Parrot_io_printf(interp, " ],\n");
- break;
- case PFC_PMC:
+ }
+ else {
+ Parrot_Sub_attributes *sub;
+ STRING * const null = Parrot_str_new_constant(interp, "(null)");
+ STRING *namespace_description;
+
Parrot_io_printf(interp, " [ 'PFC_PMC', {\n");
- {
- PMC * const pmc = self->u.key;
- Parrot_Sub_attributes *sub;
- STRING * const null = Parrot_str_new_constant(interp, "(null)");
- STRING *namespace_description;
-
- pobj_flag_dump(interp, (long)PObj_get_FLAGS(pmc));
- 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:
+ pobj_flag_dump(interp, (long)PObj_get_FLAGS(self));
+ switch (self->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:
{
- const int n = VTABLE_get_integer(interp, pmc);
- STRING* const out_buffer = VTABLE_get_repr(interp, pmc);
+ const int n = VTABLE_get_integer(interp, self);
+ STRING* const out_buffer = VTABLE_get_repr(interp, self);
Parrot_io_printf(interp,
"\t\tclass => %Ss,\n"
"\t\telement count => %d,\n"
"\t\telements => %Ss,\n",
- pmc->vtable->whoami,
+ self->vtable->whoami,
n,
out_buffer);
}
break;
- case enum_class_Sub:
- case enum_class_Coroutine:
- PMC_get_sub(interp, pmc, sub);
+ case enum_class_Sub:
+ case enum_class_Coroutine:
+ PMC_get_sub(interp, self, sub);
if (sub->namespace_name) {
switch (sub->namespace_name->vtable->base_type) {
- case enum_class_String:
- namespace_description = Parrot_str_new(interp, "'", 1);
- namespace_description = Parrot_str_concat(interp,
- namespace_description,
- VTABLE_get_string(interp, sub->namespace_name));
- namespace_description = Parrot_str_concat(interp,
- namespace_description,
- Parrot_str_new(interp, "'", 1));
- break;
- case enum_class_Key:
- namespace_description =
- key_set_to_string(interp, sub->namespace_name);
- break;
- default:
- namespace_description = sub->namespace_name->vtable->whoami;
+ case enum_class_String:
+ namespace_description = Parrot_str_new(interp, "'", 1);
+ namespace_description = Parrot_str_concat(interp,
+ namespace_description,
+ VTABLE_get_string(interp, sub->namespace_name));
+ namespace_description = Parrot_str_concat(interp,
+ namespace_description,
+ Parrot_str_new(interp, "'", 1));
+ break;
+ case enum_class_Key:
+ namespace_description =
+ key_set_to_string(interp, sub->namespace_name);
+ break;
+ default:
+ namespace_description = sub->namespace_name->vtable->whoami;
}
}
else {
namespace_description = null;
}
Parrot_io_printf(interp,
- "\t\tclass => %Ss,\n"
- "\t\tstart_offs => %d,\n"
- "\t\tend_offs => %d,\n"
- "\t\tname => '%Ss',\n"
- "\t\tsubid => '%Ss',\n"
- "\t\tmethod => '%Ss',\n"
- "\t\tnsentry => '%Ss',\n"
- "\t\tnamespace => %Ss,\n"
- "\t\tHLL_id => %d,\n"
- "\t\tn_regs_used => [ %d, %d, %d, %d ],\n",
- pmc->vtable->whoami,
- sub->start_offs,
- sub->end_offs,
- sub->name,
- sub->subid,
- sub->method_name,
- sub->ns_entry_name,
- namespace_description,
- sub->HLL_id,
- sub->n_regs_used[0],
- sub->n_regs_used[1],
- sub->n_regs_used[2],
- sub->n_regs_used[3]);
+ "\t\tclass => %Ss,\n"
+ "\t\tstart_offs => %d,\n"
+ "\t\tend_offs => %d,\n"
+ "\t\tname => '%Ss',\n"
+ "\t\tsubid => '%Ss',\n"
+ "\t\tmethod => '%Ss',\n"
+ "\t\tnsentry => '%Ss',\n"
+ "\t\tnamespace => %Ss,\n"
+ "\t\tHLL_id => %d,\n"
+ "\t\tn_regs_used => [ %d, %d, %d, %d ],\n",
+ self->vtable->whoami,
+ sub->start_offs,
+ sub->end_offs,
+ sub->name,
+ sub->subid,
+ sub->method_name,
+ sub->ns_entry_name,
+ namespace_description,
+ sub->HLL_id,
+ sub->n_regs_used[0],
+ sub->n_regs_used[1],
+ sub->n_regs_used[2],
+ sub->n_regs_used[3]);
break;
- case enum_class_FixedIntegerArray:
+ case enum_class_FixedIntegerArray:
Parrot_io_printf(interp,
- "\t\tclass => %Ss,\n"
- "\t\trepr => '%Ss'\n",
- pmc->vtable->whoami,
- VTABLE_get_repr(interp, pmc));
+ "\t\tclass => %Ss,\n"
+ "\t\trepr => '%Ss'\n",
+ self->vtable->whoami,
+ VTABLE_get_repr(interp, self));
break;
- default:
+ default:
Parrot_io_printf(interp, "\t\tno dump info for PMC %ld %Ss\n",
- pmc->vtable->base_type, pmc->vtable->whoami);
- Parrot_io_printf(interp, "\t\tclass => %Ss,\n", pmc->vtable->whoami);
- }
+ self->vtable->base_type, self->vtable->whoami);
+ Parrot_io_printf(interp, "\t\tclass => %Ss,\n", self->vtable->whoami);
}
Parrot_io_printf(interp, " } ],\n");
- break;
- default:
- Parrot_io_printf(interp, " [ 'PFC_\?\?\?', type '0x%x' ],\n",
- self->type);
- break;
}
}
+
/*
Modified: branches/typesafe_consttable/src/pbc_merge.c
==============================================================================
--- branches/typesafe_consttable/src/pbc_merge.c Tue Sep 21 23:07:16 2010 (r49215)
+++ branches/typesafe_consttable/src/pbc_merge.c Wed Sep 22 00:41:36 2010 (r49216)
@@ -44,17 +44,18 @@
#include "parrot/oplib/core_ops.h"
#include "pmc/pmc_sub.h"
-
/* This struct describes an input file. */
typedef struct pbc_merge_input {
- const char *filename; /* name of the input file */
- PackFile *pf; /* loaded packfile struct */
- opcode_t code_start; /* where the bytecode is located in the merged
- packfile */
- opcode_t const_start;/* where the const table is located within the
- merged table */
- opcode_t *const_map; /* map constants from input files to their location
- in the output file */
+ const char *filename; /* name of the input file */
+ PackFile *pf; /* loaded packfile struct */
+ opcode_t code_start; /* where the bytecode is located in the merged
+ packfile */
+ struct {
+ opcode_t const_start; /* where the const table is located within the
+ merged table */
+ opcode_t *const_map; /* map constants from input files to their location
+ in the output file */
+ } num, str, pmc;
} pbc_merge_input;
/* HEADERIZER HFILE: none */
@@ -376,11 +377,15 @@
ARGMOD(PackFile_ByteCode *bc))
{
ASSERT_ARGS(pbc_merge_constants)
- PackFile_Constant *constants = mem_gc_allocate_typed(interp, PackFile_Constant);
- opcode_t cursor = 0;
- opcode_t output_const_num = 0;
- opcode_t input_const_num = 0;
+ FLOATVAL *num_constants = mem_gc_allocate_typed(interp, FLOATVAL);
+ STRING **str_constants = mem_gc_allocate_typed(interp, STRING *);
+ PMC **pmc_constants = mem_gc_allocate_typed(interp, PMC *);
+
+ opcode_t num_cursor = 0;
+ opcode_t str_cursor = 0;
+ opcode_t pmc_cursor = 0;
+
int i, j;
/* Add a constant table segment. */
@@ -407,51 +412,65 @@
}
/* Store cursor as position where constant table starts. */
- inputs[i]->const_start = cursor;
- input_const_num = 0;
+ inputs[i]->num.const_start = num_cursor;
+ inputs[i]->str.const_start = str_cursor;
+ inputs[i]->pmc.const_start = pmc_cursor;
/* Allocate space for the constant list, provided we have some. */
- if (in_seg->const_count > 0)
- constants = mem_gc_realloc_n_typed(interp, constants,
- cursor + in_seg->const_count, PackFile_Constant);
+ if (in_seg->num.const_count > 0)
+ num_constants = mem_gc_realloc_n_typed(interp, num_constants,
+ num_cursor + in_seg->num.const_count, FLOATVAL);
+ if (in_seg->str.const_count > 0)
+ str_constants = mem_gc_realloc_n_typed(interp, str_constants,
+ str_cursor + in_seg->str.const_count, STRING *);
+ if (in_seg->pmc.const_count > 0)
+ pmc_constants = mem_gc_realloc_n_typed(interp, pmc_constants,
+ pmc_cursor + in_seg->pmc.const_count, PMC *);
/* Loop over the constants and copy them to the output PBC. */
- for (j = 0; j < in_seg->const_count; ++j) {
- /* Get the entry and the copy. */
- PackFile_Constant *cur_entry = &in_seg->constants[j];
- PackFile_Constant *copy = &constants[cursor];
- STRUCT_COPY(copy, cur_entry);
+ for (j = 0; j < in_seg->num.const_count; j++) {
+ num_constants[num_cursor] = in_seg->num.constants[j];
+ inputs[i]->num.const_map[j] = num_cursor;
+ num_cursor++;
+ }
+
+ for (j = 0; j < in_seg->str.const_count; j++) {
+ str_constants[str_cursor] = in_seg->str.constants[j];
+ inputs[i]->str.const_map[j] = str_cursor;
+ str_cursor++;
+ }
+
+ for (j = 0; j < in_seg->pmc.const_count; j++) {
+ PMC *v = pmc_constants[pmc_cursor] = in_seg->pmc.constants[j];
+ inputs[i]->pmc.const_map[j] = pmc_cursor;
+ pmc_cursor++;
/* If it's a sub PMC, need to deal with offsets. */
- if (copy->type == PFC_PMC) {
- switch (copy->u.key->vtable->base_type) {
- case enum_class_Sub:
- case enum_class_Coroutine:
- {
- Parrot_Sub_attributes *sub;
- PMC_get_sub(interp, copy->u.key, sub);
- sub->start_offs += inputs[i]->code_start;
- sub->end_offs += inputs[i]->code_start;
- }
- break;
- default:
- break;
- }
+ switch (v->vtable->base_type) {
+ case enum_class_Sub:
+ case enum_class_Coroutine:
+ {
+ Parrot_Sub_attributes *sub;
+ PMC_get_sub(interp, v, sub);
+ sub->start_offs += inputs[i]->code_start;
+ sub->end_offs += inputs[i]->code_start;
+ }
+ break;
+ default:
+ break;
}
-
- inputs[i]->const_map[input_const_num] = output_const_num;
- ++input_const_num;
- ++output_const_num;
-
- ++cursor;
}
}
/* Stash merged constants table and count and return the new segment. */
- const_seg->constants = constants;
- const_seg->const_count = cursor;
- const_seg->code = bc;
- bc->const_table = const_seg;
+ const_seg->num.const_count = num_cursor;
+ const_seg->num.constants = num_constants;
+ const_seg->str.const_count = str_cursor;
+ const_seg->str.constants = str_constants;
+ const_seg->pmc.const_count = pmc_cursor;
+ const_seg->pmc.constants = pmc_constants;
+ const_seg->code = bc;
+ bc->const_table = const_seg;
return const_seg;
}
@@ -523,7 +542,7 @@
/* Set new offset and bytecode pointer. */
switch (copy->type) {
case enum_fixup_sub:
- copy->offset = cur_entry->offset + inputs[i]->const_start;
+ copy->offset = cur_entry->offset + inputs[i]->pmc.const_start;
break;
default:
Parrot_io_eprintf(interp, "PBC Merge: Unknown fixup type");
@@ -593,7 +612,7 @@
STRUCT_COPY_FROM_STRUCT(mapping, in_seg->mappings[j]);
mapping->offset += num_lines;
- mapping->filename += inputs[i]->const_start;
+ mapping->filename += inputs[i]->str.const_start;
}
num_lines += in_seg->base.size - 1;
@@ -724,12 +743,19 @@
/* Pick out any indexes into the constant table and correct them. */
switch (op->types[cur_arg - 1]) {
case PARROT_ARG_NC:
- case PARROT_ARG_PC:
+ ops[cur_op] = inputs[cur_input]->num.const_map[ ops[cur_op] ];
+ break;
+
case PARROT_ARG_SC:
case PARROT_ARG_NAME_SC:
+ ops[cur_op] = inputs[cur_input]->str.const_map[ ops[cur_op] ];
+ break;
+
+ case PARROT_ARG_PC:
case PARROT_ARG_KC:
- ops[cur_op] = inputs[cur_input]->const_map[ ops[cur_op] ];
+ ops[cur_op] = inputs[cur_input]->pmc.const_map[ ops[cur_op] ];
break;
+
default:
break;
}
@@ -745,19 +771,26 @@
op_func == core_ops->op_func_table[PARROT_OP_get_params_pc] ||
op_func == core_ops->op_func_table[PARROT_OP_set_returns_pc]) {
/* Get the signature. */
- PMC * const sig = bc->const_table->constants[op_ptr[1]].u.key;
+ PMC * const sig = bc->const_table->pmc.constants[op_ptr[1]];
/* Loop over the arguments to locate any that need a fixup. */
const int sig_items = VTABLE_elements(interp, sig);
for (cur_arg = 0; cur_arg < sig_items; ++cur_arg) {
switch (VTABLE_get_integer_keyed_int(interp, sig, cur_arg)) {
case PARROT_ARG_NC:
- case PARROT_ARG_PC:
+ ops[cur_op] = inputs[cur_input]->num.const_map[ ops[cur_op] ];
+ break;
+
case PARROT_ARG_SC:
case PARROT_ARG_NAME_SC:
+ ops[cur_op] = inputs[cur_input]->str.const_map[ ops[cur_op] ];
+ break;
+
+ case PARROT_ARG_PC:
case PARROT_ARG_KC:
- ops[cur_op] = inputs[cur_input]->const_map[ ops[cur_op] ];
+ ops[cur_op] = inputs[cur_input]->pmc.const_map[ ops[cur_op] ];
break;
+
default:
break;
}
@@ -802,9 +835,13 @@
for (j = 0; j < pf_dir->num_segments; ++j) {
PackFile_Segment *seg = (PackFile_Segment *)pf_dir->segments[j];
if (seg->type == PF_CONST_SEG) {
- opcode_t const_count = ((PackFile_ConstTable *)seg)->const_count;
- inputs[i]->const_map = mem_gc_allocate_n_typed(interp,
- const_count, opcode_t);
+ PackFile_ConstTable *ct = (PackFile_ConstTable *)seg;
+ inputs[i]->num.const_map = mem_gc_allocate_n_typed(interp, ct->num.const_count,
+ opcode_t);
+ inputs[i]->str.const_map = mem_gc_allocate_n_typed(interp, ct->str.const_count,
+ opcode_t);
+ inputs[i]->pmc.const_map = mem_gc_allocate_n_typed(interp, ct->pmc.const_count,
+ opcode_t);
}
}
}
@@ -821,7 +858,9 @@
pbc_fixup_bytecode(interp, inputs, num_inputs, bc);
for (i = 0; i < num_inputs; ++i) {
- mem_gc_free(interp, inputs[i]->const_map);
+ mem_gc_free(interp, inputs[i]->num.const_map);
+ mem_gc_free(interp, inputs[i]->str.const_map);
+ mem_gc_free(interp, inputs[i]->pmc.const_map);
}
/* Return merged result. */
More information about the parrot-commits
mailing list