@@ -146,13 +146,20 @@ static const SupportedConditionalValue SupportedConditionalCompilationHasAtomicB
146
146
" _128"
147
147
};
148
148
149
+ static const SupportedConditionalValue SupportedConditionalCompilationObjectFileFormats[] = {
150
+ " MachO" ,
151
+ " ELF" ,
152
+ " COFF" ,
153
+ " Wasm" ,
154
+ };
155
+
149
156
static const PlatformConditionKind AllPublicPlatformConditionKinds[] = {
150
157
#define PLATFORM_CONDITION (LABEL, IDENTIFIER ) PlatformConditionKind::LABEL,
151
158
#define PLATFORM_CONDITION_ (LABEL, IDENTIFIER )
152
159
#include " swift/AST/PlatformConditionKinds.def"
153
160
};
154
161
155
- ArrayRef<SupportedConditionalValue> getSupportedConditionalCompilationValues (const PlatformConditionKind &Kind) {
162
+ static ArrayRef<SupportedConditionalValue> getSupportedConditionalCompilationValues (const PlatformConditionKind &Kind) {
156
163
switch (Kind) {
157
164
case PlatformConditionKind::OS:
158
165
return SupportedConditionalCompilationOSs;
@@ -172,12 +179,14 @@ ArrayRef<SupportedConditionalValue> getSupportedConditionalCompilationValues(con
172
179
return SupportedConditionalCompilationPtrAuthSchemes;
173
180
case PlatformConditionKind::HasAtomicBitWidth:
174
181
return SupportedConditionalCompilationHasAtomicBitWidths;
182
+ case PlatformConditionKind::ObjectFileFormat:
183
+ return SupportedConditionalCompilationObjectFileFormats;
175
184
}
176
185
llvm_unreachable (" Unhandled PlatformConditionKind in switch" );
177
186
}
178
187
179
- PlatformConditionKind suggestedPlatformConditionKind (PlatformConditionKind Kind, const StringRef &V,
180
- std::vector<StringRef> &suggestedValues) {
188
+ static PlatformConditionKind suggestedPlatformConditionKind (PlatformConditionKind Kind, const StringRef &V,
189
+ std::vector<StringRef> &suggestedValues) {
181
190
std::string lower = V.lower ();
182
191
for (const PlatformConditionKind& candidateKind : AllPublicPlatformConditionKinds) {
183
192
if (candidateKind != Kind) {
@@ -196,8 +205,8 @@ PlatformConditionKind suggestedPlatformConditionKind(PlatformConditionKind Kind,
196
205
return Kind;
197
206
}
198
207
199
- bool isMatching (PlatformConditionKind Kind, const StringRef &V,
200
- PlatformConditionKind &suggestedKind, std::vector<StringRef> &suggestions) {
208
+ static bool isMatching (PlatformConditionKind Kind, const StringRef &V,
209
+ PlatformConditionKind &suggestedKind, std::vector<StringRef> &suggestions) {
201
210
// Compare against known values, ignoring case to avoid penalizing
202
211
// characters with incorrect case.
203
212
unsigned minDistance = std::numeric_limits<unsigned >::max ();
@@ -236,6 +245,7 @@ checkPlatformConditionSupported(PlatformConditionKind Kind, StringRef Value,
236
245
case PlatformConditionKind::TargetEnvironment:
237
246
case PlatformConditionKind::PtrAuth:
238
247
case PlatformConditionKind::HasAtomicBitWidth:
248
+ case PlatformConditionKind::ObjectFileFormat:
239
249
return isMatching (Kind, Value, suggestedKind, suggestedValues);
240
250
case PlatformConditionKind::CanImport:
241
251
// All importable names are valid.
@@ -641,6 +651,17 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
641
651
addPlatformConditionValue (PlatformConditionKind::PointerBitWidth, " _64" );
642
652
}
643
653
654
+ // Set the "_objectFileFormat" platform condition.
655
+ if (Target.isOSBinFormatMachO ()) {
656
+ addPlatformConditionValue (PlatformConditionKind::ObjectFileFormat, " MachO" );
657
+ } else if (Target.isOSBinFormatELF ()) {
658
+ addPlatformConditionValue (PlatformConditionKind::ObjectFileFormat, " ELF" );
659
+ } else if (Target.isOSBinFormatCOFF ()) {
660
+ addPlatformConditionValue (PlatformConditionKind::ObjectFileFormat, " COFF" );
661
+ } else if (Target.isOSBinFormatWasm ()) {
662
+ addPlatformConditionValue (PlatformConditionKind::ObjectFileFormat, " Wasm" );
663
+ }
664
+
644
665
// Set the "runtime" platform condition.
645
666
addPlatformConditionValue (PlatformConditionKind::Runtime,
646
667
EnableObjCInterop ? " _ObjC" : " _Native" );
0 commit comments