2011-02-18 02:08:59 +08: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 21:29:38 +08:00
|
|
|
my $tmptarg = $target;
|
|
|
|
|
|
|
|
$tmptarg =~ s/\.[^\\\/\.]+$/.tmp/;
|
2011-02-18 02:08:59 +08:00
|
|
|
|
2011-02-23 23:03:43 +08:00
|
|
|
my $runasm = 1;
|
|
|
|
|
|
|
|
if ($ARGS[0] eq "norunasm")
|
|
|
|
{
|
|
|
|
$runasm = 0;
|
|
|
|
shift @ARGS;
|
|
|
|
}
|
|
|
|
|
2011-02-18 03:03:52 +08:00
|
|
|
my $enabled = 0;
|
|
|
|
|
2011-06-22 20:30:18 +08:00
|
|
|
$enabled = 1 if $ENV{FIPSCANISTERINTERNAL} eq "y";
|
2011-02-18 03:03:52 +08:00
|
|
|
|
2011-02-23 23:03:43 +08:00
|
|
|
if ($enabled == 0 && $runasm)
|
2011-02-18 03:03:52 +08:00
|
|
|
{
|
|
|
|
system @ARGS;
|
|
|
|
exit $?
|
|
|
|
}
|
|
|
|
|
2011-02-23 23:03:43 +08:00
|
|
|
|
2011-02-18 02:08:59 +08: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 21:29:38 +08:00
|
|
|
#delete any temp file lying around
|
|
|
|
|
|
|
|
unlink $tmptarg;
|
|
|
|
|
2011-02-18 02:08:59 +08:00
|
|
|
#rename target temporarily
|
2011-12-10 21:29:38 +08:00
|
|
|
rename($target, $tmptarg) || die "Can't rename $target";
|
2011-02-18 02:08:59 +08:00
|
|
|
|
|
|
|
#edit target
|
2011-12-10 21:29:38 +08:00
|
|
|
open(IN,$tmptarg) || die "Can't open temporary file";
|
2011-07-02 23:57:35 +08:00
|
|
|
open(OUT, ">$target") || die "Can't open output file $target";
|
2011-02-18 02:08:59 +08:00
|
|
|
|
|
|
|
while (<IN>)
|
|
|
|
{
|
|
|
|
while (($from, $to) = each %edits)
|
|
|
|
{
|
2011-02-23 23:03:43 +08:00
|
|
|
s/(\b_*)$from(\b)/$1$to$2/g;
|
2011-02-18 02:08:59 +08:00
|
|
|
}
|
|
|
|
print OUT $_;
|
|
|
|
}
|
|
|
|
|
2011-02-23 23:03:43 +08:00
|
|
|
close OUT;
|
|
|
|
|
|
|
|
if ($runasm)
|
|
|
|
{
|
|
|
|
# run assembler
|
|
|
|
system @ARGS;
|
2011-05-20 01:55:15 +08:00
|
|
|
|
2011-02-23 23:03:43 +08:00
|
|
|
my $rv = $?;
|
2011-05-20 01:55:15 +08:00
|
|
|
|
2011-02-23 23:03:43 +08:00
|
|
|
# restore target
|
|
|
|
unlink $target;
|
2011-12-10 21:29:38 +08:00
|
|
|
rename $tmptarg, $target;
|
2011-02-23 23:03:43 +08:00
|
|
|
|
|
|
|
die "Error executing assembler!" if $rv != 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
# Don't care about target
|
2011-12-10 21:29:38 +08:00
|
|
|
unlink $tmptarg;
|
2011-02-23 23:03:43 +08:00
|
|
|
}
|