Skip to content

Commit

Permalink
readme + scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
probably-neb committed Jun 16, 2024
1 parent 60c0956 commit acba8fd
Show file tree
Hide file tree
Showing 4 changed files with 160 additions and 1 deletion.
65 changes: 65 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
72 changes: 72 additions & 0 deletions run-suite-test.sh
Original file line number Diff line number Diff line change
@@ -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/
22 changes: 22 additions & 0 deletions run-suite.sh
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10 200 100
10 200

0 comments on commit acba8fd

Please sign in to comment.