1#!/bin/sh 2# 3# GCC compatible C compiler based on Sparse LLVM 4 5set +e 6 7SPARSEOPTS="" 8DIRNAME=`dirname $0` 9 10NEED_LINK=1 11 12if [ $# -eq 0 ]; then 13 echo "`basename $0`: no input files" 14 exit 1 15fi 16 17while [ $# -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 30done 31 32TMPFILE=`mktemp -t tmp.XXXXXX` 33 34 35LLC=`"${LLVM_CONFIG:-llvm-config}" --bindir`/llc 36 37LLC_ARCH_OPTS= 38case "$(uname -s)" in 39*CYGWIN*) 40 # cygwin uses the sjlj (setjmp-longjmp) exception model 41 LLC_ARCH_OPTS="-exception-model=sjlj" 42 LLC_ARCH_OPTS="$LLC_ARCH_OPTS -mtriple=$(llvm-config --host-target)" 43 ;; 44*) 45 ;; 46esac 47 48$DIRNAME/sparse-llvm $SPARSEOPTS | $LLC ${LLC_ARCH_OPTS} | as -o $TMPFILE 49 50if [ $NEED_LINK -eq 1 ]; then 51 if [ -z $OUTFILE ]; then 52 OUTFILE=a.out 53 fi 54 gcc $TMPFILE -o $OUTFILE 55 rm -f $TMPFILE 56else 57 if [ -z $OUTFILE ]; then 58 echo "`basename $0`: no output file" 59 exit 1 60 fi 61 mv $TMPFILE $OUTFILE 62fi 63