[svn:parrot] r46908 - in branches/ops_pct/compilers/opsc: . src/Ops
cotto at svn.parrot.org
cotto at svn.parrot.org
Sun May 23 06:33:57 UTC 2010
Author: cotto
Date: Sun May 23 06:33:57 2010
New Revision: 46908
URL: https://trac.parrot.org/parrot/changeset/46908
Log:
[opsc] move renumbering code into Emitter, fixing opsc emitter tests
add --force-regen to ops2c as an alternative to making trivial changes to ops.num
Modified:
branches/ops_pct/compilers/opsc/ops2c.nqp
branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm
branches/ops_pct/compilers/opsc/src/Ops/File.pm
branches/ops_pct/compilers/opsc/src/Ops/Renumberer.pm
Modified: branches/ops_pct/compilers/opsc/ops2c.nqp
==============================================================================
--- branches/ops_pct/compilers/opsc/ops2c.nqp Sun May 23 04:23:13 2010 (r46907)
+++ branches/ops_pct/compilers/opsc/ops2c.nqp Sun May 23 06:33:57 2010 (r46908)
@@ -32,6 +32,10 @@
$arg.long('help');
$arg.short('h');
+$arg := $getopts.add();
+$arg.long('force-regen');
+$arg.short('f');
+
my $opts := $getopts.get_options(pir::getinterp__p()[2]);
if $opts<core> {
@@ -57,12 +61,15 @@
@files.push( $opts<dynamic>);
}
elsif (+$opts == 0 || $opts<help>) {
- say("usage:
+ say("This is ops2c, part of Parrot build infrastructure.
+usage:
ops2c --core
ops2c --dynamic path/to/dynops.ops");
pir::exit(0);
}
+my $force_regen := ?$opts<force-regen>;
+
if ($opts<no-lines>) {
#TODO: figure out how to generate line numbers
# $emit_lines is currently ignored
@@ -96,6 +103,9 @@
);
unless $debug {
+ if $force_regen || $f<renum>.need_regeneration {
+ $emitter.print_ops_num_files();
+ }
$emitter.print_c_header_files();
$emitter.print_c_source_file();
}
Modified: branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm Sun May 23 04:23:13 2010 (r46907)
+++ branches/ops_pct/compilers/opsc/src/Ops/Emitter.pm Sun May 23 06:33:57 2010 (r46908)
@@ -72,10 +72,12 @@
method bs() { self<bs> };
method print_c_header_files() {
+
my $fh := pir::open__PSs(self<func_header>, 'w')
|| die("Can't open "~ self<func_header>);
self.emit_c_op_func_header($fh);
$fh.close();
+
if self.ops_file<core> {
$fh := pir::open__PSs(self<enum_header>, 'w')
|| die("Can't open "~ self<enum_header>);
@@ -113,6 +115,138 @@
self._emit_coda($fh);
}
+method print_ops_num_files() {
+
+ my $file := ~self<dir> ~ ~self<ops_file>.oplib.num_file;
+ my $fh := pir::open__pss($file, 'w')
+ || die("Can't open $file for writing: " ~ ~pir::err__s());
+ self.emit_ops_num_file($fh);
+ $fh.close();
+
+ $file := ~self<dir> ~ "include/parrot/opsenum.h";
+ $fh := pir::open__pss($file, 'w')
+ || die("Can't open $file for writing: " ~ ~pir::err__s());
+ self.emit_c_opsenum_header($fh);
+ $fh.close();
+}
+
+method emit_ops_num_file($fh) {
+
+ if !self.exists('max_fixed_op_num') {
+ self._prepare_ops_num();
+ }
+
+ $fh.print( join('', |self<ops_num_start>) );
+ my $max_op_num := self<max_fixed_op_num> + 0; #+ 0 to force cloning
+
+ for self.ops_file.ops -> $op {
+ if self<numbered_ops>.exists( $op.full_name ) {
+
+ $max_op_num++;
+
+ my $space := pir::repeat__SsI(' ',
+ 35 - pir::length__Is($op.full_name) - pir::length__Is(~$max_op_num));
+ $fh.print($op.full_name ~ $space ~ $max_op_num ~ "\n");
+ }
+ }
+
+}
+
+method emit_c_opsenum_header($fh) {
+
+ if !self.exists('max_fixed_op_num') {
+ self._prepare_ops_num();
+ }
+
+ self.emit_opsenum_h_preamble($fh);
+
+ self.emit_opsenum_h_body($fh);
+
+ self.emit_opsenum_h_postamble($fh);
+
+}
+
+method emit_opsenum_h_body($fh) {
+
+ my $max_op_num := self<max_fixed_op_num> + 0;
+ for self.ops_file.ops -> $op {
+ if self<numbered_ops>.exists( $op.full_name ) {
+ $max_op_num++;
+
+ my $space := pir::repeat__SsI(' ', 30 - pir::length__Is($op.full_name));
+ $fh.print(" enum_ops_" ~ $op.full_name ~ $space ~ "=");
+ $space := pir::repeat__SsI(' ', 5 - pir::length__Is(~$max_op_num));
+ $fh.print($space ~ $max_op_num ~ ",\n");
+ }
+ }
+}
+
+method _prepare_ops_num() {
+
+ #grab all ops in ops.num
+ self<numbered_ops> := hash();
+ my $found_dynamic := 0;
+ self<max_fixed_op_num> := 0;
+ self<ops_num_start> := list();
+
+ #record which ones have fixed numbers and which just need to be somewhere in ops.num
+ for self.ops_file.oplib.num_file_lines -> $line {
+
+ #copy all lines through ###DYNAMIC### into the new ops.num verbatim
+ unless $found_dynamic {
+ self<ops_num_start>.push(~$line);
+ }
+
+ if $line<op> {
+ if $found_dynamic {
+ self<numbered_ops>{ $line<op><name> } := 1;
+ #say("# added '"~$line<op><name> ~" to numered ops");
+ }
+ else {
+ #don't need to keep track of fixed ops
+ self<max_fixed_op_num> := +$line<op><number>;
+ #say("# added '"~$line<op><name> ~" to fixed ops");
+ }
+ }
+ elsif $line<dynamic> {
+ $found_dynamic := 1;
+ }
+ }
+}
+
+method emit_opsenum_h_preamble($fh) {
+ $fh.print(q|
+/* ex: set ro ft=c:
+* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
+*
+* This file is generated automatically from 'ops2c'.
+*
+* Any changes made here will be lost!
+*
+*/
+
+#ifndef OPSENUM_H_GUARD
+#define OPSENUM_H_GUARD
+
+enum OPS_ENUM {
+|);
+}
+
+method emit_opsenum_h_postamble($fh) {
+ $fh.print(q|};
+
+#endif /* OPSENUM_H_GUARD */
+
+/* GENERATED BY ops2c */
+/*
+* Local variables:
+* c-file-style: "parrot"
+* End:
+* vim: expandtab shiftwidth=4:
+*/|);
+}
+
+
method print_c_source_file() {
# Build file in memeory
my $fh := pir::new__Ps('StringHandle');
Modified: branches/ops_pct/compilers/opsc/src/Ops/File.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/File.pm Sun May 23 04:23:13 2010 (r46907)
+++ branches/ops_pct/compilers/opsc/src/Ops/File.pm Sun May 23 06:33:57 2010 (r46908)
@@ -206,11 +206,6 @@
self._calculate_op_codes();
- if self<renum>.need_regeneration() {
- self<renum>.regenerate_ops_num();
- self._calculate_op_codes();
- }
-
self;
}
@@ -328,28 +323,6 @@
self<version> := @bits;
}
-=begin
-
-=back
-
-=head1 SEE ALSO
-
-=over 4
-
-=item C<Parrot::Op>
-
-=item C<Parrot::OpTrans>
-
-=item F<tools/build/ops2c.pl>
-
-=item F<tools/build/ops2pm.pl>
-
-=item F<tools/build/pbc2c.pl>
-
-=back
-
-=end
-
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
Modified: branches/ops_pct/compilers/opsc/src/Ops/Renumberer.pm
==============================================================================
--- branches/ops_pct/compilers/opsc/src/Ops/Renumberer.pm Sun May 23 04:23:13 2010 (r46907)
+++ branches/ops_pct/compilers/opsc/src/Ops/Renumberer.pm Sun May 23 06:33:57 2010 (r46908)
@@ -16,7 +16,7 @@
=begin DESCRIPTION
-This class is responsible for renumbering src/ops/ops.num when the number or
+This class is responsible for regenerating src/ops/ops.num when the number or
order of ops there needs to be changed.
=end DESCRIPTION
@@ -61,15 +61,15 @@
=begin METHODS
-=item C<need_renumbering>
+=item C<need_regeneration>
-Check if ops.num needs to be renumbered.
+Check if ops.num needs to be regenerated.
=end METHODS
method need_regeneration() {
- #only need renumbering for core ops
+ #only need regeneration for core ops
unless self<ops_file>.oplib {
return 0;
}
@@ -82,7 +82,7 @@
my $op_num_table := self<ops_file>.oplib.op_num_table;
my $opsfile_ops := self<ops_file>.ops;
my $opsfile_num := 0;
- my $need_renumbering := 0;
+ my $need_regeneration := 0;
#find out if the order in ops.num reflects the order in Ops::File
for $opsfile_ops -> $opsfile_op {
@@ -93,103 +93,14 @@
if (!$opsfile_op<experimental> && $opsfile_num != $op_num_table_num) {
say("# Opsfile and ops.num disagree about $op_name: $opsfile_num vs $op_num_table_num");
- $need_renumbering := 1;
+ $need_regeneration := 1;
}
$opsfile_num++;
}
- $need_renumbering;
+ $need_regeneration;
}
-method regenerate_ops_num() {
-
- #grab all ops in ops.num
- my %fixed_ops := hash();
- my %numbered_ops := hash();
- my $found_dynamic := 0;
- my $max_op_num := 0;
- my $ops_num_fh := pir::open__PSs(self<ops_file>.oplib.num_file, 'w')
- || die("Can't open "~ self<ops_file>.oplib.num_file);
-
- #record which ones have fixed numbers and which just need to be somewhere in ops.num
- say("# regenerating ops.num and include/parrot/opsenum.h");
- for self<ops_file>.oplib.num_file_lines -> $line {
-
- #copy all lines through ###DYNAMIC### into the new ops.num verbatim
- unless $found_dynamic {
- $ops_num_fh.print(~$line);
- }
-
- if $line<op> {
- if $found_dynamic {
- %numbered_ops{ $line<op><name> } := 1;
- #say("# added '"~$line<op><name> ~" to numered ops");
- }
- else {
- %fixed_ops{ $line<op><name> } := +$line<op><number>;
- $max_op_num := +$line<op><number>;
- }
- }
- elsif $line<dynamic> {
- $found_dynamic := 1;
- }
- }
-
- my $opsenum_fh := pir::open__pss("include/parrot/opsenum.h", "w");
- $opsenum_fh.print( self._opsenum_h_preamble )
- || die("Can't open include/parrot/opsenum.h");
-
- for self<ops_file>.ops -> $op {
- if %numbered_ops.exists( $op.full_name ) {
- $max_op_num++;
- my $space := pir::repeat__SsI(' ',
- 35 - pir::length__Is($op.full_name) - pir::length__Is(~$max_op_num));
- $ops_num_fh.print($op.full_name ~ $space ~ $max_op_num ~ "\n");
-
- $space := pir::repeat__SsI(' ', 30 - pir::length__Is($op.full_name));
- $opsenum_fh.print(" enum_ops_" ~ $op.full_name ~ $space ~ "=");
- $space := pir::repeat__SsI(' ', 5 - pir::length__Is(~$max_op_num));
- $opsenum_fh.print($space ~ $max_op_num ~ ",\n");
- }
- }
-
- $opsenum_fh.print( self._opsenum_h_postamble );
-
- $opsenum_fh.close();
- $ops_num_fh.close();
-}
-
-method _opsenum_h_preamble() {
- return q|
-/* ex: set ro ft=c:
-* !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
-*
-* This file is generated automatically from 'ops2c'.
-*
-* Any changes made here will be lost!
-*
-*/
-
-#ifndef OPSENUM_H_GUARD
-#define OPSENUM_H_GUARD
-
-enum OPS_ENUM {
-|;
-}
-
-method _opsenum_h_postamble() {
- return q|};
-
-#endif /* OPSENUM_H_GUARD */
-
-/* GENERATED BY ops2c */
-/*
-* Local variables:
-* c-file-style: "parrot"
-* End:
-* vim: expandtab shiftwidth=4:
-*/|;
-}
# Local Variables:
# mode: perl6
# fill-column: 100
More information about the parrot-commits
mailing list