cvsuser     03/02/06 04:41:12

  Modified:    config/auto cgoto.pl
               .        interpreter.c ops2c.pl
  Added:       lib/Parrot/OpTrans CGP.pm
  Log:
  CGP - CGoto Prederefed runloop
  
  Revision  Changes    Path
  1.4       +7 -3      parrot/config/auto/cgoto.pl
  
  Index: cgoto.pl
  ===================================================================
  RCS file: /cvs/public/parrot/config/auto/cgoto.pl,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -w -r1.3 -r1.4
  --- cgoto.pl  6 Feb 2003 09:38:04 -0000       1.3
  +++ cgoto.pl  6 Feb 2003 12:41:00 -0000       1.4
  @@ -25,15 +25,19 @@
   
     if ($test) {
       Configure::Data->set(
  -      cg_h          => '$(INC)/oplib/core_ops_cg.h',
  +      cg_h          => '$(INC)/oplib/core_ops_cg.h $(INC)/oplib/core_ops_cgp.h',
         cg_c          => <<'EOF',
   core_ops_cg$(O): $(GENERAL_H_FILES) core_ops_cg.c
  +core_ops_cgp$(O): $(GENERAL_H_FILES) core_ops_cgp.c
   
   core_ops_cg.c $(INC)/oplib/core_ops_cg.h: $(OPS_FILES) ops2c.pl 
lib/Parrot/OpsFile.pm lib/Parrot/Op.pm
        $(PERL) ops2c.pl CGoto $(OPS_FILES)
  +core_ops_cgp.c $(INC)/oplib/core_ops_cgp.h: $(OPS_FILES) ops2c.pl 
lib/Parrot/OpsFile.pm lib/Parrot/Op.pm
  +     $(PERL) ops2c.pl CGP $(OPS_FILES)
   EOF
  -      cg_o          => 'core_ops_cg$(O)',
  -      cg_r          => '$(RM_F) $(INC)/oplib/core_ops_cg.h core_ops_cg.c',
  +      cg_o          => 'core_ops_cg$(O) core_ops_cgp$(O)',
  +      cg_r          => '$(RM_F) $(INC)/oplib/core_ops_cg.h core_ops_cg.c \
  +                                $(INC)/oplib/core_ops_cgp.h core_ops_cgp.c',
         cg_flag       => '-DHAVE_COMPUTED_GOTO'
       );
     }
  
  
  
  1.141     +37 -4     parrot/interpreter.c
  
  Index: interpreter.c
  ===================================================================
  RCS file: /cvs/public/parrot/interpreter.c,v
  retrieving revision 1.140
  retrieving revision 1.141
  diff -u -w -r1.140 -r1.141
  --- interpreter.c     6 Feb 2003 09:38:06 -0000       1.140
  +++ interpreter.c     6 Feb 2003 12:41:05 -0000       1.141
  @@ -1,7 +1,7 @@
   /* interpreter.c
    *  Copyright: (When this is determined...it will go here)
    *  CVS Info
  - *     $Id: interpreter.c,v 1.140 2003/02/06 09:38:06 leo Exp $
  + *     $Id: interpreter.c,v 1.141 2003/02/06 12:41:05 leo Exp $
    *  Overview:
    *     The interpreter api handles running the operations
    *  Data Structure and Algorithms:
  @@ -175,7 +175,7 @@
    *   prederef has no op_info_table
    */
   static void
  -init_prederef(struct Parrot_Interp *interpreter)
  +init_prederef(struct Parrot_Interp *interpreter, int cgp)
   {
       interpreter->op_lib = PARROT_CORE_PREDEREF_OPLIB_INIT(1);
       interpreter->op_lib->op_code = PARROT_CORE_OPLIB_INIT(1)->op_code;
  @@ -194,6 +194,19 @@
   
           interpreter->prederef_code = temp;
           interpreter->code->cur_cs->prederef_code = temp;
  +        if (cgp) {
  +            opcode_t *pc = interpreter->code->cur_cs->base.data;
  +            size_t n;
  +            for (i = 0; i < N; ) {
  +                prederef(temp, interpreter);
  +                *temp = (void*)*pc;
  +                n = interpreter->op_info_table[*pc].arg_count;
  +                pc += n;
  +                i += n;
  +                temp += n;
  +            }
  +        }
  +
       }
   }
   
  @@ -255,7 +268,7 @@
       opcode_t *code_end;
       void **pc_prederef;
   
  -    init_prederef(interpreter);
  +    init_prederef(interpreter, 0);
       pc_prederef = interpreter->prederef_code + (pc - code_start);
   
       while (pc_prederef) {
  @@ -268,6 +281,23 @@
       return 0;
   }
   
  +static opcode_t *
  +runops_cgp(struct Parrot_Interp *interpreter, opcode_t *pc)
  +{
  +#ifdef HAVE_COMPUTED_GOTO
  +    opcode_t *code_start = (opcode_t *)interpreter->code->byte_code;
  +    void **pc_prederef;
  +    init_prederef(interpreter, 1);
  +    pc_prederef = interpreter->prederef_code + (pc - code_start);
  +    pc = cgp_core((opcode_t*)pc_prederef, interpreter);
  +    return pc;
  +#else
  +    PIO_eprintf(interpreter,
  +            "Computed goto unavailable in this configuration.\n");
  +    Parrot_exit(1);
  +    return NULL;
  +#endif
  +}
   
   /*=for api interpreter runops
    * run parrot operations of loaded code segment until an end opcode is reached
  @@ -309,6 +339,9 @@
           }
           /* CGOTO is set per default, so test other cores first */
           else if (Interp_flags_TEST(interpreter, PARROT_PREDEREF_FLAG)) {
  +            if  (Interp_flags_TEST(interpreter, PARROT_CGOTO_FLAG))
  +                core = runops_cgp;
  +            else
               core = runops_prederef;
           }
           else if (Interp_flags_TEST(interpreter, PARROT_JIT_FLAG)) {
  
  
  
  1.39      +4 -3      parrot/ops2c.pl
  
  Index: ops2c.pl
  ===================================================================
  RCS file: /cvs/public/parrot/ops2c.pl,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -w -r1.38 -r1.39
  --- ops2c.pl  6 Feb 2003 09:38:06 -0000       1.38
  +++ ops2c.pl  6 Feb 2003 12:41:05 -0000       1.39
  @@ -5,7 +5,7 @@
   # Generate a C header and source file from the operation definitions in
   # an .ops file, using a supplied transform.
   #
  -# $Id: ops2c.pl,v 1.38 2003/02/06 09:38:06 leo Exp $
  +# $Id: ops2c.pl,v 1.39 2003/02/06 12:41:05 leo Exp $
   #
   
   use strict;
  @@ -131,11 +131,12 @@
   extern op_lib_t 
*Parrot_DynOp_${base}${suffix}_${major_version}_${minor_version}_${patch_version}(int 
init);
   
   END_C
  +my $cg_func = $suffix =~ /cgp/ ? 'cgp_' : 'cg_';
   
   if ($suffix =~ /cg/) {
        print HEADER <<END_C;
   
  -opcode_t *cg_${base}(opcode_t *, struct Parrot_Interp *);
  +opcode_t *$cg_func${base}(opcode_t *, struct Parrot_Interp *);
   END_C
   }
   
  @@ -154,7 +155,7 @@
        print SOURCE <<END_C;
   
   opcode_t *
  -cg_$base(opcode_t *cur_opcode, struct Parrot_Interp *interpreter)
  +$cg_func$base(opcode_t *cur_opcode, struct Parrot_Interp *interpreter)
   {
       static void *ops_addr[] = {
   END_C
  
  
  
  1.1                  parrot/lib/Parrot/OpTrans/CGP.pm
  
  Index: CGP.pm
  ===================================================================
  #
  # CGP.pm CGoto Prederefed
  #        this is a mixture of prederefed register addressing and the
  #        CGoto runloop
  #        Please consult the corresponding OpTrans files for more
  #
  # Author: leo
  #
  # $Id: CGP.pm,v 1.1 2003/02/06 12:41:12 leo Exp $
  #
  
  use strict;
  #use warnings;
  
  package Parrot::OpTrans::CGP;
  
  use Parrot::OpTrans;
  use Parrot::OpTrans::CPrederef;
  use vars qw(@ISA);
  @ISA = qw(Parrot::OpTrans::CPrederef);
  
  
  #
  # suffix()
  #
  
  sub suffix
  {
    return "_cgp";
  }
  
  sub defines
  {
    return <<END;
  #define REL_PC ((size_t)((opcode_t*)cur_opcode - 
(opcode_t*)interpreter->prederef_code))
  #define CUR_OPCODE (interpreter->code->byte_code + REL_PC)
  
  
  static void** opcode_to_prederef(struct Parrot_Interp* interpreter,
                                          opcode_t* opcode_addr)
  {
      INTVAL offset_in_ops;
      if (opcode_addr == NULL) return NULL;
      offset_in_ops = opcode_addr - (opcode_t*) interpreter->code->byte_code;
      return interpreter->prederef_code + offset_in_ops;
  }
  
  END
  }
  #
  # goto_address()
  #
  
  sub goto_address
  {
    my ($self, $addr) = @_;
  #print STDERR "pbcc: map_ret_abs($addr)\n";
    if ($addr eq '0') {
        return "return (0);"
    } else {
        return "goto *ops_addr[*(cur_opcode = (opcode_t *)
        opcode_to_prederef(interpreter, $addr))]";
    }
  }
  
  #
  # goto_offset()
  #
  
  sub goto_offset
  {
    my ($self, $offset) = @_;
    return "goto *ops_addr[*(cur_opcode += $offset)]";
  }
  #
  # goto_pop()
  #
  
  sub goto_pop
  {
    my ($self) = @_;
    return "opcode_t* pop_addr = 
(opcode_t*)opcode_to_prederef(interpreter,pop_dest(interpreter));\ncur_opcode = 
pop_addr;goto *ops_addr[*(pop_addr)]";
  }
  sub expr_address
  {
    my ($self, $addr) = @_;
    return "opcode_to_prederef(interpreter, $addr)";
  }
  sub expr_offset {
      my ($self, $offset) = @_;
      return "CUR_OPCODE + $offset";
  }
  sub expr_pop
  {
    my ($self) = @_;
    return "opcode_to_prederef(interpreter, pop_dest(interpreter))";
  }
  
  
  


Reply via email to