1 #!/bin/sh
   2 #
   3 # GCC compatible C compiler based on Sparse LLVM
   4 
   5 set +e
   6 
   7 SPARSEOPTS=""
   8 DIRNAME=`dirname $0`
   9 
  10 NEED_LINK=1
  11 
  12 if [ $# -eq 0 ]; then
  13   echo "`basename $0`: no input files"
  14   exit 1
  15 fi
  16 
  17 while [ $# -gt 0 ]; do
  18         case $1 in
  19         '-o')
  20                 OUTFILE=$2
  21                 shift
  22                 ;;
  23         '-c')
  24                 NEED_LINK=0
  25                 ;;
  26         *)
  27                 SPARSEOPTS="$SPARSEOPTS $1 " ;;
  28         esac
  29         shift
  30 done
  31 
  32 TMPLLVM=`mktemp -t tmp.XXXXXX`".llvm"
  33 TMPFILE=`mktemp -t tmp.XXXXXX`".o"
  34 
  35 $DIRNAME/sparse-llvm $SPARSEOPTS > $TMPLLVM
  36 
  37 LLC=`"${LLVM_CONFIG:-llvm-config}" --bindir`/llc
  38 
  39 $LLC -o - $TMPLLVM | as -o $TMPFILE
  40 
  41 if [ $NEED_LINK -eq 1 ]; then
  42         if [ -z $OUTFILE ]; then
  43                 OUTFILE=a.out
  44         fi
  45         gcc $TMPFILE -o $OUTFILE
  46 else
  47         if [ -z $OUTFILE ]; then
  48                 echo "`basename $0`: no output file"
  49                 exit 1
  50         fi
  51         mv $TMPFILE $OUTFILE
  52 fi
  53 
  54 rm -f $TMPLLVM