Add automated build scripts

This commit is contained in:
Gabriel Tofvesson 2019-04-07 13:54:18 +02:00
parent c2dc8dec0d
commit ddd50eb165
2 changed files with 98 additions and 0 deletions

8
Makefile Normal file
View File

@ -0,0 +1,8 @@
KCOMPILER=kotlinc
KEXEC=kotlin
TEMPLATE=weaver.jar compiler.jar microcompiler.jar
$(TEMPLATE): %: $(%:.jar=.kt)
$(KCOMPILER) $(@:.jar=.kt) -d $@
all: weaver.jar compiler.jar microcompiler.jar

90
build.sh Executable file
View File

@ -0,0 +1,90 @@
#!/bin/bash
usage(){
echo "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"
}
if [ $# -eq 0 ]; then
>&2 echo "Not enough arguments!"
exit
fi
TARGET=$1
case $# in
1)
TYPE="asm"
OUTPUT="build.mia"
;;
2)
if [ "$2" = "asm" ] || [ "$2" = "micro" ] ; then
TYPE=$2
OUTPUT="build.mia"
else
TYPE="asm"
OUTPUT=$2
fi
;;
3)
if [ "$2" = "asm" ] || [ "$2" = "micro" ]; then
TYPE=$2
OUTPUT=$3
else
TYPE="asm"
OUTPUT=$2
MICRO=$3
fi
;;
4)
TYPE=$2
OUTPUT=$3
COMBINE=$4
;;
5)
if [ "$2" != "asm" ]; then
>&2 echo "TYPE must be asm"
exit
fi
TYPE=$2
OUTPUT=$3
COMBINE=$4
MICRO=$5
;;
*)
>&2 echo "Too many arguments!"
exit
;;
esac
make all
if [ "$TYPE" = "asm" ]; then
KJAR="compiler.jar"
KCLASS="CompilerKt"
else
KJAR="microcompiler.jar"
KCLASS="MicrocompilerKt"
fi
kotlin -classpath $KJAR $KCLASS $TARGET > comp.out || exit
if [ "$COMBINE" = "" ]; then
if [ "$MICRO" != "" ]; then
kotlin -classpath microcompiler.jar MicrocompilerKt $MICRO >> comp.out || exit
fi
kotlin -classpath weaver.jar WeaverKt comp.out $OUTPUT || exit
else
if [ "$MICRO" != "" ]; then
kotlin -classpath microcompiler.jar MicrocompilerKt $MICRO >> comp.out || exit
fi
kotlin -classpath weaver.jar WeaverKt comp.out $COMBINE $OUTPUT || exit
fi
echo "Compiled successfully to $OUTPUT"