-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaf
155 lines (131 loc) · 2.51 KB
/
leaf
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
#Compilador temporal de lenguaje de programacion leaf
#Autor: Colmenares David
function imprimir_mensaje(){
echo "Compilador de lenguaje de programacion Leaf."
echo "Uso:"
echo " leaf [programa] [OPCIONES]"
echo ""
echo "OPCIONES:"
echo " -r [-nd] Ejecuta el programa una vez compilado"
echo " -o <out> Lugar donde se guardara el programa ejecutable"
echo " -nd No eliminar el programa de salida luego de ejecutar"
echo " -m <32|64> Arquitectura de salida"
echo " -c Ensambla y compila programa ASM"
echo " -h Imprime este mensaje"
echo ""
echo "Autor:"
echo " [email protected]"
}
if [ $# = 0 ]; then
imprimir_mensaje
exit 1
fi
PROGRAM=$1
TMP_ASM="test/leaf.asm"
ARCH="-m64"
ARCH_NASM="elf64"
OUTPUT="test/out/a.out"
RUN=0
ONLYNASM=0
NODELETE=0
#parse arch
u=0
x=1
for a in $@; do
if [ $a = "-m" ]; then
u=`echo $x+1|bc`
fi
x=`echo $x+1|bc`
done
x=1
for a in $@; do
if [ $x = $u ]; then
ARCH="-m"$a
ARCH_NASM="elf"$a
fi
x=`echo $x+1|bc`
done
#parse arch
#parse output
u=0
x=1
for a in $@; do
if [ $a = "-o" ]; then
u=`echo $x+1|bc`
fi
x=`echo $x+1|bc`
done
x=1
for a in $@; do
if [ $x = $u ]; then
OUTPUT=$a
#echo $OUTPUT
fi
x=`echo $x+1|bc`
done
#parse output
#parse if run
u=0
x=1
for a in $@; do
if [ $a = "-r" ]; then
RUN=1
fi
x=`echo $x+1|bc`
done
#parse if run
#parse out help
u=0
x=1
for a in $@; do
if [ $a = "-h" ]; then
imprimir_mensaje
exit 0
fi
x=`echo $x+1|bc`
done
#parse if run
#parse no delete
u=0
x=1
for a in $@; do
if [ $a = "-nd" ]; then
NODELETE=1
fi
x=`echo $x+1|bc`
done
#parse no delete
#parse compilar solo el asm
u=0
x=1
for a in $@; do
if [ $a = "-c" ]; then
ONLYNASM=1
if [ $1 != "" ]; then
if [ $1 != "-c" ];then
TMP_ASM=$1
#echo $TMP_ASM
fi
fi
fi
x=`echo $x+1|bc`
done
#parse compilar solo el asm
if [ $ONLYNASM = 0 ]; then
./leafc $PROGRAM
fi
if [ 1 = 1 ]; then
nasm -f $ARCH_NASM $TMP_ASM
gcc -c test/lib.c -o test/out/lib.o $ARCH
gcc test/leaf.o test/out/lib.o $ARCH -o $OUTPUT
rm test/leaf.o
#rm test/out/leaf.asm
if [ $RUN = 1 ]; then
./$OUTPUT
echo $?
if [ $NODELETE = 0 ]; then
rm $OUTPUT
fi
fi
fi