|
22 | 22 | #include "llvm/IR/Function.h" |
23 | 23 | #include "llvm/Support/CommandLine.h" |
24 | 24 | #include "llvm/Support/raw_ostream.h" |
| 25 | +#include "llvm/BinaryFormat/MachO.h" |
25 | 26 |
|
26 | 27 | #include "Callee.h" |
27 | 28 | #include "Explosion.h" |
@@ -289,6 +290,35 @@ void IRGenFunction::emitTSanInoutAccessCall(llvm::Value *address) { |
289 | 290 | Builder.CreateCall(fn, {castAddress, callerPC, castTag}); |
290 | 291 | } |
291 | 292 |
|
| 293 | +// This is shamelessly copied from clang's codegen. We need to get the clang |
| 294 | +// functionality into a shared header so that platforms only |
| 295 | +// needs to be updated in one place. |
| 296 | +static unsigned getBaseMachOPlatformID(const llvm::Triple &TT) { |
| 297 | + switch (TT.getOS()) { |
| 298 | + case llvm::Triple::Darwin: |
| 299 | + case llvm::Triple::MacOSX: |
| 300 | + return llvm::MachO::PLATFORM_MACOS; |
| 301 | + case llvm::Triple::IOS: |
| 302 | + return llvm::MachO::PLATFORM_IOS; |
| 303 | + case llvm::Triple::TvOS: |
| 304 | + return llvm::MachO::PLATFORM_TVOS; |
| 305 | + case llvm::Triple::WatchOS: |
| 306 | + return llvm::MachO::PLATFORM_WATCHOS; |
| 307 | + default: |
| 308 | + return /*Unknown platform*/ 0; |
| 309 | + } |
| 310 | +} |
| 311 | + |
| 312 | +llvm::Value * |
| 313 | +IRGenFunction::emitTargetOSVersionAtLeastCall(llvm::Value *major, |
| 314 | + llvm::Value *minor, |
| 315 | + llvm::Value *patch) { |
| 316 | + auto *fn = cast<llvm::Function>(IGM.getPlatformVersionAtLeastFn()); |
| 317 | + |
| 318 | + llvm::Value *platformID = |
| 319 | + llvm::ConstantInt::get(IGM.Int32Ty, getBaseMachOPlatformID(IGM.Triple)); |
| 320 | + return Builder.CreateCall(fn, {platformID, major, minor, patch}); |
| 321 | +} |
292 | 322 |
|
293 | 323 | /// Initialize a relative indirectable pointer to the given value. |
294 | 324 | /// This always leaves the value in the direct state; if it's not a |
|
0 commit comments