unroll.pl 492 B

123456789101112131415161718192021222324
  1. #!/usr/bin/perl
  2. #
  3. # Take a piece of C code and for each line which contains the sequence $$
  4. # repeat n times with $ replaced by 0...n-1; the sequence $# is replaced
  5. # by the unrolling factor, and $* with a single $
  6. #
  7. ($n) = @ARGV;
  8. $n += 0;
  9. while ( defined($line = <STDIN>) ) {
  10. if ( $line =~ /\$\$/ ) {
  11. $rep = $n;
  12. } else {
  13. $rep = 1;
  14. }
  15. for ( $i = 0 ; $i < $rep ; $i++ ) {
  16. $tmp = $line;
  17. $tmp =~ s/\$\$/$i/g;
  18. $tmp =~ s/\$\#/$n/g;
  19. $tmp =~ s/\$\*/\$/g;
  20. print $tmp;
  21. }
  22. }