2011-02-17 18:08:59 +00:00
|
|
|
|
|
|
|
# FIPS assembly language preprocessor
|
|
|
|
# Renames all symbols in the file to
|
|
|
|
# their modified fips versions.
|
|
|
|
|
|
|
|
|
|
|
|
my @ARGS = @ARGV;
|
|
|
|
|
|
|
|
my $top = shift @ARGS;
|
|
|
|
my $target = shift @ARGS;
|
2011-12-10 13:29:23 +00:00
|
|
|
my $tmptarg = $target;
|
|
|
|
|
|
|
|
$tmptarg =~ s/\.[^\\\/\.]+$/.tmp/;
|
2011-02-17 18:08:59 +00:00
|
|
|
|
2011-02-23 15:03:43 +00:00
|
|
|
my $runasm = 1;
|
|
|
|
|
|
|
|
if ($ARGS[0] eq "norunasm")
|
|
|
|
{
|
|
|
|
$runasm = 0;
|
|
|
|
shift @ARGS;
|
|
|
|
}
|
|
|
|
|
2011-02-17 19:03:52 +00:00
|
|
|
my $enabled = 0;
|
|
|
|
|
2011-06-22 12:30:18 +00:00
|
|
|
$enabled = 1 if $ENV{FIPSCANISTERINTERNAL} eq "y";
|
2011-02-17 19:03:52 +00:00
|
|
|
|
2011-02-23 15:03:43 +00:00
|
|
|
if ($enabled == 0 && $runasm)
|
2011-02-17 19:03:52 +00:00
|
|
|
{
|
|
|
|
system @ARGS;
|
|
|
|
exit $?
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:03:43 +00:00
|
|
|
|
2011-02-17 18:08:59 +00:00
|
|
|
# Open symbol rename file.
|
|
|
|
open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";
|
|
|
|
|
|
|
|
# Skip to assembler symbols
|
|
|
|
while (<IN>)
|
|
|
|
{
|
|
|
|
last if (/assembler/)
|
|
|
|
}
|
|
|
|
|
|
|
|
# Store all renames.
|
|
|
|
while (<IN>)
|
|
|
|
{
|
|
|
|
if (/^#define\s+(\w+)\s+(\w+)\b/)
|
|
|
|
{
|
|
|
|
$edits{$1} = $2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my ($from, $to);
|
|
|
|
|
2011-12-10 13:29:23 +00:00
|
|
|
#delete any temp file lying around
|
|
|
|
|
|
|
|
unlink $tmptarg;
|
|
|
|
|
2011-02-17 18:08:59 +00:00
|
|
|
#rename target temporarily
|
2011-12-10 18:06:55 +00:00
|
|
|
my $rencnt = 0;
|
|
|
|
# On windows the previous file doesn't always close straight away
|
|
|
|
# so retry the rename operation a few times if it fails.
|
|
|
|
while (!rename($target, $tmptarg))
|
|
|
|
{
|
|
|
|
sleep 2;
|
|
|
|
die "Can't rename $target" if ($rencnt++ > 10);
|
|
|
|
}
|
2011-02-17 18:08:59 +00:00
|
|
|
|
|
|
|
#edit target
|
2011-12-10 13:29:23 +00:00
|
|
|
open(IN,$tmptarg) || die "Can't open temporary file";
|
2011-07-02 15:57:35 +00:00
|
|
|
open(OUT, ">$target") || die "Can't open output file $target";
|
2011-02-17 18:08:59 +00:00
|
|
|
|
|
|
|
while (<IN>)
|
|
|
|
{
|
|
|
|
while (($from, $to) = each %edits)
|
|
|
|
{
|
2011-02-23 15:03:43 +00:00
|
|
|
s/(\b_*)$from(\b)/$1$to$2/g;
|
2011-02-17 18:08:59 +00:00
|
|
|
}
|
|
|
|
print OUT $_;
|
|
|
|
}
|
|
|
|
|
2011-02-23 15:03:43 +00:00
|
|
|
close OUT;
|
|
|
|
|
|
|
|
if ($runasm)
|
|
|
|
{
|
|
|
|
# run assembler
|
|
|
|
system @ARGS;
|
2011-05-19 17:55:15 +00:00
|
|
|
|
2011-02-23 15:03:43 +00:00
|
|
|
my $rv = $?;
|
2011-05-19 17:55:15 +00:00
|
|
|
|
2011-02-23 15:03:43 +00:00
|
|
|
# restore target
|
|
|
|
unlink $target;
|
2011-12-10 13:29:23 +00:00
|
|
|
rename $tmptarg, $target;
|
2011-02-23 15:03:43 +00:00
|
|
|
|
|
|
|
die "Error executing assembler!" if $rv != 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Don't care about target
|
2011-12-10 13:29:23 +00:00
|
|
|
unlink $tmptarg;
|
2011-02-23 15:03:43 +00:00
|
|
|
}
|