Author: jkeenan
Date: Mon Feb 12 19:36:00 2007
New Revision: 16961
Modified:
branches/buildtools/lib/Parrot/Ops2c/Utils.pm
branches/buildtools/tools/build/ops2c.pl
Log:
1. Added 'script' as argument to Parrot::Ops2c::Utils::new().
2. Completed migration of initialization code from tools/build/ops2c.pl to
Parrot::Ops2c::Utils::new(). This entailed moving these subroutines to
Utils.pm: _compose_preamble().
3. Migrated code for printing C-header file from tools/build/ops2c.pl to
Parrot::Ops2c::Utils::print_c_header_file. This entailed moving these
subroutines to Utils.pm: _print_preamble_header();
_print_run_core_func_decl_header(); _print_coda() (though latter is still also
defined in ops2c.pl, as it is still needed by printing to source file).
Modified: branches/buildtools/lib/Parrot/Ops2c/Utils.pm
==============================================================================
--- branches/buildtools/lib/Parrot/Ops2c/Utils.pm (original)
+++ branches/buildtools/lib/Parrot/Ops2c/Utils.pm Mon Feb 12 19:36:00 2007
@@ -1,5 +1,5 @@
# Copyright (C) 2004-2006, The Perl Foundation.
-# $Id: Utils.pm 16894 2007-02-04 22:54:29Z jkeenan $
+# $Id$
package Parrot::Ops2c::Utils;
use strict;
use lib ("lib/");
@@ -14,6 +14,7 @@
}
my $flagref = $argsref->{flag};
my @argv = @{$argsref->{argv}};
+ $argsref->{script} ||= "tools/build/ops2c.pl";
unless (@argv) {
print STDERR "Parrot::Ops2c::Utils::new() requires 'trans' options:
$!";
return;
@@ -41,15 +42,15 @@
$base =~ s/\.ops$//;
my $base_ops_stub = $base . q{_ops} . $suffix;
my $base_ops_h = $base_ops_stub . q{.h};
-
+
my $incdir = "include/parrot/oplib";
my $include = "parrot/oplib/$base_ops_h";
my $header = "include/$include";
-
+
# SOURCE is closed and reread, which confuses make -j
# create a temp file and rename it
my $source = "src/ops/$base_ops_stub.c.temp";
-
+
if ( $base =~ m!^src/dynoplibs/! || $flagref->{dynamic} ) {
$source =~ s!src/ops/!!;
$header = $base_ops_h;
@@ -57,7 +58,7 @@
$include = $base_ops_h;
$flagref->{dynamic} = 1;
}
-
+
my $sym_export = $flagref->{dynamic}
? 'PARROT_DYNEXT_EXPORT'
: 'PARROT_API';
@@ -76,7 +77,7 @@
flag => $flagref,
} );
}
-
+
my %versions = (
major => $ops->major_version,
minor => $ops->minor_version,
@@ -85,6 +86,20 @@
my $num_ops = scalar $ops->ops;
my $num_entries = $num_ops + 1; # For trailing NULL
+ if ( ! $flagref->{dynamic} && ! -d $incdir ) {
+ mkdir( $incdir, 0755 )
+ or die "ops2c.pl: Could not mkdir $incdir $!!\n";
+ }
+
+ my $preamble = _compose_preamble($file, $argsref->{script});
+
+ my $init_func = join q{_}, (
+ q{Parrot},
+ q{DynOp},
+ $base . $suffix,
+ @versions{ qw(major minor patch) },
+ );
+
###############################
$argsref->{argv} = [EMAIL PROTECTED];
$argsref->{trans} = $trans;
@@ -103,6 +118,9 @@
$argsref->{num_ops} = $num_ops;
$argsref->{num_entries} = $num_entries;
+ $argsref->{preamble} = $preamble;
+ $argsref->{init_func} = $init_func;
+
$argsref->{flag} = $flagref;
return bless $argsref, $class;
}
@@ -125,14 +143,14 @@
foreach my $f ( $argsref->{file}, @{$argsref->{argv}} ) {
if ( $opsfiles{$f} ) {
- print STDERR "$0: Ops file '$f' mentioned more than once!\n";
+ print STDERR "$argsref->{script}: Ops file '$f' mentioned more
than once!\n";
next;
}
$opsfiles{$f} = 1;
push @opsfiles, $f;
- die "$0: Could not read ops file '$f'!\n" unless -r $f;
+ die "$argsref->{script}: Could not read ops file '$f'!\n" unless -r $f;
}
my $ops = Parrot::OpsFile->new( [EMAIL PROTECTED],
$argsref->{flag}->{nolines} );
@@ -144,4 +162,91 @@
return $ops;
}
+sub _compose_preamble {
+ my ($file, $script) = @_;
+ my $preamble = <<END_C;
+/* ex: set ro:
+ * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
+ *
+ * This file is generated automatically from '$file' (and possibly other
+ * .ops files). by $script.
+ *
+ * Any changes made here will be lost!
+ *
+ */
+
+END_C
+ return $preamble;
+}
+
+sub print_c_header_file {
+ my $self = shift;
+
+ open my $HEADER, '>', $self->{header}
+ or die "ops2c.pl: Cannot open header file '$self->{header}' for
writing: $!!\n";
+
+ _print_preamble_header( {
+ fh => $HEADER,
+ preamble => $self->{preamble},
+ flag => $self->{flag},
+ sym_export => $self->{sym_export},
+ init_func => $self->{init_func},
+ } );
+
+ _print_run_core_func_decl_header( {
+ trans => $self->{trans},
+ fh => $HEADER,
+ base => $self->{base},
+ } );
+
+ _print_coda($HEADER);
+
+ close $HEADER or die "Unable to close handle to $self->{header}: $!";
+ (-e $self->{header}) or die "$self->{header} not created: $!";
+ (-s $self->{header}) or die "$self->{header} has 0 size: $!";
+ return $self->{header};
+}
+
+sub _print_preamble_header {
+ my $argsref = shift;
+ my $fh = $argsref->{fh};
+
+ print $fh $argsref->{preamble};
+ if ($argsref->{flag}->{dynamic}) {
+ print $fh "#define PARROT_IN_EXTENSION\n";
+ }
+ print $fh <<END_C;
+#include "parrot/parrot.h"
+#include "parrot/oplib.h"
+
+$argsref->{sym_export} extern op_lib_t *$argsref->{init_func}(long init);
+
+END_C
+}
+
+sub _print_run_core_func_decl_header {
+ my $argsref = shift;
+ if ( $argsref->{trans}->can("run_core_func_decl") ) {
+ my $run_core_func =
+ $argsref->{trans}->run_core_func_decl($argsref->{base});
+ my $fh = $argsref->{fh};
+ print $fh "$run_core_func;\n";
+ } else {
+ return;
+ }
+}
+
+sub _print_coda {
+ my $fh = shift;
+ print $fh <<END_C;
+
+/*
+ * Local variables:
+ * c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */
+END_C
+}
+
1;
Modified: branches/buildtools/tools/build/ops2c.pl
==============================================================================
--- branches/buildtools/tools/build/ops2c.pl (original)
+++ branches/buildtools/tools/build/ops2c.pl Mon Feb 12 19:36:00 2007
@@ -35,8 +35,9 @@
#########################
my $self = Parrot::Ops2c::Utils->new( {
- argv => [ @ARGV ],
- flag => $flagref,
+ argv => [ @ARGV ],
+ flag => $flagref,
+ script => $0,
} );
if (not defined $self) {
Usage();
@@ -96,6 +97,19 @@
#my $num_ops = scalar $ops->ops;
#my $num_entries = $num_ops + 1; # For trailing NULL
+#if ( !$flagref->{dynamic} && !-d $incdir ) {
+# mkdir( $incdir, 0755 ) or die "ops2c.pl: Could not mkdir $incdir $!!\n";
+#}
+#
+#my $preamble = _compose_preamble($file, $0);
+#
+#my $init_func = join q{_}, (
+# q{Parrot},
+# q{DynOp},
+# $base . $suffix,
+# @versions{ qw(major minor patch) },
+#);
+
#########################
local @ARGV = @{$self->{argv}};
my $trans = $self->{trans};
@@ -114,61 +128,33 @@
my $num_ops = $self->{num_ops};
my $num_entries = $self->{num_entries};
-#print STDERR Dumper (
-# [EMAIL PROTECTED],
-# $trans,
-# $suffix,
-# $file,
-# $base,
-# $incdir,
-# $include,
-# $header,
-# $source,
-# $sym_export,
-# $ops,
-# \%versions,
-# $num_ops,
-# $num_entries,
-#);
-#########################
-#
-# Open the output files:
-#
-
-if ( !$flagref->{dynamic} && !-d $incdir ) {
- mkdir( $incdir, 0755 ) or die "ops2c.pl: Could not mkdir $incdir $!!\n";
-}
-
-my $preamble = _compose_preamble($file, $0);
+my $preamble = $self->{preamble};
+my $init_func = $self->{init_func};
-my $init_func = join q{_}, (
- q{Parrot},
- q{DynOp},
- $base . $suffix,
- @versions{ qw(major minor patch) },
-);
+#########################
# Open the C-header (.h) file
-open my $HEADER, '>', $header
- or die "ops2c.pl: Cannot open header file '$header' for writing: $!!\n";
-
-_print_preamble_header( {
- fh => $HEADER,
- preamble => $preamble,
- flag => $flagref,
- sym_export => $sym_export,
- init_func => $init_func,
-} );
-
-_print_run_core_func_decl_header( {
- trans => $trans,
- fh => $HEADER,
- base => $base,
-} );
-
-_print_coda($HEADER);
-
-close $HEADER or die "Unable to close handle to $header: $!";
+#open my $HEADER, '>', $header
+# or die "ops2c.pl: Cannot open header file '$header' for writing: $!!\n";
+#
+#_print_preamble_header( {
+# fh => $HEADER,
+# preamble => $preamble,
+# flag => $flagref,
+# sym_export => $sym_export,
+# init_func => $init_func,
+#} );
+#
+#_print_run_core_func_decl_header( {
+# trans => $trans,
+# fh => $HEADER,
+# base => $base,
+#} );
+#
+#_print_coda($HEADER);
+#
+#close $HEADER or die "Unable to close handle to $header: $!";
+$self->print_c_header_file();
##### END printing to $HEADER #####
my $defines = $trans->defines(); # Invoked as: ${defines}
@@ -359,50 +345,33 @@
# return $ops;
#}
-sub _compose_preamble {
- my ($file, $script) = @_;
- my $preamble = <<END_C;
-/* ex: set ro:
- * !!!!!!! DO NOT EDIT THIS FILE !!!!!!!
- *
- * This file is generated automatically from '$file' (and possibly other
- * .ops files). by $script.
- *
- * Any changes made here will be lost!
- *
- */
-
-END_C
- return $preamble;
-}
-
-sub _print_preamble_header {
- my $argsref = shift;
- my $fh = $argsref->{fh};
-
- print $fh $argsref->{preamble};
- if ($argsref->{flag}->{dynamic}) {
- print $fh "#define PARROT_IN_EXTENSION\n";
- }
- print $fh <<END_C;
-#include "parrot/parrot.h"
-#include "parrot/oplib.h"
-
-$argsref->{sym_export} extern op_lib_t *$argsref->{init_func}(long init);
-
-END_C
-}
-
-sub _print_run_core_func_decl_header {
- my $argsref = shift;
- if ( $argsref->{trans}->can("run_core_func_decl") ) {
- my $run_core_func = $trans->run_core_func_decl($argsref->{base});
- my $fh = $argsref->{fh};
- print $fh "$run_core_func;\n";
- } else {
- return;
- }
-}
+#sub _print_preamble_header {
+# my $argsref = shift;
+# my $fh = $argsref->{fh};
+#
+# print $fh $argsref->{preamble};
+# if ($argsref->{flag}->{dynamic}) {
+# print $fh "#define PARROT_IN_EXTENSION\n";
+# }
+# print $fh <<END_C;
+##include "parrot/parrot.h"
+##include "parrot/oplib.h"
+#
+#$argsref->{sym_export} extern op_lib_t *$argsref->{init_func}(long init);
+#
+#END_C
+#}
+#
+#sub _print_run_core_func_decl_header {
+# my $argsref = shift;
+# if ( $argsref->{trans}->can("run_core_func_decl") ) {
+# my $run_core_func = $trans->run_core_func_decl($argsref->{base});
+# my $fh = $argsref->{fh};
+# print $fh "$run_core_func;\n";
+# } else {
+# return;
+# }
+#}
sub _print_coda {
my $fh = shift;
@@ -1058,3 +1027,23 @@
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4:
+
+
+__END__
+
+#print STDERR Dumper (
+# [EMAIL PROTECTED],
+# $trans,
+# $suffix,
+# $file,
+# $base,
+# $incdir,
+# $include,
+# $header,
+# $source,
+# $sym_export,
+# $ops,
+# \%versions,
+# $num_ops,
+# $num_entries,
+#);