OK, there is another workaround to make pbc2c.pl work which still uses the
"goto model" so speed is not affected but it's harder to maintain since
it's not as generic as the other one.
                                        Daniel.

Index: pbc2c.pl
===================================================================
RCS file: /home/perlcvs/parrot/pbc2c.pl,v
retrieving revision 1.3
diff -r1.3 pbc2c.pl
68a69
> my $op;
70a72
> my @pcs = ();
88c90
<     int                        i;
---
>     int                        cur_opcode,to;
142c144
<     my $op;
---
>     my $jump;
145a148
>         $jump .= "        case " . $pc . ": goto PC_" . $pc . ";\n";
162a166
>        $source = "cur_opcode = " . $pc . ";\n" . $source if ($op->full_name eq 
>'bsr_ic');
172a177,187
> JUMP:{
>     switch (to) {
>         case 0: goto PC_0;
> END_C
> 
>     print $jump;
>     print <<END_C;
>         default: exit(0);
>     }
> }
> 
189c204,208
<   return sprintf("goto PC_%d", $addr);
---
>   if ($op->full_name =~ 'ret') {
>     return sprintf("to = dest;\ngoto JUMP");
>   } else {
>     return sprintf("goto PC_%d", $addr);
>   }
201c220,224
<   return sprintf("goto PC_%d", $pc + $offset);
---
>   if ($op->full_name eq 'jump_i') {
>     return sprintf("to = " . $pc . "+" . $offset . ";\ngoto JUMP");
>   } else {
>      return sprintf("goto PC_%d", $pc + $offset);
>   }
Index: pbc2c.pl
===================================================================
RCS file: /home/perlcvs/parrot/pbc2c.pl,v
retrieving revision 1.3
diff -r1.3 pbc2c.pl
70a71
> my @functions = ();
79a81,82
> 
> void start();
85a89,90
> struct Parrot_Interp *     interpreter;
> 
88,89d92
<     int                        i;
<     struct Parrot_Interp *     interpreter;
134a138,142
> print <<END_C;
>     start();
>     return 0;
> }
> END_C
163c171,172
<         printf("PC_%d: { /* %s */\n%s}\n\n", $pc, $op->full_name, $source);
---
>         push(@functions,$pc);
>         printf("int\nPC_%d(int cur_opcode) /* %s */\n{\n%s}\n\n", $pc, 
>$op->full_name, $source);
168,171c177,181
< PC_$new_pc:
< PC_0: {
<     exit(0);
< }
---
> void
> start()
> {
>     int                        (*functions[$pc])(int);
>     int                        j = 1;
173c183,191
<     return 0;
---
> END_C
>     foreach (0..scalar(@functions) - 1) {
>         print "    functions[" . $functions[$_] . "] = (int (*)(int))PC_" . 
>$functions[$_] . ";\n";
>     }
> 
>     print <<END_C;
> 
>     while (j) { j = (*functions[j])(j); };
>     exit(0);
189c207
<   return sprintf("goto PC_%d", $addr);
---
>   return sprintf "return (" . $addr . ")";
201c219
<   return sprintf("goto PC_%d", $pc + $offset);
---
>   return sprintf "return (cur_opcode+" . $offset . ")";

Reply via email to