fipsas.pl 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # FIPS assembly language preprocessor
  2. # Renames all symbols in the file to
  3. # their modified fips versions.
  4. my @ARGS = @ARGV;
  5. my $top = shift @ARGS;
  6. my $target = shift @ARGS;
  7. my $runasm = 1;
  8. if ($ARGS[0] eq "norunasm")
  9. {
  10. $runasm = 0;
  11. shift @ARGS;
  12. }
  13. my $enabled = 0;
  14. $enabled = 1 if $ENV{FIPSCANISTERINTERNAL} eq "y";
  15. if ($enabled == 0 && $runasm)
  16. {
  17. system @ARGS;
  18. exit $?
  19. }
  20. # Open symbol rename file.
  21. open(IN, "$top/fips/fipssyms.h") || die "Can't open fipssyms.h";
  22. # Skip to assembler symbols
  23. while (<IN>)
  24. {
  25. last if (/assembler/)
  26. }
  27. # Store all renames [noting minimal length].
  28. my $minlen=0x10000;
  29. while (<IN>)
  30. {
  31. if (/^#define\s+_?(\w+)\s+_?(\w+)\b/)
  32. {
  33. $edits{$1} = $2;
  34. my $len = length($1);
  35. $minlen = $len if ($len<$minlen);
  36. }
  37. }
  38. open(IN,"$target") || die "Can't open $target for reading";
  39. @code = <IN>; # suck in whole file
  40. close IN;
  41. open(OUT,">$target") || die "Can't open $target for writing";
  42. foreach $line (@code)
  43. {
  44. $line =~ s/\b(_?)(\w{$minlen,})\b/$1.($edits{$2} or $2)/geo;
  45. print OUT $line;
  46. }
  47. close OUT;
  48. if ($runasm)
  49. {
  50. # run assembler
  51. system @ARGS;
  52. my $rv = $?;
  53. die "Error executing assembler!" if $rv != 0;
  54. }