From 2bb4e63d1e7bf42c3ad6c9a45b29637b95609d20 Mon Sep 17 00:00:00 2001 From: Andrew Johnson Date: Thu, 29 Jul 2010 14:58:14 -0500 Subject: [PATCH] Clean up munch.pl, add -o option chmod -x src/tools/*.pl --- configure/RULES_BUILD | 2 +- src/tools/convertRelease.pl | 0 src/tools/cvsclean.pl | 0 src/tools/filterWarnings.pl | 0 src/tools/fullPathName.pl | 0 src/tools/mkmf.pl | 0 src/tools/munch.pl | 105 +++++++++++++++++++++++------------- src/tools/replaceVAR.pl | 0 8 files changed, 68 insertions(+), 39 deletions(-) mode change 100755 => 100644 src/tools/convertRelease.pl mode change 100755 => 100644 src/tools/cvsclean.pl mode change 100755 => 100644 src/tools/filterWarnings.pl mode change 100755 => 100644 src/tools/fullPathName.pl mode change 100755 => 100644 src/tools/mkmf.pl mode change 100755 => 100644 src/tools/munch.pl mode change 100755 => 100644 src/tools/replaceVAR.pl diff --git a/configure/RULES_BUILD b/configure/RULES_BUILD index 7d955798e..fd34fc76b 100644 --- a/configure/RULES_BUILD +++ b/configure/RULES_BUILD @@ -302,7 +302,7 @@ $(LOADABLE_SHRLIBNAME):$(LOADABLE_SHRLIB_PREFIX)%$(LOADABLE_SHRLIB_SUFFIX): %_ctdt.c : %.nm @$(RM) $@ - $(PERL) $(TOOLS)/munch.pl < $< > $@ + $(PERL) $(TOOLS)/munch.pl -o $@ $< $(MUNCHNAME):%$(MUNCH_SUFFIX) : $(MUNCH_DEPENDS) %$(EXE) @$(RM) $@ diff --git a/src/tools/convertRelease.pl b/src/tools/convertRelease.pl old mode 100755 new mode 100644 diff --git a/src/tools/cvsclean.pl b/src/tools/cvsclean.pl old mode 100755 new mode 100644 diff --git a/src/tools/filterWarnings.pl b/src/tools/filterWarnings.pl old mode 100755 new mode 100644 diff --git a/src/tools/fullPathName.pl b/src/tools/fullPathName.pl old mode 100755 new mode 100644 diff --git a/src/tools/mkmf.pl b/src/tools/mkmf.pl old mode 100755 new mode 100644 diff --git a/src/tools/munch.pl b/src/tools/munch.pl old mode 100755 new mode 100644 index 5b962f86d..c4d5f50be --- a/src/tools/munch.pl +++ b/src/tools/munch.pl @@ -1,7 +1,6 @@ -eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- - if $running_under_some_shell; +#!/usr/bin/perl #************************************************************************* -# Copyright (c) 2006 UChicago Argonne LLC, as Operator of Argonne +# Copyright (c) 2010 UChicago Argonne LLC, as Operator of Argonne # National Laboratory. # Copyright (c) 2002 The Regents of the University of California, as # Operator of Los Alamos National Laboratory. @@ -13,50 +12,75 @@ eval 'exec perl -S $0 ${1+"$@"}' # -*- Mode: perl -*- # Creates a ctdt.c file of C++ static constructors and destructors, # as required for all vxWorks binaries containing C++ code. +use strict; +use warnings; +use Getopt::Std; + +our ($opt_o); + +$Getopt::Std::OUTPUT_HELP_VERSION = 1; +&HELP_MESSAGE if !getopts('o:') || @ARGV != 1; + # Is exception handler frame info required? my $need_eh_frame = 0; -@ctors = (); %ctors = (); -@dtors = (); %dtors = (); +# Constructor and destructor names: +# Array contains names from input file. +# Hash is used to skip duplicate names. +my (@ctors, %ctors); +my (@dtors, %dtors); -while (my $line = ) +while (<>) { - chomp $line; - $need_eh_frame++ if m/__?gxx_personality_v[0-9]/; - next if ($line =~ m/__?GLOBAL_.F.+/); - next if ($line =~ m/__?GLOBAL_.I._GLOBAL_.D.+/); - if ($line =~ m/__?GLOBAL_.D.+/) { - ($adr,$type,$name) = split ' ', $line, 3; - push @dtors, $name unless exists $dtors{$name}; - $dtors{$name} = 1; + chomp; + $need_eh_frame++ if m/__? gxx_personality_v [0-9]/x; + next if m/__? GLOBAL_. (F | I._GLOBAL_.D) .+/x; + if (m/__? GLOBAL_ . D .+/x) { + my ($addr, $type, $name) = split ' ', $_, 3; + push @dtors, $name unless exists $dtors{$name}; + $dtors{$name} = 1; } - if ($line =~ m/__?GLOBAL_.I.+/) { - ($adr,$type,$name) = split ' ', $line, 3; - push @ctors, $name unless exists $ctors{$name}; - $ctors{$name} = 1; + if (m/__? GLOBAL_ . I .+/x) { + my ($addr, $type, $name) = split ' ', $_, 3; + push @ctors, $name unless exists $ctors{$name}; + $ctors{$name} = 1; } } -print join "\n", - "/* C++ static constructor and destructor lists */", - "/* This is a generated file, do not edit! */", - "#include ", - "\n/* Declarations */", - (map cDecl($_), @ctors, @dtors), +push my @out, + '/* C++ static constructor and destructor lists */', + '/* This is generated by munch.pl, do not edit! */', + '', + '#include ', + '', + '/* Declarations */', + (map {cDecl($_)} @ctors, @dtors), ''; exceptionHandlerFrame() if $need_eh_frame; -print join "\n", - "\n/* Constructors */", - "void (*_ctors[])() = {", - (join ",\n", (map " " . cName($_), @ctors), " NULL"), - "};", - "\n/* Destructors */", - "void (*_dtors[])() = {", - (join ",\n", (map " " . cName($_), reverse @dtors), " NULL"), - "};", - "\n"; +push @out, + '/* List of Constructors */', + 'void (*_ctors[])(void) = {', + (join ",\n", (map {' ' . cName($_)} @ctors), ' NULL'), + '};', + '', + '/* List of Destructors */', + 'void (*_dtors[])(void) = {', + (join ",\n", (map {' ' . cName($_)} @dtors), ' NULL'), + '};', + ''; + +if ($opt_o) { + open(my $OUT, '>', $opt_o) + or die "Can't create $opt_o: $!\n"; + print $OUT join "\n", @out; + close $OUT + or die "Can't close $opt_o: $!\n"; +} else { + print join "\n", @out; +} + # Outputs the C code for registering exception handler frame info sub exceptionHandlerFrame { @@ -67,7 +91,7 @@ sub exceptionHandlerFrame { unshift @ctors, $eh_ctor; unshift @dtors, $eh_dtor; - print join "\n", + push @out, '/* Exception handler frame */', 'extern const unsigned __EH_FRAME_BEGIN__[];', '', @@ -96,13 +120,18 @@ sub cName { sub cDecl { my ($name) = @_; - my $decl = 'void ' . cName($name) . '()'; + my $decl = 'extern void ' . cName($name) . '(void)'; # 68k and MIPS targets allow periods in symbol names, which # can only be reached using an assembler string. if (m/\./) { - $decl .= "\n __asm__ (\"" . $name . "\");"; + $decl .= "\n __asm__ (\"" . $name . "\");"; } else { - $decl .= ';'; + $decl .= ';'; } return $decl; } + +sub HELP_MESSAGE { + print STDERR "Usage: munch.pl [-o file_ctdt.c] file.nm\n"; + exit 2; +} diff --git a/src/tools/replaceVAR.pl b/src/tools/replaceVAR.pl old mode 100755 new mode 100644