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