-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.sh
More file actions
executable file
·48 lines (38 loc) · 1.26 KB
/
run.sh
File metadata and controls
executable file
·48 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
ARCH=$1
ASM_FILE=$2
PLATFORM=""
LD_FLAGS=""
BENCHMARKING="true" # "true" to enable
QEMU=""
if [[ -z "$ARCH" || -z "$ASM_FILE" ]]; then
echo "Error: Architecture and assembly (.S) file must be provided."
echo "Usage: ./run.sh [riscv|arm] <assembly_file.S>"
exit 1
fi
if [[ "$ARCH" != "riscv" && "$ARCH" != "arm" ]]; then
echo "Error: Architecture must be either 'riscv' or 'arm'."
echo "Usage: ./run.sh [riscv|arm] <assembly_file.S>"
exit 1
fi
if [[ "$ARCH" == "riscv" ]]; then
QEMU="qemu-riscv64"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
PLATFORM="riscv64-unknown-linux-gnu-"
fi
elif [[ "$ARCH" == "arm" ]]; then
QEMU="qemu-aarch64"
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
PLATFORM="aarch64-unknown-linux-gnu-"
fi
fi
if [[ "$OSTYPE" == "darwin"* ]]; then
LD_FLAGS="-lSystem -macosx_version_min 11.3 -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib"
fi
"$PLATFORM"as "$ASM_FILE" -o "$ASM_FILE".as || { echo "Assembly compilation failed"; exit 1; }
"$PLATFORM"ld "$ASM_FILE".as -o "$ASM_FILE".bin $LD_FLAGS || { echo "Linking failed"; exit 1; }
"$QEMU" ./"$ASM_FILE".bin
echo "$?"
if [ "$BENCHMARKING" = true ]; then
hyperfine -r 1000 -w 100 -Ni ""$QEMU" ./"$ASM_FILE".bin"
fi