Author: kjs
Date: Fri Dec 19 04:52:21 2008
New Revision: 34101
Modified:
trunk/compilers/pirc/new/bcgen.c
trunk/compilers/pirc/new/bcgen.h
trunk/compilers/pirc/new/pircompiler.c
trunk/compilers/pirc/new/pirsymbol.c
Log:
[pirc] refactor of codesegment creation which is needed to get things working
in future.
+ add runtime checks for lin.scan.reg.alloc; only if it's requested create the
data structures. The tests are worth it, as they are only simple checks
(probably 1 or 2 machine instructions), whereas data structure creation will
invoke memory allocators, which is much more painful.
Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c (original)
+++ trunk/compilers/pirc/new/bcgen.c Fri Dec 19 04:52:21 2008
@@ -209,16 +209,46 @@
self = VTABLE_get_pmc_keyed_int(interp, interp->iglobals,
IGLOBALS_INTERPRETER);
add_pmc_const(bc, self);
+ create_codesegment(bc, codesize);
+
+ return bc;
+}
+
+/*
+
+Create a code segment of size C<codesize>.
+
+*/
+void
+create_codesegment(bytecode * const bc, int codesize) {
/* allocate enough space. XXX I *think* bytes is /always/ codesize * 4. */
- interp->code->base.data = (opcode_t
*)mem_sys_realloc(interp->code->base.data, bytes);
- interp->code->base.size = codesize;
+ bc->interp->code->base.data = (opcode_t
*)mem_sys_realloc(bc->interp->code->base.data,
+ codesize * 4);
+
+ bc->interp->code->base.size = codesize;
/* initialize the cursor to write opcodes into the code segment */
- bc->opcursor = (opcode_t *)interp->code->base.data;
+ bc->opcursor = (opcode_t *)bc->interp->code->base.data;
+}
- return bc;
+/*
+
+=item C<void
+destroy_bytecode(bytecode * bc)>
+
+Destructor for bytecode struct; frees all memory.
+
+=cut
+
+*/
+void
+destroy_bytecode(bytecode * bc) {
+ /* XXX should we do this? Not Parrot? */
+ mem_sys_free(bc->interp->code->base.data);
+ mem_sys_free(bc);
}
+
/*
=item C<void
Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h (original)
+++ trunk/compilers/pirc/new/bcgen.h Fri Dec 19 04:52:21 2008
@@ -16,6 +16,9 @@
bytecode *new_bytecode(Interp *interp, char const * const filename, int bytes,
int codesize);
+
+void create_codesegment(bytecode * const bc, int codesize);
+
/* call this to write the PBC file */
void write_pbc_file(bytecode * const bc, char const * const filename) ;
Modified: trunk/compilers/pirc/new/pircompiler.c
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.c (original)
+++ trunk/compilers/pirc/new/pircompiler.c Fri Dec 19 04:52:21 2008
@@ -181,8 +181,9 @@
lexer->macros = new_macro_table(NULL);
lexer->macro_size = INIT_MACRO_SIZE;
- /* create a new linear scan register allocator */
- lexer->lsr = new_linear_scan_register_allocator(lexer);
+ /* create a new linear scan register allocator, if requested */
+ if (TEST_FLAG(flags, LEXER_FLAG_REGALLOC))
+ lexer->lsr = new_linear_scan_register_allocator(lexer);
return lexer;
}
Modified: trunk/compilers/pirc/new/pirsymbol.c
==============================================================================
--- trunk/compilers/pirc/new/pirsymbol.c (original)
+++ trunk/compilers/pirc/new/pirsymbol.c Fri Dec 19 04:52:21 2008
@@ -82,10 +82,12 @@
assign_vanilla_register(NOTNULL(lexer_state * const lexer), symbol * const
sym) {
sym->info.color = next_register(lexer, sym->info.type);
- sym->info.interval = new_live_interval(lexer->lsr, lexer->stmt_counter,
sym->info.type);
+ if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC)) {
+ sym->info.interval = new_live_interval(lexer->lsr,
lexer->stmt_counter, sym->info.type);
- /* set the reference of the interval to the symbol's color */
- sym->info.interval->color = &sym->info.color;
+ /* set the reference of the interval to the symbol's color */
+ sym->info.interval->color = &sym->info.color;
+ }
/* mark the interval, so that its register is not reused, if the
:unique_reg
* flag was set.
@@ -299,7 +301,8 @@
/* get a new reg from vanilla reg. allocator */
assign_vanilla_register(lexer, sym);
else /* update end point of interval */
- sym->info.interval->endpoint = lexer->stmt_counter;
+ if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
+ sym->info.interval->endpoint = lexer->stmt_counter;
if (TEST_FLAG(lexer->flags, LEXER_FLAG_VERBOSE))
@@ -361,7 +364,9 @@
while (iter != NULL) {
if (iter->info.id.regno == regno) {
/* update the end point of this register's live interval */
- iter->info.interval->endpoint = lexer->stmt_counter;
+ if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
+ iter->info.interval->endpoint = lexer->stmt_counter;
+
return iter;
}
@@ -403,9 +408,12 @@
reg->info.color = pasmregno;
/* create a new live interval for this symbolic register */
- reg->info.interval = new_live_interval(lexer->lsr, lexer->stmt_counter,
type);
- /* let the interval have a pointer to this symbolic register */
- reg->info.interval->color = ®->info.color;
+ if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC)) {
+ reg->info.interval = new_live_interval(lexer->lsr,
lexer->stmt_counter, type);
+
+ /* let the interval have a pointer to this symbolic register */
+ reg->info.interval->color = ®->info.color;
+ }
/* link this register into the list of "colored" registers; each of
@@ -465,7 +473,9 @@
*/
if (reg) {
/* update end point of interval */
- reg->info.interval->endpoint = lexer->stmt_counter;
+ if (TEST_FLAG(lexer->flags, LEXER_FLAG_REGALLOC))
+ reg->info.interval->endpoint = lexer->stmt_counter;
+
return reg->info.color;
}
@@ -678,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)->sub_name, labelname);
return 0;
}