Author: kjs
Date: Sat Dec 27 11:02:09 2008
New Revision: 34435
Modified:
trunk/compilers/pirc/new/bcgen.h
trunk/compilers/pirc/new/pircompunit.c
trunk/compilers/pirc/new/pircompunit.h
trunk/compilers/pirc/new/piremit.c
trunk/compilers/pirc/new/pirsymbol.c
Log:
[pirc] refactoring of sub structure.
Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h (original)
+++ trunk/compilers/pirc/new/bcgen.h Sat Dec 27 11:02:09 2008
@@ -18,13 +18,13 @@
* generator needs to know.
*/
typedef struct sub_info {
- char const * const subname;
- char const * const nsentry;
- char const * const subid;
- int vtable_index;
- unsigned regs_used[4];
- int startoffset;
- int endoffset;
+ char const * subname;
+ char const * nsentry;
+ char const * subid;
+ int vtable_index;
+ unsigned regs_used[4];
+ int startoffset;
+ int endoffset;
} sub_info;
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Sat Dec 27 11:02:09 2008
@@ -140,7 +140,7 @@
int vtable_index;
if (vtablename == NULL) /* the sub's name I<is> the vtablename */
- vtablename = CURRENT_SUB(lexer)->sub_name;
+ vtablename = CURRENT_SUB(lexer)->info.subname;
/* get the index number of this vtable method */
vtable_index = Parrot_get_vtable_index(lexer->interp,
@@ -152,7 +152,7 @@
yypirerror(lexer->yyscanner, lexer,
"'%s' is not a vtable method but was used with :vtable
flag", vtablename);
else {
- CURRENT_SUB(lexer)->vtable_index = vtable_index;
+ CURRENT_SUB(lexer)->info.vtable_index = vtable_index;
SET_FLAG(lexer->subs->flags, SUB_FLAG_VTABLE);
}
}
@@ -169,7 +169,7 @@
*/
void
set_sub_subid(lexer_state * const lexer, char const * const subid) {
- CURRENT_SUB(lexer)->subid = subid;
+ CURRENT_SUB(lexer)->info.subid = subid;
SET_FLAG(lexer->subs->flags, SUB_FLAG_SUBID);
}
@@ -189,7 +189,7 @@
if (methodname) /* :method("foo") */
CURRENT_SUB(lexer)->methodname = methodname;
else /* :method without a value defaults to the subname. */
- CURRENT_SUB(lexer)->methodname = CURRENT_SUB(lexer)->sub_name;
+ CURRENT_SUB(lexer)->methodname = CURRENT_SUB(lexer)->info.subname;
SET_FLAG(lexer->subs->flags, SUB_FLAG_METHOD);
}
@@ -223,7 +223,7 @@
*/
void
set_sub_nsentry(lexer_state * const lexer, char const * const nsentry) {
- CURRENT_SUB(lexer)->nsentry = nsentry;
+ CURRENT_SUB(lexer)->info.nsentry = nsentry;
}
/*
@@ -264,25 +264,25 @@
int index;
/* set the sub fields */
- newsub->sub_name = subname;
+ newsub->info.subname = subname;
/* set default lexid */
- newsub->subid = subname;
+ newsub->info.subid = subname;
/* take namespace of this sub of the lexer, which keeps track of that */
- newsub->name_space = lexer->current_ns;
+ newsub->name_space = lexer->current_ns;
- newsub->parameters = NULL;
- newsub->statements = NULL;
- newsub->flags = 0;
- newsub->startoffset = lexer->codesize; /* start offset in bytecode */
+ newsub->parameters = NULL;
+ newsub->statements = NULL;
+ newsub->flags = 0;
+ newsub->info.startoffset = lexer->codesize; /* start offset in bytecode */
init_hashtable(lexer, &newsub->symbols, HASHTABLE_SIZE_INIT);
init_hashtable(lexer, &newsub->labels, HASHTABLE_SIZE_INIT);
for (index = 0; index < NUM_PARROT_TYPES; ++index) {
- newsub->registers[index] = NULL; /* set all "register" tables to NULL
*/
- newsub->regs_used[index] = 0; /* set all register counts to 0 */
+ newsub->registers[index] = NULL; /* set all "register" tables to
NULL */
+ newsub->info.regs_used[index] = 0; /* set all register counts to 0
*/
}
/* link the new sub node into the list of subroutines */
@@ -318,7 +318,7 @@
*/
void
set_sub_name(struct lexer_state * const lexer, char const * const subname) {
- CURRENT_SUB(lexer)->sub_name = subname;
+ CURRENT_SUB(lexer)->info.subname = subname;
}
@@ -2398,7 +2398,7 @@
fixup_local_labels(lexer);
/* store end offset in bytecode of this subroutine */
- CURRENT_SUB(lexer)->endoffset = lexer->codesize;
+ CURRENT_SUB(lexer)->info.endoffset = lexer->codesize;
/* if register allocation was requested, do that now */
if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
@@ -2420,7 +2420,7 @@
update_sub_register_usage(lexer_state * const lexer, unsigned
reg_usage[NUM_PARROT_TYPES]) {
int i;
for (i = 0; i < NUM_PARROT_TYPES; ++i)
- CURRENT_SUB(lexer)->regs_used[i] = reg_usage[i];
+ CURRENT_SUB(lexer)->info.regs_used[i] = reg_usage[i];
}
Modified: trunk/compilers/pirc/new/pircompunit.h
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.h (original)
+++ trunk/compilers/pirc/new/pircompunit.h Sat Dec 27 11:02:09 2008
@@ -301,16 +301,11 @@
/* a sub */
typedef struct subroutine {
key *name_space; /* this sub's namespace */
- char const *sub_name; /* this sub's name */
+
char const *outer_sub; /* this sub's outer subroutine, if any
*/
- char const *subid; /* this sub's subid, if any */
- int vtable_index; /* index of vtable method this sub's
overriding, if any */
char const *instanceof; /* XXX document this XXX */
- char const *nsentry; /* name by which the sub is stored in
the namespace */
char const *methodname; /* name of this sub by which it's
stored as a method */
int flags; /* this sub's flags */
- int startoffset; /* start offset in bytecode where this
sub starts */
- int endoffset; /* end offset in bytecode where this
sub ends */
sub_info info;
@@ -324,7 +319,6 @@
hashtable labels; /* local labels */
struct pir_reg *registers[4]; /* used PIR registers in this sub (1
list for each type) */
- unsigned regs_used[4]; /* number of PASM registers allocated
for this sub */
struct subroutine *next; /* pointer to next subroutine in the
list */
Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c (original)
+++ trunk/compilers/pirc/new/piremit.c Sat Dec 27 11:02:09 2008
@@ -297,7 +297,7 @@
}
- fprintf(out, "%s:\n", subiter->sub_name);
+ fprintf(out, "%s:\n", subiter->info.subname);
print_statement(lexer, subiter);
subiter = subiter->next;
}
@@ -344,7 +344,7 @@
fprintf(out, "\n.namespace ");
print_key(lexer, subiter->name_space);
- fprintf(out, "\n.sub %s", subiter->sub_name);
+ fprintf(out, "\n.sub %s", subiter->info.subname);
for (i = 0; i < BIT(i); i++) {
if (TEST_FLAG(subiter->flags, BIT(i))) {
@@ -556,16 +556,16 @@
/* iterate over all instructions and emit them */
do {
fprintf(stderr, "start offset of sub '%s' is: %d\tend offest: %d\n",
- subiter->sub_name, subiter->startoffset,
subiter->endoffset);
+ subiter->info.subname, subiter->info.startoffset,
subiter->info.endoffset);
add_sub_pmc(lexer->bc,
- subiter->sub_name,
- subiter->nsentry,
- subiter->subid,
- subiter->vtable_index,
- subiter->regs_used,
- subiter->startoffset,
- subiter->endoffset);
+ subiter->info.subname,
+ subiter->info.nsentry,
+ subiter->info.subid,
+ subiter->info.vtable_index,
+ subiter->info.regs_used,
+ subiter->info.startoffset,
+ subiter->info.endoffset);
emit_pbc_sub(lexer, subiter);
subiter = subiter->next;
Modified: trunk/compilers/pirc/new/pirsymbol.c
==============================================================================
--- trunk/compilers/pirc/new/pirsymbol.c (original)
+++ trunk/compilers/pirc/new/pirsymbol.c Sat Dec 27 11:02:09 2008
@@ -63,7 +63,7 @@
*/
static int
next_register(NOTNULL(lexer_state * const lexer), pir_type type) {
- CURRENT_SUB(lexer)->regs_used[type]++; /* count number of registers used */
+ CURRENT_SUB(lexer)->info.regs_used[type]++; /* count number of registers
used */
return lexer->curregister[type]++;
}
@@ -261,7 +261,7 @@
while (b) {
if (bucket_symbol(b)->info.color == NO_REG_ALLOCATED)
fprintf(stderr, "Warning: in sub '%s': symbol '%s'
declared but not used\n",
- subiter->sub_name,
bucket_symbol(b)->info.id.name);
+ subiter->info.subname,
bucket_symbol(b)->info.id.name);
b = b->next;
}
@@ -688,7 +688,7 @@
/* no label found, emit an error message. */
yypirerror(lexer->yyscanner, lexer, "in sub '%s': cannot find offset for
label '%s'",
- CURRENT_SUB(lexer)->sub_name, labelname);
+ CURRENT_SUB(lexer)->info.subname, labelname);
return 0;
}