From acba8fd328a21c0c10b7ec89a22da10a4ae6b382 Mon Sep 17 00:00:00 2001 From: Ben Kunkle Date: Sat, 15 Jun 2024 19:16:44 -0700 Subject: [PATCH] readme + scripts --- README.md | 65 +++++++++++++++++ run-suite-test.sh | 72 +++++++++++++++++++ run-suite.sh | 22 ++++++ .../swap_problem/output.longer.expected | 2 +- 4 files changed, 160 insertions(+), 1 deletion(-) create mode 100755 run-suite-test.sh create mode 100755 run-suite.sh diff --git a/README.md b/README.md index 0bf45f6..5fbd892 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,67 @@ ## Mini language Implementation + CSC-431 + + +## BUILD INSTRUCTIONS + +### Setup + +In Order to build the project zig version 0.11 must be installed. + +There is a nix shell setup for the project that will get you into a shell with [`just`](https://github.com/casey/just) (an alternative to `make`), clang (llvm) v7.0.1, and the correct version of zig. + - If you have `nix` and `just` installed you can run `just nix` to get into a shell with the correct versions of everything installed + - If you do not have `just` installed you can copy line 139 from the file named `Justfile` in the root of the project which will enter the nix shell + +If you do not wish to use nix the project can still be built with zig v0.11. + + +### Building + +To build the compiler you must run `zig build` in the root directory of the project. The binary will be placed in `./zig-out/bin/minipp` + + +### Arguments + +#### Modes + +The arguments to the compiler are as follows + +`-stack` | `-phi` +: These arguments set the mode for llvm generation. If both are provided the one that appears last will be used. If neither of these flags is passed + +`-opt` +: Meaningless unless the phi llvm IR gen mode is active. Enables optimizations on the IR + +#### Optimization Flags + +The following flags are meaningless unless the `-phi` and `-opt` flags are passed as well. + +`-opt-use-sccp` +: By default comparison propogation will be used instead of sparse conditional constant propogation as constant propogation is an extension on top of sccp. Pass this flag if you wish to use sccp instead of comp-prop + +`-opt-no-sccp-like` +: Disables both sccp and comp-prop passes + +`-opt-no-dce` +: Disables the dead code elimintion pass + +`-opt-no-ebe` +: Disables the empty block elimination pass + +### Input/Output + +`-i` | `-input` +: **REQUIRED** The input `-mini` file + +`-o` | `-out` +: The file to output the `.ll` LLVM IR output to. If no output file is passed will default to stdout + +`-dot` +: File to output a `.dot` file to containing the graphviz dot for the mini files CFG + +### Test Suite + +If you have just installed you can run `just run-suite [BUILD ARGS...]` to run the entire test suite or `just run-suite-test [TEST NAME] [BUILD ARGS...]` to run just one test. Both commands will place the `.ll` file as well as the compiled binary in the same directory as the original test in `./test-suite/tests/milestone2/benchmarks` + +If just is not installed there is a script at `./run-suite.sh` that will do the same as the `just run-suite` test above. Note the script should be ran from the root directory. This script will place the resulting .ll file and binary in `./tests/milestone2/benchmarks/[test name]` rather than the `test-suite` directory like the just script. diff --git a/run-suite-test.sh b/run-suite-test.sh new file mode 100755 index 0000000..6146789 --- /dev/null +++ b/run-suite-test.sh @@ -0,0 +1,72 @@ +#!/usr/bin/env bash + +set -euxo pipefail + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +TEST_SUITE=${TEST_SUITE_PATH:-"./tests/milestone2/benchmarks"} + +name="${1}" +shift +BUILD_ARGS="$@" + +echo -e "Running Test Suite Test: ${YELLOW}${name}${NC}" +echo -e "${BLUE}Building Test Suite Test...${NC} ${BUILD_ARGS}" + +minipp="./zig-out/bin/minipp" +zig build + +build-suite-test() { + name_no_arr="${name#array_}" + dir="${TEST_SUITE}/${name}" + rm -f "${TEST_SUITE}/output" + rm -f "${TEST_SUITE}/output.longer" + ${minipp} -i "$dir/${name_no_arr}.mini" -o "$dir/${name}.ll" ${BUILD_ARGS} + clang "$dir/${name}.ll" -o "$dir/${name}" +} + +rm -rf ./dot_svg/ +rm -rf ./dot_generated/ +mkdir dot_generated +mkdir dot_svg + +echo -e "Running Test Suite Test: ${YELLOW}${name}${NC}" +echo -e "${BLUE}Building Test Suite Test...${NC}" +build-suite-test ${name} ${BUILD_ARGS} +echo -e "${GREEN}BUILD SUCCESS${NC}" + +dir="${TEST_SUITE}/${name}" +bin="$dir/${name}" + + +echo "Checking Normal Input..." +$bin < "$dir/input" > "$dir/output" +diff "$dir/output" "$dir/output.expected" +if [ $? -eq 0 ]; then + echo -e "${GREEN}SUCCESS${NC}" +else + echo -e "${RED}FAIL${NC}" +fi + +echo "Checking Longer Input..." +longer="$dir/input.longer" +if [ -f "$longer" ]; then + $bin < "$longer" > "$dir/output.longer" + diff "$dir/output.longer" "$dir/output.longer.expected" + if [ $? -eq 0 ]; then + echo -e "${GREEN}SUCCESS${NC}" + else + echo -e "${RED}FAIL${NC}" + fi +else + echo "Longer Input Not Found" + echo -e "${GREEN}SUCCESS${NC}" +fi + +# Comment out the following if you wish to preserve the genrated dot files +rm -rf ./dot_svg/ +rm -rf ./dot_generated/ diff --git a/run-suite.sh b/run-suite.sh new file mode 100755 index 0000000..ff3d56f --- /dev/null +++ b/run-suite.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -uo pipefail + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[0;33m' +BLUE='\033[0;34m' +NC='\033[0m' + + +BUILD_ARGS="$@" + +TEST_SUITE=${TEST_SUITE_PATH:-"./tests/milestone2/benchmarks"} + +for test in $(ls ${TEST_SUITE}); do + ./run-suite-test.sh $test ${BUILD_ARGS} > /dev/null 2>&1 + if [ $? -eq 0 ]; then + echo -e "${GREEN}SUCCESS${NC} - ${test}" + else + echo -e "${RED}FAIL ${NC} - ${test}" + fi +done diff --git a/tests/milestone2/benchmarks/swap_problem/output.longer.expected b/tests/milestone2/benchmarks/swap_problem/output.longer.expected index 0855e3a..e7a760d 100644 --- a/tests/milestone2/benchmarks/swap_problem/output.longer.expected +++ b/tests/milestone2/benchmarks/swap_problem/output.longer.expected @@ -1 +1 @@ -10 200 100 +10 200