genx
This commit is contained in:
8
Makefile
8
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
|
||||
# -----------
|
74
genx.sh
Executable file
74
genx.sh
Executable file
@ -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 <file.alpha>${WHITE} Generates executable file from <file.alpha>\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
|
@ -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;
|
||||
|
Reference in New Issue
Block a user