|
4 | 4 | from __future__ import print_function
|
5 | 5 | import os
|
6 | 6 | import sys
|
| 7 | + |
7 | 8 | wopt = " -w"
|
8 | 9 | test_params = {
|
9 |
| - "bindump" : "nm", |
10 |
| - "runtool" : "", # if None, then runtool_func must exists |
11 |
| - "Platform" : "linux-gcc", |
12 |
| - "cxx_rtti" : "-frtti", # option to enable rtti |
13 |
| - "cxx_exceptions" : "-fexceptions", # option to enable rtti |
14 |
| - "cxx_cpp11" : "-std=c++0x" , |
| 10 | + "bindump": "nm", |
| 11 | + "runtool": "", # if None, then runtool_func must exists |
| 12 | + "Platform": "linux-gcc", |
| 13 | + "cxx_rtti": "-frtti", # option to enable rtti |
| 14 | + "cxx_exceptions": "-fexceptions", # option to enable rtti |
| 15 | + "cxx_cpp11": "-std=c++0x", |
15 | 16 | }
|
16 | 17 |
|
| 18 | + |
17 | 19 | def build_cxx_compiler_name(cn):
|
18 |
| - # build c++ compiler name from C compiler name |
19 |
| - # <prefix>clang <options> : becomes <prefix>clang -x c++ <options> |
20 |
| - # <prefix>gcc <options> : becomes <prefix>g++ <options> |
21 |
| - # <prefix>gcc-<vers> <options>: becomes <prefix>g++-<vers> <options> |
| 20 | + # build c++ compiler name from C compiler name |
| 21 | + # <prefix>clang <options> : becomes <prefix>clang -x c++ <options> |
| 22 | + # <prefix>gcc <options> : becomes <prefix>g++ <options> |
| 23 | + # <prefix>gcc-<vers> <options>: becomes <prefix>g++-<vers> <options> |
22 | 24 |
|
23 |
| - cnlen = len(cn) |
24 |
| - if (cn == 'clang'): #plain clang |
25 |
| - return "clang -x c++" |
| 25 | + cnlen = len(cn) |
| 26 | + if cn == "clang": # plain clang |
| 27 | + return "clang -x c++" |
26 | 28 |
|
27 |
| - idx = cn.find("clang ") |
28 |
| - if (idx >= 0): # clang with some options |
29 |
| - return cn[:(idx+6)] + "-x c++ " + cn[(idx+6):] |
| 29 | + idx = cn.find("clang ") |
| 30 | + if idx >= 0: # clang with some options |
| 31 | + return cn[: (idx + 6)] + "-x c++ " + cn[(idx + 6) :] |
30 | 32 |
|
31 |
| - idx = cn.rfind('clang') |
32 |
| - if (idx == (cnlen-5)): # ends in gcc |
33 |
| - return cn + " -x c++" |
| 33 | + idx = cn.rfind("clang") |
| 34 | + if idx == (cnlen - 5): # ends in gcc |
| 35 | + return cn + " -x c++" |
34 | 36 |
|
35 |
| - if (cn == 'gcc'): |
36 |
| - return "g++" |
| 37 | + if cn == "gcc": |
| 38 | + return "g++" |
37 | 39 |
|
38 |
| - idx = cn.rfind('gcc') |
39 |
| - if (idx == (cnlen-3)): # ends in gcc |
40 |
| - return cn + " -x c++" |
| 40 | + idx = cn.rfind("gcc") |
| 41 | + if idx == (cnlen - 3): # ends in gcc |
| 42 | + return cn + " -x c++" |
41 | 43 |
|
42 |
| - idx = cn.find("gcc ") |
43 |
| - if (idx >= 0): # gcc with some options |
44 |
| - return cn[:(idx+1)] + "++ " + cn[(idx+4):] |
| 44 | + idx = cn.find("gcc ") |
| 45 | + if idx >= 0: # gcc with some options |
| 46 | + return cn[: (idx + 1)] + "++ " + cn[(idx + 4) :] |
45 | 47 |
|
46 |
| - idx = cn.find("gcc-") |
47 |
| - if (idx >= 0): # gcc-<version> |
48 |
| - return cn[:(idx+1)] + "++" + cn[(idx+3):] |
| 48 | + idx = cn.find("gcc-") |
| 49 | + if idx >= 0: # gcc-<version> |
| 50 | + return cn[: (idx + 1)] + "++" + cn[(idx + 3) :] |
| 51 | + |
| 52 | + return "UNEXPECTED COMPILER" |
49 | 53 |
|
50 |
| - return "UNEXPECTED COMPILER" |
51 | 54 |
|
52 | 55 | def build_linker_name(cn):
|
53 |
| - # build linkercompiler name from C compiler name |
54 |
| - # <prefix>clang <options> : becomes <prefix>clang++ <options> |
55 |
| - # <prefix>gcc <options> : becomes <prefix>g++ <options> |
56 |
| - # <prefix>gcc-<vers> <options>: becomes <prefix>g++-<vers> <options> |
| 56 | + # build linkercompiler name from C compiler name |
| 57 | + # <prefix>clang <options> : becomes <prefix>clang++ <options> |
| 58 | + # <prefix>gcc <options> : becomes <prefix>g++ <options> |
| 59 | + # <prefix>gcc-<vers> <options>: becomes <prefix>g++-<vers> <options> |
57 | 60 |
|
58 |
| - if (cn == 'clang'): #plain clang |
59 |
| - return "clang++" |
| 61 | + if cn == "clang": # plain clang |
| 62 | + return "clang++" |
60 | 63 |
|
61 |
| - idx = cn.find("clang ") |
62 |
| - if (idx >= 0): # clang with some options |
63 |
| - return cn[:(idx+5)] + "++ " + cn[(idx+6):] |
| 64 | + idx = cn.find("clang ") |
| 65 | + if idx >= 0: # clang with some options |
| 66 | + return cn[: (idx + 5)] + "++ " + cn[(idx + 6) :] |
64 | 67 |
|
65 |
| - cnlen = len(cn) |
66 |
| - idx = cn.rfind('clang') |
67 |
| - if (idx == (cnlen-5)): # ends in clang |
68 |
| - return cn + "++" |
| 68 | + cnlen = len(cn) |
| 69 | + idx = cn.rfind("clang") |
| 70 | + if idx == (cnlen - 5): # ends in clang |
| 71 | + return cn + "++" |
69 | 72 |
|
70 |
| - return build_cxx_compiler_name(cn) # for gcc, linekr name is same as c++ compiler name |
| 73 | + return build_cxx_compiler_name( |
| 74 | + cn |
| 75 | + ) # for gcc, linekr name is same as c++ compiler name |
71 | 76 |
|
72 | 77 |
|
73 | 78 | import subprocess
|
| 79 | + |
74 | 80 | if __name__ == "__main__":
|
75 |
| - print(sys.argv) |
76 |
| - litargs = [sys.argv[0]] # args for lit.main |
77 |
| - c_compiler_name = sys.argv[1].strip() |
78 |
| - cxx_compiler_name = build_cxx_compiler_name(c_compiler_name) |
79 |
| - linker_name = build_linker_name(c_compiler_name) |
80 |
| - #print("C++ compiler:", cxx_compiler_name) |
81 |
| - #print("linker :", linker_name) |
82 |
| - for la in sys.argv[2:]: |
83 |
| - litargs.append(la) |
84 |
| - sys.argv = litargs |
85 |
| - cmd = c_compiler_name.split() + [ "-o", "b.exe", "test/common/genselector.c"] |
86 |
| - #print("cmd = ", cmd) |
87 |
| - rv = subprocess.call(cmd) |
88 |
| - #print("rv = " , rv) |
89 |
| - if rv != 0: |
90 |
| - print("compiler failed: ", cmd) |
91 |
| - sys.exit(1) |
92 |
| - rv = subprocess.call("./b.exe") |
93 |
| - fp = open("nselector.h") |
94 |
| - fi = fp.read(); |
95 |
| - fp.close() |
96 |
| - if ("LP64" in fi): |
97 |
| - test_params["Mode"] = "LP64-x86" |
98 |
| - prf = "--check-prefix=LP64" |
99 |
| - else: |
100 |
| - # 'gcc -m32' or 'clang -m32' mode |
101 |
| - test_params["Mode"] = "ILP32-x86" |
102 |
| - prf = "--check-prefix=ILP32" |
103 |
| - test_params["prefixes"] = prf; |
104 |
| - test_params["c_compiler"] = c_compiler_name |
105 |
| - test_params["cxx_compiler"] = cxx_compiler_name |
106 |
| - test_params["linker"] = linker_name |
107 |
| - test_params["Platform"] = "linux-" + cmd[0] |
108 |
| - |
109 |
| - print("test_params = " , test_params) |
110 |
| - builtin_parameters = { |
111 |
| - 'build_mode' : "Release", |
112 |
| - 'llvm_site_config' : os.path.join(os.getcwd(), 'lit.site.cfg'), |
113 |
| - 'clang_site_config': os.path.join(os.getcwd(), 'lit.site.cfg'), |
114 |
| - 'test_params' : test_params |
| 81 | + print(sys.argv) |
| 82 | + litargs = [sys.argv[0]] # args for lit.main |
| 83 | + c_compiler_name = sys.argv[1].strip() |
| 84 | + cxx_compiler_name = build_cxx_compiler_name(c_compiler_name) |
| 85 | + linker_name = build_linker_name(c_compiler_name) |
| 86 | + # print("C++ compiler:", cxx_compiler_name) |
| 87 | + # print("linker :", linker_name) |
| 88 | + for la in sys.argv[2:]: |
| 89 | + litargs.append(la) |
| 90 | + sys.argv = litargs |
| 91 | + cmd = c_compiler_name.split() + ["-o", "b.exe", "test/common/genselector.c"] |
| 92 | + # print("cmd = ", cmd) |
| 93 | + rv = subprocess.call(cmd) |
| 94 | + # print("rv = " , rv) |
| 95 | + if rv != 0: |
| 96 | + print("compiler failed: ", cmd) |
| 97 | + sys.exit(1) |
| 98 | + rv = subprocess.call("./b.exe") |
| 99 | + fp = open("nselector.h") |
| 100 | + fi = fp.read() |
| 101 | + fp.close() |
| 102 | + if "LP64" in fi: |
| 103 | + test_params["Mode"] = "LP64-x86" |
| 104 | + prf = "--check-prefix=LP64" |
| 105 | + else: |
| 106 | + # 'gcc -m32' or 'clang -m32' mode |
| 107 | + test_params["Mode"] = "ILP32-x86" |
| 108 | + prf = "--check-prefix=ILP32" |
| 109 | + test_params["prefixes"] = prf |
| 110 | + test_params["c_compiler"] = c_compiler_name |
| 111 | + test_params["cxx_compiler"] = cxx_compiler_name |
| 112 | + test_params["linker"] = linker_name |
| 113 | + test_params["Platform"] = "linux-" + cmd[0] |
| 114 | + |
| 115 | + print("test_params = ", test_params) |
| 116 | + builtin_parameters = { |
| 117 | + "build_mode": "Release", |
| 118 | + "llvm_site_config": os.path.join(os.getcwd(), "lit.site.cfg"), |
| 119 | + "clang_site_config": os.path.join(os.getcwd(), "lit.site.cfg"), |
| 120 | + "test_params": test_params, |
115 | 121 | }
|
116 |
| - #print("builtin_params = " , test_params) |
117 |
| - from lit.main import main |
118 |
| - main(builtin_parameters) |
| 122 | + # print("builtin_params = " , test_params) |
| 123 | + from lit.main import main |
119 | 124 |
|
| 125 | + main(builtin_parameters) |
0 commit comments