@@ -51,13 +51,99 @@ class ArchType:
51
51
spir64 = 37
52
52
kalimba = 38
53
53
shave = 39
54
-
54
+ # Do not assume that these are 1:1 mapping. This should follow
55
+ # canonical naming conventions for arm, etc. architectures.
56
+ # See apple/swift PR #608
57
+ @staticmethod
58
+ def to_string (value ):
59
+ if value == ArchType .arm :
60
+ return "armv7"
61
+ if value == ArchType .armeb :
62
+ return "armeb"
63
+ if value == ArchType .aarch64 :
64
+ return "aarch64"
65
+ if value == ArchType .aarch64_be :
66
+ return "aarch64_be"
67
+ if value == ArchType .bpfel :
68
+ return "bpfel"
69
+ if value == ArchType .bpfeb :
70
+ return "bpfeb"
71
+ if value == ArchType .hexagon :
72
+ return "hexagon"
73
+ if value == ArchType .mips :
74
+ return "mips"
75
+ if value == ArchType .mipsel :
76
+ return "mipsel"
77
+ if value == ArchType .mips64 :
78
+ return "mips64"
79
+ if value == ArchType .mips64el :
80
+ return "mips64el"
81
+ if value == ArchType .msp430 :
82
+ return "msp430"
83
+ if value == ArchType .ppc :
84
+ return "ppc"
85
+ if value == ArchType .ppc64 :
86
+ return "ppc64"
87
+ if value == ArchType .ppc64le :
88
+ return "ppc64le"
89
+ if value == ArchType .r600 :
90
+ return "r600"
91
+ if value == ArchType .amdgcn :
92
+ return "amdgcn"
93
+ if value == ArchType .sparc :
94
+ return "sparc"
95
+ if value == ArchType .sparcv9 :
96
+ return "sparcv9"
97
+ if value == ArchType .sparcel :
98
+ return "sparcel"
99
+ if value == ArchType .systemz :
100
+ return "systemz"
101
+ if value == ArchType .tce :
102
+ return "tce"
103
+ if value == ArchType .thumb :
104
+ return "armv7"
105
+ if value == ArchType .thumbeb :
106
+ return "thumbeb"
107
+ if value == ArchType .x86 :
108
+ return "i386"
109
+ if value == ArchType .x86_64 :
110
+ return "x86_64"
111
+ if value == ArchType .xcore :
112
+ return "xcore"
113
+ if value == ArchType .nvptx :
114
+ return "nvptx"
115
+ if value == ArchType .nvptx64 :
116
+ return "nvptx64"
117
+ if value == ArchType .le32 :
118
+ return "le32"
119
+ if value == ArchType .le64 :
120
+ return "le64"
121
+ if value == ArchType .amdil :
122
+ return "amdil"
123
+ if value == ArchType .amdil64 :
124
+ return "amdil64"
125
+ if value == ArchType .hsail :
126
+ return "hsail"
127
+ if value == ArchType .hsail64 :
128
+ return "hsail64"
129
+ if value == ArchType .spir :
130
+ return "spir"
131
+ if value == ArchType .spir64 :
132
+ return "spir64"
133
+ if value == ArchType .kalimba :
134
+ return "kalimba"
135
+ if value == ArchType .shave :
136
+ return "shave"
137
+ return "unknown"
138
+ # Not 1:1, See to_string
55
139
@staticmethod
56
140
def from_string (string ):
57
- if string == "arm" :
58
- return ArchType .arm
141
+ # Match big endian arm first
59
142
if string == "armeb" :
60
143
return ArchType .armeb
144
+ # Catch-all for little endian arm
145
+ if "arm" in string :
146
+ return ArchType .arm
61
147
if string == "aarch64" :
62
148
return ArchType .aarch64
63
149
if string == "aarch64_be" :
@@ -223,8 +309,8 @@ class Vendor:
223
309
224
310
class Target :
225
311
triple = None
226
- sdk = OSType . MacOSX
227
- arch = ArchType . x86_64
312
+ sdk = None
313
+ arch = None
228
314
executable_suffix = ""
229
315
dynamic_library_prefix = "lib"
230
316
dynamic_library_suffix = ".dylib"
@@ -242,20 +328,30 @@ def __init__(self, triple):
242
328
self .sdk = OSType .Win32
243
329
self .dynamic_library_suffix = ".dll"
244
330
self .executable_suffix = ".exe"
331
+ elif "darwin" in triple :
332
+ self .sdk = OSType .MacOSX
333
+ else :
334
+ print ("Unknown platform" )
335
+
245
336
self .triple = triple
337
+
246
338
comps = triple .split ('-' )
247
- ArchType .from_string (comps [0 ])
339
+ self . arch = ArchType .from_string (comps [0 ])
248
340
249
341
@staticmethod
250
342
def default ():
251
- triple = platform .machine () + "-"
343
+ arch = ArchType .from_string (platform .machine ())
344
+ triple = ArchType .to_string (arch )
252
345
if platform .system () == "Linux" :
253
- triple += "linux-gnu"
346
+ if arch == ArchType .arm :
347
+ triple += "-linux-gnueabihf"
348
+ else :
349
+ triple += "-linux-gnu"
254
350
elif platform .system () == "Darwin" :
255
- triple += "apple-darwin"
351
+ triple += "- apple-darwin"
256
352
elif platform .system () == "FreeBSD" :
257
- # Make this working on 10 as well.
258
- triple += "freebsd11.0"
353
+ # Make this work on 10 as well.
354
+ triple += "- freebsd11.0"
259
355
else :
260
356
# TODO: This should be a bit more exhaustive
261
357
print ("unknown host os" )
@@ -264,21 +360,17 @@ def default():
264
360
265
361
@property
266
362
def swift_triple (self ):
267
- triple = ""
268
- if self .arch == ArchType .x86_64 :
269
- triple = "x86_64"
270
- else :
271
- print ("unknown arch for swift" )
272
- return None
363
+ triple = ArchType .to_string (self .arch )
273
364
if self .sdk == OSType .MacOSX :
274
365
return None
275
366
elif self .sdk == OSType .Linux :
276
- triple += "-pc -linux"
367
+ triple += "-unknown -linux"
277
368
elif self .sdk == OSType .FreeBSD :
278
369
triple += "-unknown-freebsd"
279
370
else :
280
371
print ("unknown sdk for swift" )
281
372
return None
373
+
282
374
return triple
283
375
284
376
@property
@@ -296,13 +388,7 @@ def swift_sdk_name(self):
296
388
297
389
@property
298
390
def swift_arch (self ):
299
- arch = ""
300
- if self .arch == ArchType .x86_64 :
301
- arch = "x86_64"
302
- else :
303
- print ("unknown arch for swift" )
304
- return None
305
- return arch
391
+ return ArchType .to_string (self .arch )
306
392
307
393
class TargetConditional :
308
394
_sdk = None
0 commit comments