swh:1:snp:49cd9498d6cccc5e78252c27dcb645bcf7bf0c91
Raw File
Tip revision: 74fca6a42863ffacaf7ba6f1936a9f228950f657 authored by Linus Torvalds on 09 September 2009, 22:13:59 UTC
Linux 2.6.31
Tip revision: 74fca6a
unroll.pl
#!/usr/bin/perl
#
# Take a piece of C code and for each line which contains the sequence $$
# repeat n times with $ replaced by 0...n-1; the sequence $# is replaced
# by the unrolling factor, and $* with a single $
#

($n) = @ARGV;
$n += 0;

while ( defined($line = <STDIN>) ) {
    if ( $line =~ /\$\$/ ) {
	$rep = $n;
    } else {
	$rep = 1;
    }
    for ( $i = 0 ; $i < $rep ; $i++ ) {
	$tmp = $line;
	$tmp =~ s/\$\$/$i/g;
	$tmp =~ s/\$\#/$n/g;
	$tmp =~ s/\$\*/\$/g;
	print $tmp;
    }
}
back to top