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