cvsuser     04/12/30 02:49:15

  Modified:    build_tools ops2c.pl ops2pm.pl
               lib/Parrot OpsFile.pm
  Log:
  [perl #33589] [PATCH] --no-lines and --help for ops2*.pl
  
  This patch let's ops2c.pl and ops2pm.pl use Getopt::Long. The command line
  options
  '--help' and '--no-lines' are new.
  
  Courtesy of Bernhard Schmalhofer <[EMAIL PROTECTED]>
  
  Revision  Changes    Path
  1.81      +46 -35    parrot/build_tools/ops2c.pl
  
  Index: ops2c.pl
  ===================================================================
  RCS file: /cvs/public/parrot/build_tools/ops2c.pl,v
  retrieving revision 1.80
  retrieving revision 1.81
  diff -u -r1.80 -r1.81
  --- ops2c.pl  24 Nov 2004 17:43:11 -0000      1.80
  +++ ops2c.pl  30 Dec 2004 10:49:14 -0000      1.81
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: ops2c.pl,v 1.80 2004/11/24 17:43:11 leo Exp $
  +# $Id: ops2c.pl,v 1.81 2004/12/30 10:49:14 leo Exp $
   
   =head1 NAME
   
  @@ -8,7 +8,8 @@
   
   =head1 SYNOPSIS
   
  -    % perl build_tools/ops2c.pl transform options
  +    % perl build_tools/ops2c.pl trans [--help] [--no-lines] [--dynamic] 
[--core | input.ops [input2.ops ...]]
  +       trans := C | CGoto | CGP | CSwitch | CPrederef
   
   For example:
   
  @@ -58,6 +59,10 @@
   
   =over 4
   
  +=item C<--help>
  +
  +Print synopsis.
  +
   =item C<--dynamic>
   
   Indicate that the opcode library is dynamic.
  @@ -66,6 +71,10 @@
   
   Build the Parrot core opcode library.
   
  +=item C<--no-lines>
  +
  +Do not generate C<#line> directives in the generated C code.
  +
   =back
   
   =head1 SEE ALSO
  @@ -98,6 +107,9 @@
   
   use strict;
   use lib 'lib';
  +
  +use Getopt::Long;
  +
   use Parrot::OpsFile;
   use Parrot::OpLib::core;
   
  @@ -108,45 +120,44 @@
        'io' => 'PARROT_ARGDIR_INOUT'
   );
   
  +#
  +# Look at the command line options
  +#
  +
  +# TODO: Use Pod::Usage
  +my ( $nolines_flag, $help_flag, $dynamic_flag, $core_flag );
  +GetOptions( "no-lines"      => \$nolines_flag,
  +            "help"          => \$help_flag,
  +            "dynamic|d"     => \$dynamic_flag,
  +            "core"          => \$core_flag,
  +          );
  +
   sub Usage {
       print STDERR <<_EOF_;
  -usage: $0 trans [--dynamic] [--core | input.ops [input2.ops ...]]
  +usage: $0 trans [--help] [--no-lines] [--dynamic] [--core | input.ops 
[input2.ops ...]]
          trans := C | CGoto | CGP | CSwitch | CPrederef
   _EOF_
       exit 1;
   }
   
  -#
  -# Process command-line argument:
  -#
  -
  -Usage() unless @ARGV >= 2;
  +Usage() if $help_flag;
  +Usage() unless @ARGV;
   
   my $trans_class = "Parrot::OpTrans::" . shift @ARGV;
   
   eval "require $trans_class";
   
  -my $trans = $trans_class->new;
  +my $trans = $trans_class->new();
   
   # Not used
  -my $prefix  = $trans->prefix;
  -my $suffix  = $trans->suffix;
  +my $prefix  = $trans->prefix();
  +my $suffix  = $trans->suffix();
   # Used as ${defines}
  -my $defines = $trans->defines;
  -my $opsarraytype = $trans->opsarraytype;
  -my $core_type = $trans->core_type;
  -
  -my $dynamic;
  -my $file = shift @ARGV;
  -if ($file eq '-d' || $file eq '--dynamic') {
  -    $file = shift @ARGV;
  -    $dynamic = 1;
  -}
  -my $core = 0;
  -if ($file eq '--core') {
  -     $file = 'core.ops';
  -     $core = 1;
  -}
  +my $defines = $trans->defines();
  +my $opsarraytype = $trans->opsarraytype();
  +my $core_type = $trans->core_type();
  +
  +my $file = $core_flag ? 'core.ops' : shift @ARGV;
   
   my $base = $file;
   $base =~ s/\.ops$//;
  @@ -156,12 +167,12 @@
   my $header  = "include/$include";
   my $source  = "ops/${base}_ops${suffix}.c";
   
  -if ($base =~ m!^dynoplibs/! || $dynamic) {
  +if ($base =~ m!^dynoplibs/! || $dynamic_flag) {
       $source  =~ s!ops/!!;
       $header = "${base}_ops${suffix}.h";
       $base =~ s!^.*[/\\]!!;
       $include = "${base}_ops${suffix}.h";
  -    $dynamic = 1;
  +    $dynamic_flag = 1;
   }
   
   my %hashed_ops;
  @@ -171,8 +182,8 @@
   #
   
   my $ops;
  -if ($core) {
  -    $ops = Parrot::OpsFile->new('ops/core.ops');
  +if ($core_flag) {
  +    $ops = Parrot::OpsFile->new( [ "ops/$file" ], $nolines_flag );
       $ops->{OPS} = $Parrot::OpLib::core::ops;
       $ops->{PREAMBLE} = $Parrot::OpLib::core::preamble;
   }
  @@ -192,7 +203,7 @@
        die "$0: Could not read ops file '$opsfile'!\n" unless -r $opsfile;
       }
   
  -    $ops = new Parrot::OpsFile @opsfiles;
  +    $ops = Parrot::OpsFile->new( [EMAIL PROTECTED], $nolines_flag );
   
       my $cur_code = 0;
       for(@{$ops->{OPS}}) {
  @@ -214,7 +225,7 @@
   # Open the output files:
   #
   
  -if (!$dynamic && ! -d $incdir) {
  +if (!$dynamic_flag && ! -d $incdir) {
       mkdir($incdir, 0755) or die "ops2c.pl: Could not mkdir $incdir $!!\n";
   }
   
  @@ -405,7 +416,7 @@
   my $line = 0; while (<SOURCE>) { $line++; } $line+=2;
   close(SOURCE);
   open(SOURCE, ">>$source") || die "Error appending to $source: $!\n";
  -print SOURCE "#line $line \"$source\"\n" unless $ENV{PARROT_NO_LINE};
  +print SOURCE qq{#line $line "$source"\n} unless $nolines_flag;
   
   
   #
  @@ -497,7 +508,7 @@
   END_C
   }
   
  -if ($suffix eq '' && !$dynamic) {
  +if ($suffix eq '' && !$dynamic_flag) {
       $getop = 'get_op';
       my $hash_size = 3041;
       $tot = $index + scalar keys(%names);
  @@ -672,7 +683,7 @@
   
   END_C
   
  -if ($dynamic) {
  +if ($dynamic_flag) {
       my $load_func = "Parrot_lib_${base}_ops${suffix}_load";
       print SOURCE <<END_C;
   /*
  
  
  
  1.21      +48 -24    parrot/build_tools/ops2pm.pl
  
  Index: ops2pm.pl
  ===================================================================
  RCS file: /cvs/public/parrot/build_tools/ops2pm.pl,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ops2pm.pl 30 Nov 2004 11:15:44 -0000      1.20
  +++ ops2pm.pl 30 Dec 2004 10:49:14 -0000      1.21
  @@ -1,6 +1,7 @@
   #! perl -w
  -# Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
  -# $Id: ops2pm.pl,v 1.20 2004/11/30 11:15:44 leo Exp $
  +
  +# Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  +# $Id: ops2pm.pl,v 1.21 2004/12/30 10:49:14 leo Exp $
   
   =head1 NAME
   
  @@ -8,13 +9,27 @@
   
   =head1 SYNOPSIS
   
  -    % perl build_tools/ops2pm.pl ops/core.ops ops/bit.ops ...
  +    % perl build_tools/ops2pm.pl [--help] [--no-lines] input.ops [input2.ops 
...]
   
   =head1 DESCRIPTION
   
   Reads the ops files listed on the command line and outputs a
   C<Parrot::OpLib::core> module containing information about the ops.
   
  +=head2 Options
  +
  +=over 4
  +
  +=item C<--help>
  +
  +Print synopsis.
  +
  +=item C<--no-lines>
  +
  +Do not generate C<#line> directives in the generated C code.
  +
  +=back
  +
   =head2 WARNING
   
   Generating a C<Parrot::OpLib::core> module for a set of ops files that
  @@ -56,22 +71,33 @@
   
   use strict;
   use lib 'lib';
  -use Parrot::OpsFile;
   
   use Data::Dumper;
   $Data::Dumper::Useqq  = 1;
   #$Data::Dumper::Terse  = 1;
   #$Data::Dumper::Indent = 0;
  +use Getopt::Long;
   
  -my $moddir  = "lib/Parrot/OpLib";
  +use Parrot::OpsFile;
  +
  +#
  +# Look at the command line options
  +#
  +
  +# TODO: Use Pod::Usage
  +my ( $nolines_flag, $help_flag );
  +GetOptions( "no-lines"      => \$nolines_flag,
  +            "help"          => \$help_flag,
  +          );
   
   sub Usage {
       print STDERR <<_EOF_;
  -usage: $0 input.ops [input2.ops ...]
  +usage: $0 [--help] [--no-lines] input.ops [input2.ops ...]
   _EOF_
       exit;
   }
   
  +Usage() if $help_flag;
   Usage() unless @ARGV;
   
   
  @@ -79,15 +105,15 @@
   # Read in the first ops file.
   #
   
  -my $file = shift @ARGV;
   my $package = "core";
  -my $module  = "lib/Parrot/OpLib/core.pm";
  +my $moddir  = "lib/Parrot/OpLib";
  +my $module  = "$moddir/core.pm";
   
  +my $file = shift @ARGV;
   die "$0: Could not find ops file '$file'!\n" unless -e $file;
  -my $ops = new Parrot::OpsFile $file;
  +my $ops = Parrot::OpsFile->new( [ $file ], $nolines_flag );
   die "$0: Could not read ops file '$file'!\n" unless defined $ops;
   
  -
   #
   # Copy the ops from the remaining .ops files to the object just created.
   #
  @@ -102,7 +128,7 @@
       $seen{$file} = 1;
   
       die "$0: Could not find ops file '$file'!\n" unless -e $file;
  -    my $temp_ops = new Parrot::OpsFile $file;
  +    my $temp_ops = Parrot::OpsFile->new( [ $file ], $nolines_flag );
       die "$0: Could not read ops file '$file'!\n" unless defined $temp_ops;
   
       die "OPS invalid for $file" unless ref $temp_ops->{OPS};
  @@ -122,22 +148,21 @@
   
   
   # Renumber the ops based on ops.num
  -#
  +{
  +    load_op_map_file();
   
  -&load_op_map_file;
  +    my $cur_code = 0;
  +    for(@{$ops->{OPS}}) {
  +        $_->{CODE} = find_op_number($_->full_name, $_->{experimental});
  +    }
   
  -my $cur_code = 0;
  -for(@{$ops->{OPS}}) {
  -    $_->{CODE} = find_op_number($_->full_name, $_->{experimental});
  +    @{$ops->{OPS}} = sort { $a->{CODE} <=> $b->{CODE} } (@{$ops->{OPS}} );
   }
   
  -my @sorted = sort { $a->{CODE} <=> $b->{CODE} } (@{$ops->{OPS}} );
  [EMAIL PROTECTED]>{OPS}} = @sorted;
  -
   # create opsfile with valid ops from ops.num
   # or from experimental
   
  -my $real_ops = new Parrot::OpsFile;
  +my $real_ops = Parrot::OpsFile->new( [ ], $nolines_flag );
   $real_ops->{PREAMBLE} = $ops->{PREAMBLE};
   $real_ops->version($ops->version);
   
  @@ -156,10 +181,8 @@
       push @{$real_ops->{OPS}}, $_;
       ++$seq;
   }
  -#
  + 
   # Open the output file:
  -#
  -
   if (! -d $moddir) {
       mkdir($moddir, 0755) or die "$0: Could not mkdir $moddir: $!!\n";
   }
  @@ -171,7 +194,7 @@
   # Print the preamble for the MODULE file:
   #
   
  -my $version = $real_ops->version;
  +my $version = $real_ops->version();
   
   # Hide the pod.
   
  @@ -325,3 +348,4 @@
   
   exit 0;
   
  +# vim: expandtab shiftwidth=4:
  
  
  
  1.47      +9 -16     parrot/lib/Parrot/OpsFile.pm
  
  Index: OpsFile.pm
  ===================================================================
  RCS file: /cvs/public/parrot/lib/Parrot/OpsFile.pm,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- OpsFile.pm        27 Nov 2004 09:32:16 -0000      1.46
  +++ OpsFile.pm        30 Dec 2004 10:49:15 -0000      1.47
  @@ -1,6 +1,6 @@
   #! perl -w
   # Copyright: 2001-2004 The Perl Foundation.  All Rights Reserved.
  -# $Id: OpsFile.pm,v 1.46 2004/11/27 09:32:16 leo Exp $
  +# $Id: OpsFile.pm,v 1.47 2004/12/30 10:49:15 leo Exp $
   
   =head1 NAME
   
  @@ -189,11 +189,11 @@
   
   sub new
   {
  -    my ($class, @files) = @_;
  +    my ($class, $files, $nolines) = @_;
   
       my $self = bless { PREAMBLE => '' }, $class;
   
  -    $self->read_ops($_) for @files;
  +    $self->read_ops($_, $nolines) for @{$files};
   
       # FILE holds a space separated list of opsfile name
       if ($self->{FILE}) {
  @@ -210,7 +210,7 @@
   
   =over 4
   
  -=item C<read_ops($file)>
  +=item C<read_ops($file,$nolines)>
   
   Reads in the specified .ops file, gathering information about the ops.
   
  @@ -218,7 +218,7 @@
   
   sub read_ops
   {
  -    my ($self, $file) = @_;
  +    my ($self, $file, $nolines) = @_;
       my $ops_file = "src/" . $file;
   
       open OPS, $file or die "Could not open ops file '$file' ($!)!";
  @@ -413,7 +413,7 @@
           if (/^}\s*$/)
           {
               $count += $self->make_op($count, $type, $short_name, $body, 
[EMAIL PROTECTED],
  -                [EMAIL PROTECTED], $line, $orig, [EMAIL PROTECTED], $flags);
  +                [EMAIL PROTECTED], $line, $orig, [EMAIL PROTECTED], $flags, 
$nolines);
   
               $seen_op = 0;
   
  @@ -460,7 +460,7 @@
   }
   
   =item C<make_op($code,
  -$type, $short_name, $body, $args, $argdirs, $line, $file, $labels, $flags)>
  +$type, $short_name, $body, $args, $argdirs, $line, $file, $labels, $flags, 
$nolines)>
   
   Returns a new C<Parrot::Op> instance for the specified arguments.
   
  @@ -469,7 +469,7 @@
   sub make_op
   {
       my ($self, $code, $type, $short_name, $body, $args, $argdirs,
  -            $line, $file, $labels, $flags) = @_;
  +        $line, $file, $labels, $flags, $nolines) = @_;
       my $counter = 0;
       my $absolute = 0;
       my $branch = 0;
  @@ -564,14 +564,7 @@
   
           $body =~ s/\$(\d+)/[EMAIL PROTECTED]/mg;
   
  -        if ($ENV{PARROT_NO_LINE})
  -        {
  -            $op->body($body);
  -        }
  -        else
  -        {
  -            $op->body(qq{#line $line "$file"\n}.$body);
  -        }
  +        $op->body( $nolines ? $body : qq{#line $line "$file"\n$body} );
   
           # Constants here are defined in include/parrot/op.h
           or_flag(\$jumps, "PARROT_JUMP_RELATIVE")   if ($branch);
  
  
  

Reply via email to