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