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