Ticket #469: opsrenum.patch

File opsrenum.patch, 7.3 KB (added by jkeenan, 6 years ago)

Summation of changes applied in r38825 and r38829

  • lib/Parrot/OpsRenumber.pm

     
    1717 
    1818    $self = Parrot::OpsRenumber->new( { 
    1919        argv            => [ @ARGV ], 
    20         nolines         => $nolines_flag, 
    2120        moddir          => "lib/Parrot/OpLib", 
    2221        module          => "core.pm", 
    2322        inc_dir         => "include/parrot/oplib", 
    2423        inc_f           => "ops.h", 
    25         script          => "tools/build/opsrenumber.pl", 
     24        script          => "tools/dev/opsrenumber.pl", 
    2625    } ); 
    2726 
    2827    $self->prepare_ops(); 
    29     $self->renum_op_map_file( $PConfig{MAJOR} ); 
     28    $self->renum_op_map_file(); 
    3029 
    3130=cut 
    3231 
     
    7271 
    7372sub renum_op_map_file { 
    7473    my $self = shift; 
    75     my $major_version = shift; 
    7674 
    77     my $file = scalar(@_) ? shift : $self->{num_file}; 
     75    my $file = $self->{num_file}; 
    7876 
    7977    # We open up the currently existing ops.num and file and read it 
    8078    # line-by-line.  That file is basically divided into two halves 
     
    123121    # Parrot::Ops2pm::Base.  prepare_ops(), in turn, works off 
    124122    # Parrot::OpsFile. 
    125123 
    126     # So whether a particular opcode will appear in the *new* ops.num 
     124    # So whether a particular opcode will continue to appear in ops.num 
    127125    # depends entirely on whether or not it's found in 
    128126    # @{ $self->{ops}->{OPS} }.  If a particular opcode has been deleted or 
    129127    # gone missing from that array, then it won't appear in the new 
  • tools/dev/opsrenumber.pl

     
    66use warnings; 
    77 
    88use lib 'lib'; 
    9 use Parrot::Config qw( %PConfig ); 
    109use Parrot::OpsRenumber; 
    1110 
    1211my $self = Parrot::OpsRenumber->new( 
     
    2120); 
    2221 
    2322$self->prepare_ops(); 
    24 $self->renum_op_map_file($PConfig{MAJOR}); 
     23$self->renum_op_map_file(); 
    2524 
    2625exit 0; 
    2726 
     
    4140 
    4241All opcodes except the first seven are potentially deletable and the opcodes' 
    4342order 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 the 
    45 list. 
     43opcodes should be a rare event.  The program will automatically detect which 
     44opcodes have been deleted and will renumber the remaining codes appropriately. 
    4645 
     46The program, however, will B<not> automatically detect new opcodes.   This is 
     47a feature, not a bug, as it is intended to require someone to think about why 
     48new opcodes should be added.  Once a decision to add new opcodes has been 
     49made, those opcodes should be entered manually at the endc of 
     50F<src/ops/ops.num>, then F<tools/dev/opsrenumber.pl> (or F<make opsrenumber>) 
     51should be run. 
     52 
    4753=head1 SEE ALSO 
    4854 
    4955=over 4 
  • t/tools/ops2pm/05-renum_op_map_file.t

     
    66use strict; 
    77use warnings; 
    88 
    9 use Test::More qw(no_plan); # tests => 14; 
     9use Test::More tests =>  6; 
    1010use Carp; 
    1111use Cwd; 
    12 use File::Basename; 
    1312use File::Copy; 
    1413use File::Path qw( mkpath ); 
    1514use File::Spec; 
     
    3534    my $opsdir = File::Spec->catdir ( $tdir, 'src', 'ops' ); 
    3635    mkpath( $opsdir, 0, 755 ) or croak "Unable to make testing directory"; 
    3736 
    38     ##### Test pre-Parrot 1.0 case 
    39     my $major_version = 0; 
    40  
    4137    ##### Stage 1:  Generate ops.num de novo ##### 
    4238 
    4339    my @stage1 = qw( 
     
    5652            src/ops/bit.ops 
    5753        ) ], 
    5854        $numoutput, 
    59         $major_version, 
    6055    ); 
    6156    is($lastcode, q{bxors_s_s_sc}, 
    6257        "Stage 1:  Got expected last opcode"); 
     
    7368            src/ops/bit.ops 
    7469        ) ], 
    7570        $numoutput, 
    76         $major_version, 
    7771    ); 
    7872 
    7973    is($lastcode, q{bxor_i_i_ic}, 
     
    8175    is($lastnumber, 172, 
    8276        "Stage 2:  Got expected last opcode number"); 
    8377 
    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.ops 
    93             src/ops/bit.ops 
    94             src/ops/pic.ops 
    95         ) ], 
    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.original 
    109         bit_ops.original 
    110         ops_num.original 
    111     ); 
    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.ops 
    120             src/ops/bit.ops 
    121         ) ], 
    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 case 
    131     $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.ops 
    142             src/ops/bit.ops 
    143         ) ], 
    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.ops 
    159             src/ops/bit.ops 
    160             src/ops/pic.ops 
    161         ) ], 
    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  
    17178    # Go back where we started to activate cleanup 
    17279    chdir $cwd or croak "Unable to change back to starting directory: $!"; 
    17380} 
     
    17784#################### SUBROUTINES #################### 
    17885 
    17986sub run_test_stage { 
    180     my ($opsfilesref, $numoutput, $major_version) = @_; 
     87    my ($opsfilesref, $numoutput) = @_; 
    18188    my $self = Parrot::OpsRenumber->new( 
    18289        { 
    18390            argv    => $opsfilesref, 
     
    19097    ); 
    19198 
    19299    $self->prepare_ops(); 
    193     $self->renum_op_map_file($major_version); 
     100    $self->renum_op_map_file(); 
    194101    my ($lastcode, $lastnumber) = get_last_opcode($numoutput); 
    195102    return ($lastcode, $lastnumber); 
    196103}