From ddd50eb165bbe579af7f5c95ad7f9d6a39986904 Mon Sep 17 00:00:00 2001 From: Gabriel Tofvesson Date: Sun, 7 Apr 2019 13:54:18 +0200 Subject: [PATCH] Add automated build scripts --- Makefile | 8 +++++ build.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 Makefile create mode 100755 build.sh diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..cb2dfe8 --- /dev/null +++ b/Makefile @@ -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 diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..0a114d5 --- /dev/null +++ b/build.sh @@ -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"