cvsuser 03/10/16 07:11:03
Modified: . interpreter.c jit.c jit2h.pl
jit/i386 jit_emit.h
lib/Parrot/OpTrans CSwitch.pm
Log:
dynamic oplibs - switch, JIT/i386 cores
both are a bit tricky: switched core calls the wrapper from
the final default case.
JIT/i386 emits a call to the wrapper__ opcode. Other architectures
probably only need a similar change in Parrot_normal_op
Revision Changes Path
1.220 +19 -11 parrot/interpreter.c
Index: interpreter.c
===================================================================
RCS file: /cvs/public/parrot/interpreter.c,v
retrieving revision 1.219
retrieving revision 1.220
diff -u -w -r1.219 -r1.220
--- interpreter.c 16 Oct 2003 11:50:04 -0000 1.219
+++ interpreter.c 16 Oct 2003 14:10:59 -0000 1.220
@@ -1,7 +1,7 @@
/* interpreter.c
* Copyright: 2001-2003 The Perl Foundation. All Rights Reserved.
* CVS Info
- * $Id: interpreter.c,v 1.219 2003/10/16 11:50:04 leo Exp $
+ * $Id: interpreter.c,v 1.220 2003/10/16 14:10:59 leo Exp $
* Overview:
* The interpreter api handles running the operations
* Data Structure and Algorithms:
@@ -1049,8 +1049,10 @@
/*
* dynamic loading stuff
*/
-static void dynop_register_xx(Parrot_Interp, PMC*, op_lib_t *, op_lib_t *,
+static void dynop_register_xx(Parrot_Interp, PMC*, size_t, size_t,
oplib_init_f init_func);
+static void dynop_register_switch(Parrot_Interp, PMC*, size_t, size_t);
+
/*=for api interpreter dynop_register
*
@@ -1113,13 +1115,14 @@
core->flags = OP_FUNC_IS_ALLOCATED | OP_INFO_IS_ALLOCATED;
/* done for plain core */
#if defined HAVE_COMPUTED_GOTO
- dynop_register_xx(interpreter, lib_pmc, lib, core,
+ dynop_register_xx(interpreter, lib_pmc, n_old, n_new,
PARROT_CORE_CGP_OPLIB_INIT);
- dynop_register_xx(interpreter, lib_pmc, lib, core,
+ dynop_register_xx(interpreter, lib_pmc, n_old, n_new,
PARROT_CORE_CG_OPLIB_INIT);
#endif
- dynop_register_xx(interpreter, lib_pmc, lib, core,
+ dynop_register_xx(interpreter, lib_pmc, n_old, n_new,
PARROT_CORE_PREDEREF_OPLIB_INIT);
+ dynop_register_switch(interpreter, lib_pmc, n_old, n_new);
}
/*
@@ -1127,16 +1130,13 @@
*/
static void
dynop_register_xx(Parrot_Interp interpreter, PMC* lib_pmc,
- op_lib_t *lib, op_lib_t *core, oplib_init_f init_func)
+ size_t n_old, size_t n_new, oplib_init_f init_func)
{
op_lib_t *cg_lib;
void **ops_addr;
- size_t i, n_old, n_new, n_tot;
-
- n_new = lib->op_count;
- n_tot = n_old = core->op_count;
- n_old -= n_new;
+ size_t i, n_tot;
+ n_tot = n_old + n_new;
cg_lib = init_func(1);
if (cg_lib->flags & OP_FUNC_IS_ALLOCATED) {
@@ -1160,6 +1160,14 @@
cg_lib->op_func_table = (void *) ops_addr;
cg_lib->op_count = n_tot;
init_func((int) ops_addr);
+}
+
+static void
+dynop_register_switch(Parrot_Interp interpreter, PMC* lib_pmc,
+ size_t n_old, size_t n_new)
+{
+ op_lib_t *lib = PARROT_CORE_SWITCH_OPLIB_INIT(1);
+ lib->op_count = n_old + n_new;
}
/*
1.76 +28 -6 parrot/jit.c
Index: jit.c
===================================================================
RCS file: /cvs/public/parrot/jit.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -w -r1.75 -r1.76
--- jit.c 15 Oct 2003 08:31:20 -0000 1.75
+++ jit.c 16 Oct 2003 14:10:59 -0000 1.76
@@ -1,7 +1,7 @@
/*
* jit.c
*
- * $Id: jit.c,v 1.75 2003/10/15 08:31:20 leo Exp $
+ * $Id: jit.c,v 1.76 2003/10/16 14:10:59 leo Exp $
*/
#include <parrot/parrot.h>
@@ -14,6 +14,7 @@
#include "parrot/jit_emit.h"
#include "parrot/packfile.h"
+extern int jit_op_count(void);
/*
* s. jit/$arch/jit_emit.h for the meaning of these defs
*/
@@ -154,9 +155,13 @@
*/
while (cur_op < code_end) {
+ opcode_t op = *cur_op;
+ if (*cur_op >= jit_op_count())
+ op = CORE_OPS_wrapper__;
+
/* Predereference the opcode information table for this opcode
* early since it's going to be used many times */
- op_info = &interpreter->op_info_table[*cur_op];
+ op_info = &interpreter->op_info_table[op];
/* if op_info->jump is not 0 this opcode may jump,
* so mark this opcode as a branch source */
@@ -317,10 +322,13 @@
cur_op = code_start;
while (cur_section) {
+ opcode_t op = *cur_op;
+ if (*cur_op >= jit_op_count())
+ op = CORE_OPS_wrapper__;
branched = start_new = 0;
/* Predereference the opcode information for this opcode
* early since it's going to be used many times */
- op_info = &interpreter->op_info_table[*cur_op];
+ op_info = &interpreter->op_info_table[op];
/* Calculate the next pc */
next_op = cur_op + op_info->arg_count;
@@ -546,7 +554,10 @@
/* For each opcode in this section */
cur_op = cur_section->begin;
while (cur_op <= cur_section->end) {
- op_info = &interpreter->op_info_table[*cur_op];
+ opcode_t op = *cur_op;
+ if (*cur_op >= jit_op_count())
+ op = CORE_OPS_wrapper__;
+ op_info = &interpreter->op_info_table[op];
/* For each argument of the current opcode */
for (op_arg = 1; op_arg < op_info->arg_count; op_arg++) {
/* get the register typ */
@@ -627,7 +638,10 @@
cur_section->block);
for (cur_op = cur_section->begin; cur_op <= cur_section->end;) {
char instr[256];
- op_info = &interpreter->op_info_table[*cur_op];
+ opcode_t op = *cur_op;
+ if (*cur_op >= jit_op_count())
+ op = CORE_OPS_wrapper__;
+ op_info = &interpreter->op_info_table[op];
PDB_disassemble_op(interpreter, instr, sizeof(instr),
op_info, cur_op, NULL, code_start, 0);
PIO_eprintf(interpreter, "\t\tOP%vu: ext %3d\t%s\n",
@@ -769,7 +783,10 @@
}
while (cur_op <= section->end) {
- op_info = &interpreter->op_info_table[*cur_op];
+ opcode_t op = *cur_op;
+ if (*cur_op >= jit_op_count())
+ op = CORE_OPS_wrapper__;
+ op_info = &interpreter->op_info_table[op];
set_register_usage(interpreter, optimizer, section,
op_info, cur_op, code_start);
section->op_count++;
@@ -932,6 +949,8 @@
** build_asm()
*/
+
+
jit_f
build_asm(struct Parrot_Interp *interpreter, opcode_t *pc,
opcode_t *code_start, opcode_t *code_end,
@@ -1089,6 +1108,9 @@
}
/* Generate native code for current op */
+ if (cur_opcode_byte >= jit_op_count()) {
+ cur_opcode_byte = CORE_OPS_wrapper__;
+ }
(op_func[cur_opcode_byte].fn) (jit_info, interpreter);
/* Update the previous opcode */
1.48 +8 -2 parrot/jit2h.pl
Index: jit2h.pl
===================================================================
RCS file: /cvs/public/parrot/jit2h.pl,v
retrieving revision 1.47
retrieving revision 1.48
diff -u -w -r1.47 -r1.48
--- jit2h.pl 11 Oct 2003 13:04:58 -0000 1.47
+++ jit2h.pl 16 Oct 2003 14:10:59 -0000 1.48
@@ -2,7 +2,7 @@
#
# jit2h.pl
#
-# $Id: jit2h.pl,v 1.47 2003/10/11 13:04:58 leo Exp $
+# $Id: jit2h.pl,v 1.48 2003/10/16 14:10:59 leo Exp $
#
use strict;
@@ -243,7 +243,6 @@
#define Parrot_jit_restart_op Parrot_jit_cpcf_op
-
#include"parrot/jit_emit.h"
#undef CONST
@@ -417,6 +416,13 @@
}
print JITCPU @jit_funcs, "};\n";
+
+if ($genfile eq "jit_cpu.c") {
+ print JITCPU <<EOC;
+ extern int jit_op_count(void);
+ int jit_op_count() { return $core_numops; }
+EOC
+}
print("jit2h: $njit (+ $vjit vtable) of $core_numops ops are JITed.\n");
sub make_subs {
1.90 +8 -2 parrot/jit/i386/jit_emit.h
Index: jit_emit.h
===================================================================
RCS file: /cvs/public/parrot/jit/i386/jit_emit.h,v
retrieving revision 1.89
retrieving revision 1.90
diff -u -w -r1.89 -r1.90
--- jit_emit.h 14 Oct 2003 07:39:57 -0000 1.89
+++ jit_emit.h 16 Oct 2003 14:11:01 -0000 1.90
@@ -3,7 +3,7 @@
*
* i386
*
- * $Id: jit_emit.h,v 1.89 2003/10/14 07:39:57 leo Exp $
+ * $Id: jit_emit.h,v 1.90 2003/10/16 14:11:01 leo Exp $
*/
#include <assert.h>
@@ -2747,15 +2747,21 @@
}
# else /* JIT_CGP */
+extern int jit_op_count(void);
void
Parrot_jit_normal_op(Parrot_jit_info_t *jit_info,
struct Parrot_Interp * interpreter)
{
+ int cur_op = *jit_info->cur_op;
+
+ if (cur_op >= jit_op_count()) {
+ cur_op = CORE_OPS_wrapper__;
+ }
emitm_pushl_i(jit_info->native_ptr, jit_info->cur_op);
call_func(jit_info,
- (void (*)(void))interpreter->op_func_table[*(jit_info->cur_op)]);
+ (void (*)(void))interpreter->op_func_table[cur_op]);
emitm_addb_i_r(jit_info->native_ptr, 4, emit_ESP);
}
1.4 +5 -1 parrot/lib/Parrot/OpTrans/CSwitch.pm
Index: CSwitch.pm
===================================================================
RCS file: /cvs/public/parrot/lib/Parrot/OpTrans/CSwitch.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -w -r1.3 -r1.4
--- CSwitch.pm 16 Oct 2003 10:43:16 -0000 1.3
+++ CSwitch.pm 16 Oct 2003 14:11:03 -0000 1.4
@@ -6,7 +6,7 @@
#
# Author: leo
#
-# $Id: CSwitch.pm,v 1.3 2003/10/16 10:43:16 leo Exp $
+# $Id: CSwitch.pm,v 1.4 2003/10/16 14:11:03 leo Exp $
#
use strict;
@@ -113,6 +113,10 @@
my ($self, $base) = @_;
my $c = <<END_C;
default:
+ if (*cur_opcode >= 0 && *cur_opcode < (opcode_t)op_lib.op_count) {
+ *cur_opcode = CORE_OPS_wrapper__;
+ continue;
+ }
internal_exception(1, "illegal opcode\\n");
break;
} /* switch */