GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — compiler-2/run.sh at master · calint/compiler-2

Expand file tree

/

run.sh

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
executable file
·
107 lines (102 loc) · 3.21 KB
/

run.sh

Copy path

File metadata and controls

executable file
·
107 lines (102 loc) · 3.21 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/sh
# compiles, assembles and runs a baz program
# usage: run.sh [options] [NAME.baz]
# NAME.baz is relative to the repository root since the script changes to it
# first, the options are passed to 'baz'
set -eu
cd "$(dirname "$0")"
TARGET=x86_64
# same default source as the compiler
SRC=prog.baz
IMAGE=
for arg in "$@"; do
case "$arg" in
--target=*) TARGET="${arg#--target=}" ;;
--bin=*) IMAGE="${arg#--bin=}" ;;
-*) ;;
*) SRC="$arg" ;;
esac
done
# keeps a directory part so the binary can be run as a path
BIN="$(dirname "$SRC")/$(basename "$SRC" .baz)"
# same default image name as the compiler
IMAGE="${IMAGE:-$BIN-$TARGET.bin}"
ASM="$BIN.s"
ASM_NO_COMMENTS="$BIN-without-comments.s"
OBJ="$BIN.o"
case "$TARGET" in
x86_64 | rv32i | rv32i-qemu | rv32i-fpga) ;;
*)
printf 'Unsupported target: %s (use --target=x86_64, --target=rv32i, --target=rv32i-qemu or --target=rv32i-fpga)\n' "$TARGET" >&2
exit 1
;;
esac
# a missing source would leave an empty listing behind
if [ ! -f "$SRC" ]; then
printf 'source not found: %s\n' "$SRC" >&2
exit 1
fi
# rv32i-qemu and rv32i-fpga emit rv32i assembly
RV32I=
case "$TARGET" in
rv32i*) RV32I=1 ;;
esac
SEP="--------------------------------------------------------------------------------"
echo "$SEP"
printf './baz --checks=noub,line --report=registers'
# quoted so the shown command can be copied; without arguments 'printf'
# would still write one space
if [ $# -gt 0 ]; then
printf " '%s'" "$@"
fi
printf '\n'
# a '--checks' in the arguments replaces the default one
./baz --checks=noub,line --report=registers "$@" >"$ASM"
echo "$SEP"
COMMENT=';'
if [ -n "$RV32I" ]; then
COMMENT='#'
fi
awk -v comment="$COMMENT" '$0 !~ "^[[:space:]]*" comment && $0 !~ /^[[:space:]]*$/ { print }' "$ASM" >"$ASM_NO_COMMENTS"
# the count of the footer of the listing: machine instructions, a pseudo
# instruction as those it expands to, no directive or data
awk -v comment="$COMMENT" '$1 == comment && $2 == "instructions:" { print "instructions: " $3 }' "$ASM"
if [ -n "$RV32I" ]; then
awk '
/^[[:space:]]*[[:alpha:]][[:alnum:]]*[[:space:]]/ {
if ($1 == "j") jumps++
if ($1 ~ /^b/) branches++
}
END { print "jmp: " jumps+0; print "jcc: " branches+0 }
' "$ASM_NO_COMMENTS"
else
grep -E '^\s*jmp\s.*.*$' "$ASM" | wc | awk '{print "jmp: " $1}'
grep -E '^\s*j[a-z]{1,2}\s' "$ASM" | grep -v '^\s*jmp\s' | wc | awk '{print "jcc: " $1}'
fi
echo "$SEP"
if [ "$TARGET" = rv32i-qemu ] || [ "$TARGET" = rv32i-fpga ]; then
# the compiler writes the image, no linking needed
ls --color -la "$ASM" "$ASM_NO_COMMENTS" "$IMAGE"
elif [ "$TARGET" = rv32i ]; then
llvm-mc -triple=riscv32 -mattr=-m,-a,-f,-d,-c -filetype=obj "$ASM" -o "$OBJ"
ld.lld -m elf32lriscv -e _start -o "$BIN" "$OBJ"
ls --color -la "$ASM" "$ASM_NO_COMMENTS" "$BIN"
else
nasm -w+error -f elf64 "$ASM"
ld -s -T baz.ld -o "$BIN" "$OBJ"
ls --color -la "$ASM" "$ASM_NO_COMMENTS" "$BIN"
fi
echo "$SEP"
set +e # don't stop at errors
if [ "$TARGET" = rv32i-qemu ]; then
./run-rv32i-qemu.sh "$IMAGE"
elif [ "$TARGET" = rv32i ]; then
qemu-riscv32 "$BIN"
elif [ "$TARGET" = rv32i-fpga ]; then
./run-rv32i-fpga.sh "$IMAGE"
else
"$BIN"
fi
RET=$?
echo "$SEP"
echo "returned: $RET"
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.