Clean up munch.pl, add -o option

chmod -x src/tools/*.pl
This commit is contained in:
Andrew Johnson
2010-07-29 14:58:14 -05:00
parent 0f431edbe6
commit 2bb4e63d1e
8 changed files with 68 additions and 39 deletions

View File

@@ -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) $@

0
src/tools/convertRelease.pl Executable file → Normal file
View File

0
src/tools/cvsclean.pl Executable file → Normal file
View File

0
src/tools/filterWarnings.pl Executable file → Normal file
View File

0
src/tools/fullPathName.pl Executable file → Normal file
View File

0
src/tools/mkmf.pl Executable file → Normal file
View File

105
src/tools/munch.pl Executable file → Normal file
View File

@@ -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 = <STDIN>)
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 <vxWorks.h>",
"\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 <vxWorks.h>',
'',
'/* 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;
}

0
src/tools/replaceVAR.pl Executable file → Normal file
View File