diff --git a/llvm-lua/lua-compiler.in b/llvm-lua/lua-compiler.in index 4601b25..05772c3 100755 --- a/llvm-lua/lua-compiler.in +++ b/llvm-lua/lua-compiler.in @@ -5,7 +5,7 @@ DIR=`realpath $0` DIR=`dirname $DIR` -CC=gcc +CC=clang LIBTOOL="libtool --tag=CC --silent" RPATH=`pwd` LLVM_LUAC="./llvm-luac" @@ -19,8 +19,7 @@ if [[ ! -x "$LLVM_LUAC" ]]; then LLVM_LUAC=`which llvm-luac` fi -TARGET= -FORCE_TARGET="0" +ARCH= CPU=i686 #CPU=pentium4 #CPU=athlon64 @@ -31,9 +30,8 @@ OUTPUT_FILE="" DEBUG="0" KEEP_TMPS="0" STATIC="0" -MODE="full_bc" +MODE="standalone" EXPORT_SYMBOLS=" -Wl,-E " -LLC_FLAGS=" -relocation-model=pic " EXTRA_ARGS= LIBS= @@ -61,19 +59,8 @@ OPTIONS: info and gcc debug symbols are enabled. -keep-tmps - Don't delete temp. files generated by intermediate stages. Use only for debuging generated code or if you are really curious! - -target= - is passed to llc as '-target=', see llc --version for targets + -march= - is passed to llc as '-march=', see llc --version for targets -mcpu= - is passed to gcc as '-march=' - -mode= - Switch how LLVM bitcode is generated and compiled into native code. - - full_bc - (default mode) compiles Lua scripts into LLVM bitcode - linked with bitcode liblua_main.bc then converted to assembly - before being compiled with gcc to a native executable. - - lua_mod - Only used by the '-lua-module' option. Don't use - it directly. - The following modes are for testing only: - - cbe - compile Lua script into C-code from LLVM bitcode, then use - gcc to compile to native executable binary. - - c - compiles Lua scripts into C-code. - - ll - compiles Lua scripts into LLVM IR code. -****** - All other options passed to 'llvm-luac'. See below for a list of options supported by 'llvm-luac'. @@ -97,11 +84,11 @@ for arg in "$@" ; do case "$arg" in -lua-mod*) MODE="lua_mod"; EXTRA_ARGS="$EXTRA_ARGS $arg" ;; -static) STATIC="1" ;; - -c++) CC=g++ ;; + -c++) CC=clang++ ;; -debug) DEBUG="1" ;; -keep-tmps) KEEP_TMPS="1" ;; -mode=*) MODE=` echo "$arg" | sed -e 's/-mode=//'` ;; - -target=*) FORCE_TARGET="1"; TARGET=` echo "$arg" | sed -e 's/-target=//'` ;; + -march=*) ARCH=` echo "$arg" | sed -e 's/-march=//'` ;; -mcpu=*) FORCE_CPU="1"; CPU=` echo "$arg" | sed -e 's/-mcpu=//'` ;; -help|--help|-h) usage ;; -version|--version|-v) version ;; @@ -115,7 +102,6 @@ done # find the mode's output file extension. OUTPUT_EXT="" case "$MODE" in - c) OUTPUT_EXT=".c" ;; ll) OUTPUT_EXT=".ll" ;; lua_mod) OUTPUT_EXT=".so" ;; esac @@ -128,8 +114,6 @@ fi # get source file's path & filename. FPATH=`dirname ${FILE}` FNAME=`basename ${FILE}` -# strip extension from filename. -FILE="${FILE%\.*}" # select debug/optimize parameters. if [[ $DEBUG == "1" ]]; then @@ -137,37 +121,18 @@ if [[ $DEBUG == "1" ]]; then LUA_FLAGS=" -O0 -g " #LUA_FLAGS=" -O3 -do-not-inline-opcodes " #CFLAGS=" -ggdb -O3 -fomit-frame-pointer -pipe -Wall " - OPT_FLAGS=" -disable-opt " - if [[ ! -z $CPU && $FORCE_CPU == "1" ]]; then - CFLAGS=" -march=$CPU $CFLAGS " - fi else LUA_FLAGS=" -O3 -s " #LUA_FLAGS=" -O3 -g " #CFLAGS=" -ggdb -O3 -fomit-frame-pointer -pipe -Wall " CFLAGS=" -O3 -fomit-frame-pointer -pipe " - if [[ ! -z $CPU ]]; then - CFLAGS=" -march=$CPU $CFLAGS " - fi - OPT_FLAGS=" -O3 -std-compile-opts -tailcallelim " - LLC_FLAGS=" -tailcallopt $LLC_FLAGS " fi if [[ ! -z $CPU && $FORCE_CPU == "1" ]]; then - LLC_FLAGS=" -mcpu=$CPU $LLC_FLAGS " + CFLAGS=" -mcpu=$CPU $LLC_FLAGS " fi -if [[ $MODE == "cbe" ]]; then - EXTRA_ARGS="$EXTRA_ARGS -no-main " - - # path to liblua_main.a - LIBS="$LIBS -L$DIR -L$DIR/../lib -L$PREFIX/lib " -elif [[ $MODE == "c" ]]; then - EXTRA_ARGS="$EXTRA_ARGS -no-main " -else - # if mode not "cbe" or "c" - if [[ ! -z $TARGET && $FORCE_TARGET == "1" ]]; then - LLC_FLAGS=" -march=$TARGET $LLC_FLAGS " - fi +if [[ ! -z $ARCH && $FORCE_ARCH == "1" ]]; then + CFLAGS=" -march=$ARCH $LLC_FLAGS " fi # @@ -181,35 +146,14 @@ TMPS="${FILE}.bc" # use one of the compile modes. case "$MODE" in - cbe) - TMPS="$TMPS ${FILE}_opt.bc ${FILE}_run.c" - echo_cmd opt $OPT_FLAGS -o ${FILE}_opt.bc ${FILE}.bc - echo_cmd llc $LLC_FLAGS --march=c -o ${FILE}_run.c ${FILE}_opt.bc - echo_cmd $CC $EXPORT_SYMBOLS $CFLAGS $LIBS -o ${OUTPUT_FILE} ${FILE}_run.c -lllvm-lua_main -lm -ldl - ;; - c) - TMPS="$TMPS ${FILE}_opt.bc" - echo_cmd opt $OPT_FLAGS -o ${FILE}_opt.bc ${FILE}.bc - echo_cmd llc $LLC_FLAGS --march=c -o ${OUTPUT_FILE} ${FILE}_opt.bc - ;; - ll) - echo_cmd llvm-dis -o ${OUTPUT_FILE} ${FILE}.bc - ;; - full_bc) - TMPS="$TMPS ${FILE}_opt.bc ${FILE}_run.bc ${FILE}_run.s" - echo_cmd opt $OPT_FLAGS -o ${FILE}_run.bc ${FILE}.bc - echo_cmd llc $LLC_FLAGS -filetype=asm -o ${FILE}_run.s ${FILE}_run.bc - echo_cmd $CC $EXPORT_SYMBOLS $CFLAGS -o ${OUTPUT_FILE} ${FILE}_run.s -lm -ldl + standalone) + TMPS="$TMPS ${FILE}_run.s" + echo_cmd $CC $EXPORT_SYMBOLS $CFLAGS -o ${OUTPUT_FILE} ${FILE}.bc -lm -ldl ;; lua_mod) - TMPS="$TMPS ${FILE}_opt.bc ${FILE}_mod.s ${FPATH}/${FNAME}.lo ${FPATH}/lib${FNAME}.la" - echo_cmd opt $OPT_FLAGS -o ${FILE}_opt.bc ${FILE}.bc - echo_cmd llc $LLC_FLAGS -filetype=asm -o ${FILE}_mod.s ${FILE}_opt.bc || { - echo "Error compiling LLVM bitcode to assembly code." - exit 1; - } + TMPS="$TMPS ${FILE}_mod.s ${FPATH}/${FNAME}.lo ${FPATH}/lib${FNAME}.la" # compile assembly code to object file. - $LIBTOOL --mode=compile $CC $CFLAGS -c -o ${FILE}.lo ${FILE}_mod.s + $LIBTOOL --mode=compile $CC $CFLAGS -c -o ${FILE}.lo ${FILE}.bc # compile to dynamic module if [[ $STATIC == "0" ]]; then $LIBTOOL --mode=link $CC -rpath ${RPATH} -o ${FPATH}/lib${FNAME}.la ${FILE}.lo && \ diff --git a/llvm-lua/lua-cross-compiler.in b/llvm-lua/lua-cross-compiler.in index 550daa5..46949e9 100755 --- a/llvm-lua/lua-cross-compiler.in +++ b/llvm-lua/lua-cross-compiler.in @@ -18,13 +18,13 @@ fi ARCH=@CROSS_ARCH@ CPU=@CROSS_CPU@ +FORCE_CPU="0" MODULE="0" NO_ASSEMBLE="0" FILE=lua-native-out FILES="" DEBUG="0" KEEP_TMPS="0" -MODE="asm" EXTRA_ARGS= function echo_cmd() { @@ -50,9 +50,8 @@ OPTIONS: info and gcc debug symbols are enabled. -keep-tmps - Don't delete temp. files generated by intermediate stages. Use only for debuging generated code or if you are really curious! - -mode= - Switch how LLVM bitcode is generated and compiled into native code. - - asm - compiles Lua scripts into asm-code. - - cbe - compiles Lua scripts into C-code. (only for testing, don't use it.) + -march= - is passed to llc as '-march=', see llc --version for targets + -mcpu= - is passed to gcc as '-march=' -****** - All other options passed to 'llvm-luac'. See below for a list of options supported by 'llvm-luac'. @@ -78,7 +77,8 @@ for arg in "$@" ; do -debug) DEBUG="1" ;; -no-assemble) NO_ASSEMBLE="1" ;; -keep-tmps) KEEP_TMPS="1" ;; - -mode=*) MODE=` echo "$arg" | sed -e 's/-mode=//'` ;; + -march=*) ARCH=` echo "$arg" | sed -e 's/-march=//'` ;; + -mcpu=*) FORCE_CPU="1"; CPU=` echo "$arg" | sed -e 's/-mcpu=//'` ;; -help|--help|-h) usage ;; -version|--version|-v) version ;; -o|-L) CONSUME="$arg" ;; @@ -91,10 +91,7 @@ done # find the mode's output file extension. OUTPUT_EXT="" MODE_OUT="" -case "$MODE" in - cbe) OUTPUT_EXT=".c" ;; - asm) OUTPUT_EXT=".s" ;; -esac +OUTPUT_EXT=".s" if [[ -z "$OUTPUT_FILE" ]]; then if [[ $MODULE == "0" && $NO_ASSEMBLE == "0" ]]; then OUTPUT_FILE="${FILE}" @@ -109,14 +106,17 @@ MODE_OUT="${FILE}${OUTPUT_EXT}" # select debug/optimize parameters. if [[ $DEBUG == "1" ]]; then LUA_FLAGS=" -O0 -g " - OPT_FLAGS=" -disable-opt " - LLC_FLAGS=" " + LLC_FLAGS=" -O0 " else LUA_FLAGS=" -O3 -s " - OPT_FLAGS=" -O3 -std-compile-opts -tailcallelim " - LLC_FLAGS=" -tailcallopt " + LLC_FLAGS=" -O3 -tailcallopt " +fi +if [[ ! -z "$CPU" ]]; then + LLC_FLAGS=" -mcpu=$CPU $LLC_FLAGS " +fi +if [[ ! -z $ARCH ]]; then + LLC_FLAGS=" -march=$ARCH $LLC_FLAGS " fi -LLC_FLAGS=" -mcpu=$CPU $LLC_FLAGS " # # run llvm-luac to compile Lua source/bytecode to LLVM bitcode. @@ -126,24 +126,7 @@ echo_cmd $LLVM_LUAC $EXTRA_ARGS $LUA_FLAGS -bc -o ${FILE}.bc ${FILES} || { exit 1; } TMPS="${FILE}.bc" - -# use one of the compile modes. -case "$MODE" in - cbe) - TMPS="$TMPS ${FILE}_opt.bc ${FILE}_run.c" - echo_cmd opt $OPT_FLAGS -o ${FILE}_opt.bc ${FILE}.bc - echo_cmd llc $LLC_FLAGS --march=c -o ${FILE}_run.c ${FILE}_opt.bc - echo_cmd $CC $EXPORT_SYMBOLS $CFLAGS $LIBS -o ${OUTPUT_FILE} ${FILE}_run.c -lllvm-lua_main -lm -ldl - ;; - asm) - TMPS="$TMPS ${FILE}_opt.bc" - echo_cmd opt $OPT_FLAGS -o ${FILE}_opt.bc ${FILE}.bc - echo_cmd llc -march=$ARCH $LLC_FLAGS -filetype=asm -o ${MODE_OUT} ${FILE}_opt.bc - ;; - *) - echo "Invalid compile mode: $MODE" - ;; -esac +echo_cmd llc $LLC_FLAGS -filetype=asm -o ${MODE_OUT} ${FILE}.bc # compile to stand-alone if [[ $MODULE == "0" && $NO_ASSEMBLE == "0" ]]; then