diff --git a/build.sh b/build.sh index 5a19293..1127842 100755 --- a/build.sh +++ b/build.sh @@ -1,9 +1,32 @@ #!/bin/bash +MODULE_PATH=$(realpath $PWD/${0%build\.sh}) + +# JARs +UCOMP=microcompiler.jar +COMP=compiler.jar +WEAVER=weaver.jar + +# Main classes +UCOMPMAIN=MicrocompilerKt +COMPMAIN=CompilerKt +WEAVERMAIN=WeaverKt + +# Random number generator +RGEN=rand_gen.py + +# Intermediate file +INTER=comp.out + + usage(){ echo -e "Usage:\n\t$0 [TARGET] {TYPE | OUTFILE}\n\t$0 [TARGET] [MICROTARGET] [OUTFILE]\n\t$0 [TARGET] [TYPE] [OUTFILE] [COMBINE]\n\t$0 [TARGET] asm [OUTFILE] [COMBINE] [MICROTARGET]\n\nWhere:\n\tTARGET: main compilation target file\n\tTYPE: either \"asm\" or \"micro\"\n\tOUTFILE: output .mia file\n\tCOMBINE: existing .mia file to combine compilation output with\n\tMICROTARGET: explicit microinstruction target" } +path_of(){ + echo "$MODULE_PATH/$1" +} + if [ $# -eq 0 ]; then >&2 echo "Not enough arguments!" usage @@ -66,29 +89,33 @@ case $# in ;; esac -make all +(cd $MODULE_PATH && make all) if [ "$TYPE" = "asm" ]; then - KJAR="compiler.jar" - KCLASS="CompilerKt" + KJAR=$COMP + KCLASS=$COMPMAIN else - KJAR="microcompiler.jar" - KCLASS="MicrocompilerKt" + KJAR=$UCOMP + KCLASS=$UCOMPMAIN fi -kotlin -classpath $KJAR $KCLASS $TARGET > comp.out || exit -python rand_gen.py >> comp.out + +kotlin -classpath $(path_of $KJAR) $KCLASS $TARGET > $INTER || exit +python "$(path_of $RGEN)" >> $INTER if [ "$COMBINE" = "" ]; then if [ "$MICRO" != "" ]; then - kotlin -classpath microcompiler.jar MicrocompilerKt $MICRO >> comp.out || exit + kotlin -classpath $(path_of $UCOMP) $UCOMPMAIN $MICRO >> $INTER || exit fi - kotlin -classpath weaver.jar WeaverKt comp.out $OUTPUT || exit + kotlin -classpath $(path_of $WEAVER) $WEAVERMAIN $INTER $OUTPUT || exit else if [ "$MICRO" != "" ]; then - kotlin -classpath microcompiler.jar MicrocompilerKt $MICRO >> comp.out || exit + kotlin -classpath $(path_of $UCOMP) $UCOMPMAIN $MICRO >> $INTER || exit fi - kotlin -classpath weaver.jar WeaverKt comp.out $COMBINE $OUTPUT || exit + kotlin -classpath $(path_of $WEAVERJAR) $WEAVERMAIN $INTER $COMBINE $OUTPUT || exit fi +# Remove intermediate compilation file +rm -f $INTER + echo "Compiled successfully to $OUTPUT"