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