[svn:parrot] r47781 - in branches/dynop_mapping: compilers/imcc include/parrot src
plobsing at svn.parrot.org
plobsing at svn.parrot.org
Wed Jun 23 08:04:24 UTC 2010
Author: plobsing
Date: Wed Jun 23 08:04:24 2010
New Revision: 47781
URL: https://trac.parrot.org/parrot/changeset/47781
Log:
Actually remap ops.
Remapping is done in imcc. Also some fixups to be able to execute trivial
examples. Larger exmples/tests are still extremely segfaulty.
Modified:
branches/dynop_mapping/compilers/imcc/pbc.c
branches/dynop_mapping/include/parrot/runcore_api.h
branches/dynop_mapping/src/packfile.c
Modified: branches/dynop_mapping/compilers/imcc/pbc.c
==============================================================================
--- branches/dynop_mapping/compilers/imcc/pbc.c Wed Jun 23 08:00:36 2010 (r47780)
+++ branches/dynop_mapping/compilers/imcc/pbc.c Wed Jun 23 08:04:24 2010 (r47781)
@@ -2216,6 +2216,81 @@
/*
+=item C<opcode_t bytecode_map_op(PARROT_INTERP, opcode_t op)>
+
+Lookup the mapping of an op for the current bytecode segment or make one if
+none exists.
+
+=cut
+
+*/
+
+static
+opcode_t
+bytecode_map_op(PARROT_INTERP, opcode_t op) {
+ int i;
+ op_info_t *info = &interp->op_info_table[op];
+ op_lib_t *lib = info->lib;
+ op_func_t op_func = interp->op_func_table[op];
+ PackFile_ByteCode *bc = interp->code;
+ PackFile_ByteCode_OpMappingEntry *om;
+
+ for (i = 0; i < bc->op_mapping.n_libs; i++) {
+ if (lib == bc->op_mapping.libs[i].lib) {
+ om = &bc->op_mapping.libs[i];
+ goto found_lib;
+ }
+ }
+
+ /* library not yet mapped */
+ bc->op_mapping.n_libs++;
+ bc->op_mapping.libs = mem_gc_realloc_n_typed_zeroed(interp, bc->op_mapping.libs,
+ bc->op_mapping.n_libs, bc->op_mapping.n_libs - 1,
+ PackFile_ByteCode_OpMappingEntry);
+
+ /* initialize a new lib entry */
+ om = &bc->op_mapping.libs[bc->op_mapping.n_libs - 1];
+ om->lib = lib;
+ om->n_ops = 0;
+ om->lib_ops = mem_gc_allocate_n_zeroed_typed(interp, 0, opcode_t);
+ om->table_ops = mem_gc_allocate_n_zeroed_typed(interp, 0, opcode_t);
+
+ found_lib:
+ for (i = 0; i < om->n_ops; i++) {
+ if (bc->op_func_table[om->table_ops[i]] == op_func)
+ return om->table_ops[i];
+ }
+
+ /* op not yet mapped */
+ bc->op_count++;
+ bc->op_func_table =
+ mem_gc_realloc_n_typed_zeroed(interp, bc->op_func_table, bc->op_count, bc->op_count,
+ op_func_t);
+ bc->op_func_table[bc->op_count - 1] = op_func;
+
+ /* initialize new op mapping */
+ om->n_ops++;
+
+ om->lib_ops =
+ mem_gc_realloc_n_typed_zeroed(interp, om->lib_ops, om->n_ops, om->n_ops - 1, opcode_t);
+ for (i = 0; i < lib->op_count; i++) {
+ if (lib->op_func_table[i] == op_func) {
+ om->lib_ops[om->n_ops - 1] = i;
+ break;
+ }
+ }
+ PARROT_ASSERT(om->lib_ops[om->n_ops - 1] || !i);
+
+ om->table_ops =
+ mem_gc_realloc_n_typed_zeroed(interp, om->table_ops, om->n_ops, om->n_ops - 1, opcode_t);
+ om->table_ops[om->n_ops - 1] = bc->op_count - 1;
+
+ return bc->op_count - 1;
+}
+
+
+/*
+
=item C<int e_pbc_emit(PARROT_INTERP, void *param, const IMC_Unit *unit, const
Instruction *ins)>
@@ -2357,15 +2432,15 @@
op = (opcode_t)ins->opnum;
- /* Start generating the bytecode */
- *(IMCC_INFO(interp)->pc)++ = op;
-
/* Get the info for that opcode */
op_info = &interp->op_info_table[op];
IMCC_debug(interp, DEBUG_PBC, "%d %s", IMCC_INFO(interp)->npc,
op_info->full_name);
+ /* Start generating the bytecode */
+ *(IMCC_INFO(interp)->pc)++ = bytecode_map_op(interp, op);
+
for (i = 0; i < op_info->op_count-1; i++) {
switch (op_info->types[i]) {
case PARROT_ARG_IC:
Modified: branches/dynop_mapping/include/parrot/runcore_api.h
==============================================================================
--- branches/dynop_mapping/include/parrot/runcore_api.h Wed Jun 23 08:00:36 2010 (r47780)
+++ branches/dynop_mapping/include/parrot/runcore_api.h Wed Jun 23 08:04:24 2010 (r47781)
@@ -15,7 +15,7 @@
#include "parrot/parrot.h"
#include "parrot/op.h"
-# define DO_OP(PC, INTERP) ((PC) = (((INTERP)->op_func_table)[*(PC)])((PC), (INTERP)))
+# define DO_OP(PC, INTERP) ((PC) = (((INTERP)->code->op_func_table)[*(PC)])((PC), (INTERP)))
typedef opcode_t * (*runcore_runops_fn_type) (PARROT_INTERP, ARGIN(Parrot_runcore_t *), ARGIN(opcode_t *pc));
typedef void (*runcore_destroy_fn_type)(PARROT_INTERP, ARGIN(Parrot_runcore_t *));
Modified: branches/dynop_mapping/src/packfile.c
==============================================================================
--- branches/dynop_mapping/src/packfile.c Wed Jun 23 08:00:36 2010 (r47780)
+++ branches/dynop_mapping/src/packfile.c Wed Jun 23 08:04:24 2010 (r47781)
@@ -36,6 +36,7 @@
#include "pmc/pmc_key.h"
#include "pmc/pmc_callcontext.h"
#include "pmc/pmc_parrotlibrary.h"
+#include "parrot/oplib/core_ops.h"
/* HEADERIZER HFILE: include/parrot/packfile.h */
@@ -2703,9 +2704,10 @@
/* op entries */
*cursor++ = entry->n_ops;
- for (j = 0; j < entry->n_ops; j++)
+ for (j = 0; j < entry->n_ops; j++) {
*cursor++ = entry->table_ops[j];
*cursor++ = entry->lib_ops[j];
+ }
}
return cursor;
@@ -2740,16 +2742,17 @@
const opcode_t major = PF_fetch_opcode(self->pf, &cursor);
const opcode_t minor = PF_fetch_opcode(self->pf, &cursor);
const opcode_t patch = PF_fetch_opcode(self->pf, &cursor);
- const PMC *lib_pmc = Parrot_load_lib(interp,
- Parrot_str_new(interp, lib_name, 0),
- NULL);
-
- mem_gc_free(interp, lib_name);
- {
- /* XXX
- * broken encapsulation => should make this data easier to access somehow
- */
+ /* XXX
+ * broken encapsulation => should make this data easier to access somehow
+ */
+ if (STREQ(lib_name, PARROT_CORE_OPLIB_NAME)) {
+ entry->lib = PARROT_CORE_OPLIB_INIT(interp, 1);
+ }
+ else {
+ const PMC *lib_pmc = Parrot_load_lib(interp,
+ Parrot_str_new(interp, lib_name, 0),
+ NULL);
void *oplib_init;
op_lib_t *(*oplib_init_f)(PARROT_INTERP, long init);
GETATTR_ParrotLibrary_oplib_init(interp, lib_pmc, oplib_init);
@@ -2757,6 +2760,9 @@
entry->lib = oplib_init_f(interp, 1);
}
+
+ mem_gc_free(interp, lib_name);
+
if (entry->lib->major_version != major
|| entry->lib->minor_version != minor
|| entry->lib->patch_version != patch)
More information about the parrot-commits
mailing list