forked from seyko2/cfront-3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CC1
executable file
·237 lines (227 loc) · 3.74 KB
/
CC1
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#!/bin/sh
#
# CC from the cfront-1. Can't handle templates.
# Much smaller and faster by 1/3 then
# CC from cfront-3.0.3
# -----------------------------------------
# CF=~/projects/cfront-1b
CF=$(dirname $0)
cfrontC="$CF/cfront +a1"
munch=$CF/munch
I=$CF/incl
Y="-Du3b"
LIBRARY=$CF/libC.a
TINYCC=$(which tcc)
if test -z "$TINYCC"
then
ccC="gcc -w"
cppC="gcc -U__GNUC__ -D__cfront__ -D__cplusplus=1 -D__signed__= -D__null=0 -E"
else
ccC="tcc -w"
cppC="tcc -U__GNUC__ -D__cfront__ -D__cplusplus=1 -D__signed__= -D__null=0 -E"
cppC="$cppC -U__SIZE_TYPE__ -D__SIZE_TYPE__=unsigned -U__PTRDIFF_TYPE__ -D__PTRDIFF_TYPE__=int"
fi
# -----------------------------------------
LIB_ID=${LIB_ID-C}
LIBRARY=${LIBRARY--l${LIB_ID}}
NMFLAGS=${NMFLAGS-}
C= EE=0 FON=
O=
PON= R= SUF= X= Y=${Y-} DASHR=
#PLUSI=1
Z=
E=0
CF=
P=
OO="a.out"
I=${I-"/usr/include/CC"}
ISUF="..c"
MVLIST=
ccC=${ccC-cc}
cfrontC=${cfrontC-cfront}
cppC=${cppC-/lib/cpp}
G=0
for A do
case $A in
+V) I="/usr/include"
O="$O $A"
;;
+i) PLUSI=1
;;
+*) O="$O $A"
;;
-E) PON=1
;;
-F) FON=1
;;
-Fc) FON=1
O="$O +L"
;;
-C) Y="$Y $A"
O="$O +C"
;;
-I*) Y="$Y $A"
;;
-D*) Y="$Y $A"
;;
-U*) Y="$Y $A"
;;
-p) P="-p"
;;
-r) DASHR=1
Z="$Z $A"
;;
-c) CF=1
;;
-o) X="$X $A"
Z="$Z $A"
OX=1
;;
-.c) echo "bad suffix option: -.c" 1>&2
;;
-.*) SUF=`expr "$A" : '-\(.*\)'`
;;
*.C) if test -f $A
then
B=`basename $A .C`
if test $PON
then
if test $SUF
then
echo "$cppC $O $A > $B$SUF:" 1>&2
$cppC $Y -I$I $A >$B$SUF
E=$?
else
$cppC $Y -I$I $A
E=$?
case $E in
0) ;;
*) break
;;
esac
fi
elif test $FON
then
if test $SUF
then
echo "$cfrontC $O $A > $B$SUF:" 1>&2
$cppC $Y -I$I $A | $cfrontC +L +f$A $O > $B$SUF
E=$?
else
$cppC $Y -I$I $A | $cfrontC +L +f$A $O
E=$?
case $E in
0) ;;
*) break
;;
esac
fi
else
echo "CC $O $A:" 1>&2
$cppC $Y -I$I $A | $cfrontC +L +f$A $O > $B$ISUF
E=$?
R=1
C="$C $B$ISUF"
case $E in
0) X="$X $B$ISUF"
Z="$Z $B.o"
MVLIST="$MVLIST $B"
G=1
;;
1) echo "1 error" 1>&2
;;
*) echo "$E errors" 1>&2
;;
esac
fi
else
echo "$A not found" 1>&2
fi
;;
*.i) X="$X $A"
B=`basename $A .i`
Z="$Z $B.o"
;;
*) X="$X $A"
Z="$Z $A"
if test $OX
then
OO=$A
OX=""
else
G=1
fi
;;
esac
done
case $G in
0) ;;
*) # generate code
if test "$PLUSI" #leave ..c's lying around
then
#remove #line's from the ..c's for sdb
for f in $C
do
sed "/^#/d" $f >temp$$
mv temp$$ $f
done
fi
if test $CF # -c: skip link edit
then
echo "$ccC $P -c $X" 1>&2
$ccC $P -c $X
EE=$?
for A in $MVLIST
do
[ -f $A..o ] && mv $A..o $A.o
done
else
# echo "$ccC $P $X $LIBRARY" 1>&2
X=$(echo $X | sed -e 's/-o[ \t]*[^ \t]*//')
A=$(echo $X | grep '[^ \t]*\.c')
EE=0
[ -n "$A" ] && {
$ccC $P -c $X >__err # compile, no load
EE=$?
for A in $MVLIST
do
[ -f $A..o ] && mv $A..o $A.o
done
}
case $EE in
0) #echo "ld $Z $LIBRARY -lc"
$ccC $P $Z $LIBRARY > __err # load
EE=$?
if test $EE != 0 -o -s __err
then
echo "error: $EE"
cat __err
elif test "$DASHR" != 1 # find ctors/dtors
then
# echo "nm $NMFLAGS $OO | $munch $P >__ctdt.c"
nm $NMFLAGS $OO | $munch $P >__ctdt.c
$ccC -c __ctdt.c >/dev/null
#echo "ld $Z __ctdt.o $LIBRARY -lc"
$ccC $P $Z __ctdt.o $LIBRARY # re-load
rm __ctdt.o
EE=$?
rm __ctdt.c
fi
;;
esac
for A in $MVLIST
do
[ -f $A.o ] && rm $A.o
done
rm __err
fi
esac
if test "$R" -a ! "$PLUSI"
then
rm $C
fi
case $E in
0) exit $EE
;;
*) exit $E
esac