[svn:parrot] r47685 - in branches/dynop_mapping: compilers/imcc include/parrot src

plobsing at svn.parrot.org plobsing at svn.parrot.org
Fri Jun 18 05:22:32 UTC 2010


Author: plobsing
Date: Fri Jun 18 05:22:31 2010
New Revision: 47685
URL: https://trac.parrot.org/parrot/changeset/47685

Log:
make room for optable index for 2-word-per-op bytecode mapping for dynops

Modified:
   branches/dynop_mapping/compilers/imcc/imc.c
   branches/dynop_mapping/include/parrot/packfile.h
   branches/dynop_mapping/src/packfile.c

Modified: branches/dynop_mapping/compilers/imcc/imc.c
==============================================================================
--- branches/dynop_mapping/compilers/imcc/imc.c	Fri Jun 18 03:58:07 2010	(r47684)
+++ branches/dynop_mapping/compilers/imcc/imc.c	Fri Jun 18 05:22:31 2010	(r47685)
@@ -50,7 +50,7 @@
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 /* HEADERIZER END: static */
 
-#define COMPILE_IMMEDIATE 0
+#define COMPILE_IMMEDIATE 1
 
 /*
 

Modified: branches/dynop_mapping/include/parrot/packfile.h
==============================================================================
--- branches/dynop_mapping/include/parrot/packfile.h	Fri Jun 18 03:58:07 2010	(r47684)
+++ branches/dynop_mapping/include/parrot/packfile.h	Fri Jun 18 05:22:31 2010	(r47685)
@@ -254,9 +254,10 @@
 } PackFile_ConstTable;
 
 typedef struct PackFile_ByteCode_OpMappingEntry {
-    op_lib_t *lib;     /* library for this entry */
-    opcode_t  n_ops;   /* number of ops used */
-    opcode_t *lib_ops; /* indices of ops within the library */
+    op_lib_t *lib;       /* library for this entry */
+    opcode_t  n_ops;     /* number of ops used */
+    opcode_t *lib_ops;   /* indices of ops within the library */
+    opcode_t *table_ops; /* indices of ops within the op table */
 } PackFile_ByteCode_OpMappingEntry;
 
 typedef struct PackFile_ByteCode_OpMapping {

Modified: branches/dynop_mapping/src/packfile.c
==============================================================================
--- branches/dynop_mapping/src/packfile.c	Fri Jun 18 03:58:07 2010	(r47684)
+++ branches/dynop_mapping/src/packfile.c	Fri Jun 18 05:22:31 2010	(r47685)
@@ -2674,7 +2674,7 @@
 
         /* op entries */
         size += 1;            /* n_ops */
-        size += entry->n_ops; /* lib_ops */
+        size += entry->n_ops * 2; /* lib_ops and table_ops */
     }
 
     return size;
@@ -2689,6 +2689,7 @@
     PackFile_ByteCode * const byte_code = (PackFile_ByteCode *)self;
     int i, j;
 
+    *cursor++ = byte_code->op_count;
     *cursor++ = byte_code->op_mapping.n_libs;
 
     for (i = 0; i < byte_code->op_mapping.n_libs; i++) {
@@ -2703,6 +2704,7 @@
         /* op entries */
         *cursor++ = entry->n_ops;
         for (j = 0; j < entry->n_ops; j++)
+            *cursor++ = entry->table_ops[j];
             *cursor++ = entry->lib_ops[j];
     }
 
@@ -2717,9 +2719,12 @@
     ASSERT_ARGS(byte_code_unpack)
     PackFile_ByteCode * const byte_code = (PackFile_ByteCode *)self;
     int i;
+    int total_ops = 0;
+
+    byte_code->op_count          = PF_fetch_opcode(self->pf, &cursor);
+    byte_code->op_func_table     = mem_gc_allocate_n_zeroed_typed(interp,
+                                        byte_code->op_count, op_func_t);
 
-    byte_code->op_count          = 0;
-    byte_code->op_func_table     = NULL;
 
     byte_code->op_mapping.n_libs = PF_fetch_opcode(self->pf, &cursor);
     byte_code->op_mapping.libs   = mem_gc_allocate_n_zeroed_typed(interp,
@@ -2764,29 +2769,44 @@
         /* op entries */
         {
             int       j;
-            const int old_op_count = byte_code->op_count;
-            byte_code->op_count += entry->n_ops = PF_fetch_opcode(self->pf, &cursor);
+            total_ops += entry->n_ops = PF_fetch_opcode(self->pf, &cursor);
 
-            /* XXX could probably avoid reallocing by filling the func_table later */
-            if (!byte_code->op_func_table)
-                byte_code->op_func_table = mem_gc_allocate_n_typed(interp,
-                                            byte_code->op_count, op_func_t);
-            else
-                mem_gc_realloc_n_typed(interp, byte_code->op_func_table,
-                    byte_code->op_count, op_func_t);
+            entry->table_ops = mem_gc_allocate_n_zeroed_typed(interp,
+                                    entry->n_ops, opcode_t);
+            entry->lib_ops   = mem_gc_allocate_n_zeroed_typed(interp,
+                                    entry->n_ops, opcode_t);
 
             for (j = 0; j < entry->n_ops; j++) {
-                int op = PF_fetch_opcode(self->pf, &cursor);
-                if (0 < op || op < entry->lib->op_count)
+                opcode_t idx = PF_fetch_opcode(self->pf, &cursor);
+                opcode_t op  = PF_fetch_opcode(self->pf, &cursor);
+
+                if (0 > op || op >= entry->lib->op_count)
                     Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE,
-                        "opcode index out of bounds on library `%s'. Found %d, expection 0 to %d.",
-                        entry->lib->name, op, entry->lib->op_count);
-                entry->lib_ops[j]                          = op;
-                byte_code->op_func_table[old_op_count + j] = entry->lib->op_func_table[j];
+                        "opcode index out of bounds on library `%s'. Found %d, expected 0 to %d.",
+                        entry->lib->name, op, entry->lib->op_count - 1);
+
+                if (0 > idx || idx >= byte_code->op_count)
+                    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE,
+                        "op table index out of bounds for entry from library `%s'."
+                        " Found %d, expected 0 to %d",
+                        entry->lib->name, idx, byte_code->op_count - 1);
+
+                if (byte_code->op_func_table[idx])
+                    Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE,
+                        "duplicate entries in optable");
+
+                entry->table_ops[j]           = idx;
+                entry->lib_ops[j]             = op;
+                byte_code->op_func_table[idx] = entry->lib->op_func_table[op];
             }
         }
     }
 
+    if (total_ops != byte_code->op_count)
+        Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_MALFORMED_PACKFILE,
+            "wrong number of ops decoded for optable. Decoded %d, but expected %d",
+            total_ops, byte_code->op_count);
+
     return cursor;
 }
 


More information about the parrot-commits mailing list