From 3f7c79b801d778f87ec0b5a8d7b22054af4a9c10 Mon Sep 17 00:00:00 2001 From: Scarlett Date: Sun, 4 May 2025 18:41:02 -0400 Subject: [PATCH] genx --- Makefile | 8 ++++ genx.sh | 74 +++++++++++++++++++++++++++++ tests/sprint4/test/sp4_cg_add.alpha | 10 ++-- 3 files changed, 86 insertions(+), 6 deletions(-) create mode 100755 genx.sh diff --git a/Makefile b/Makefile index 45c4b02..3e6cbc7 100644 --- a/Makefile +++ b/Makefile @@ -21,6 +21,8 @@ all: compiler compiler: clean tmp $(OBJS) $(CC) $(CFLAGS) -o $(EXE) $(OBJS) $(LDFLAGS) + chmod +x ./genx.sh + chmod +x ./test.sh clean: rm -f $(EXE) @@ -68,6 +70,7 @@ tmp/runner.o: src/runner.c src/runner.h tmp/flex.h tmp/grammar.tab.h # ----- Tests ----- test: chmod +x ./test.sh + chmod +x ./genx.sh ./test.sh tests/sprint1/test/ -diff ./test.sh tests/sprint2/test/ -diff ./test.sh tests/sprint3/test/ -diff @@ -76,21 +79,26 @@ test: test-s1: chmod +x ./test.sh + chmod +x ./genx.sh ./test.sh tests/sprint1/test/ -diff test-s2: chmod +x ./test.sh + chmod +x ./genx.sh ./test.sh tests/sprint2/test/ -diff test-s3: chmod +x ./test.sh + chmod +x ./genx.sh ./test.sh tests/sprint3/test/ -diff test-s4: chmod +x ./test.sh + chmod +x ./genx.sh ./test.sh tests/sprint4/test/ -diff test-given: chmod +x ./test.sh + chmod +x ./genx.sh ./test.sh tests/given/test/ -diff # ----------- \ No newline at end of file diff --git a/genx.sh b/genx.sh new file mode 100755 index 0000000..3534a7d --- /dev/null +++ b/genx.sh @@ -0,0 +1,74 @@ +#!/bin/bash + +# GenX Tool # +# The Translators - Spring 2025 # + +RED='\033[0;31m' +GREEN='\033[0;32m' +ORANGE='\033[0;33m' +BLUE='\033[0;34m' +PURPLE='\033[0;35m' +CYAN='\033[0;36m' +LIGHTGRAY='\033[0;37m' +DARKGRAY='\033[1;30m' +LIGHTRED='\033[1;31m' +LIGHTGREEN='\033[1;32m' +YELLOW='\033[1;33m' +LIGHTBLUE='\033[1;34m' +LIGHTPURPLE='\033[1;35m' +LIGHTCYAN='\033[1;36m' +WHITE='\033[1;37m' + +if [ ! -f "./alpha" ]; then + echo -e "${RED}[GenX] ${YELLOW}File ./alpha not found! Generating with 'make'.${WHITE}" + make +fi + +help() { + echo -e "${WHITE}-----{ ${BLUE}GenX.sh Help ${WHITE}}-----\n" + echo -e "${YELLOW} Arguments: ${WHITE}" + echo -e "${GREEN} -help ${WHITE} Displays this message\n" + echo -e "${YELLOW} Usage: ${WHITE}" + echo -e "${GREEN} ./genx.sh ${WHITE} Generates executable file from \n" + echo -e "${YELLOW} Notes: ${WHITE}" + echo -e "${ORANGE} Generates .s and links alpha driver and general library." + echo -e "${WHITE}-----------------------------------------\n" + exit 1 +} + +if [ $# -eq 0 ]; then + help +fi + +if [ ! -d "binaries" ]; then + mkdir -p binaries +fi + +if [ $# -eq 1 ]; then + if [ -f "$1" ]; then + if [[ "$1" == *.alpha ]]; then + ./alpha -cg "$1" + filename=$(basename -- "$1") + filename="${filename:0:${#filename}-6}" + s_name="out/${filename}.s" + echo -e "${GREEN}[GenX] ${WHITE}Generated .s file..." + gcc ${s_name} library/alpha_lib_reg.s library/alpha_driver.s -no-pie -o binaries/${filename} + if [ $? -eq 0 ]; then + echo -e "${GREEN}[GenX] ${WHITE}Generated executable file..." + echo -e "${GREEN}[GenX] ${WHITE}Executable file: binaries/${filename}" + echo -e "${GREEN}[GenX] ${WHITE}Done!" + else + echo -e "${RED}[GenX] ${YELLOW}Error generating executable file!${WHITE}" + exit 1 + fi + else + echo -e "${RED}[GenX] ${YELLOW}File $1 is not a .alpha file!${WHITE}" + exit 1 + fi + else + echo -e "${RED}[GenX] ${YELLOW}File $1 not found!${WHITE}" + exit 1 + fi +else + help +fi \ No newline at end of file diff --git a/tests/sprint4/test/sp4_cg_add.alpha b/tests/sprint4/test/sp4_cg_add.alpha index 97d23b4..3344ed5 100644 --- a/tests/sprint4/test/sp4_cg_add.alpha +++ b/tests/sprint4/test/sp4_cg_add.alpha @@ -1,11 +1,9 @@ (* TEST: [-asc -tc -cg -ir] *) -#include "alpha.h" -#include "alpha.h2" -#include "alpha.h3" -type main: integer -> integer -function test: main + +type main: string -> integer +function entry: main -test (a) := { +entry (arg) := { [integer:x; integer:y] y := 1; x := 3;