author | Claus Gittinger <cg@exept.de> |
Sat, 25 Feb 2017 19:34:20 +0100 | |
changeset 4135 | ec9b0d7c8952 |
parent 4058 | 1e87dfa2ea9e |
child 4225 | 53895f16c1e2 |
permissions | -rw-r--r-- |
1669 | 1 |
" |
2 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
3 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
4 |
All Rights Reserved |
|
5 |
||
6 |
This software is furnished under a license and may be used |
|
7 |
only in accordance with the terms of that license and with the |
|
8 |
inclusion of the above copyright notice. This software may not |
|
9 |
be provided or otherwise made available to, or used by, any |
|
10 |
other person. No title to or ownership of the software is |
|
11 |
hereby transferred. |
|
12 |
" |
|
13 |
"{ Package: 'stx:libcomp' }" |
|
14 |
||
3659 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
1669 | 17 |
Object subclass:#STCCompilerInterface |
3240 | 18 |
instanceVariableNames:'originator parserFlags initName theNonMetaclassToCompileFor |
19 |
classToCompileFor stFileName cFileName oFileName stcFlags cFlags |
|
20 |
stcPath ccPath requestor methodCategory executionStatus package' |
|
21 |
classVariableNames:'SequenceNumber Verbose KeepIntermediateFiles' |
|
22 |
poolDictionaries:'' |
|
23 |
category:'System-Compiler' |
|
1669 | 24 |
! |
25 |
||
26 |
!STCCompilerInterface class methodsFor:'documentation'! |
|
27 |
||
28 |
copyright |
|
29 |
" |
|
30 |
COPYRIGHT (c) 1989 by Claus Gittinger |
|
31 |
COPYRIGHT (c) 2006 by eXept Software AG |
|
32 |
All Rights Reserved |
|
33 |
||
34 |
This software is furnished under a license and may be used |
|
35 |
only in accordance with the terms of that license and with the |
|
36 |
inclusion of the above copyright notice. This software may not |
|
37 |
be provided or otherwise made available to, or used by, any |
|
38 |
other person. No title to or ownership of the software is |
|
39 |
hereby transferred. |
|
40 |
" |
|
41 |
! |
|
42 |
||
43 |
documentation |
|
44 |
" |
|
45 |
a refactored complex method - originally found in ByteCodeCompiler. |
|
46 |
" |
|
47 |
! ! |
|
48 |
||
49 |
!STCCompilerInterface class methodsFor:'accessing'! |
|
50 |
||
4023 | 51 |
getCCDefine |
52 |
"return a string which was used to identify the C-Compiler used |
|
53 |
when STX was compiled, and which should be passed down when compiling methods. |
|
54 |
For example, when compiled with GNUC, this is '__GNUC__'; |
|
55 |
on windows, this is either '__VISUAL__', '__BORLANDC__' or '__MINGW64__'" |
|
56 |
||
57 |
%{ /* NOCONTEXT */ |
|
58 |
#ifndef CC_DEFINE |
|
59 |
# ifdef __win32__ |
|
60 |
# if defined( __BORLANDC__ ) |
|
61 |
# define CC_DEFINE "__BORLANDC__" |
|
62 |
# else |
|
63 |
# if defined( __VISUALC__ ) |
|
64 |
# define CC_DEFINE "__VISUALC__" |
|
65 |
# else |
|
66 |
# if defined( __MINGW64__ ) |
|
67 |
# define CC_DEFINE "__MINGW64__" |
|
68 |
# else |
|
69 |
# if defined( __MINGW32__ ) |
|
70 |
# define CC_DEFINE "__MINGW32__" |
|
71 |
# else |
|
72 |
# define CC_DEFINE "__CC__" |
|
73 |
# endif |
|
74 |
# endif |
|
75 |
# endif |
|
76 |
# endif |
|
77 |
# else /* not __win32__ */ |
|
78 |
# if defined(__CLANG__) || defined( __clang__ ) |
|
79 |
# define CC_DEFINE "__CLANG__" |
|
80 |
# else |
|
81 |
# ifdef __GNUC__ |
|
82 |
# define CC_DEFINE "__GNUC__" |
|
83 |
# else |
|
84 |
# define CC_DEFINE "__CC__" |
|
85 |
# endif |
|
86 |
# endif |
|
87 |
# endif |
|
88 |
#endif |
|
89 |
RETURN ( __MKSTRING(CC_DEFINE)); |
|
90 |
%} |
|
91 |
" |
|
92 |
STCCompilerInterface getCCDefine |
|
93 |
" |
|
94 |
! |
|
95 |
||
96 |
getCPUDefine |
|
97 |
"return a string which was used to identify this CPU type when STX was |
|
98 |
compiled, and which should be passed down when compiling methods. |
|
99 |
For example, on a 386 (and successors), this may be '-D__x86__'; |
|
100 |
on a vax, this would be '-D__vax__'. |
|
101 |
This is normally not of interest to 'normal' users; however, it is passed |
|
102 |
down to the c-compiler when methods are incrementally compiled to machine code. |
|
103 |
Do not use this for CPU determination; only to pass on to stc for compilation. |
|
104 |
(see OperatingSystem getCPUType for this)" |
|
105 |
||
106 |
%{ /* NOCONTEXT */ |
|
107 |
# ifndef CPU_DEFINE |
|
108 |
# define CPU_DEFINE "-DunknownCPU" |
|
109 |
# endif |
|
110 |
||
111 |
RETURN ( __MKSTRING(CPU_DEFINE)); |
|
112 |
%} |
|
113 |
" |
|
114 |
STCCompilerInterface getCPUDefine |
|
115 |
" |
|
116 |
! |
|
117 |
||
118 |
getOSDefine |
|
119 |
"return a string which was used to identify this machine when stx was |
|
120 |
compiled, and which should be passed down when compiling methods. |
|
121 |
For example, on linux, this is '-D__linux__'; on osx, it is '-D__osx__'. |
|
122 |
Do not use this for OS determination; only to pass on to stc for compilation. |
|
123 |
(see OperatingSystem getOSType for this)" |
|
124 |
||
125 |
%{ /* NOCONTEXT */ |
|
126 |
||
127 |
#ifndef OS_DEFINE |
|
128 |
# ifdef __win32__ |
|
129 |
# define OS_DEFINE "-D__win32__" |
|
130 |
# endif |
|
131 |
||
132 |
# ifndef OS_DEFINE |
|
133 |
# define OS_DEFINE "-DunknownOS" |
|
134 |
# endif |
|
135 |
#endif |
|
136 |
||
137 |
RETURN ( __MKSTRING(OS_DEFINE)); |
|
138 |
||
139 |
#undef OS_DEFINE |
|
140 |
%} |
|
141 |
" |
|
142 |
STCCompilerInterface getOSDefine |
|
143 |
" |
|
144 |
! |
|
145 |
||
1669 | 146 |
stcPathOf:command |
147 |
"return the path to an stc command, or nil if not found." |
|
148 |
||
149 |
|f d reqdSuffix cmd| |
|
150 |
||
151 |
"/ |
|
152 |
"/ care for executable suffix |
|
153 |
"/ |
|
154 |
cmd := command. |
|
155 |
OperatingSystem isMSDOSlike ifTrue:[ |
|
156 |
reqdSuffix := 'exe' |
|
157 |
] ifFalse:[ |
|
158 |
OperatingSystem isVMSlike ifTrue:[ |
|
159 |
reqdSuffix := 'EXE' |
|
160 |
]. |
|
161 |
]. |
|
162 |
reqdSuffix notNil ifTrue:[ |
|
163 |
(f := cmd asFilename) suffix isEmpty ifTrue:[ |
|
164 |
cmd := (f withSuffix:reqdSuffix) name |
|
165 |
] |
|
166 |
]. |
|
167 |
"/ |
|
168 |
"/ for our convenience, also check in current |
|
169 |
"/ and parent directories; even if PATH does not |
|
170 |
"/ include them ... |
|
171 |
"/ |
|
3720 | 172 |
#('.' '../stc' '../../stc') do:[:relPath | |
173 |
d := Filename currentDirectory construct:relPath. |
|
174 |
(f := d construct:cmd) isExecutable ifTrue:[ |
|
175 |
^ f pathName |
|
176 |
]. |
|
1669 | 177 |
]. |
178 |
||
179 |
"/ |
|
180 |
"/ ok, stc must be installed in some directory along the PATH |
|
181 |
"/ |
|
182 |
^ OperatingSystem pathOfCommand:command |
|
183 |
||
184 |
" |
|
185 |
STCCompilerInterface stcPathOf:'stc' |
|
186 |
" |
|
187 |
||
188 |
"Created: 13.9.1995 / 14:37:16 / claus" |
|
3173 | 189 |
! |
190 |
||
191 |
verbose |
|
192 |
"if on, trace command execution on the Transcript" |
|
193 |
||
194 |
^ Verbose |
|
195 |
! |
|
196 |
||
197 |
verbose:aBoolean |
|
198 |
"if on, trace command execution on the Transcript" |
|
199 |
||
200 |
Verbose := aBoolean |
|
1669 | 201 |
! ! |
202 |
||
203 |
!STCCompilerInterface class methodsFor:'class initialization'! |
|
204 |
||
205 |
initialize |
|
206 |
Verbose := false. |
|
207 |
! ! |
|
208 |
||
209 |
!STCCompilerInterface methodsFor:'accessing'! |
|
210 |
||
2335 | 211 |
cFileName:something |
212 |
cFileName := something. |
|
213 |
! |
|
214 |
||
1669 | 215 |
incrementalStcPath |
216 |
"return the path to the stc command for incremental method compilation, |
|
217 |
or nil if not found." |
|
218 |
||
219 |
|f cmd| |
|
220 |
||
221 |
(cmd := parserFlags stcPath) isEmptyOrNil ifTrue:[ |
|
222 |
(f := self class stcPathOf:'stc') notNil ifTrue:[ |
|
223 |
cmd := f |
|
224 |
] ifFalse:[ |
|
225 |
cmd := self class stcPathOf:'demostc' |
|
226 |
] |
|
227 |
]. |
|
228 |
(cmd notNil and:[cmd includes:Character space]) ifTrue:[ |
|
229 |
cmd := '"' , cmd , '"'. |
|
230 |
]. |
|
231 |
^ cmd |
|
232 |
||
233 |
"Created: 13.9.1995 / 14:36:36 / claus" |
|
234 |
"Modified: 13.9.1995 / 15:15:04 / claus" |
|
235 |
! |
|
236 |
||
237 |
originator:something |
|
238 |
originator := something. |
|
239 |
! |
|
240 |
||
241 |
parserFlags:something |
|
242 |
parserFlags := something. |
|
2335 | 243 |
! |
244 |
||
245 |
stFileName:something |
|
246 |
stFileName := something. |
|
1669 | 247 |
! ! |
248 |
||
3411 | 249 |
!STCCompilerInterface methodsFor:'error raising'! |
250 |
||
251 |
parseError:messageText position:position |
|
252 |
originator parseError:messageText position:position. |
|
253 |
"not normally reached" |
|
254 |
ParseError raiseErrorString:messageText. |
|
255 |
! ! |
|
256 |
||
1669 | 257 |
!STCCompilerInterface methodsFor:'machine code generation'! |
258 |
||
1939 | 259 |
compileToMachineCode:aString forClass:aClass selector:selector inCategory:categoryArg |
260 |
notifying:requestorArg install:install skipIfSame:skipIfSame silent:silent |
|
1669 | 261 |
"this is called to compile primitive code. |
3357 | 262 |
It saves the code to a tmporary, calls stc to create C-code, compiles it, links |
263 |
it to a tiny little dll and loads it. |
|
264 |
As you already see, this takes some time and is therefore ONLY done for code containing prims; |
|
265 |
all pure smalltalk code is compiled to bytecode and jitted by the VM." |
|
1669 | 266 |
|
3042 | 267 |
|handle oldMethod newMethod ok dllFileName| |
1669 | 268 |
|
269 |
install ifFalse:[ |
|
270 |
"/ cannot do it uninstalled. reason: |
|
271 |
"/ if it is loaded twice, the first version could be unloaded by |
|
272 |
"/ finalization, which would also unload the second version |
|
273 |
"/ (because the first unload would unload the second version too) |
|
274 |
^ #CannotLoad |
|
275 |
]. |
|
2704
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
276 |
parserFlags isNil ifTrue:[ |
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
277 |
parserFlags := ParserFlags new |
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
278 |
]. |
1669 | 279 |
parserFlags stcCompilation == #never ifTrue:[^ #CannotLoad]. |
1670 | 280 |
|
1939 | 281 |
classToCompileFor := aClass. |
282 |
requestor := requestorArg. |
|
283 |
methodCategory := categoryArg. |
|
1669 | 284 |
|
3411 | 285 |
self ensureExternalToolsArePresent. |
1939 | 286 |
self ensureModuleDirectoryExists. |
1669 | 287 |
|
1939 | 288 |
theNonMetaclassToCompileFor := classToCompileFor theNonMetaclass. |
1941 | 289 |
|
1939 | 290 |
self ensureSuperClassesAreLoadedOf:theNonMetaclassToCompileFor. |
291 |
theNonMetaclassToCompileFor privateClassesSorted do:[:aPrivateClass | |
|
1670 | 292 |
self ensureSuperClassesAreLoadedOf:aPrivateClass. |
293 |
]. |
|
294 |
||
1939 | 295 |
(classToCompileFor isNil |
296 |
or:[parserFlags allowExtensionsToPrivateClasses |
|
297 |
or:[classToCompileFor owningClass isNil]]) ifTrue:[ |
|
298 |
(requestor respondsTo:#packageToInstall) ifFalse:[ |
|
299 |
package := Class packageQuerySignal query. |
|
300 |
] ifTrue:[ |
|
301 |
package := requestor packageToInstall |
|
302 |
]. |
|
303 |
] ifFalse:[ |
|
304 |
package := classToCompileFor owningClass package |
|
1669 | 305 |
]. |
306 |
||
307 |
[ |
|
1939 | 308 |
self generateSTSource:aString. |
309 |
self setupCompilationCommandArguments. |
|
4018 | 310 |
ok := self |
311 |
compileToC_onError:[:errorFile | |
|
312 |
self reportCompilationErrorFor:stcPath fromFile:errorFile |
|
313 |
]. |
|
1669 | 314 |
|
4018 | 315 |
parserFlags stcKeepSIntermediate ifTrue:[ |
316 |
self compileToS_onError:[:errorFile | ] |
|
317 |
]. |
|
3042 | 318 |
"/ now compile to machine code |
4018 | 319 |
ok := self |
320 |
compileToObj_onError:[:errorFile | |
|
321 |
self reportCompilationErrorFor:ccPath fromFile:errorFile. |
|
322 |
]. |
|
1669 | 323 |
|
324 |
originator activityNotification:''. |
|
325 |
||
326 |
" |
|
327 |
if required, make a shared or otherwise loadable object file for it |
|
328 |
" |
|
329 |
originator activityNotification:'linking'. |
|
2656 | 330 |
dllFileName := ObjectFileLoader createLoadableObjectFor:(oFileName asFilename withoutSuffix name). |
331 |
dllFileName isNil ifTrue:[ |
|
1669 | 332 |
"/ something went wrong |
3411 | 333 |
self parseError:('link error: ' , ObjectFileLoader lastError) position:1. |
1669 | 334 |
]. |
2656 | 335 |
dllFileName asFilename exists ifFalse:[ |
3411 | 336 |
self parseError:'link failed - cannot create machine code' position:1. |
1669 | 337 |
]. |
338 |
||
1939 | 339 |
oldMethod := classToCompileFor compiledMethodAt:selector. |
340 |
oldMethod notNil ifTrue:[package := oldMethod package]. |
|
3159 | 341 |
install ifTrue:[ |
342 |
(Smalltalk |
|
343 |
changeRequest:#methodInClass |
|
344 |
with:(Array with:classToCompileFor with:selector with:oldMethod)) ifFalse:[ |
|
345 |
^ #CannotLoad |
|
346 |
]. |
|
347 |
]. |
|
1669 | 348 |
|
349 |
" |
|
350 |
load the method objectfile |
|
351 |
" |
|
352 |
originator activityNotification:'loading'. |
|
3361 | 353 |
handle := ObjectFileLoader loadMethodObjectFile:dllFileName. |
354 |
originator activityNotification:''. |
|
1669 | 355 |
|
356 |
handle isNil ifTrue:[ |
|
3173 | 357 |
KeepIntermediateFiles ~~ true ifTrue:[ OperatingSystem removeFile:dllFileName ]. |
2185
cb311d08a486
changed #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2068
diff
changeset
|
358 |
"catch, so that #CannotLoad processing is done" |
3069 | 359 |
ParseError catch:[ |
2185
cb311d08a486
changed #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2068
diff
changeset
|
360 |
originator parseError:'dynamic load of machine code failed' position:1. |
cb311d08a486
changed #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2068
diff
changeset
|
361 |
]. |
1669 | 362 |
^ #CannotLoad |
363 |
]. |
|
364 |
||
365 |
" |
|
366 |
did it work ? |
|
367 |
" |
|
1939 | 368 |
newMethod := classToCompileFor compiledMethodAt:selector. |
1669 | 369 |
|
370 |
"/ if install is false, we have to undo the install (which is always done, when loading machine code) |
|
371 |
install ifFalse:[ |
|
372 |
oldMethod isNil ifTrue:[ |
|
1939 | 373 |
classToCompileFor removeSelector:selector |
1669 | 374 |
] ifFalse:[ |
375 |
newMethod setPackage:oldMethod package. |
|
1939 | 376 |
classToCompileFor addSelector:selector withMethod:oldMethod. |
377 |
oldMethod setPackage:package. |
|
1669 | 378 |
] |
379 |
]. |
|
380 |
||
381 |
newMethod notNil ifTrue:[ |
|
382 |
handle method ~~ newMethod ifTrue:[ |
|
383 |
'Compiler [warning]: loaded method installed itself in another class' errorPrintCR. |
|
384 |
]. |
|
385 |
||
386 |
newMethod source:aString string. |
|
1939 | 387 |
newMethod setPackage:package. |
1669 | 388 |
"/ Project notNil ifTrue:[ |
389 |
"/ newMethod package:(Project currentPackageName) |
|
390 |
"/ ]. |
|
391 |
||
1939 | 392 |
"/ classToCompileFor updateRevisionString. |
1669 | 393 |
install ifTrue:[ |
1939 | 394 |
classToCompileFor addChangeRecordForMethod:newMethod fromOld:oldMethod. |
1669 | 395 |
|
396 |
"/ kludge-sigh: must send change messages manually here (stc-loaded code does not do it) |
|
397 |
"/ see addMethod:... in ClassDescription |
|
1939 | 398 |
classToCompileFor changed:#methodDictionary with:(Array with:selector with:oldMethod). |
399 |
Smalltalk changed:#methodInClass with:(Array with:classToCompileFor with:selector with:oldMethod). |
|
2350
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
400 |
] ifFalse:[ |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
401 |
oldMethod := nil. |
1669 | 402 |
]. |
403 |
||
1986 | 404 |
silent ifFalse:[ |
1941 | 405 |
Transcript showCR:(' compiled: ', aClass name,' ',selector,' - machine code') |
1669 | 406 |
]. |
407 |
ObjectMemory flushCaches. |
|
408 |
||
409 |
handle method:newMethod. |
|
410 |
||
2350
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
411 |
"/ check for obsolete compiled method code and unload the |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
412 |
"/ corresponding ObjectFileHandle. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
413 |
"/ The old method with its source code is usually kept in the method history. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
414 |
"/ and will be recompiled on an undo |
1669 | 415 |
|
416 |
ObjectFileLoader loadedObjectHandlesDo:[:anotherHandle | |
|
417 |
anotherHandle isMethodHandle ifTrue:[ |
|
2350
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
418 |
anotherHandle method == oldMethod ifTrue:[ |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
419 |
"break association betwen old method, code and handle" |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
420 |
anotherHandle removeConnectedObjects. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
421 |
]. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
422 |
anotherHandle isObsolete ifTrue:[ |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
423 |
anotherHandle unload. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
424 |
anotherHandle removeUnusedObjectFile. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
425 |
]. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
426 |
]. |
1669 | 427 |
]. |
428 |
^ newMethod. |
|
429 |
]. |
|
430 |
||
3013 | 431 |
"/ OperatingSystem removeFile:moduleFileName. |
3411 | 432 |
self parseError:'dynamic load failed' position:1. |
1669 | 433 |
] ensure:[ |
3173 | 434 |
KeepIntermediateFiles == true ifTrue:[ |
435 |
Transcript showCR:'keeping files' |
|
2703
2e966ec31082
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2658
diff
changeset
|
436 |
] ifFalse:[ |
3173 | 437 |
parserFlags stcKeepSTIntermediate ifTrue:[ |
438 |
Transcript showCR:'keeping st file: ', stFileName asFilename pathName |
|
439 |
] ifFalse:[ |
|
440 |
OperatingSystem removeFile:stFileName. |
|
441 |
]. |
|
442 |
cFileName notNil ifTrue:[ |
|
443 |
parserFlags stcKeepCIntermediate == true ifTrue:[ |
|
444 |
Transcript showCR:'keeping c file: ', cFileName asFilename pathName |
|
445 |
] ifFalse:[ |
|
446 |
OperatingSystem removeFile:cFileName. |
|
447 |
] |
|
448 |
]. |
|
449 |
oFileName notNil ifTrue:[ |
|
450 |
parserFlags stcKeepOIntermediate == true ifTrue:[ |
|
451 |
Transcript showCR:'keeping o file: ', oFileName asFilename pathName |
|
452 |
] ifFalse:[ |
|
453 |
OperatingSystem removeFile:oFileName. |
|
454 |
]. |
|
455 |
]. |
|
456 |
"/ OperatingSystem isMSDOSlike ifTrue:[ |
|
457 |
"/ mapFileName notNil ifTrue:[ |
|
458 |
"/ OperatingSystem removeFile:mapFileName. |
|
459 |
"/ ]. |
|
460 |
"/ libFileName notNil ifTrue:[ |
|
461 |
"/ OperatingSystem removeFile:libFileName. |
|
462 |
"/ ]. |
|
463 |
"/ ]. |
|
464 |
] |
|
1669 | 465 |
]. |
466 |
||
467 |
" |
|
468 |
|m| |
|
469 |
||
470 |
Object subclass:#Test |
|
471 |
instanceVariableNames:'' |
|
472 |
classVariableNames:'' |
|
473 |
poolDictionaries:'' |
|
474 |
category:'tests'. |
|
475 |
m := ByteCodeCompiler |
|
476 |
compile:'foo ^ ''hello''' |
|
477 |
forClass:Test |
|
478 |
inCategory:'tests' |
|
479 |
notifying:nil |
|
480 |
install:false |
|
481 |
skipIfSame:false. |
|
482 |
m inspect |
|
483 |
" |
|
484 |
" |
|
485 |
|m| |
|
486 |
||
487 |
Object subclass:#Test |
|
488 |
instanceVariableNames:'' |
|
489 |
classVariableNames:'' |
|
490 |
poolDictionaries:'' |
|
491 |
category:'tests'. |
|
492 |
m := ByteCodeCompiler |
|
493 |
compileToMachineCode:'foo %{ RETURN (_MKSMALLINT(1)); %}' |
|
494 |
forClass:Test |
|
495 |
inCategory:'tests' |
|
496 |
notifying:nil |
|
497 |
install:false |
|
498 |
skipIfSame:false |
|
499 |
silent:false. |
|
500 |
m inspect |
|
501 |
" |
|
502 |
||
1939 | 503 |
"Modified: / 14-09-1995 / 22:33:04 / claus" |
504 |
"Modified: / 19-03-1999 / 08:31:42 / stefan" |
|
2704
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
505 |
"Modified: / 17-09-2011 / 10:39:25 / cg" |
1939 | 506 |
! ! |
507 |
||
508 |
!STCCompilerInterface methodsFor:'machine code generation-helpers'! |
|
509 |
||
4019 | 510 |
compileToC_onError:aBlock |
511 |
"compile st to C using stc. |
|
512 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
513 |
||
514 |
|command ok errorOutputFile| |
|
515 |
||
516 |
command := (self possiblyQuotedPath:stcPath) , ' ' , stcFlags |
|
4021 | 517 |
, ' -E:',(self possiblyQuotedPath:(Filename tempDirectory / 'lastIncrStcErrorOutput') pathName) |
4019 | 518 |
, ' -defdir=', (self possiblyQuotedPath:cFileName asFilename directory pathName). |
519 |
cFileName asFilename suffix ~= 'c' ifTrue:[ |
|
520 |
command := command , ' -cSuffix=',cFileName asFilename suffix. |
|
521 |
]. |
|
522 |
command := command , ' -C ' , (self possiblyQuotedPath:stFileName asFilename pathName). |
|
523 |
||
524 |
Verbose == true ifTrue:[ |
|
525 |
Transcript show:'executing: '; showCR:command. |
|
526 |
]. |
|
527 |
||
528 |
originator activityNotification:'compiling (stc)'. |
|
529 |
||
530 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
|
531 |
errorOutputFile writingFileDo:[:errorStream | |
|
532 |
ok := OperatingSystem |
|
533 |
executeCommand:command |
|
534 |
inputFrom:nil |
|
535 |
outputTo:errorStream |
|
536 |
errorTo:errorStream |
|
537 |
showWindow:false |
|
538 |
onError:[:stat| |
|
4021 | 539 |
self breakPoint:#cg. |
4019 | 540 |
executionStatus := stat. |
541 |
false |
|
542 |
]. |
|
543 |
]. |
|
544 |
||
545 |
cFileName asFilename exists ifTrue:[ |
|
546 |
ok ifFalse:[ |
|
547 |
'Compiler [info]: oops - system says stc failed - but c-file is there ...' infoPrintCR. |
|
548 |
ok := true |
|
549 |
] |
|
550 |
] ifFalse:[ |
|
551 |
ok ifTrue:[ |
|
552 |
'Compiler [info]: oops - system says stc ok - but no c-file is there ...' infoPrintCR |
|
553 |
]. |
|
554 |
ok := false |
|
555 |
]. |
|
556 |
||
557 |
[ |
|
558 |
ok ifFalse:[ |
|
559 |
aBlock value:errorOutputFile |
|
560 |
]. |
|
561 |
] ensure:[ |
|
562 |
errorOutputFile remove. |
|
563 |
]. |
|
564 |
^ ok |
|
565 |
||
566 |
"Created: / 07-11-2006 / 12:11:24 / cg" |
|
567 |
"Modified: / 08-08-2011 / 22:12:01 / cg" |
|
568 |
! |
|
569 |
||
4018 | 570 |
compileToExe_onError:aBlock |
571 |
"compile C to exe, using cc. |
|
572 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
1939 | 573 |
|
4018 | 574 |
|command errorOutputFile ok| |
2336 | 575 |
|
2658 | 576 |
command := (self possiblyQuotedPath:ccPath) , ' ' , cFlags , ' -D__INCREMENTAL_COMPILE__ ' , (self possiblyQuotedPath:cFileName). |
2336 | 577 |
|
578 |
Verbose == true ifTrue:[ |
|
3957 | 579 |
Transcript show:'executing: ' showCR:command. |
2336 | 580 |
]. |
581 |
originator activityNotification:'compiling (' , ccPath , ')'. |
|
582 |
||
4018 | 583 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
584 |
errorOutputFile writingFileDo:[:errorStream | |
|
585 |
ok := OperatingSystem |
|
586 |
executeCommand:command |
|
587 |
inputFrom:nil |
|
588 |
outputTo:errorStream |
|
589 |
errorTo:errorStream |
|
590 |
showWindow:false |
|
591 |
onError:[:stat| |
|
592 |
executionStatus := stat. |
|
593 |
false |
|
594 |
]. |
|
2336 | 595 |
]. |
4018 | 596 |
|
597 |
[ |
|
598 |
ok ifFalse:[ |
|
599 |
aBlock value:errorOutputFile |
|
600 |
]. |
|
601 |
] ensure:[ |
|
602 |
errorOutputFile remove. |
|
603 |
]. |
|
2336 | 604 |
^ ok |
605 |
! |
|
606 |
||
4018 | 607 |
compileToObj_onError:aBlock |
608 |
"compile C to obj, using cc. |
|
609 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
1939 | 610 |
|
4018 | 611 |
|errorOutputFile ok commandTemplate command ccDefine env| |
1939 | 612 |
|
4018 | 613 |
"/ bcc does not like -D__BORLANDC__ (needs to be set to a version, such as 0x0505) |
3170 | 614 |
"/ others do not need it (is already predefined in the compiler) |
615 |
"/ ccDefine := ' -D',ParserFlags usedCompilerDefine. |
|
3173 | 616 |
"/ so, never redefine ccDefine |
3170 | 617 |
ccDefine := ''. |
618 |
||
3010
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
619 |
ParserFlags useBorlandC ifTrue:[ |
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
620 |
"Note: Windows/bcc32 does not understand a space between -o and filename" |
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
621 |
"/ cg: I guess, this does not work for visual-c |
3423 | 622 |
commandTemplate := '%1 %2%3 -D__INCREMENTAL_COMPILE__ -o%4 -c %5'. |
3010
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
623 |
] ifFalse:[ |
3423 | 624 |
commandTemplate := '%1 %2%3 -D__INCREMENTAL_COMPILE__ -o %4 -c %5'. |
3010
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
625 |
]. |
3423 | 626 |
command := commandTemplate |
627 |
bindWith:(self possiblyQuotedPath:ccPath) |
|
628 |
with:cFlags |
|
629 |
with:ccDefine |
|
630 |
with:(self possiblyQuotedPath:oFileName) |
|
631 |
with:(self possiblyQuotedPath:cFileName). |
|
1939 | 632 |
|
633 |
Verbose == true ifTrue:[ |
|
3957 | 634 |
Transcript show:'executing: '; showCR:command. |
1939 | 635 |
]. |
636 |
originator activityNotification:'compiling (' , ccPath , ')'. |
|
3423 | 637 |
|
638 |
env := OperatingSystem isUNIXlike |
|
639 |
ifTrue:[OperatingSystem getEnvironment copy] |
|
640 |
ifFalse:[env := Dictionary new]. |
|
641 |
env at:'LANG' put:'C'. |
|
642 |
env at:'LC_MESSAGES' put:'C'. |
|
643 |
||
4018 | 644 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
645 |
errorOutputFile writingFileDo:[:errorStream | |
|
646 |
ok := OperatingSystem |
|
647 |
executeCommand:command |
|
648 |
inputFrom:nil |
|
649 |
outputTo:errorStream |
|
650 |
errorTo:errorStream |
|
651 |
environment:env |
|
652 |
showWindow:false |
|
653 |
onError: |
|
654 |
[:stat| |
|
655 |
executionStatus := stat. |
|
656 |
false |
|
657 |
]. |
|
2195
2996fe27c2f8
Add primitive functions when compiling
Stefan Vogel <sv@exept.de>
parents:
2185
diff
changeset
|
658 |
]. |
4018 | 659 |
|
1939 | 660 |
oFileName asFilename exists ifTrue:[ |
661 |
ok ifFalse:[ |
|
4018 | 662 |
'Compiler [info]: system says compile failed - but o-file is there ...' infoPrintCR. |
1939 | 663 |
ok := true |
664 |
] |
|
665 |
] ifFalse:[ |
|
666 |
ok ifTrue:[ |
|
4018 | 667 |
'Compiler [info]: system says compile ok - but no o-file is there ...' infoPrintCR. |
1939 | 668 |
]. |
669 |
ok := false |
|
670 |
]. |
|
4018 | 671 |
[ |
672 |
ok ifFalse:[ |
|
673 |
aBlock value:errorOutputFile |
|
674 |
]. |
|
675 |
] ensure:[ |
|
676 |
errorOutputFile remove. |
|
677 |
]. |
|
1939 | 678 |
^ ok |
679 |
||
680 |
"Created: / 07-11-2006 / 12:14:51 / cg" |
|
681 |
! |
|
682 |
||
4018 | 683 |
compileToS_onError:aBlock |
684 |
"compile C to assembler, using cc. |
|
685 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
2491 | 686 |
|
4018 | 687 |
|command errorOutputFile ok| |
2491 | 688 |
|
2658 | 689 |
command := (self possiblyQuotedPath:ccPath) , ' ' , cFlags , ' -D__INCREMENTAL_COMPILE__ -S ' , (self possiblyQuotedPath:cFileName). |
2491 | 690 |
|
691 |
Verbose == true ifTrue:[ |
|
3957 | 692 |
Transcript show:'executing: '; showCR:command. |
2491 | 693 |
]. |
694 |
originator activityNotification:'compiling (' , ccPath , ')'. |
|
695 |
||
4018 | 696 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
697 |
errorOutputFile writingFileDo:[:errorStream | |
|
698 |
ok := OperatingSystem |
|
699 |
executeCommand:command |
|
700 |
inputFrom:nil |
|
701 |
outputTo:errorStream |
|
702 |
errorTo:errorStream |
|
703 |
showWindow:false |
|
704 |
onError:[:stat| |
|
705 |
executionStatus := stat. |
|
706 |
false |
|
707 |
]. |
|
2491 | 708 |
]. |
4018 | 709 |
[ |
710 |
ok ifFalse:[ |
|
711 |
aBlock value:errorOutputFile |
|
712 |
]. |
|
713 |
] ensure:[ |
|
714 |
errorOutputFile remove. |
|
715 |
]. |
|
2491 | 716 |
^ ok |
717 |
! |
|
718 |
||
1939 | 719 |
ensureExternalToolsArePresent |
720 |
(stcPath := self incrementalStcPath) isNil ifTrue:[ |
|
3411 | 721 |
self parseError:'no stc compiler available - cannot create machine code' position:1. |
1939 | 722 |
]. |
2649 | 723 |
|
724 |
"make it absolute, so that we are immune to directory changes" |
|
725 |
stcPath := stcPath asFilename pathName. |
|
1939 | 726 |
(ccPath := parserFlags ccPath) isNil ifTrue:[ |
3411 | 727 |
self parseError:'no cc compiler available - cannot create machine code' position:1. |
1939 | 728 |
]. |
2649 | 729 |
"make it absolute, so that we are immune to directory changes" |
730 |
ccPath := ccPath asFilename pathName. |
|
1939 | 731 |
|
732 |
(ObjectFileLoader notNil and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[ |
|
3411 | 733 |
self parseError:'no dynamic loader configured - cannot create machine code' position:1. |
1939 | 734 |
]. |
735 |
||
736 |
"Created: / 07-11-2006 / 12:31:48 / cg" |
|
1670 | 737 |
! |
738 |
||
739 |
ensureModuleDirectoryExists |
|
3664 | 740 |
|mP t msg| |
1670 | 741 |
|
3411 | 742 |
mP := parserFlags stcModulePath. |
743 |
mP isEmptyOrNil ifTrue:[ |
|
744 |
self parseError:'No temporary module directory, check your settings!!' position:1. |
|
745 |
]. |
|
746 |
mP := mP asFilename. |
|
747 |
mP exists ifFalse:[ |
|
4058 | 748 |
mP recursiveMakeDirectory |
1670 | 749 |
]. |
3240 | 750 |
(mP isWritableDirectory and:[mP isReadable]) ifFalse:[ |
3664 | 751 |
(mP exists and:[mP isDirectory]) ifTrue:[ |
752 |
msg := 'No write permission in temporary module directory: '. |
|
753 |
] ifFalse:[ |
|
754 |
msg := 'No access to temporary module directory: '. |
|
755 |
]. |
|
756 |
self parseError:(msg , mP pathName) position:1. |
|
1670 | 757 |
]. |
3664 | 758 |
|
1670 | 759 |
"/ create a small README there ... |
760 |
||
761 |
(t := mP construct:'README') exists ifFalse:[ |
|
3411 | 762 |
t contents:'This temporary ST/X directory contains machine code for |
1670 | 763 |
accepted methods with embedded C-code |
764 |
(i.e. dynamic compiled code for inline-C methods). |
|
765 |
||
766 |
Files here are not automatically removed, since ST/X |
|
767 |
cannot determine if any (other) snapshot image still |
|
768 |
requires a file here. |
|
769 |
||
770 |
Please be careful when removing files here - a snapshot |
|
771 |
image which was saved with accepted embedded C-code |
|
772 |
may not be able to restart correctly if you remove a |
|
773 |
required file. |
|
774 |
Also, when you export a snapshot image for execution |
|
775 |
on another machine, make certain that the required |
|
776 |
module-files are also present there. |
|
777 |
||
778 |
You should periodically clean dead entries here. |
|
779 |
i.e. remove files, when you are certain that none |
|
780 |
of your snapshot images refers to any module here. |
|
781 |
||
782 |
See the launchers File-Modules dialog for a list of |
|
783 |
modules which are still required by your running image. |
|
784 |
||
785 |
With kind regards - your ST/X. |
|
786 |
'. |
|
787 |
]. |
|
788 |
! |
|
789 |
||
790 |
ensureSuperClassesAreLoadedOf:aClass |
|
791 |
|supers| |
|
792 |
||
793 |
supers := aClass allSuperclasses. |
|
794 |
supers reverseDo:[:cls| |
|
795 |
cls isLoaded ifFalse:[ |
|
3411 | 796 |
self parseError:('Cannot stc-compile (superclass %1 is unloaded)' bindWith:cls) position:1. |
1670 | 797 |
] |
798 |
]. |
|
799 |
! |
|
800 |
||
801 |
fileOutAllDefinitionsOf:aClass to:aStream rememberIn:definedClasses |
|
802 |
|defineAction| |
|
803 |
||
804 |
defineAction := |
|
805 |
[:cls| |
|
806 |
(definedClasses includes:cls) ifFalse:[ |
|
807 |
cls |
|
808 |
basicFileOutDefinitionOn:aStream |
|
809 |
withNameSpace:false withPackage:false |
|
810 |
syntaxHilighting:false. |
|
811 |
||
812 |
aStream nextPut:(aStream class chunkSeparator); cr. |
|
813 |
definedClasses add:cls. |
|
814 |
]. |
|
815 |
]. |
|
816 |
||
817 |
aClass allSuperclasses reverseDo:defineAction. |
|
818 |
defineAction value:aClass. |
|
1939 | 819 |
! |
820 |
||
821 |
generateSTSource:aString |
|
3359 | 822 |
|stream definedClasses sep className modulesDir ns nsName| |
1939 | 823 |
|
824 |
"/ generate a unique name, consisting of my processID and a sequence number |
|
825 |
"/ the processId is added to allow filein of modules from different |
|
826 |
"/ lifes |
|
827 |
||
828 |
SequenceNumber := (SequenceNumber ? 0) + 1. |
|
829 |
||
830 |
initName := 'm_' , OperatingSystem getProcessId printString, '_' , SequenceNumber printString. |
|
831 |
||
2646 | 832 |
"/ Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ |
833 |
"/ modulesParentDir := Filename currentDirectory. |
|
834 |
"/ ] ifFalse:[ |
|
835 |
"/ modulesParentDir := Filename tempDirectory. |
|
836 |
"/ ]. |
|
837 |
"/ modulesDir := modulesParentDir construct:'modules'. |
|
838 |
modulesDir := ParserFlags stcModulePath. |
|
2647 | 839 |
stFileName := (modulesDir asFilename construct:(initName , '.st')) name. |
2646 | 840 |
|
1939 | 841 |
[ |
842 |
stream := stFileName asFilename writeStream. |
|
843 |
] on:FileStream openErrorSignal do:[:ex| |
|
3411 | 844 |
self parseError:'cannot create temporary sourcefile for compilation' position:1. |
1939 | 845 |
^ #CannotLoad |
846 |
]. |
|
3419 | 847 |
stream := EncodedStream stream:stream encoder:(CharacterEncoder encoderForUTF8). |
848 |
stream nextPutLine:'"{ Encoding: utf8 }" !!'. |
|
1939 | 849 |
|
850 |
definedClasses := IdentitySet new. |
|
851 |
||
852 |
sep := stream class chunkSeparator. |
|
853 |
||
854 |
Class fileOutNameSpaceQuerySignal answer:true |
|
855 |
do:[ |
|
2467 | 856 |
theNonMetaclassToCompileFor realSharedPoolNames do:[:eachPoolname | |
2067
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
857 |
|pool| |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
858 |
|
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
859 |
pool := Smalltalk at:eachPoolname. |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
860 |
self |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
861 |
fileOutAllDefinitionsOf:pool |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
862 |
to:stream |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
863 |
rememberIn:definedClasses. |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
864 |
]. |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
865 |
|
1939 | 866 |
self |
867 |
fileOutAllDefinitionsOf:theNonMetaclassToCompileFor |
|
868 |
to:stream |
|
869 |
rememberIn:definedClasses. |
|
870 |
||
871 |
theNonMetaclassToCompileFor privateClassesSorted do:[:aPrivateClass | |
|
872 |
self |
|
873 |
fileOutAllDefinitionsOf:aPrivateClass |
|
874 |
to:stream |
|
875 |
rememberIn:definedClasses. |
|
876 |
]. |
|
2195
2996fe27c2f8
Add primitive functions when compiling
Stefan Vogel <sv@exept.de>
parents:
2185
diff
changeset
|
877 |
"/ theNonMetaclassToCompileFor fileOutPrimitiveDefinitionsOn:stream. |
2026 | 878 |
"/ If a method uses a static primitive function... - but this doesn't work |
2195
2996fe27c2f8
Add primitive functions when compiling
Stefan Vogel <sv@exept.de>
parents:
2185
diff
changeset
|
879 |
"/ Yes it does work, but primitive functions have to be strictly static!! |
2996fe27c2f8
Add primitive functions when compiling
Stefan Vogel <sv@exept.de>
parents:
2185
diff
changeset
|
880 |
theNonMetaclassToCompileFor fileOutPrimitiveSpecsOn:stream. |
1939 | 881 |
]. |
882 |
||
2026 | 883 |
"/ stream cr. |
884 |
"/ stream nextPutLine:'"{ Package: ''' , package , ''' }"'. |
|
885 |
"/ stream cr. |
|
1939 | 886 |
|
3357 | 887 |
className := theNonMetaclassToCompileFor name. |
888 |
ns := theNonMetaclassToCompileFor topNameSpace. |
|
3359 | 889 |
(ns notNil and:[ns ~= Smalltalk and:[nsName := ns name. className startsWith:(nsName,'::')]]) ifTrue:[ |
890 |
className := className copyFrom:nsName size+2+1. |
|
891 |
"/ split to avoid being regognized as a directive |
|
892 |
stream nextPutLine:('"','{ NameSpace: ',nsName,' }"'). |
|
3357 | 893 |
]. |
894 |
||
1939 | 895 |
stream nextPut:sep. |
896 |
stream nextPutAll:className. |
|
897 |
classToCompileFor isMeta ifTrue:[ |
|
898 |
stream nextPutAll:' class'. |
|
899 |
]. |
|
900 |
stream nextPutAll:' methodsFor:'''; nextPutAll:methodCategory; nextPutAll:''''. |
|
901 |
stream nextPut:sep; cr. |
|
902 |
||
903 |
stream nextPutLine:'"{ Line: 0 }"'; |
|
904 |
nextChunkPut:aString; |
|
905 |
space; nextPut:sep. |
|
906 |
||
907 |
stream close. |
|
908 |
||
2646 | 909 |
"Modified: / 08-08-2011 / 23:23:10 / cg" |
1939 | 910 |
! |
911 |
||
2658 | 912 |
possiblyQuotedPath:aPath |
3173 | 913 |
(aPath includes:Character space) ifTrue:[ |
3793 | 914 |
(aPath startsWith:$") ifFalse:[ |
2658 | 915 |
^ '"',aPath,'"' |
916 |
] |
|
917 |
]. |
|
918 |
^ aPath |
|
919 |
! |
|
920 |
||
3005 | 921 |
reportCompilationErrorFor:aCommand |
1939 | 922 |
|eMsg errorMessages lNr| |
923 |
||
924 |
(executionStatus notNil and:[executionStatus couldNotExecute]) ifTrue:[ |
|
3411 | 925 |
eMsg := 'oops, no %1 - cannot create machine code' bindWith:aCommand. |
1939 | 926 |
] ifFalse:[ |
3437 | 927 |
errorMessages := 'errorOutput' asFilename contents collect:[:l | OperatingSystem decodePathOrCommandOutput: l ]. |
1939 | 928 |
OperatingSystem removeFile:'errorOutput'. |
929 |
||
930 |
errorMessages notNil ifTrue:[ |
|
931 |
errorMessages := errorMessages reject:[:line | line includesString:'Warning:']. |
|
932 |
||
933 |
errorMessages size > 20 ifTrue:[ |
|
934 |
errorMessages := errorMessages select:[:line | line asLowercase startsWith:'error']. |
|
935 |
errorMessages size > 20 ifTrue:[ |
|
936 |
errorMessages := (errorMessages copyTo:20) copyWith:'... more messages skipped' |
|
937 |
]. |
|
938 |
]. |
|
939 |
"/ errorMessages := errorMessages collect:[:line | |
|
940 |
"/ (line startsWith:(stFileName , ':')) ifTrue:[ |
|
941 |
"/ 'Line: ' , (line copyFrom:(stFileName size + 2)) |
|
942 |
"/ ] ifFalse:[ |
|
943 |
"/ line |
|
944 |
"/ ] |
|
945 |
"/ ]. |
|
946 |
]. |
|
947 |
errorMessages isNil ifTrue:[ |
|
948 |
errorMessages := #('') |
|
949 |
]. |
|
3005 | 950 |
errorMessages := (Array with:'Failed to execute: "', aCommand,'"') , errorMessages. |
1939 | 951 |
|
952 |
"/ try to extract a line number" |
|
953 |
(errorMessages contains:[:line | line includesString:'Borland']) ifTrue:[ |
|
954 |
|i i2 s| |
|
955 |
i := errorMessages findFirst:[:l | l startsWith:(cFileName,':')]. |
|
956 |
i ~~ 0 ifTrue:[ |
|
957 |
((errorMessages at:i+1) startsWith:'Error') ifTrue:[ |
|
958 |
i2 := (errorMessages at:i+1) indexOfSubCollection:(stFileName). |
|
959 |
i2 ~~ 0 ifTrue:[ |
|
960 |
s := (errorMessages at:i+1) copyFrom:(i2+stFileName size+1). |
|
961 |
s := s readStream. |
|
962 |
lNr := Integer readFrom:s. |
|
963 |
s skipSeparators. |
|
964 |
]. |
|
965 |
] |
|
966 |
]. |
|
967 |
]. |
|
968 |
||
969 |
errorMessages isEmpty ifTrue:[ |
|
970 |
eMsg := 'Error during compilation:\\Unspecified error (no output)' withCRs |
|
971 |
] ifFalse:[ |
|
972 |
eMsg := 'Error during compilation:\\' withCRs , |
|
973 |
(errorMessages asStringCollection asString). |
|
974 |
]. |
|
975 |
]. |
|
2461
89458faaeeb3
changed: #reportCompilationError
Stefan Vogel <sv@exept.de>
parents:
2350
diff
changeset
|
976 |
|
1939 | 977 |
originator activityNotification:''. |
978 |
||
3069 | 979 |
ParseError new |
2461
89458faaeeb3
changed: #reportCompilationError
Stefan Vogel <sv@exept.de>
parents:
2350
diff
changeset
|
980 |
lineNumber:lNr; |
89458faaeeb3
changed: #reportCompilationError
Stefan Vogel <sv@exept.de>
parents:
2350
diff
changeset
|
981 |
errorMessage:eMsg; |
89458faaeeb3
changed: #reportCompilationError
Stefan Vogel <sv@exept.de>
parents:
2350
diff
changeset
|
982 |
raise. |
89458faaeeb3
changed: #reportCompilationError
Stefan Vogel <sv@exept.de>
parents:
2350
diff
changeset
|
983 |
|
1939 | 984 |
"Created: / 07-11-2006 / 12:29:04 / cg" |
3348
b59a15a24ab3
class: STCCompilerInterface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3240
diff
changeset
|
985 |
"Modified: / 21-12-2013 / 00:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
1939 | 986 |
! |
987 |
||
4018 | 988 |
reportCompilationErrorFor:aCommand fromFile:anErrorFilename |
989 |
|eMsg errorMessages lNr| |
|
990 |
||
991 |
(executionStatus notNil and:[executionStatus couldNotExecute]) ifTrue:[ |
|
992 |
eMsg := 'oops, no %1 - cannot create machine code' bindWith:aCommand. |
|
993 |
] ifFalse:[ |
|
994 |
errorMessages := anErrorFilename contents |
|
995 |
collect:[:l | OperatingSystem decodePathOrCommandOutput: l ]. |
|
4135 | 996 |
Transcript showCR:errorMessages asString. |
4018 | 997 |
errorMessages notNil ifTrue:[ |
998 |
errorMessages := errorMessages reject:[:line | line includesString:'Warning:']. |
|
999 |
||
1000 |
errorMessages size > 20 ifTrue:[ |
|
4135 | 1001 |
"/ errorMessages := errorMessages select:[:line | line asLowercase startsWith:'error']. |
4018 | 1002 |
errorMessages size > 20 ifTrue:[ |
1003 |
errorMessages := (errorMessages copyTo:20) copyWith:'... more messages skipped' |
|
1004 |
]. |
|
1005 |
]. |
|
1006 |
"/ errorMessages := errorMessages collect:[:line | |
|
1007 |
"/ (line startsWith:(stFileName , ':')) ifTrue:[ |
|
1008 |
"/ 'Line: ' , (line copyFrom:(stFileName size + 2)) |
|
1009 |
"/ ] ifFalse:[ |
|
1010 |
"/ line |
|
1011 |
"/ ] |
|
1012 |
"/ ]. |
|
1013 |
]. |
|
1014 |
errorMessages isNil ifTrue:[ |
|
1015 |
errorMessages := #('') |
|
1016 |
]. |
|
1017 |
errorMessages := (Array with:'Failed to execute: "', aCommand,'"') , errorMessages. |
|
1018 |
||
1019 |
"/ try to extract a line number" |
|
1020 |
(errorMessages contains:[:line | line includesString:'Borland']) ifTrue:[ |
|
1021 |
|i i2 s| |
|
1022 |
i := errorMessages findFirst:[:l | l startsWith:(cFileName,':')]. |
|
1023 |
i ~~ 0 ifTrue:[ |
|
1024 |
((errorMessages at:i+1) startsWith:'Error') ifTrue:[ |
|
1025 |
i2 := (errorMessages at:i+1) indexOfSubCollection:(stFileName). |
|
1026 |
i2 ~~ 0 ifTrue:[ |
|
1027 |
s := (errorMessages at:i+1) copyFrom:(i2+stFileName size+1). |
|
1028 |
s := s readStream. |
|
1029 |
lNr := Integer readFrom:s. |
|
1030 |
s skipSeparators. |
|
1031 |
]. |
|
1032 |
] |
|
1033 |
]. |
|
1034 |
]. |
|
1035 |
||
1036 |
errorMessages isEmpty ifTrue:[ |
|
1037 |
eMsg := 'Error during compilation:\\Unspecified error (no output)' withCRs |
|
1038 |
] ifFalse:[ |
|
1039 |
eMsg := 'Error during compilation:\\' withCRs , |
|
1040 |
(errorMessages asStringCollection asString). |
|
1041 |
]. |
|
1042 |
]. |
|
1043 |
||
1044 |
originator activityNotification:''. |
|
1045 |
||
1046 |
ParseError new |
|
1047 |
lineNumber:lNr; |
|
1048 |
errorMessage:eMsg; |
|
1049 |
raise. |
|
1050 |
||
1051 |
"Created: / 07-11-2006 / 12:29:04 / cg" |
|
1052 |
"Modified: / 21-12-2013 / 00:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4135 | 1053 |
"Modified: / 25-02-2017 / 09:58:18 / cg" |
1054 |
"Modified (format): / 25-02-2017 / 19:33:58 / cg" |
|
4018 | 1055 |
! |
1056 |
||
1939 | 1057 |
setupCompilationCommandArguments |
2335 | 1058 |
|stFn mapFileName libFileName def libDir incDir incDirArg defs incl opts| |
1059 |
||
1060 |
parserFlags isNil ifTrue:[ parserFlags := ParserFlags new]. |
|
1939 | 1061 |
|
1941 | 1062 |
stFn := stFileName asFilename. |
1063 |
oFileName := stFn nameWithoutSuffix , (ObjectFileLoader objectFileExtension). |
|
1064 |
cFileName := (stFn withSuffix:'c') name. |
|
3170 | 1065 |
"/ ParserFlags useBorlandC ifTrue:[ |
1066 |
"/ cFileName := (stFn withSuffix:'sc') name. |
|
1067 |
"/ ]. |
|
1941 | 1068 |
mapFileName := (stFn withSuffix:'map') name. |
1069 |
libFileName := (stFn withSuffix:'lib') name. |
|
1939 | 1070 |
oFileName asFilename delete. |
1071 |
cFileName asFilename delete. |
|
1072 |
||
1073 |
"/ stcFlags := '-commonSymbols +sharedLibCode +newIncremental -E:errorOutput -N' , initName . |
|
4018 | 1074 |
stcFlags := '+newIncremental'. |
3659 | 1075 |
initName notEmptyOrNil ifTrue:[ |
2335 | 1076 |
stcFlags := stcFlags,' -N' , initName . |
1077 |
]. |
|
4023 | 1078 |
cFlags := STCCompilerInterface getOSDefine. |
1939 | 1079 |
cFlags isNil ifTrue:[ |
1080 |
cFlags := '' |
|
1081 |
]. |
|
4023 | 1082 |
(def := STCCompilerInterface getCPUDefine) notEmptyOrNil ifTrue:[ |
1939 | 1083 |
cFlags := cFlags , ' ' , def |
1084 |
]. |
|
1085 |
||
3659 | 1086 |
(defs := parserFlags stcCompilationDefines) notEmptyOrNil ifTrue:[ |
2335 | 1087 |
cFlags := cFlags , ' ' , defs |
1939 | 1088 |
]. |
3659 | 1089 |
(incl := parserFlags stcCompilationIncludes) notEmptyOrNil ifTrue:[ |
2335 | 1090 |
stcFlags := incl , ' ' , stcFlags. |
1091 |
cFlags := cFlags , ' ' , incl. |
|
1939 | 1092 |
|
1093 |
"/ if STX_LIBDIR is defined, and not in passed argument, |
|
1094 |
"/ add it here. |
|
1095 |
||
1096 |
libDir := OperatingSystem getEnvironment:'STX_LIBDIR'. |
|
1097 |
(libDir notNil and:[libDir asFilename exists]) ifTrue:[ |
|
1098 |
incDir := libDir asFilename construct:'include'. |
|
1099 |
incDir exists ifTrue:[ |
|
1100 |
incDirArg := '-I' , incDir pathName. |
|
2335 | 1101 |
(incl asCollectionOfWords includes:incDirArg) ifFalse:[ |
1939 | 1102 |
stcFlags := stcFlags , ' ' , incDirArg. |
1103 |
cFlags := cFlags , ' ' , incDirArg. |
|
1104 |
] |
|
1105 |
] |
|
1106 |
]. |
|
1107 |
]. |
|
3659 | 1108 |
(opts := parserFlags stcCompilationOptions) notEmptyOrNil ifTrue:[ |
2335 | 1109 |
stcFlags := opts , ' ' , stcFlags |
1939 | 1110 |
]. |
3659 | 1111 |
(opts := parserFlags ccCompilationOptions) notEmptyOrNil ifTrue:[ |
2335 | 1112 |
cFlags := cFlags , ' ' , opts |
1939 | 1113 |
]. |
1114 |
||
1115 |
"Created: / 07-11-2006 / 12:24:47 / cg" |
|
1941 | 1116 |
"Modified: / 07-11-2006 / 13:58:54 / cg" |
1669 | 1117 |
! ! |
1118 |
||
1119 |
!STCCompilerInterface class methodsFor:'documentation'! |
|
1120 |
||
1121 |
version |
|
3659 | 1122 |
^ '$Header$' |
2335 | 1123 |
! |
1124 |
||
1125 |
version_CVS |
|
3659 | 1126 |
^ '$Header$' |
1669 | 1127 |
! ! |
1128 |
||
3005 | 1129 |
|
1669 | 1130 |
STCCompilerInterface initialize! |