author | Claus Gittinger <cg@exept.de> |
Sun, 23 Sep 2018 01:09:40 +0200 | |
changeset 4302 | 97c125843381 |
parent 4292 | c52d721695b2 |
child 4309 | c8afd1b2aa81 |
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 |
|
261 |
originator parseError:messageText position:position. |
|
262 |
"not normally reached" |
|
263 |
ParseError raiseErrorString:messageText. |
|
264 |
! ! |
|
265 |
||
1669 | 266 |
!STCCompilerInterface methodsFor:'machine code generation'! |
267 |
||
1939 | 268 |
compileToMachineCode:aString forClass:aClass selector:selector inCategory:categoryArg |
269 |
notifying:requestorArg install:install skipIfSame:skipIfSame silent:silent |
|
1669 | 270 |
"this is called to compile primitive code. |
3357 | 271 |
It saves the code to a tmporary, calls stc to create C-code, compiles it, links |
272 |
it to a tiny little dll and loads it. |
|
273 |
As you already see, this takes some time and is therefore ONLY done for code containing prims; |
|
274 |
all pure smalltalk code is compiled to bytecode and jitted by the VM." |
|
1669 | 275 |
|
3042 | 276 |
|handle oldMethod newMethod ok dllFileName| |
1669 | 277 |
|
278 |
install ifFalse:[ |
|
279 |
"/ cannot do it uninstalled. reason: |
|
280 |
"/ if it is loaded twice, the first version could be unloaded by |
|
281 |
"/ finalization, which would also unload the second version |
|
282 |
"/ (because the first unload would unload the second version too) |
|
283 |
^ #CannotLoad |
|
284 |
]. |
|
2704
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
285 |
parserFlags isNil ifTrue:[ |
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
286 |
parserFlags := ParserFlags new |
19bedf5ff15e
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2703
diff
changeset
|
287 |
]. |
1669 | 288 |
parserFlags stcCompilation == #never ifTrue:[^ #CannotLoad]. |
1670 | 289 |
|
1939 | 290 |
classToCompileFor := aClass. |
291 |
requestor := requestorArg. |
|
292 |
methodCategory := categoryArg. |
|
1669 | 293 |
|
3411 | 294 |
self ensureExternalToolsArePresent. |
1939 | 295 |
self ensureModuleDirectoryExists. |
1669 | 296 |
|
1939 | 297 |
theNonMetaclassToCompileFor := classToCompileFor theNonMetaclass. |
1941 | 298 |
|
1939 | 299 |
self ensureSuperClassesAreLoadedOf:theNonMetaclassToCompileFor. |
300 |
theNonMetaclassToCompileFor privateClassesSorted do:[:aPrivateClass | |
|
1670 | 301 |
self ensureSuperClassesAreLoadedOf:aPrivateClass. |
302 |
]. |
|
303 |
||
1939 | 304 |
(classToCompileFor isNil |
305 |
or:[parserFlags allowExtensionsToPrivateClasses |
|
306 |
or:[classToCompileFor owningClass isNil]]) ifTrue:[ |
|
307 |
(requestor respondsTo:#packageToInstall) ifFalse:[ |
|
308 |
package := Class packageQuerySignal query. |
|
309 |
] ifTrue:[ |
|
310 |
package := requestor packageToInstall |
|
311 |
]. |
|
312 |
] ifFalse:[ |
|
313 |
package := classToCompileFor owningClass package |
|
1669 | 314 |
]. |
315 |
||
316 |
[ |
|
1939 | 317 |
self generateSTSource:aString. |
318 |
self setupCompilationCommandArguments. |
|
4018 | 319 |
ok := self |
320 |
compileToC_onError:[:errorFile | |
|
4260 | 321 |
self reportCompilationErrorFor:stcPath fromFile:errorFile |
4018 | 322 |
]. |
1669 | 323 |
|
4018 | 324 |
parserFlags stcKeepSIntermediate ifTrue:[ |
325 |
self compileToS_onError:[:errorFile | ] |
|
326 |
]. |
|
3042 | 327 |
"/ now compile to machine code |
4018 | 328 |
ok := self |
329 |
compileToObj_onError:[:errorFile | |
|
4250 | 330 |
self reportCompilationErrorFor:ccPath, cFlags fromFile:errorFile. |
4018 | 331 |
]. |
1669 | 332 |
|
333 |
originator activityNotification:''. |
|
334 |
||
335 |
" |
|
336 |
if required, make a shared or otherwise loadable object file for it |
|
337 |
" |
|
338 |
originator activityNotification:'linking'. |
|
2656 | 339 |
dllFileName := ObjectFileLoader createLoadableObjectFor:(oFileName asFilename withoutSuffix name). |
340 |
dllFileName isNil ifTrue:[ |
|
1669 | 341 |
"/ something went wrong |
3411 | 342 |
self parseError:('link error: ' , ObjectFileLoader lastError) position:1. |
1669 | 343 |
]. |
2656 | 344 |
dllFileName asFilename exists ifFalse:[ |
3411 | 345 |
self parseError:'link failed - cannot create machine code' position:1. |
1669 | 346 |
]. |
347 |
||
1939 | 348 |
oldMethod := classToCompileFor compiledMethodAt:selector. |
349 |
oldMethod notNil ifTrue:[package := oldMethod package]. |
|
3159 | 350 |
install ifTrue:[ |
351 |
(Smalltalk |
|
352 |
changeRequest:#methodInClass |
|
353 |
with:(Array with:classToCompileFor with:selector with:oldMethod)) ifFalse:[ |
|
354 |
^ #CannotLoad |
|
355 |
]. |
|
356 |
]. |
|
1669 | 357 |
|
358 |
" |
|
359 |
load the method objectfile |
|
360 |
" |
|
361 |
originator activityNotification:'loading'. |
|
3361 | 362 |
handle := ObjectFileLoader loadMethodObjectFile:dllFileName. |
363 |
originator activityNotification:''. |
|
1669 | 364 |
|
365 |
handle isNil ifTrue:[ |
|
4250 | 366 |
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
|
367 |
"catch, so that #CannotLoad processing is done" |
3069 | 368 |
ParseError catch:[ |
2185
cb311d08a486
changed #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2068
diff
changeset
|
369 |
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
|
370 |
]. |
1669 | 371 |
^ #CannotLoad |
372 |
]. |
|
373 |
||
374 |
" |
|
375 |
did it work ? |
|
376 |
" |
|
1939 | 377 |
newMethod := classToCompileFor compiledMethodAt:selector. |
1669 | 378 |
|
379 |
"/ if install is false, we have to undo the install (which is always done, when loading machine code) |
|
380 |
install ifFalse:[ |
|
381 |
oldMethod isNil ifTrue:[ |
|
1939 | 382 |
classToCompileFor removeSelector:selector |
1669 | 383 |
] ifFalse:[ |
384 |
newMethod setPackage:oldMethod package. |
|
1939 | 385 |
classToCompileFor addSelector:selector withMethod:oldMethod. |
386 |
oldMethod setPackage:package. |
|
1669 | 387 |
] |
388 |
]. |
|
389 |
||
390 |
newMethod notNil ifTrue:[ |
|
391 |
handle method ~~ newMethod ifTrue:[ |
|
392 |
'Compiler [warning]: loaded method installed itself in another class' errorPrintCR. |
|
393 |
]. |
|
394 |
||
395 |
newMethod source:aString string. |
|
1939 | 396 |
newMethod setPackage:package. |
1669 | 397 |
"/ Project notNil ifTrue:[ |
398 |
"/ newMethod package:(Project currentPackageName) |
|
399 |
"/ ]. |
|
400 |
||
1939 | 401 |
"/ classToCompileFor updateRevisionString. |
1669 | 402 |
install ifTrue:[ |
1939 | 403 |
classToCompileFor addChangeRecordForMethod:newMethod fromOld:oldMethod. |
1669 | 404 |
|
405 |
"/ kludge-sigh: must send change messages manually here (stc-loaded code does not do it) |
|
406 |
"/ see addMethod:... in ClassDescription |
|
1939 | 407 |
classToCompileFor changed:#methodDictionary with:(Array with:selector with:oldMethod). |
408 |
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
|
409 |
] ifFalse:[ |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
410 |
oldMethod := nil. |
1669 | 411 |
]. |
412 |
||
1986 | 413 |
silent ifFalse:[ |
1941 | 414 |
Transcript showCR:(' compiled: ', aClass name,' ',selector,' - machine code') |
1669 | 415 |
]. |
416 |
ObjectMemory flushCaches. |
|
417 |
||
418 |
handle method:newMethod. |
|
419 |
||
2350
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
420 |
"/ 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
|
421 |
"/ corresponding ObjectFileHandle. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
422 |
"/ 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
|
423 |
"/ and will be recompiled on an undo |
1669 | 424 |
|
425 |
ObjectFileLoader loadedObjectHandlesDo:[:anotherHandle | |
|
426 |
anotherHandle isMethodHandle ifTrue:[ |
|
2350
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
427 |
anotherHandle method == oldMethod ifTrue:[ |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
428 |
"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
|
429 |
anotherHandle removeConnectedObjects. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
430 |
]. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
431 |
anotherHandle isObsolete ifTrue:[ |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
432 |
anotherHandle unload. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
433 |
anotherHandle removeUnusedObjectFile. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
434 |
]. |
16caba266df4
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Stefan Vogel <sv@exept.de>
parents:
2336
diff
changeset
|
435 |
]. |
1669 | 436 |
]. |
437 |
^ newMethod. |
|
438 |
]. |
|
439 |
||
4250 | 440 |
"/ moduleFileName asFilename remove. |
3411 | 441 |
self parseError:'dynamic load failed' position:1. |
1669 | 442 |
] ensure:[ |
4250 | 443 |
KeepIntermediateFiles ifTrue:[ |
3173 | 444 |
Transcript showCR:'keeping files' |
2703
2e966ec31082
changed: #compileToMachineCode:forClass:selector:inCategory:notifying:install:skipIfSame:silent:
Claus Gittinger <cg@exept.de>
parents:
2658
diff
changeset
|
445 |
] ifFalse:[ |
3173 | 446 |
parserFlags stcKeepSTIntermediate ifTrue:[ |
447 |
Transcript showCR:'keeping st file: ', stFileName asFilename pathName |
|
448 |
] ifFalse:[ |
|
4250 | 449 |
stFileName asFilename remove. |
3173 | 450 |
]. |
451 |
cFileName notNil ifTrue:[ |
|
452 |
parserFlags stcKeepCIntermediate == true ifTrue:[ |
|
453 |
Transcript showCR:'keeping c file: ', cFileName asFilename pathName |
|
454 |
] ifFalse:[ |
|
4250 | 455 |
cFileName asFilename remove. |
3173 | 456 |
] |
457 |
]. |
|
458 |
oFileName notNil ifTrue:[ |
|
459 |
parserFlags stcKeepOIntermediate == true ifTrue:[ |
|
460 |
Transcript showCR:'keeping o file: ', oFileName asFilename pathName |
|
461 |
] ifFalse:[ |
|
4250 | 462 |
oFileName asFilename remove. |
3173 | 463 |
]. |
464 |
]. |
|
465 |
"/ OperatingSystem isMSDOSlike ifTrue:[ |
|
466 |
"/ mapFileName notNil ifTrue:[ |
|
4250 | 467 |
"/ mapFileName asFilename remove. |
3173 | 468 |
"/ ]. |
469 |
"/ libFileName notNil ifTrue:[ |
|
4250 | 470 |
"/ libFileName asFilename remove. |
3173 | 471 |
"/ ]. |
472 |
"/ ]. |
|
473 |
] |
|
1669 | 474 |
]. |
475 |
||
476 |
" |
|
477 |
|m| |
|
478 |
||
479 |
Object subclass:#Test |
|
480 |
instanceVariableNames:'' |
|
481 |
classVariableNames:'' |
|
482 |
poolDictionaries:'' |
|
483 |
category:'tests'. |
|
484 |
m := ByteCodeCompiler |
|
485 |
compile:'foo ^ ''hello''' |
|
486 |
forClass:Test |
|
487 |
inCategory:'tests' |
|
488 |
notifying:nil |
|
489 |
install:false |
|
490 |
skipIfSame:false. |
|
491 |
m inspect |
|
492 |
" |
|
493 |
" |
|
494 |
|m| |
|
495 |
||
496 |
Object subclass:#Test |
|
497 |
instanceVariableNames:'' |
|
498 |
classVariableNames:'' |
|
499 |
poolDictionaries:'' |
|
500 |
category:'tests'. |
|
501 |
m := ByteCodeCompiler |
|
502 |
compileToMachineCode:'foo %{ RETURN (_MKSMALLINT(1)); %}' |
|
503 |
forClass:Test |
|
504 |
inCategory:'tests' |
|
505 |
notifying:nil |
|
506 |
install:false |
|
507 |
skipIfSame:false |
|
508 |
silent:false. |
|
509 |
m inspect |
|
510 |
" |
|
511 |
||
1939 | 512 |
"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
|
513 |
"Modified: / 17-09-2011 / 10:39:25 / cg" |
4260 | 514 |
"Modified: / 16-05-2018 / 13:48:25 / stefan" |
1939 | 515 |
! ! |
516 |
||
517 |
!STCCompilerInterface methodsFor:'machine code generation-helpers'! |
|
518 |
||
4019 | 519 |
compileToC_onError:aBlock |
520 |
"compile st to C using stc. |
|
521 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
522 |
||
523 |
|command ok errorOutputFile| |
|
524 |
||
525 |
command := (self possiblyQuotedPath:stcPath) , ' ' , stcFlags |
|
526 |
, ' -defdir=', (self possiblyQuotedPath:cFileName asFilename directory pathName). |
|
527 |
cFileName asFilename suffix ~= 'c' ifTrue:[ |
|
528 |
command := command , ' -cSuffix=',cFileName asFilename suffix. |
|
529 |
]. |
|
530 |
command := command , ' -C ' , (self possiblyQuotedPath:stFileName asFilename pathName). |
|
531 |
||
532 |
Verbose == true ifTrue:[ |
|
533 |
Transcript show:'executing: '; showCR:command. |
|
534 |
]. |
|
535 |
||
536 |
originator activityNotification:'compiling (stc)'. |
|
537 |
||
538 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
|
539 |
errorOutputFile writingFileDo:[:errorStream | |
|
4260 | 540 |
errorStream nextPutAll:'Command: '; nextPutLine:command; cr; flush. |
4019 | 541 |
ok := OperatingSystem |
542 |
executeCommand:command |
|
543 |
inputFrom:nil |
|
544 |
outputTo:errorStream |
|
545 |
errorTo:errorStream |
|
546 |
showWindow:false |
|
547 |
onError:[:stat| |
|
4021 | 548 |
self breakPoint:#cg. |
4019 | 549 |
executionStatus := stat. |
550 |
false |
|
551 |
]. |
|
552 |
]. |
|
553 |
||
554 |
cFileName asFilename exists ifTrue:[ |
|
555 |
ok ifFalse:[ |
|
556 |
'Compiler [info]: oops - system says stc failed - but c-file is there ...' infoPrintCR. |
|
557 |
ok := true |
|
558 |
] |
|
559 |
] ifFalse:[ |
|
560 |
ok ifTrue:[ |
|
561 |
'Compiler [info]: oops - system says stc ok - but no c-file is there ...' infoPrintCR |
|
562 |
]. |
|
563 |
ok := false |
|
564 |
]. |
|
565 |
||
566 |
[ |
|
567 |
ok ifFalse:[ |
|
568 |
aBlock value:errorOutputFile |
|
569 |
]. |
|
570 |
] ensure:[ |
|
571 |
errorOutputFile remove. |
|
572 |
]. |
|
573 |
^ ok |
|
574 |
||
575 |
"Created: / 07-11-2006 / 12:11:24 / cg" |
|
576 |
"Modified: / 08-08-2011 / 22:12:01 / cg" |
|
4260 | 577 |
"Modified: / 16-05-2018 / 13:49:01 / stefan" |
4019 | 578 |
! |
579 |
||
4018 | 580 |
compileToExe_onError:aBlock |
581 |
"compile C to exe, using cc. |
|
582 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
1939 | 583 |
|
4018 | 584 |
|command errorOutputFile ok| |
2336 | 585 |
|
2658 | 586 |
command := (self possiblyQuotedPath:ccPath) , ' ' , cFlags , ' -D__INCREMENTAL_COMPILE__ ' , (self possiblyQuotedPath:cFileName). |
2336 | 587 |
|
588 |
Verbose == true ifTrue:[ |
|
3957 | 589 |
Transcript show:'executing: ' showCR:command. |
2336 | 590 |
]. |
591 |
originator activityNotification:'compiling (' , ccPath , ')'. |
|
592 |
||
4018 | 593 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
594 |
errorOutputFile writingFileDo:[:errorStream | |
|
595 |
ok := OperatingSystem |
|
596 |
executeCommand:command |
|
597 |
inputFrom:nil |
|
598 |
outputTo:errorStream |
|
599 |
errorTo:errorStream |
|
600 |
showWindow:false |
|
601 |
onError:[:stat| |
|
602 |
executionStatus := stat. |
|
603 |
false |
|
604 |
]. |
|
2336 | 605 |
]. |
4018 | 606 |
|
607 |
[ |
|
608 |
ok ifFalse:[ |
|
609 |
aBlock value:errorOutputFile |
|
610 |
]. |
|
611 |
] ensure:[ |
|
612 |
errorOutputFile remove. |
|
613 |
]. |
|
2336 | 614 |
^ ok |
615 |
! |
|
616 |
||
4018 | 617 |
compileToObj_onError:aBlock |
618 |
"compile C to obj, using cc. |
|
619 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
1939 | 620 |
|
4018 | 621 |
|errorOutputFile ok commandTemplate command ccDefine env| |
1939 | 622 |
|
4018 | 623 |
"/ bcc does not like -D__BORLANDC__ (needs to be set to a version, such as 0x0505) |
3170 | 624 |
"/ others do not need it (is already predefined in the compiler) |
625 |
"/ ccDefine := ' -D',ParserFlags usedCompilerDefine. |
|
3173 | 626 |
"/ so, never redefine ccDefine |
3170 | 627 |
ccDefine := ''. |
628 |
||
3010
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
629 |
ParserFlags useBorlandC ifTrue:[ |
7970294627a3
flag settings for 64bit mingw
Claus Gittinger <cg@exept.de>
parents:
3005
diff
changeset
|
630 |
"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
|
631 |
"/ cg: I guess, this does not work for visual-c |
3423 | 632 |
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
|
633 |
] ifFalse:[ |
3423 | 634 |
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
|
635 |
]. |
3423 | 636 |
command := commandTemplate |
637 |
bindWith:(self possiblyQuotedPath:ccPath) |
|
638 |
with:cFlags |
|
639 |
with:ccDefine |
|
640 |
with:(self possiblyQuotedPath:oFileName) |
|
641 |
with:(self possiblyQuotedPath:cFileName). |
|
1939 | 642 |
|
643 |
Verbose == true ifTrue:[ |
|
3957 | 644 |
Transcript show:'executing: '; showCR:command. |
1939 | 645 |
]. |
646 |
originator activityNotification:'compiling (' , ccPath , ')'. |
|
3423 | 647 |
|
648 |
env := OperatingSystem isUNIXlike |
|
649 |
ifTrue:[OperatingSystem getEnvironment copy] |
|
650 |
ifFalse:[env := Dictionary new]. |
|
651 |
env at:'LANG' put:'C'. |
|
652 |
env at:'LC_MESSAGES' put:'C'. |
|
653 |
||
4018 | 654 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
655 |
errorOutputFile writingFileDo:[:errorStream | |
|
656 |
ok := OperatingSystem |
|
657 |
executeCommand:command |
|
658 |
inputFrom:nil |
|
659 |
outputTo:errorStream |
|
660 |
errorTo:errorStream |
|
661 |
environment:env |
|
662 |
showWindow:false |
|
663 |
onError: |
|
664 |
[:stat| |
|
665 |
executionStatus := stat. |
|
666 |
false |
|
667 |
]. |
|
2195
2996fe27c2f8
Add primitive functions when compiling
Stefan Vogel <sv@exept.de>
parents:
2185
diff
changeset
|
668 |
]. |
4018 | 669 |
|
1939 | 670 |
oFileName asFilename exists ifTrue:[ |
671 |
ok ifFalse:[ |
|
4018 | 672 |
'Compiler [info]: system says compile failed - but o-file is there ...' infoPrintCR. |
1939 | 673 |
ok := true |
674 |
] |
|
675 |
] ifFalse:[ |
|
676 |
ok ifTrue:[ |
|
4018 | 677 |
'Compiler [info]: system says compile ok - but no o-file is there ...' infoPrintCR. |
1939 | 678 |
]. |
679 |
ok := false |
|
680 |
]. |
|
4018 | 681 |
[ |
682 |
ok ifFalse:[ |
|
683 |
aBlock value:errorOutputFile |
|
684 |
]. |
|
685 |
] ensure:[ |
|
686 |
errorOutputFile remove. |
|
687 |
]. |
|
1939 | 688 |
^ ok |
689 |
||
690 |
"Created: / 07-11-2006 / 12:14:51 / cg" |
|
691 |
! |
|
692 |
||
4018 | 693 |
compileToS_onError:aBlock |
694 |
"compile C to assembler, using cc. |
|
695 |
If any error happens, call aBlock passing it the fileName containing diagnostics" |
|
2491 | 696 |
|
4018 | 697 |
|command errorOutputFile ok| |
2491 | 698 |
|
2658 | 699 |
command := (self possiblyQuotedPath:ccPath) , ' ' , cFlags , ' -D__INCREMENTAL_COMPILE__ -S ' , (self possiblyQuotedPath:cFileName). |
2491 | 700 |
|
701 |
Verbose == true ifTrue:[ |
|
3957 | 702 |
Transcript show:'executing: '; showCR:command. |
2491 | 703 |
]. |
704 |
originator activityNotification:'compiling (' , ccPath , ')'. |
|
705 |
||
4018 | 706 |
errorOutputFile := Filename tempDirectory / 'stcErrorOutput'. |
707 |
errorOutputFile writingFileDo:[:errorStream | |
|
708 |
ok := OperatingSystem |
|
709 |
executeCommand:command |
|
710 |
inputFrom:nil |
|
711 |
outputTo:errorStream |
|
712 |
errorTo:errorStream |
|
713 |
showWindow:false |
|
714 |
onError:[:stat| |
|
715 |
executionStatus := stat. |
|
716 |
false |
|
717 |
]. |
|
2491 | 718 |
]. |
4018 | 719 |
[ |
720 |
ok ifFalse:[ |
|
721 |
aBlock value:errorOutputFile |
|
722 |
]. |
|
723 |
] ensure:[ |
|
724 |
errorOutputFile remove. |
|
725 |
]. |
|
2491 | 726 |
^ ok |
727 |
! |
|
728 |
||
1939 | 729 |
ensureExternalToolsArePresent |
730 |
(stcPath := self incrementalStcPath) isNil ifTrue:[ |
|
3411 | 731 |
self parseError:'no stc compiler available - cannot create machine code' position:1. |
1939 | 732 |
]. |
2649 | 733 |
|
734 |
"make it absolute, so that we are immune to directory changes" |
|
735 |
stcPath := stcPath asFilename pathName. |
|
1939 | 736 |
(ccPath := parserFlags ccPath) isNil ifTrue:[ |
3411 | 737 |
self parseError:'no cc compiler available - cannot create machine code' position:1. |
1939 | 738 |
]. |
2649 | 739 |
"make it absolute, so that we are immune to directory changes" |
740 |
ccPath := ccPath asFilename pathName. |
|
1939 | 741 |
|
742 |
(ObjectFileLoader notNil and:[ObjectFileLoader canLoadObjectFiles]) ifFalse:[ |
|
3411 | 743 |
self parseError:'no dynamic loader configured - cannot create machine code' position:1. |
1939 | 744 |
]. |
745 |
||
746 |
"Created: / 07-11-2006 / 12:31:48 / cg" |
|
1670 | 747 |
! |
748 |
||
749 |
ensureModuleDirectoryExists |
|
3664 | 750 |
|mP t msg| |
1670 | 751 |
|
3411 | 752 |
mP := parserFlags stcModulePath. |
753 |
mP isEmptyOrNil ifTrue:[ |
|
754 |
self parseError:'No temporary module directory, check your settings!!' position:1. |
|
755 |
]. |
|
756 |
mP := mP asFilename. |
|
757 |
mP exists ifFalse:[ |
|
4058 | 758 |
mP recursiveMakeDirectory |
1670 | 759 |
]. |
3240 | 760 |
(mP isWritableDirectory and:[mP isReadable]) ifFalse:[ |
3664 | 761 |
(mP exists and:[mP isDirectory]) ifTrue:[ |
762 |
msg := 'No write permission in temporary module directory: '. |
|
763 |
] ifFalse:[ |
|
764 |
msg := 'No access to temporary module directory: '. |
|
765 |
]. |
|
766 |
self parseError:(msg , mP pathName) position:1. |
|
1670 | 767 |
]. |
3664 | 768 |
|
1670 | 769 |
"/ create a small README there ... |
770 |
||
771 |
(t := mP construct:'README') exists ifFalse:[ |
|
3411 | 772 |
t contents:'This temporary ST/X directory contains machine code for |
1670 | 773 |
accepted methods with embedded C-code |
774 |
(i.e. dynamic compiled code for inline-C methods). |
|
775 |
||
776 |
Files here are not automatically removed, since ST/X |
|
777 |
cannot determine if any (other) snapshot image still |
|
778 |
requires a file here. |
|
779 |
||
780 |
Please be careful when removing files here - a snapshot |
|
781 |
image which was saved with accepted embedded C-code |
|
782 |
may not be able to restart correctly if you remove a |
|
783 |
required file. |
|
784 |
Also, when you export a snapshot image for execution |
|
785 |
on another machine, make certain that the required |
|
786 |
module-files are also present there. |
|
787 |
||
788 |
You should periodically clean dead entries here. |
|
789 |
i.e. remove files, when you are certain that none |
|
790 |
of your snapshot images refers to any module here. |
|
791 |
||
792 |
See the launchers File-Modules dialog for a list of |
|
793 |
modules which are still required by your running image. |
|
794 |
||
795 |
With kind regards - your ST/X. |
|
796 |
'. |
|
797 |
]. |
|
798 |
! |
|
799 |
||
800 |
ensureSuperClassesAreLoadedOf:aClass |
|
801 |
|supers| |
|
802 |
||
803 |
supers := aClass allSuperclasses. |
|
804 |
supers reverseDo:[:cls| |
|
805 |
cls isLoaded ifFalse:[ |
|
3411 | 806 |
self parseError:('Cannot stc-compile (superclass %1 is unloaded)' bindWith:cls) position:1. |
1670 | 807 |
] |
808 |
]. |
|
809 |
! |
|
810 |
||
811 |
fileOutAllDefinitionsOf:aClass to:aStream rememberIn:definedClasses |
|
812 |
|defineAction| |
|
813 |
||
814 |
defineAction := |
|
815 |
[:cls| |
|
816 |
(definedClasses includes:cls) ifFalse:[ |
|
817 |
cls |
|
818 |
basicFileOutDefinitionOn:aStream |
|
819 |
withNameSpace:false withPackage:false |
|
820 |
syntaxHilighting:false. |
|
821 |
||
822 |
aStream nextPut:(aStream class chunkSeparator); cr. |
|
823 |
definedClasses add:cls. |
|
824 |
]. |
|
825 |
]. |
|
826 |
||
827 |
aClass allSuperclasses reverseDo:defineAction. |
|
828 |
defineAction value:aClass. |
|
1939 | 829 |
! |
830 |
||
831 |
generateSTSource:aString |
|
3359 | 832 |
|stream definedClasses sep className modulesDir ns nsName| |
1939 | 833 |
|
834 |
"/ generate a unique name, consisting of my processID and a sequence number |
|
835 |
"/ the processId is added to allow filein of modules from different |
|
836 |
"/ lifes |
|
837 |
||
838 |
SequenceNumber := (SequenceNumber ? 0) + 1. |
|
839 |
||
840 |
initName := 'm_' , OperatingSystem getProcessId printString, '_' , SequenceNumber printString. |
|
841 |
||
2646 | 842 |
"/ Smalltalk isSmalltalkDevelopmentSystem ifTrue:[ |
843 |
"/ modulesParentDir := Filename currentDirectory. |
|
844 |
"/ ] ifFalse:[ |
|
845 |
"/ modulesParentDir := Filename tempDirectory. |
|
846 |
"/ ]. |
|
847 |
"/ modulesDir := modulesParentDir construct:'modules'. |
|
848 |
modulesDir := ParserFlags stcModulePath. |
|
2647 | 849 |
stFileName := (modulesDir asFilename construct:(initName , '.st')) name. |
2646 | 850 |
|
1939 | 851 |
[ |
852 |
stream := stFileName asFilename writeStream. |
|
853 |
] on:FileStream openErrorSignal do:[:ex| |
|
3411 | 854 |
self parseError:'cannot create temporary sourcefile for compilation' position:1. |
1939 | 855 |
^ #CannotLoad |
856 |
]. |
|
3419 | 857 |
stream := EncodedStream stream:stream encoder:(CharacterEncoder encoderForUTF8). |
858 |
stream nextPutLine:'"{ Encoding: utf8 }" !!'. |
|
1939 | 859 |
|
860 |
definedClasses := IdentitySet new. |
|
861 |
||
862 |
sep := stream class chunkSeparator. |
|
863 |
||
864 |
Class fileOutNameSpaceQuerySignal answer:true |
|
865 |
do:[ |
|
2467 | 866 |
theNonMetaclassToCompileFor realSharedPoolNames do:[:eachPoolname | |
2067
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
867 |
|pool| |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
868 |
|
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
869 |
pool := Smalltalk at:eachPoolname. |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
870 |
self |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
871 |
fileOutAllDefinitionsOf:pool |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
872 |
to:stream |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
873 |
rememberIn:definedClasses. |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
874 |
]. |
6204fefb44a3
must also file-out the definition of sharedPools
Claus Gittinger <cg@exept.de>
parents:
2026
diff
changeset
|
875 |
|
1939 | 876 |
self |
877 |
fileOutAllDefinitionsOf:theNonMetaclassToCompileFor |
|
878 |
to:stream |
|
879 |
rememberIn:definedClasses. |
|
880 |
||
881 |
theNonMetaclassToCompileFor privateClassesSorted do:[:aPrivateClass | |
|
882 |
self |
|
883 |
fileOutAllDefinitionsOf:aPrivateClass |
|
884 |
to:stream |
|
885 |
rememberIn:definedClasses. |
|
886 |
]. |
|
2195
2996fe27c2f8
Add primitive functions when compiling
Stefan Vogel <sv@exept.de>
parents:
2185
diff
changeset
|
887 |
"/ theNonMetaclassToCompileFor fileOutPrimitiveDefinitionsOn:stream. |
2026 | 888 |
"/ 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
|
889 |
"/ 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
|
890 |
theNonMetaclassToCompileFor fileOutPrimitiveSpecsOn:stream. |
1939 | 891 |
]. |
892 |
||
2026 | 893 |
"/ stream cr. |
894 |
"/ stream nextPutLine:'"{ Package: ''' , package , ''' }"'. |
|
895 |
"/ stream cr. |
|
1939 | 896 |
|
3357 | 897 |
className := theNonMetaclassToCompileFor name. |
898 |
ns := theNonMetaclassToCompileFor topNameSpace. |
|
4292 | 899 |
|
900 |
(ns notNil |
|
901 |
and:[ns ~= Smalltalk |
|
902 |
and:[nsName := ns name. |
|
903 |
className startsWith:(nsName,'::') |
|
904 |
]]) ifTrue:[ |
|
3359 | 905 |
className := className copyFrom:nsName size+2+1. |
906 |
"/ split to avoid being regognized as a directive |
|
907 |
stream nextPutLine:('"','{ NameSpace: ',nsName,' }"'). |
|
3357 | 908 |
]. |
909 |
||
1939 | 910 |
stream nextPut:sep. |
911 |
stream nextPutAll:className. |
|
912 |
classToCompileFor isMeta ifTrue:[ |
|
913 |
stream nextPutAll:' class'. |
|
914 |
]. |
|
915 |
stream nextPutAll:' methodsFor:'''; nextPutAll:methodCategory; nextPutAll:''''. |
|
916 |
stream nextPut:sep; cr. |
|
917 |
||
918 |
stream nextPutLine:'"{ Line: 0 }"'; |
|
919 |
nextChunkPut:aString; |
|
920 |
space; nextPut:sep. |
|
921 |
||
922 |
stream close. |
|
923 |
||
2646 | 924 |
"Modified: / 08-08-2011 / 23:23:10 / cg" |
4292 | 925 |
"Modified (format): / 08-08-2018 / 08:58:35 / Claus Gittinger" |
1939 | 926 |
! |
927 |
||
2658 | 928 |
possiblyQuotedPath:aPath |
3173 | 929 |
(aPath includes:Character space) ifTrue:[ |
3793 | 930 |
(aPath startsWith:$") ifFalse:[ |
2658 | 931 |
^ '"',aPath,'"' |
932 |
] |
|
933 |
]. |
|
934 |
^ aPath |
|
935 |
! |
|
936 |
||
3005 | 937 |
reportCompilationErrorFor:aCommand |
4250 | 938 |
<resource: #obsolete> |
939 |
self obsoleteMethodWarning. |
|
940 |
^ self reportCompilationErrorFor:aCommand fromFile:'errorOutput' asFilename. |
|
2461
89458faaeeb3
changed: #reportCompilationError
Stefan Vogel <sv@exept.de>
parents:
2350
diff
changeset
|
941 |
|
1939 | 942 |
"Created: / 07-11-2006 / 12:29:04 / cg" |
3348
b59a15a24ab3
class: STCCompilerInterface
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
3240
diff
changeset
|
943 |
"Modified: / 21-12-2013 / 00:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
4250 | 944 |
"Modified: / 11-05-2018 / 09:29:20 / stefan" |
1939 | 945 |
! |
946 |
||
4018 | 947 |
reportCompilationErrorFor:aCommand fromFile:anErrorFilename |
948 |
|eMsg errorMessages lNr| |
|
949 |
||
950 |
(executionStatus notNil and:[executionStatus couldNotExecute]) ifTrue:[ |
|
951 |
eMsg := 'oops, no %1 - cannot create machine code' bindWith:aCommand. |
|
952 |
] ifFalse:[ |
|
953 |
errorMessages := anErrorFilename contents |
|
954 |
collect:[:l | OperatingSystem decodePathOrCommandOutput: l ]. |
|
4135 | 955 |
Transcript showCR:errorMessages asString. |
4018 | 956 |
errorMessages notNil ifTrue:[ |
957 |
errorMessages := errorMessages reject:[:line | line includesString:'Warning:']. |
|
958 |
||
959 |
errorMessages size > 20 ifTrue:[ |
|
4135 | 960 |
"/ errorMessages := errorMessages select:[:line | line asLowercase startsWith:'error']. |
4018 | 961 |
errorMessages size > 20 ifTrue:[ |
962 |
errorMessages := (errorMessages copyTo:20) copyWith:'... more messages skipped' |
|
963 |
]. |
|
964 |
]. |
|
965 |
"/ errorMessages := errorMessages collect:[:line | |
|
966 |
"/ (line startsWith:(stFileName , ':')) ifTrue:[ |
|
967 |
"/ 'Line: ' , (line copyFrom:(stFileName size + 2)) |
|
968 |
"/ ] ifFalse:[ |
|
969 |
"/ line |
|
970 |
"/ ] |
|
971 |
"/ ]. |
|
972 |
]. |
|
973 |
errorMessages isNil ifTrue:[ |
|
974 |
errorMessages := #('') |
|
975 |
]. |
|
976 |
errorMessages := (Array with:'Failed to execute: "', aCommand,'"') , errorMessages. |
|
977 |
||
978 |
"/ try to extract a line number" |
|
979 |
(errorMessages contains:[:line | line includesString:'Borland']) ifTrue:[ |
|
980 |
|i i2 s| |
|
981 |
i := errorMessages findFirst:[:l | l startsWith:(cFileName,':')]. |
|
982 |
i ~~ 0 ifTrue:[ |
|
983 |
((errorMessages at:i+1) startsWith:'Error') ifTrue:[ |
|
984 |
i2 := (errorMessages at:i+1) indexOfSubCollection:(stFileName). |
|
985 |
i2 ~~ 0 ifTrue:[ |
|
986 |
s := (errorMessages at:i+1) copyFrom:(i2+stFileName size+1). |
|
987 |
s := s readStream. |
|
988 |
lNr := Integer readFrom:s. |
|
989 |
s skipSeparators. |
|
990 |
]. |
|
991 |
] |
|
992 |
]. |
|
993 |
]. |
|
994 |
||
995 |
errorMessages isEmpty ifTrue:[ |
|
996 |
eMsg := 'Error during compilation:\\Unspecified error (no output)' withCRs |
|
997 |
] ifFalse:[ |
|
998 |
eMsg := 'Error during compilation:\\' withCRs , |
|
999 |
(errorMessages asStringCollection asString). |
|
1000 |
]. |
|
1001 |
]. |
|
1002 |
||
1003 |
originator activityNotification:''. |
|
1004 |
||
1005 |
ParseError new |
|
1006 |
lineNumber:lNr; |
|
1007 |
errorMessage:eMsg; |
|
1008 |
raise. |
|
1009 |
||
1010 |
"Created: / 07-11-2006 / 12:29:04 / cg" |
|
1011 |
"Modified: / 21-12-2013 / 00:08:39 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
4135 | 1012 |
"Modified: / 25-02-2017 / 09:58:18 / cg" |
1013 |
"Modified (format): / 25-02-2017 / 19:33:58 / cg" |
|
4018 | 1014 |
! |
1015 |
||
1939 | 1016 |
setupCompilationCommandArguments |
2335 | 1017 |
|stFn mapFileName libFileName def libDir incDir incDirArg defs incl opts| |
1018 |
||
1019 |
parserFlags isNil ifTrue:[ parserFlags := ParserFlags new]. |
|
1939 | 1020 |
|
1941 | 1021 |
stFn := stFileName asFilename. |
4266 | 1022 |
oFileName := (stFn withSuffix:(ObjectFileLoader objectFileSuffix)) name. |
1941 | 1023 |
cFileName := (stFn withSuffix:'c') name. |
3170 | 1024 |
"/ ParserFlags useBorlandC ifTrue:[ |
1025 |
"/ cFileName := (stFn withSuffix:'sc') name. |
|
1026 |
"/ ]. |
|
1941 | 1027 |
mapFileName := (stFn withSuffix:'map') name. |
1028 |
libFileName := (stFn withSuffix:'lib') name. |
|
4225 | 1029 |
oFileName asFilename remove. |
1030 |
cFileName asFilename remove. |
|
1939 | 1031 |
|
1032 |
"/ stcFlags := '-commonSymbols +sharedLibCode +newIncremental -E:errorOutput -N' , initName . |
|
4018 | 1033 |
stcFlags := '+newIncremental'. |
3659 | 1034 |
initName notEmptyOrNil ifTrue:[ |
2335 | 1035 |
stcFlags := stcFlags,' -N' , initName . |
1036 |
]. |
|
4023 | 1037 |
cFlags := STCCompilerInterface getOSDefine. |
1939 | 1038 |
cFlags isNil ifTrue:[ |
1039 |
cFlags := '' |
|
1040 |
]. |
|
4023 | 1041 |
(def := STCCompilerInterface getCPUDefine) notEmptyOrNil ifTrue:[ |
1939 | 1042 |
cFlags := cFlags , ' ' , def |
1043 |
]. |
|
1044 |
||
3659 | 1045 |
(defs := parserFlags stcCompilationDefines) notEmptyOrNil ifTrue:[ |
2335 | 1046 |
cFlags := cFlags , ' ' , defs |
1939 | 1047 |
]. |
3659 | 1048 |
(incl := parserFlags stcCompilationIncludes) notEmptyOrNil ifTrue:[ |
2335 | 1049 |
stcFlags := incl , ' ' , stcFlags. |
1050 |
cFlags := cFlags , ' ' , incl. |
|
1939 | 1051 |
|
1052 |
"/ if STX_LIBDIR is defined, and not in passed argument, |
|
1053 |
"/ add it here. |
|
1054 |
||
1055 |
libDir := OperatingSystem getEnvironment:'STX_LIBDIR'. |
|
1056 |
(libDir notNil and:[libDir asFilename exists]) ifTrue:[ |
|
1057 |
incDir := libDir asFilename construct:'include'. |
|
1058 |
incDir exists ifTrue:[ |
|
1059 |
incDirArg := '-I' , incDir pathName. |
|
2335 | 1060 |
(incl asCollectionOfWords includes:incDirArg) ifFalse:[ |
1939 | 1061 |
stcFlags := stcFlags , ' ' , incDirArg. |
1062 |
cFlags := cFlags , ' ' , incDirArg. |
|
1063 |
] |
|
1064 |
] |
|
1065 |
]. |
|
1066 |
]. |
|
3659 | 1067 |
(opts := parserFlags stcCompilationOptions) notEmptyOrNil ifTrue:[ |
2335 | 1068 |
stcFlags := opts , ' ' , stcFlags |
1939 | 1069 |
]. |
3659 | 1070 |
(opts := parserFlags ccCompilationOptions) notEmptyOrNil ifTrue:[ |
2335 | 1071 |
cFlags := cFlags , ' ' , opts |
1939 | 1072 |
]. |
1073 |
||
1074 |
"Created: / 07-11-2006 / 12:24:47 / cg" |
|
1941 | 1075 |
"Modified: / 07-11-2006 / 13:58:54 / cg" |
1669 | 1076 |
! ! |
1077 |
||
1078 |
!STCCompilerInterface class methodsFor:'documentation'! |
|
1079 |
||
1080 |
version |
|
3659 | 1081 |
^ '$Header$' |
2335 | 1082 |
! |
1083 |
||
1084 |
version_CVS |
|
3659 | 1085 |
^ '$Header$' |
1669 | 1086 |
! ! |
1087 |
||
3005 | 1088 |
|
1669 | 1089 |
STCCompilerInterface initialize! |