[svn:parrot] r46844 - in branches/ops_pct/compilers/opsc: . src/Ops src/Ops/Compiler

cotto at svn.parrot.org cotto at svn.parrot.org
Fri May 21 07:12:43 UTC 2010


Author: cotto
Date: Fri May 21 07:12:43 2010
New Revision: 46844
URL: https://trac.parrot.org/parrot/changeset/46844

Log:
[opsc] add Ops::Renumberer, make it complain when ops.num needs renumbering

Modified:
   branches/ops_pct/compilers/opsc/Defines.mak
   branches/ops_pct/compilers/opsc/Rules.mak
   branches/ops_pct/compilers/opsc/ops2c.nqp
   branches/ops_pct/compilers/opsc/opsc.pir
   branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
   branches/ops_pct/compilers/opsc/src/Ops/File.pm
   branches/ops_pct/compilers/opsc/src/Ops/OpLib.pm

Modified: branches/ops_pct/compilers/opsc/Defines.mak
==============================================================================
--- branches/ops_pct/compilers/opsc/Defines.mak	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/Defines.mak	Fri May 21 07:12:43 2010	(r46844)
@@ -9,7 +9,8 @@
 	$(OPSC_DIR)/gen/Ops/Trans/C.pir \
 	$(OPSC_DIR)/gen/Ops/Op.pir \
 	$(OPSC_DIR)/gen/Ops/OpLib.pir \
-	$(OPSC_DIR)/gen/Ops/File.pir
+	$(OPSC_DIR)/gen/Ops/File.pir \
+	$(OPSC_DIR)/gen/Ops/Renumberer.pir
 
 OPSC_SOURCES = \
 	$(OPSC_DIR)/opsc.pir \

Modified: branches/ops_pct/compilers/opsc/Rules.mak
==============================================================================
--- branches/ops_pct/compilers/opsc/Rules.mak	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/Rules.mak	Fri May 21 07:12:43 2010	(r46844)
@@ -28,6 +28,9 @@
 $(OPSC_DIR)/gen/Ops/Trans/C.pir: $(OPSC_DIR)/src/Ops/Trans/C.pm $(NQP_RX)
 	$(NQP_RX) --target=pir --output=$@ $(OPSC_DIR)/src/Ops/Trans/C.pm
 
+$(OPSC_DIR)/gen/Ops/Renumberer.pir: $(OPSC_DIR)/src/Ops/Renumberer.pm $(NQP_RX)
+	$(NQP_RX) --target=pir --output=$@ $(OPSC_DIR)/src/Ops/Renumberer.pm
+
 # Target to force rebuild opsc from main Makefile
 $(OPSC_DIR)/ops2c.nqp: $(LIBRARY_DIR)/opsc.pbc
 

Modified: branches/ops_pct/compilers/opsc/ops2c.nqp
==============================================================================
--- branches/ops_pct/compilers/opsc/ops2c.nqp	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/ops2c.nqp	Fri May 21 07:12:43 2010	(r46844)
@@ -68,6 +68,7 @@
 my $trans := Ops::Trans::C.new();
 my $start_time := pir::time__N();
 my $f;
+my $renum;
 
 if $core {
     my $lib := Ops::OpLib.new(
@@ -75,13 +76,18 @@
         :skip_file('src/ops/ops.skip'),
     );
     $f := Ops::File.new(|@files, :oplib($lib), :core(1));
+    $renum := Ops::Renumberer.new( :ops_file($f) );
+
+    if $renum.needs_renumbering {
+        say("renumbering ops.num...");
+    }
 }
 else {
     $f := Ops::File.new(|@files, :core(0));
 }
 
 pir::sprintf(my $time, "%.3f", [pir::time__N() - $start_time] );
-say("# Ops parsed in $time seconds.");
+#say("# Ops parsed in $time seconds.");
 
 my $emitter := Ops::Emitter.new(
     :ops_file($f), :trans($trans),

Modified: branches/ops_pct/compilers/opsc/opsc.pir
==============================================================================
--- branches/ops_pct/compilers/opsc/opsc.pir	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/opsc.pir	Fri May 21 07:12:43 2010	(r46844)
@@ -16,6 +16,7 @@
 .include 'compilers/opsc/gen/Ops/Op.pir'
 .include 'compilers/opsc/gen/Ops/OpLib.pir'
 .include 'compilers/opsc/gen/Ops/File.pir'
+.include 'compilers/opsc/gen/Ops/Renumberer.pir'
 
 # Local Variables:
 #   mode: pir

Modified: branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/src/Ops/Compiler/Actions.pm	Fri May 21 07:12:43 2010	(r46844)
@@ -35,19 +35,19 @@
 
     for $<op> {
         my $ops := $_.ast;
-        my $skiptable;
-        my $optable;
+        my $op_skip_table;
+        my $op_num_table;
         if $OPLIB {
-            $skiptable := $OPLIB.skiptable;
-            $optable   := $OPLIB.optable;
+            $op_skip_table := $OPLIB.op_skip_table;
+            $op_num_table  := $OPLIB.op_num_table;
         }
         for @($ops) -> $op {
             my $full_name := $op.full_name;
-            if $OPLIB && !$skiptable.exists($full_name) {
+            if $OPLIB && !$op_skip_table.exists($full_name) {
 
                 #ops listed in ops.num are non-experimental
-                if $optable.exists($full_name) {
-                    $op<code> := $optable{$full_name};
+                if $op_num_table.exists($full_name) {
+                    $op<code> := $op_num_table{$full_name};
                     $op<experimental> := 0;
                 }
                 #ops not explicitly listed but not skipped are experimental

Modified: branches/ops_pct/compilers/opsc/src/Ops/File.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/File.pm	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/src/Ops/File.pm	Fri May 21 07:12:43 2010	(r46844)
@@ -189,6 +189,7 @@
     self<ops>     := list(); # Ops
     self<preamble>:= '';
     self<compiler>:= pir::compreg__Ps('Ops');
+    self<op_order>:= 0;
 
     if $core {
         self<oplib>   := $oplib;
@@ -257,6 +258,8 @@
             say("# Experimental op " ~ $_.full_name ~ " is not in ops.num.");
         }
         self<ops>.push($_);
+        #say($_.full_name ~ " is number " ~ self<op_order>);
+        self<op_order>++;
     }
 
     for @( $past<preamble> ) {
@@ -271,11 +274,9 @@
 }
 
 method preamble() { self<preamble> };
-method ops() { self<ops> };
-
-method version() {
-    self<version>;
-}
+method ops()      { self<ops> };
+method oplib()    { self<oplib> };
+method version()  { self<version>; }
 
 method version_major() { self<version_major> }
 method version_minor() { self<version_minor> }

Modified: branches/ops_pct/compilers/opsc/src/Ops/OpLib.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/OpLib.pm	Fri May 21 07:02:31 2010	(r46843)
+++ branches/ops_pct/compilers/opsc/src/Ops/OpLib.pm	Fri May 21 07:12:43 2010	(r46844)
@@ -42,12 +42,12 @@
 
     'max_op_num' => 1246,
 
-=item * C<%.optable>
+=item * C<%.op_num_table>
 
 Hash holding mapping of opcode names ops to their numbers.
 Example:
 
-  'optable' => {
+  'op_num_table' => {
     'pow_p_p_i' => 650,
     'say_s' => 463,
     'lsr_p_p_i' => 207,
@@ -62,11 +62,11 @@
 the op numbers for the core opcodes in a particular version of the
 bytecode and provide backward-compatibility for bytecode.
 
-=item * C<%.skiptable>
+=item * C<%.op_skip_table>
 
 Reference to a 'seen-hash' of skipped opcodes.
 
-  'skiptable' => {
+  'op_skip_table' => {
     'bor_i_ic_ic' => 1,
     'xor_i_ic_ic' => 1,
     'tanh_n_nc' => 1,
@@ -99,8 +99,8 @@
 
     # Initialize self.
     self<max_op_num> := 0;
-    self<optable>    := hash();
-    self<skiptable>  := hash();
+    self<op_num_table>    := hash();
+    self<op_skip_table>  := hash();
     self<ops_past>   := list();
 
     self.load_op_map_files();
@@ -148,19 +148,20 @@
             if ($prev + 1 != $number) {
                 die("hole in ops.num before #$number");
             }
-            if self<optable>.exists($name) {
+            if self<op_num_table>.exists($name) {
                 die("duplicate opcode $name and $number");
             }
 
             $prev := $number;
-            self<optable>{$name} := $number;
+            self<op_num_table>{$name} := $number;
+            #say("$name maps to $number");
             if ( $number > self<max_op_num> ) {
                 self<max_op_num> := $number;
             }
         }
     }
 
-    #_dumper(self<optable>);
+    #_dumper(self<op_num_table>);
 }
 
 method _load_skip_file() {
@@ -180,10 +181,10 @@
     my $lines := SKIP.parse($buf);
 
     for $lines<op> {
-        if self<optable>.exists($_<name>) {
+        if self<op_num_table>.exists($_<name>) {
             die("skipped opcode '$_' is also in num_file");
         }
-        self<skiptable>{$_<name>} := 1;
+        self<op_skip_table>{$_<name>} := 1;
     }
 }
 
@@ -196,18 +197,21 @@
 
 =item * C<max_op_num>
 
-=item * C<optable>
+=item * C<op_num_table>
 
-=item * C<skiptable>
+=item * C<op_skip_table>
+
+=item * C<num_file>
 
 =end ACCESSORS
 
-method max_op_num() { self<max_op_num>; }
+method max_op_num()    { self<max_op_num>; }
 
-method optable()    { self<optable>; }
+method op_num_table()  { self<op_num_table>; }
 
-method skiptable()  { self<skiptable>; }
+method op_skip_table() { self<op_skip_table>; }
 
+method num_file()      { self<num_file>; }
 
 # Local Variables:
 #   mode: perl6


More information about the parrot-commits mailing list