Ticket #469: opsrenum.patch
File opsrenum.patch, 7.3 KB (added by jkeenan, 13 years ago) |
---|
-
lib/Parrot/OpsRenumber.pm
17 17 18 18 $self = Parrot::OpsRenumber->new( { 19 19 argv => [ @ARGV ], 20 nolines => $nolines_flag,21 20 moddir => "lib/Parrot/OpLib", 22 21 module => "core.pm", 23 22 inc_dir => "include/parrot/oplib", 24 23 inc_f => "ops.h", 25 script => "tools/ build/opsrenumber.pl",24 script => "tools/dev/opsrenumber.pl", 26 25 } ); 27 26 28 27 $self->prepare_ops(); 29 $self->renum_op_map_file( $PConfig{MAJOR});28 $self->renum_op_map_file(); 30 29 31 30 =cut 32 31 … … 72 71 73 72 sub renum_op_map_file { 74 73 my $self = shift; 75 my $major_version = shift;76 74 77 my $file = scalar(@_) ? shift :$self->{num_file};75 my $file = $self->{num_file}; 78 76 79 77 # We open up the currently existing ops.num and file and read it 80 78 # line-by-line. That file is basically divided into two halves … … 123 121 # Parrot::Ops2pm::Base. prepare_ops(), in turn, works off 124 122 # Parrot::OpsFile. 125 123 126 # So whether a particular opcode will appear in the *new*ops.num124 # So whether a particular opcode will continue to appear in ops.num 127 125 # depends entirely on whether or not it's found in 128 126 # @{ $self->{ops}->{OPS} }. If a particular opcode has been deleted or 129 127 # gone missing from that array, then it won't appear in the new -
tools/dev/opsrenumber.pl
6 6 use warnings; 7 7 8 8 use lib 'lib'; 9 use Parrot::Config qw( %PConfig );10 9 use Parrot::OpsRenumber; 11 10 12 11 my $self = Parrot::OpsRenumber->new( … … 21 20 ); 22 21 23 22 $self->prepare_ops(); 24 $self->renum_op_map_file( $PConfig{MAJOR});23 $self->renum_op_map_file(); 25 24 26 25 exit 0; 27 26 … … 41 40 42 41 All opcodes except the first seven are potentially deletable and the opcodes' 43 42 order may be rearranged. However, in and after Parrot 1.0.0, deletion of 44 opcodes should be a rare event. New opcodes should be added at the end of the45 list.43 opcodes should be a rare event. The program will automatically detect which 44 opcodes have been deleted and will renumber the remaining codes appropriately. 46 45 46 The program, however, will B<not> automatically detect new opcodes. This is 47 a feature, not a bug, as it is intended to require someone to think about why 48 new opcodes should be added. Once a decision to add new opcodes has been 49 made, those opcodes should be entered manually at the endc of 50 F<src/ops/ops.num>, then F<tools/dev/opsrenumber.pl> (or F<make opsrenumber>) 51 should be run. 52 47 53 =head1 SEE ALSO 48 54 49 55 =over 4 -
t/tools/ops2pm/05-renum_op_map_file.t
6 6 use strict; 7 7 use warnings; 8 8 9 use Test::More qw(no_plan); # tests => 14;9 use Test::More tests => 6; 10 10 use Carp; 11 11 use Cwd; 12 use File::Basename;13 12 use File::Copy; 14 13 use File::Path qw( mkpath ); 15 14 use File::Spec; … … 35 34 my $opsdir = File::Spec->catdir ( $tdir, 'src', 'ops' ); 36 35 mkpath( $opsdir, 0, 755 ) or croak "Unable to make testing directory"; 37 36 38 ##### Test pre-Parrot 1.0 case39 my $major_version = 0;40 41 37 ##### Stage 1: Generate ops.num de novo ##### 42 38 43 39 my @stage1 = qw( … … 56 52 src/ops/bit.ops 57 53 ) ], 58 54 $numoutput, 59 $major_version,60 55 ); 61 56 is($lastcode, q{bxors_s_s_sc}, 62 57 "Stage 1: Got expected last opcode"); … … 73 68 src/ops/bit.ops 74 69 ) ], 75 70 $numoutput, 76 $major_version,77 71 ); 78 72 79 73 is($lastcode, q{bxor_i_i_ic}, … … 81 75 is($lastnumber, 172, 82 76 "Stage 2: Got expected last opcode number"); 83 77 84 ##### Stage 3: Add some opcodes and regenerate ops.num #####85 86 TODO: {87 local $TODO = 'Post 1.0 regeneration problematic, TT #469';88 my @stage3 = qw( pic_ops.original );89 copy_into_position($samplesdir, \@stage3, q{original}, $opsdir);90 ($lastcode, $lastnumber) = run_test_stage(91 [ qw(92 src/ops/core.ops93 src/ops/bit.ops94 src/ops/pic.ops95 ) ],96 $numoutput,97 $major_version,98 );99 is($lastcode, q{pic_callr___pc},100 "Stage 3: Got expected last opcode");101 is($lastnumber, 189,102 "Stage 3: Got expected last opcode number");103 }104 105 ##### Stage 4: Again generate ops.num de novo #####106 107 my @stage4 = qw(108 core_ops.original109 bit_ops.original110 ops_num.original111 );112 copy_into_position($samplesdir, \@stage4, q{original}, $opsdir);113 foreach my $f ( qw| core bit | ) {114 copy qq{$samplesdir/${f}_ops.original}, qq{src/ops/$f.ops.post}115 or croak "Unable to store $f for later testing: $!";116 }117 ($lastcode, $lastnumber) = run_test_stage(118 [ qw(119 src/ops/core.ops120 src/ops/bit.ops121 ) ],122 $numoutput,123 $major_version,124 );125 is($lastcode, q{bxors_s_s_sc},126 "Stage 4: Got expected last opcode");127 is($lastnumber, 177,128 "Stage 4: Got expected last opcode number");129 130 ##### Test post-Parrot 1.0 case131 $major_version = 1;132 133 ###### Stage 5: Delete some opcodes and regenerate ops.num #####134 135 TODO: {136 local $TODO = 'Post 1.0 regeneration should work just like pre-1.0 regeneration, TT #469';137 my @stage5 = qw( bit_ops.second );138 copy_into_position($samplesdir, \@stage5, q{second}, $opsdir);139 ($lastcode, $lastnumber) = run_test_stage(140 [ qw(141 src/ops/core.ops142 src/ops/bit.ops143 ) ],144 $numoutput,145 $major_version,146 );147 is($lastcode, q{bxor_i_ic_ic},148 "Stage 5: Got expected last opcode");149 is($lastnumber, 189,150 "Stage 5: Got expected last opcode number");151 152 ##### Stage 6: Add some opcodes and regenerate ops.num #####153 154 my @stage6 = qw( pic_ops.original );155 copy_into_position($samplesdir, \@stage6, q{original}, $opsdir);156 ($lastcode, $lastnumber) = run_test_stage(157 [ qw(158 src/ops/core.ops159 src/ops/bit.ops160 src/ops/pic.ops161 ) ],162 $numoutput,163 $major_version,164 );165 is($lastcode, q{pic_callr___pc},166 "Stage 6: Got expected last opcode: additions permitted");167 is($lastnumber, 194,168 "Stage 6: Got expected last opcode number: additions permitted");169 }170 171 78 # Go back where we started to activate cleanup 172 79 chdir $cwd or croak "Unable to change back to starting directory: $!"; 173 80 } … … 177 84 #################### SUBROUTINES #################### 178 85 179 86 sub run_test_stage { 180 my ($opsfilesref, $numoutput , $major_version) = @_;87 my ($opsfilesref, $numoutput) = @_; 181 88 my $self = Parrot::OpsRenumber->new( 182 89 { 183 90 argv => $opsfilesref, … … 190 97 ); 191 98 192 99 $self->prepare_ops(); 193 $self->renum_op_map_file( $major_version);100 $self->renum_op_map_file(); 194 101 my ($lastcode, $lastnumber) = get_last_opcode($numoutput); 195 102 return ($lastcode, $lastnumber); 196 103 }