[svn:parrot] r43407 - in branches/one_make: . config/gen config/gen/makefiles tools/build

coke at svn.parrot.org coke at svn.parrot.org
Thu Jan 7 23:48:35 UTC 2010


Author: coke
Date: Thu Jan  7 23:48:33 2010
New Revision: 43407
URL: https://trac.parrot.org/parrot/changeset/43407

Log:
Generate these files during standard build, not during config.
* also fixup a darwin bug found by ash (requires := here.)
* this breaks -j for now; things that should depend on these .pasm files don't.

Added:
   branches/one_make/tools/build/h2pasm.pl
Modified:
   branches/one_make/MANIFEST
   branches/one_make/config/gen/makefiles/root.in
   branches/one_make/config/gen/parrot_include.pm

Modified: branches/one_make/MANIFEST
==============================================================================
--- branches/one_make/MANIFEST	Thu Jan  7 17:04:44 2010	(r43406)
+++ branches/one_make/MANIFEST	Thu Jan  7 23:48:33 2010	(r43407)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Jan  6 16:42:29 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jan  7 17:37:50 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -2144,6 +2144,7 @@
 tools/build/c2str.pl                                        []
 tools/build/dynpmc.pl                                       []
 tools/build/fixup_gen_file.pl                               []
+tools/build/h2pasm.pl                                       []
 tools/build/headerizer.pl                                   []
 tools/build/nativecall.pl                                   []
 tools/build/ops2c.pl                                        [devel]

Modified: branches/one_make/config/gen/makefiles/root.in
==============================================================================
--- branches/one_make/config/gen/makefiles/root.in	Thu Jan  7 17:04:44 2010	(r43406)
+++ branches/one_make/config/gen/makefiles/root.in	Thu Jan  7 23:48:33 2010	(r43407)
@@ -239,6 +239,12 @@
     lib/Parrot/OpLib/core.pm
 
 GEN_LIBRARY = \
+    runtime/parrot/include/cclass.pasm \
+    runtime/parrot/include/datatypes.pasm \
+    runtime/parrot/include/enums.pasm \
+    runtime/parrot/include/events.pasm \
+    runtime/parrot/include/hash_key_type.pasm \
+    runtime/parrot/include/io.pasm \
     $(LIBRARY_DIR)/CGI/QueryHash.pbc \
     $(LIBRARY_DIR)/Crow.pbc \
     $(LIBRARY_DIR)/config.pbc \
@@ -509,7 +515,7 @@
 
 # Libraries
 LIBPARROT_STATIC    = @blib_dir@/@libparrot_static@
-#IF(darwin):export DYLD_LIBRARY_PATH = @blib_dir@:$(DYLD_LIBRARY_PATH)
+#IF(darwin):export DYLD_LIBRARY_PATH := @blib_dir@:$(DYLD_LIBRARY_PATH)
 #IF(win32):LIBPARROT_SHARED  = @libparrot_shared@
 #ELSE:LIBPARROT_SHARED  = @blib_dir@/@libparrot_shared@
 
@@ -1003,6 +1009,19 @@
 #
 ###############################################################################
 
+runtime/parrot/include/cclass.pasm : $(INC_DIR)/cclass.h tools/build/h2pasm.pl
+	$(PERL) tools/build/h2pasm.pl $(INC_DIR)/cclass.h > $@
+runtime/parrot/include/datatypes.pasm : $(INC_DIR)/datatypes.h tools/build/h2pasm.pl
+	$(PERL) tools/build/h2pasm.pl $(INC_DIR)/datatypes.h > $@
+runtime/parrot/include/enums.pasm : $(INC_DIR)/enums.h tools/build/h2pasm.pl
+	$(PERL) tools/build/h2pasm.pl $(INC_DIR)/enums.h > $@
+runtime/parrot/include/events.pasm : $(INC_DIR)/events.h tools/build/h2pasm.pl
+	$(PERL) tools/build/h2pasm.pl $(INC_DIR)/events.h > $@
+runtime/parrot/include/hash_key_type.pasm : $(INC_DIR)/hash.h tools/build/h2pasm.pl
+	$(PERL) tools/build/h2pasm.pl $(INC_DIR)/hash.h > $@
+runtime/parrot/include/io.pasm : $(INC_DIR)/io.h tools/build/h2pasm.pl
+	$(PERL) tools/build/h2pasm.pl $(INC_DIR)/io.h > $@
+
 $(INC_DIR)/oplib/ops.h lib/Parrot/OpLib/core.pm : $(OPS_FILES) $(BUILD_TOOLS_DIR)/ops2pm.pl \
     lib/Parrot/OpsFile.pm lib/Parrot/Op.pm src/ops/ops.num src/ops/ops.skip
 	$(PERL) $(BUILD_TOOLS_DIR)/ops2pm.pl @no_lines_flag@ $(OPS_FILES)

Modified: branches/one_make/config/gen/parrot_include.pm
==============================================================================
--- branches/one_make/config/gen/parrot_include.pm	Thu Jan  7 17:04:44 2010	(r43406)
+++ branches/one_make/config/gen/parrot_include.pm	Thu Jan  7 23:48:33 2010	(r43407)
@@ -27,15 +27,9 @@
     $data{description} = q{Generate runtime/parrot/include};
     $data{result} = q{};
     $data{source_files} = [ qw(
-        include/parrot/cclass.h
-        include/parrot/datatypes.h
-        include/parrot/enums.h
-        include/parrot/events.h
         include/parrot/scheduler.h
         include/parrot/exceptions.h
-        include/parrot/hash.h
         include/parrot/interpreter.h
-        include/parrot/io.h
         include/parrot/library.h
         include/parrot/longopt.h
         include/parrot/multidispatch.h

Added: branches/one_make/tools/build/h2pasm.pl
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/one_make/tools/build/h2pasm.pl	Thu Jan  7 23:48:33 2010	(r43407)
@@ -0,0 +1,185 @@
+# Copyright (C) 2009, Parrot Foundation.
+# $Id: $
+
+=head1 NAME
+
+tools/build/h2pasm.pl
+
+=head1 DESCRIPTION
+
+Generate C<.pasm> files with constants based on C<.h> files.
+
+=cut
+
+use strict;
+use warnings;
+
+my $usage = "Usage: $0 <input_file> > <output file>\n";
+
+my $in_file  = shift or die $usage;
+die $usage if @ARGV;
+
+open my $fh, '<', $in_file or die "Can't open $in_file: $!\n";
+my @directives = parse_file($in_file, $fh);
+close $fh;
+for my $d (@directives) {
+    my @defs = perform_directive($d);
+    for my $target ( @{ $d->{files} } ) {
+        my $gen = join "\n", &const_to_parrot(@defs);
+        print <<"EOF";
+# DO NOT EDIT THIS FILE.
+#
+# This file is generated automatically from
+# $in_file by $0
+#
+# Any changes made here will be lost.
+#
+$gen
+EOF
+    }
+}
+
+sub const_to_parrot {
+    my $keylen = 0;
+    foreach my $element (@_) {
+        my $size = length($element->[0]);
+        if ($size > $keylen) {
+            $keylen = $size;
+        }
+    }
+    my $vallen = 0;
+    foreach my $element (@_) {
+        my $size = length($element->[1]);
+        if ($size > $vallen) {
+            $vallen = $size;
+        }
+    }
+
+    return map {sprintf ".macro_const %-${keylen}s %${vallen}s", $_->[0], $_->[1]} @_;
+}
+
+sub transform_name {
+    my $action = shift;
+
+    return map { [ $action->( $_->[0] ), $_->[1] ] } @_;
+}
+
+sub prepend_prefix {
+    my $prefix = shift;
+
+    transform_name( sub { $prefix . $_[0] }, @_ );
+}
+
+sub perform_directive {
+    my ($d) = @_;
+
+    my @defs = prepend_prefix $d->{prefix}, @{ $d->{defs} };
+    if ( my $subst = $d->{subst} ) {
+        @defs = transform_name( sub { local $_ = shift; eval $subst; $_ }, @defs );
+    }
+    @defs;
+}
+
+sub parse_file {
+    my ( $file, $fh ) = @_;
+
+    my ( @d, %values, $last_val, $cur, $or_continues );
+    while ( my $line = <$fh> ) {
+        if (
+            $line =~ m!
+            &gen_from_(enum|def) \( ( [^)]* ) \)
+            (?: \s+ prefix \( (\w+) \) )?
+            (?: \s+ subst \( (s/.*?/.*?/[eig]?) \) )?
+            !x
+            )
+        {
+            $cur and die "Missing '&end_gen' in $file\n";
+            $cur = {
+                type   => $1,
+                files  => [ split ' ', $2 ],
+                prefix => defined $3 ? $3 : '',
+                defined $4 ? ( subst => $4 ) : (),
+            };
+            $last_val = -1;
+        }
+        elsif ( $line =~ /&end_gen\b/ ) {
+            $cur or die "Missing &gen_from_(enum|def) in $file\n";
+            push @d, $cur;
+            $cur = undef;
+        }
+
+        $cur or next;
+
+        if ( $cur->{type} eq 'def' && $line =~ /^\s*#define\s+(\w+)\s+(-?\w+|"[^"]*")/ ) {
+            push @{ $cur->{defs} }, [ $1, $2 ];
+        }
+        elsif ( $cur->{type} eq 'enum' ) {
+            # Special case: enum value is or'd combination of other values
+            if ( $or_continues ) {
+                $or_continues = 0;
+                my $last_def = $cur->{defs}->[-1];
+                my ($k, $v) = @{$last_def};
+                my @or_values = grep {defined $_} $line =~ /^\s*(-?\w+)(?:\s*\|\s*(-?\w+))*/;
+                for my $or (@or_values) {
+                    if ( defined $values{$or} ) {
+                        $v |= $values{$or};
+                    }
+                    elsif ( $or =~ /^0/ ) {
+                        $v |= oct $or;
+                    }
+                }
+                if ($line =~ /\|\s*$/) {
+                    $or_continues = 1;
+                }
+                $values{$k} = $last_val = $v;
+                $cur->{defs}->[-1]->[1] = $v;
+            }
+            elsif ( $line =~ /^\s*(\w+)\s*=\s*(-?\w+)\s*\|/ ) {
+                my ( $k, $v ) = ( $1, $2 );
+                my @or_values = ($v, $line =~ /\|\s*(-?\w+)/g);
+                $v = 0;
+                for my $or (@or_values) {
+                    if ( defined $values{$or} ) {
+                        $v |= $values{$or};
+                    }
+                    elsif ( $or =~ /^0/ ) {
+                        $v |= oct $or;
+                    }
+                }
+                if ($line =~ /\|\s*$/) {
+                    $or_continues = 1;
+                }
+                $values{$k} = $last_val = $v;
+                push @{ $cur->{defs} }, [ $k, $v ];
+            }
+            elsif ( $line =~ /^\s*(\w+)\s*=\s*(-?\w+)/ ) {
+                my ( $k, $v ) = ( $1, $2 );
+                if ( defined $values{$v} ) {
+                    $v = $values{$v};
+                }
+                elsif ( $v =~ /^0/ ) {
+                    $v = oct $v;
+                }
+                $values{$k} = $last_val = $v;
+                push @{ $cur->{defs} }, [ $k, $v ];
+            }
+            elsif ( $line =~ m!^\s*(\w+)\s*(?:,\s*)?(?:/\*|$)! ) {
+                my $k = $1;
+                my $v = $values{$k} = ++$last_val;
+                push @{ $cur->{defs} }, [ $k, $v ];
+            }
+        }
+    }
+    $cur and die "Missing '&end_gen' in $file\n";
+
+    return @d;
+}
+
+1;
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:


More information about the parrot-commits mailing list