-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile
executable file
·87 lines (68 loc) · 1.48 KB
/
compile
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
#!/bin/bash
CC="riscv64-linux-gnu-gcc"
CFLAGS="-ggdb -fomit-frame-pointer -march=rv64g"
INFILE=$1
OUTFILE=$2
TYPE="comp"
if [ "${1}" = "-r" ]; then
INFILE=$2
OUTFILE=$3
TYPE="run"
fi
if [ "${1}" = "-gdb" ]; then
INFILE=$2
OUTFILE=$3
TYPE="gdb"
fi
if [ "${1}" = "-d" ]; then
INFILE=$2
OUTFILE=$3
TYPE="dump"
fi
if [ "${OUTFILE}" = "" ]; then
OUTFILE="a.out"
fi
OUTFILE="build/${OUTFILE}"
if [ ! -d "build" ]; then
mkdir build;
fi
FILENAME=$(basename -- "$INFILE");
FILENAME="${FILENAME%.*}"
ASMFILE="build/${FILENAME}.s"
OBJFILE="build/${FILENAME}.o"
cargo build --release 2> /dev/null
if [ ! "$?" -eq 0 ]; then
echo Compile Error
exit -1
fi
target/release/console_comp --asm ${INFILE} 2> build/error > ${ASMFILE}
if [ ! "$?" -eq 0 ]; then
cat build/error
exit -1
fi
${CC} ${CFLAGS} -c ${ASMFILE} -o ${OBJFILE}
${CC} ${CFLAGS} -o ${OUTFILE} ${OBJFILE} -nostdlib -static
function run() {
qemu-riscv64 -L /usr/riscv64-linux-gnu/ $1
RETURN=$?
exit $RETURN
}
function gdb() {
qemu-riscv64 -L /usr/riscv64-linux-gnu/ -g 1234 $1 &
riscv64-linux-gnu-gdb -ex 'target remote localhost:1234' -ex "file $1"
}
function dump() {
printf "input file : %s\n" $2
qemu-riscv64 -L /usr/riscv64-linux-gnu/ $1
RETURN=$?
printf "return %s\n" $RETURN
}
if [ "${TYPE}" = "run" ]; then
run "$OUTFILE"
fi
if [ "${TYPE}" = "gdb" ]; then
gdb "$OUTFILE"
fi
if [ "${TYPE}" = "dump" ]; then
dump "$OUTFILE" "$INFILE"
fi