Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 1 | # -*- Python -*- |
| 2 | |
| 3 | import os |
| 4 | import platform |
| 5 | |
| 6 | import lit.formats |
| 7 | |
| 8 | def get_required_attr(config, attr_name): |
| 9 | attr_value = getattr(config, attr_name, None) |
| 10 | if attr_value == None: |
| 11 | lit_config.fatal( |
| 12 | "No attribute %r in test configuration! You may need to run " |
| 13 | "tests from your build directory or add this attribute " |
Reid Kleckner | 8007ff1 | 2019-06-27 20:56:04 +0000 | [diff] [blame] | 14 | "to lit.site.cfg.py " % attr_name) |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 15 | return attr_value |
| 16 | |
| 17 | # Setup config name. |
| 18 | config.name = 'Builtins' + config.name_suffix |
| 19 | |
| 20 | # Platform-specific default Builtins_OPTIONS for lit tests. |
| 21 | default_builtins_opts = '' |
| 22 | |
| 23 | # Setup source root. |
| 24 | config.test_source_root = os.path.dirname(__file__) |
| 25 | |
| 26 | # Path to the static library |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 27 | is_msvc = get_required_attr(config, "is_msvc") |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 28 | if is_msvc: |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 29 | base_lib = os.path.join(config.compiler_rt_libdir, "clang_rt.builtins%s.lib " |
| 30 | % config.target_suffix) |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 31 | config.substitutions.append( ("%librt ", base_lib) ) |
Nico Weber | 34b6f49 | 2019-09-14 22:22:47 +0000 | [diff] [blame^] | 32 | elif config.host_os == 'Darwin': |
| 33 | base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.osx.a ") |
| 34 | config.substitutions.append( ("%librt ", base_lib + ' -lSystem ') ) |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 35 | else: |
Petr Hosek | 887f26d | 2018-06-28 03:11:52 +0000 | [diff] [blame] | 36 | base_lib = os.path.join(config.compiler_rt_libdir, "libclang_rt.builtins%s.a" |
| 37 | % config.target_suffix) |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 38 | config.substitutions.append( ("%librt ", base_lib + ' -lc -lm ') ) |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 39 | |
| 40 | builtins_source_dir = os.path.join( |
| 41 | get_required_attr(config, "compiler_rt_src_root"), "lib", "builtins") |
| 42 | builtins_lit_source_dir = get_required_attr(config, "builtins_lit_source_dir") |
| 43 | |
| 44 | extra_link_flags = ["-nodefaultlibs"] |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 45 | |
| 46 | target_cflags = [get_required_attr(config, "target_cflags")] |
| 47 | target_cflags += ['-fno-builtin', '-I', builtins_source_dir] |
| 48 | target_cflags += extra_link_flags |
| 49 | target_cxxflags = config.cxx_mode_flags + target_cflags |
| 50 | clang_builtins_static_cflags = ([""] + |
| 51 | config.debug_info_flags + target_cflags) |
| 52 | clang_builtins_static_cxxflags = config.cxx_mode_flags + \ |
| 53 | clang_builtins_static_cflags |
| 54 | |
| 55 | clang_builtins_cflags = clang_builtins_static_cflags |
| 56 | clang_builtins_cxxflags = clang_builtins_static_cxxflags |
| 57 | |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 58 | # FIXME: Right now we don't compile the C99 complex builtins when using |
| 59 | # clang-cl. Fix that. |
Reid Kleckner | 8c78ca2 | 2017-04-07 16:35:09 +0000 | [diff] [blame] | 60 | if not is_msvc: |
| 61 | config.available_features.add('c99-complex') |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 62 | |
Reid Kleckner | dffe5a3 | 2018-11-01 00:00:03 +0000 | [diff] [blame] | 63 | builtins_is_msvc = get_required_attr(config, "builtins_is_msvc") |
| 64 | if not builtins_is_msvc: |
| 65 | config.available_features.add('int128') |
| 66 | |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 67 | clang_wrapper = "" |
| 68 | |
| 69 | def build_invocation(compile_flags): |
| 70 | return " " + " ".join([clang_wrapper, config.clang] + compile_flags) + " " |
| 71 | |
| 72 | |
| 73 | target_arch = config.target_arch |
| 74 | if (target_arch == "arm"): |
| 75 | target_arch = "armv7" |
| 76 | |
| 77 | config.substitutions.append( ("%clang ", build_invocation(target_cflags)) ) |
| 78 | config.substitutions.append( ("%clangxx ", build_invocation(target_cxxflags)) ) |
| 79 | config.substitutions.append( ("%clang_builtins ", \ |
| 80 | build_invocation(clang_builtins_cflags))) |
| 81 | config.substitutions.append( ("%clangxx_builtins ", \ |
| 82 | build_invocation(clang_builtins_cxxflags))) |
| 83 | |
| 84 | # FIXME: move the call_apsr.s into call_apsr.h as inline-asm. |
| 85 | # some ARM tests needs call_apsr.s |
| 86 | call_apsr_source = os.path.join(builtins_lit_source_dir, 'arm', 'call_apsr.S') |
| 87 | march_flag = '-march=' + target_arch |
| 88 | call_apsr_flags = ['-c', march_flag, call_apsr_source] |
| 89 | config.substitutions.append( ("%arm_call_apsr ", \ |
| 90 | build_invocation(call_apsr_flags)) ) |
| 91 | |
| 92 | # Default test suffixes. |
Nico Weber | 307beb1 | 2019-08-05 19:25:35 +0000 | [diff] [blame] | 93 | config.suffixes = ['.c', '.cpp'] |
Weiming Zhao | 3a69512 | 2017-03-27 23:57:44 +0000 | [diff] [blame] | 94 | |
| 95 | if not config.emulator: |
| 96 | config.available_features.add('native-run') |