Author: kjs
Date: Sat Dec 27 11:13:33 2008
New Revision: 34437

Modified:
   trunk/compilers/pirc/new/bcgen.c
   trunk/compilers/pirc/new/bcgen.h
   trunk/compilers/pirc/new/pircompiler.c
   trunk/compilers/pirc/new/piremit.c

Log:
[pirc] re-organize bytecode generation stuff a bit.
+ the bytecode struct is now created at the start, so we can add constants 
before generating bytecode.
+ creating a code segment is now done in a separate step, and should be done 
right before emiting bytecodes.


Modified: trunk/compilers/pirc/new/bcgen.c
==============================================================================
--- trunk/compilers/pirc/new/bcgen.c    (original)
+++ trunk/compilers/pirc/new/bcgen.c    Sat Dec 27 11:13:33 2008
@@ -203,17 +203,15 @@
 /*
 
 =item C<bytecode *
-new_bytecode(Interp *interp, char const * const filename, int bytes, int 
codesize)>
+new_bytecode(Interp *interp, char const * const filename)>
 
 Create a new bytecode struct, representing the bytecode for file C<filename>
 
-Create a new bytecode struct and return a pointer to it.
-
 =cut
 
 */
 bytecode *
-new_bytecode(Interp *interp, char const * const filename, int bytes, int 
codesize) {
+new_bytecode(Interp *interp, char const * const filename) {
     PMC      *self;
     bytecode *bc      = (bytecode *)mem_sys_allocate(sizeof (bytecode));
 
@@ -234,15 +232,18 @@
     self              = VTABLE_get_pmc_keyed_int(interp, interp->iglobals, 
IGLOBALS_INTERPRETER);
     add_pmc_const(bc, self);
 
-    create_codesegment(bc, codesize);
-
     return bc;
 }
 
 /*
 
+=item C<void
+create_codesegment(bytecode * const bc, int codesize)>
+
 Create a code segment of size C<codesize>.
 
+=cut
+
 */
 void
 create_codesegment(bytecode * const bc, int codesize) {
@@ -353,14 +354,7 @@
 /*
 
 =item C<void
-add_sub_pmc(bytecode * const bc,
-            char const * const subname,  -- the name of this sub
-            char const * const nsentry,  -- the value of the :nsentry flag
-            char const * const subid,    -- the value of the :subid flag
-            int vtable_index,            -- vtable index, or -1 if no :vtable
-            unsigned regs_used[],        -- register usage of this sub
-            int startoffset,             -- start offset of this sub in 
bytecode
-            int endoffset)>              -- end offset of this sub in bytecode
+add_sub_pmc(bytecode * const bc, sub_info *info)>
 
 Add a sub PMC to the constant table. This function initializes the sub PMC.
 

Modified: trunk/compilers/pirc/new/bcgen.h
==============================================================================
--- trunk/compilers/pirc/new/bcgen.h    (original)
+++ trunk/compilers/pirc/new/bcgen.h    Sat Dec 27 11:13:33 2008
@@ -28,7 +28,7 @@
 
 } sub_info;
 
-bytecode *new_bytecode(Interp *interp, char const * const filename, int bytes, 
int codesize);
+bytecode *new_bytecode(Interp *interp, char const * const filename);
 
 
 void create_codesegment(bytecode * const bc, int codesize);

Modified: trunk/compilers/pirc/new/pircompiler.c
==============================================================================
--- trunk/compilers/pirc/new/pircompiler.c      (original)
+++ trunk/compilers/pirc/new/pircompiler.c      Sat Dec 27 11:13:33 2008
@@ -185,6 +185,8 @@
     if (TEST_FLAG(flags, LEXER_FLAG_REGALLOC))
         lexer->lsr = new_linear_scan_register_allocator(lexer);
 
+    lexer->bc = new_bytecode(lexer->interp, filename);
+
     return lexer;
 }
 

Modified: trunk/compilers/pirc/new/piremit.c
==============================================================================
--- trunk/compilers/pirc/new/piremit.c  (original)
+++ trunk/compilers/pirc/new/piremit.c  Sat Dec 27 11:13:33 2008
@@ -546,8 +546,7 @@
 
     fprintf(stderr, "emit_pbc(): starting...\n");
 
-    lexer->bc = new_bytecode(lexer->interp, lexer->filename,
-                             lexer->codesize * 4, lexer->codesize);
+    create_codesegment(lexer->bc, lexer->codesize);
 
     fprintf(stderr, "ok 1\n");
     subiter = lexer->subs->next;

Reply via email to