-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassemble.sh
More file actions
executable file
·133 lines (117 loc) · 2.82 KB
/
assemble.sh
File metadata and controls
executable file
·133 lines (117 loc) · 2.82 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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# **************************************************************************** #
# #
# ::: :::::::: #
# assemble.sh :+: :+: :+: #
# +:+ +:+ +:+ #
# By: advardon <advardon@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/06/19 17:57:30 by cgiron #+# #+# #
# Updated: 2019/09/30 19:34:31 by cgiron ### ########.fr #
# #
# **************************************************************************** #
#!/bin/bash
################################ Functions #####################################
function usage() {
printf "\nusage: sh ./assemble.sh [-m map_folder] [-p program]\n"
printf "Apply asm to .s file\n\
- in folder -m\n\
- wih program -p\n\
- with valgrind -v\n\
- with -vm for vm name\n\
- with -c for vm execution\n\
- with -clean to remove all *.cor\n
- -with re to clean before processing\n"
}
########################## Variables initialization ############################
map_folder=.
program=./asm
corewar=0
valgrind=0
vm=./corewar
error=0
clean=0
############################# Options parser ###################################
while [ "$1" != "" ]; do
OPT=$1
case $OPT in
-h | --help)
usage
exit 0
;;
-v)
valgrind=1
;;
-clean)
clean=1
;;
-re)
clean=2
;;
-s)
error=1
;;
-p)
shift
program=$1
;;
-vm)
shift
vm=$1
;;
-c)
corewar=1
;;
-m)
shift
map_folder=$1
;;
*)
usage
exit
;;
esac
shift
done
################################ Main loop #####################################
echo "\033[0mTEST FOLDER :\033[0;32m" $map_folder
echo "\033[0m"
if [ "$clean" -eq 1 ]; then
echo "CLeaning *.cor"
rm $map_folder/*.cor
exit 1
fi
if [ "$clean" -eq 2 ]; then
echo "CLeaning *.cor"
rm $map_folder/*.cor
fi
if test -f "$program"; then
echo "\033[0;32m$program exist\033[0m"
else
echo "\033[0;31m$program absent\033[0m"
exit 1
fi
if [ "$corewar" -eq 1 ]; then
if test -f "$vm"; then
echo "\033[0;32m$vm exist\033[0m"
else
echo "\033[0;31m$vm absent\033[0m"
exit 1
fi
fi
for filename in $map_folder/*.s; do
map_str=$filename
echo "Now testing \033[0;32m$map_str\033[0m"
$program $map_str
success=$($program $map_str | grep "Success")
if [ -z "$success" ]; then
cat -n $map_str
else
if [ "$corewar" -eq 1 ]; then
./$vm "${filename%.s}.cor"
fi
fi
if [ "$valgrind" -eq 1 ]; then
echo "With valgrind"
valgrind $program $map_str >&1
fi
done