# # reads CPP output and turns #line things into appropriate Haskell # pragmas # # considered to be GHC-project specific # # # NOTE: this script needs RAWCPP set in order to do something # useful: # $Verbose = 0; while ( $#ARGV >= 0 && $ARGV[0] eq '-v' ) { if ($ARGV[0] eq '-v') { $Verbose = 1; } else { die "hscpp: unrecognised argument: $$ARGV[0]\n"; } shift(@ARGV); } #ToDo: print a version number ? $OrigCpp = ${RAWCPP}; if ( $OrigCpp =~ /(\S+)\s+(.*)/ ) { $cmd = $1; $rest = $2; if ( -x $cmd ) { # cool $Cpp = $OrigCpp; } else { # oops; try to guess $GccV = `gcc -v 2>&1`; if ( $GccV =~ /Reading specs from (.*)\/specs/ ) { $Cpp = "$1/cpp $rest"; } else { die "hscpp: don't know how to run cpp: $OrigCpp\n"; } } } else { $Cpp = $OrigCpp; } print STDERR "hscpp:CPP invoked: $Cpp @ARGV\n" if $Verbose; open(INPIPE, "$Cpp @ARGV |") || die "Can't open C pre-processor pipe\n"; while () { # line directives come in flavo[u]rs: # s/^#\s*line\s+\d+$/\{\-# LINE \-\}/; IGNORE THIS ONE FOR NOW s/^#\s*line\s+(\d+)\s+(\".+\")$/\{\-# LINE \1 \2 \-\}/; s/^#\s*(\d+)\s+(\".*\").*/\{\-# LINE \1 \2 \-\}/; print $_; } close(INPIPE) || exit(1); # exit is so we reflect any errors. exit(0);