|
33 | 33 | from subprocess import PIPE |
34 | 34 |
|
35 | 35 |
|
36 | | -from tools import shared, system_libs, utils, ports, cmdline |
37 | | -from tools import diagnostics, building |
| 36 | +from tools import shared, system_libs, utils, cmdline |
| 37 | +from tools import diagnostics, building, compile |
38 | 38 | from tools.shared import unsuffixed, unsuffixed_basename, get_file_suffix |
39 | 39 | from tools.shared import run_process, exit_with_error, DEBUG |
40 | 40 | from tools.shared import in_temp |
41 | 41 | from tools.shared import DYLIB_EXTENSIONS |
42 | | -from tools.cmdline import SIMD_INTEL_FEATURE_TOWER, SIMD_NEON_FLAGS, CLANG_FLAGS_WITH_ARGS |
| 42 | +from tools.cmdline import CLANG_FLAGS_WITH_ARGS |
43 | 43 | from tools.response_file import substitute_response_files |
44 | 44 | from tools import config |
45 | 45 | from tools import cache |
46 | 46 | from tools.settings import default_setting, user_settings, settings, COMPILE_TIME_SETTINGS |
47 | | -from tools.utils import read_file, memoize |
| 47 | +from tools.utils import read_file |
48 | 48 |
|
49 | 49 | logger = logging.getLogger('emcc') |
50 | 50 |
|
@@ -171,126 +171,6 @@ def cxx_to_c_compiler(cxx): |
171 | 171 | return os.path.join(dirname, basename) |
172 | 172 |
|
173 | 173 |
|
174 | | -def get_target_flags(): |
175 | | - return ['-target', shared.get_llvm_target()] |
176 | | - |
177 | | - |
178 | | -def get_clang_flags(user_args): |
179 | | - flags = get_target_flags() |
180 | | - |
181 | | - # if exception catching is disabled, we can prevent that code from being |
182 | | - # generated in the frontend |
183 | | - if settings.DISABLE_EXCEPTION_CATCHING and not settings.WASM_EXCEPTIONS: |
184 | | - flags.append('-fignore-exceptions') |
185 | | - |
186 | | - if settings.INLINING_LIMIT: |
187 | | - flags.append('-fno-inline-functions') |
188 | | - |
189 | | - if settings.PTHREADS: |
190 | | - if '-pthread' not in user_args: |
191 | | - flags.append('-pthread') |
192 | | - elif settings.SHARED_MEMORY: |
193 | | - if '-matomics' not in user_args: |
194 | | - flags.append('-matomics') |
195 | | - if '-mbulk-memory' not in user_args: |
196 | | - flags.append('-mbulk-memory') |
197 | | - |
198 | | - if settings.RELOCATABLE and '-fPIC' not in user_args: |
199 | | - flags.append('-fPIC') |
200 | | - |
201 | | - if settings.RELOCATABLE or settings.LINKABLE or '-fPIC' in user_args: |
202 | | - if not any(a.startswith('-fvisibility') for a in user_args): |
203 | | - # For relocatable code we default to visibility=default in emscripten even |
204 | | - # though the upstream backend defaults visibility=hidden. This matches the |
205 | | - # expectations of C/C++ code in the wild which expects undecorated symbols |
206 | | - # to be exported to other DSO's by default. |
207 | | - flags.append('-fvisibility=default') |
208 | | - |
209 | | - if settings.LTO: |
210 | | - if not any(a.startswith('-flto') for a in user_args): |
211 | | - flags.append('-flto=' + settings.LTO) |
212 | | - # setjmp/longjmp handling using Wasm EH |
213 | | - # For non-LTO, '-mllvm -wasm-enable-eh' added in |
214 | | - # building.llvm_backend_args() sets this feature in clang. But in LTO, the |
215 | | - # argument is added to wasm-ld instead, so clang needs to know that EH is |
216 | | - # enabled so that it can be added to the attributes in LLVM IR. |
217 | | - if settings.SUPPORT_LONGJMP == 'wasm': |
218 | | - flags.append('-mexception-handling') |
219 | | - |
220 | | - else: |
221 | | - # In LTO mode these args get passed instead at link time when the backend runs. |
222 | | - for a in building.llvm_backend_args(): |
223 | | - flags += ['-mllvm', a] |
224 | | - |
225 | | - return flags |
226 | | - |
227 | | - |
228 | | -@memoize |
229 | | -def get_cflags(user_args): |
230 | | - # Flags we pass to the compiler when building C/C++ code |
231 | | - # We add these to the user's flags (newargs), but not when building .s or .S assembly files |
232 | | - cflags = get_clang_flags(user_args) |
233 | | - cflags.append('--sysroot=' + cache.get_sysroot(absolute=True)) |
234 | | - |
235 | | - if settings.EMSCRIPTEN_TRACING: |
236 | | - cflags.append('-D__EMSCRIPTEN_TRACING__=1') |
237 | | - |
238 | | - if settings.SHARED_MEMORY: |
239 | | - cflags.append('-D__EMSCRIPTEN_SHARED_MEMORY__=1') |
240 | | - |
241 | | - if settings.WASM_WORKERS: |
242 | | - cflags.append('-D__EMSCRIPTEN_WASM_WORKERS__=1') |
243 | | - |
244 | | - if not settings.STRICT: |
245 | | - # The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code |
246 | | - # in strict mode. Code should use the define __EMSCRIPTEN__ instead. |
247 | | - cflags.append('-DEMSCRIPTEN') |
248 | | - |
249 | | - ports.add_cflags(cflags, settings) |
250 | | - |
251 | | - def array_contains_any_of(hay, needles): |
252 | | - for n in needles: |
253 | | - if n in hay: |
254 | | - return True |
255 | | - |
256 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER) or array_contains_any_of(user_args, SIMD_NEON_FLAGS): |
257 | | - if '-msimd128' not in user_args and '-mrelaxed-simd' not in user_args: |
258 | | - exit_with_error('passing any of ' + ', '.join(SIMD_INTEL_FEATURE_TOWER + SIMD_NEON_FLAGS) + ' flags also requires passing -msimd128 (or -mrelaxed-simd)!') |
259 | | - cflags += ['-D__SSE__=1'] |
260 | | - |
261 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[1:]): |
262 | | - cflags += ['-D__SSE2__=1'] |
263 | | - |
264 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[2:]): |
265 | | - cflags += ['-D__SSE3__=1'] |
266 | | - |
267 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[3:]): |
268 | | - cflags += ['-D__SSSE3__=1'] |
269 | | - |
270 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[4:]): |
271 | | - cflags += ['-D__SSE4_1__=1'] |
272 | | - |
273 | | - # Handle both -msse4.2 and its alias -msse4. |
274 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[5:]): |
275 | | - cflags += ['-D__SSE4_2__=1'] |
276 | | - |
277 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[7:]): |
278 | | - cflags += ['-D__AVX__=1'] |
279 | | - |
280 | | - if array_contains_any_of(user_args, SIMD_INTEL_FEATURE_TOWER[8:]): |
281 | | - cflags += ['-D__AVX2__=1'] |
282 | | - |
283 | | - if array_contains_any_of(user_args, SIMD_NEON_FLAGS): |
284 | | - cflags += ['-D__ARM_NEON__=1'] |
285 | | - |
286 | | - if '-nostdinc' not in user_args: |
287 | | - if not settings.USE_SDL: |
288 | | - cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'fakesdl')] |
289 | | - cflags += ['-Xclang', '-iwithsysroot' + os.path.join('/include', 'compat')] |
290 | | - |
291 | | - return cflags |
292 | | - |
293 | | - |
294 | 174 | def get_library_basename(filename): |
295 | 175 | """Similar to get_file_suffix this strips off all numeric suffixes and then |
296 | 176 | then final non-numeric one. For example for 'libz.so.1.2.8' returns 'libz'""" |
@@ -319,7 +199,7 @@ def run(args): |
319 | 199 | if len(args) == 2 and args[1] == '-v': |
320 | 200 | # autoconf likes to see 'GNU' in the output to enable shared object support |
321 | 201 | print(cmdline.version_string(), file=sys.stderr) |
322 | | - return shared.check_call([clang, '-v'] + get_target_flags(), check=False).returncode |
| 202 | + return shared.check_call([clang, '-v'] + compile.get_target_flags(), check=False).returncode |
323 | 203 |
|
324 | 204 | # Additional compiler flags that we treat as if they were passed to us on the |
325 | 205 | # commandline |
@@ -652,13 +532,13 @@ def phase_compile_inputs(options, state, newargs): |
652 | 532 | system_libs.ensure_sysroot() |
653 | 533 |
|
654 | 534 | def get_clang_command(): |
655 | | - return compiler + get_cflags(state.orig_args) |
| 535 | + return compiler + compile.get_cflags(state.orig_args) |
656 | 536 |
|
657 | 537 | def get_clang_command_preprocessed(): |
658 | | - return compiler + get_clang_flags(state.orig_args) |
| 538 | + return compiler + compile.get_clang_flags(state.orig_args) |
659 | 539 |
|
660 | 540 | def get_clang_command_asm(): |
661 | | - return compiler + get_target_flags() |
| 541 | + return compiler + compile.get_target_flags() |
662 | 542 |
|
663 | 543 | if state.mode == Mode.COMPILE_ONLY: |
664 | 544 | if options.output_file and get_file_suffix(options.output_file) == '.bc' and not settings.LTO and '-emit-llvm' not in state.orig_args: |
|
0 commit comments