1f08c3bdfSopenharmony_ci#!/bin/sh
2f08c3bdfSopenharmony_ci#
3f08c3bdfSopenharmony_ci# GCC compatible C compiler based on Sparse LLVM
4f08c3bdfSopenharmony_ci
5f08c3bdfSopenharmony_ciset +e
6f08c3bdfSopenharmony_ci
7f08c3bdfSopenharmony_ciSPARSEOPTS=""
8f08c3bdfSopenharmony_ciDIRNAME=`dirname $0`
9f08c3bdfSopenharmony_ci
10f08c3bdfSopenharmony_ciNEED_LINK=1
11f08c3bdfSopenharmony_ci
12f08c3bdfSopenharmony_ciif [ $# -eq 0 ]; then
13f08c3bdfSopenharmony_ci  echo "`basename $0`: no input files"
14f08c3bdfSopenharmony_ci  exit 1
15f08c3bdfSopenharmony_cifi
16f08c3bdfSopenharmony_ci
17f08c3bdfSopenharmony_ciwhile [ $# -gt 0 ]; do
18f08c3bdfSopenharmony_ci	case $1 in
19f08c3bdfSopenharmony_ci	'-o')
20f08c3bdfSopenharmony_ci		OUTFILE=$2
21f08c3bdfSopenharmony_ci		shift
22f08c3bdfSopenharmony_ci		;;
23f08c3bdfSopenharmony_ci	'-c')
24f08c3bdfSopenharmony_ci		NEED_LINK=0
25f08c3bdfSopenharmony_ci		;;
26f08c3bdfSopenharmony_ci	*)
27f08c3bdfSopenharmony_ci		SPARSEOPTS="$SPARSEOPTS $1 " ;;
28f08c3bdfSopenharmony_ci	esac
29f08c3bdfSopenharmony_ci	shift
30f08c3bdfSopenharmony_cidone
31f08c3bdfSopenharmony_ci
32f08c3bdfSopenharmony_ciTMPFILE=`mktemp -t tmp.XXXXXX`
33f08c3bdfSopenharmony_ci
34f08c3bdfSopenharmony_ci
35f08c3bdfSopenharmony_ciLLC=`"${LLVM_CONFIG:-llvm-config}" --bindir`/llc
36f08c3bdfSopenharmony_ci
37f08c3bdfSopenharmony_ciLLC_ARCH_OPTS=
38f08c3bdfSopenharmony_cicase "$(uname -s)" in
39f08c3bdfSopenharmony_ci*CYGWIN*)
40f08c3bdfSopenharmony_ci	# cygwin uses the sjlj (setjmp-longjmp) exception model
41f08c3bdfSopenharmony_ci	LLC_ARCH_OPTS="-exception-model=sjlj"
42f08c3bdfSopenharmony_ci	LLC_ARCH_OPTS="$LLC_ARCH_OPTS -mtriple=$(llvm-config --host-target)"
43f08c3bdfSopenharmony_ci	;;
44f08c3bdfSopenharmony_ci*)
45f08c3bdfSopenharmony_ci	;;
46f08c3bdfSopenharmony_ciesac
47f08c3bdfSopenharmony_ci
48f08c3bdfSopenharmony_ci$DIRNAME/sparse-llvm $SPARSEOPTS | $LLC ${LLC_ARCH_OPTS} | as -o $TMPFILE
49f08c3bdfSopenharmony_ci
50f08c3bdfSopenharmony_ciif [ $NEED_LINK -eq 1 ]; then
51f08c3bdfSopenharmony_ci	if [ -z $OUTFILE ]; then
52f08c3bdfSopenharmony_ci		OUTFILE=a.out
53f08c3bdfSopenharmony_ci	fi
54f08c3bdfSopenharmony_ci	gcc $TMPFILE -o $OUTFILE
55f08c3bdfSopenharmony_ci	rm -f $TMPFILE
56f08c3bdfSopenharmony_cielse
57f08c3bdfSopenharmony_ci	if [ -z $OUTFILE ]; then
58f08c3bdfSopenharmony_ci		echo "`basename $0`: no output file"
59f08c3bdfSopenharmony_ci		exit 1
60f08c3bdfSopenharmony_ci	fi
61f08c3bdfSopenharmony_ci	mv $TMPFILE $OUTFILE
62f08c3bdfSopenharmony_cifi
63