diff options
| author | Matthias Braun <matze@braunis.de> | 2017-12-14 03:59:24 +0000 |
|---|---|---|
| committer | Matthias Braun <matze@braunis.de> | 2017-12-14 03:59:24 +0000 |
| commit | 5dd72adbecb3c52e1bba6b823fbc4db3f592c8f7 (patch) | |
| tree | dce9ca2510f0ca71488ab953bbbf651f413a5f4c /llvm/lib | |
| parent | 123adb507380a9061f66f75420ce7943166ce83f (diff) | |
| download | bcm5719-llvm-5dd72adbecb3c52e1bba6b823fbc4db3f592c8f7.tar.gz bcm5719-llvm-5dd72adbecb3c52e1bba6b823fbc4db3f592c8f7.zip | |
MC/AsmPrinter: Reduce code duplication.
Factor out duplicated code emitting mach-o version-min specifiers.
This should be NFC but happens to fix a bug where the code in
MCMachoStreamer didn't take the version skew between darwin and macos
versions into account.
llvm-svn: 320666
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp | 24 | ||||
| -rw-r--r-- | llvm/lib/MC/MCMachOStreamer.cpp | 22 | ||||
| -rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 29 |
3 files changed, 33 insertions, 42 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp index f1459d9d0a1..20381e4c83f 100644 --- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp @@ -254,28 +254,8 @@ bool AsmPrinter::doInitialization(Module &M) { // alternative is duplicated code in each of the target asm printers that // use the directive, where it would need the same conditionalization // anyway. - const Triple &TT = TM.getTargetTriple(); - // If there is a version specified, Major will be non-zero. - if (TT.isOSDarwin() && TT.getOSMajorVersion() != 0) { - unsigned Major, Minor, Update; - MCVersionMinType VersionType; - if (TT.isWatchOS()) { - VersionType = MCVM_WatchOSVersionMin; - TT.getWatchOSVersion(Major, Minor, Update); - } else if (TT.isTvOS()) { - VersionType = MCVM_TvOSVersionMin; - TT.getiOSVersion(Major, Minor, Update); - } else if (TT.isMacOSX()) { - VersionType = MCVM_OSXVersionMin; - if (!TT.getMacOSXVersion(Major, Minor, Update)) - Major = 0; - } else { - VersionType = MCVM_IOSVersionMin; - TT.getiOSVersion(Major, Minor, Update); - } - if (Major != 0) - OutStreamer->EmitVersionMin(VersionType, Major, Minor, Update); - } + const Triple &Target = TM.getTargetTriple(); + OutStreamer->EmitVersionForTarget(Target); // Allow the target to emit any magic that it wants at the start of the file. EmitStartOfAsmFile(M); diff --git a/llvm/lib/MC/MCMachOStreamer.cpp b/llvm/lib/MC/MCMachOStreamer.cpp index 6e1dca82033..82b75afabb3 100644 --- a/llvm/lib/MC/MCMachOStreamer.cpp +++ b/llvm/lib/MC/MCMachOStreamer.cpp @@ -502,26 +502,8 @@ MCStreamer *llvm::createMachOStreamer(MCContext &Context, MCMachOStreamer *S = new MCMachOStreamer(Context, std::move(MAB), OS, std::move(CE), DWARFMustBeAtTheEnd, LabelSections); - const Triple &TT = Context.getObjectFileInfo()->getTargetTriple(); - if (TT.isOSDarwin()) { - unsigned Major, Minor, Update; - TT.getOSVersion(Major, Minor, Update); - // If there is a version specified, Major will be non-zero. - if (Major) { - MCVersionMinType VersionType; - if (TT.isWatchOS()) - VersionType = MCVM_WatchOSVersionMin; - else if (TT.isTvOS()) - VersionType = MCVM_TvOSVersionMin; - else if (TT.isMacOSX()) - VersionType = MCVM_OSXVersionMin; - else { - assert(TT.isiOS() && "Must only be iOS platform left"); - VersionType = MCVM_IOSVersionMin; - } - S->EmitVersionMin(VersionType, Major, Minor, Update); - } - } + const Triple &Target = Context.getObjectFileInfo()->getTargetTriple(); + S->EmitVersionForTarget(Target); if (RelaxAll) S->getAssembler().setRelaxAll(true); return S; diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 4067df0eaf5..6f3647d6193 100644 --- a/llvm/lib/MC/MCStreamer.cpp +++ b/llvm/lib/MC/MCStreamer.cpp @@ -959,3 +959,32 @@ MCSymbol *MCStreamer::endSection(MCSection *Section) { EmitLabel(Sym); return Sym; } + +void MCStreamer::EmitVersionForTarget(const Triple &Target) { + if (!Target.isOSBinFormatMachO() || !Target.isOSDarwin()) + return; + // Do we even know the version? + if (Target.getOSMajorVersion() == 0) + return; + + unsigned Major; + unsigned Minor; + unsigned Update; + MCVersionMinType VersionType; + if (Target.isWatchOS()) { + VersionType = MCVM_WatchOSVersionMin; + Target.getWatchOSVersion(Major, Minor, Update); + } else if (Target.isTvOS()) { + VersionType = MCVM_TvOSVersionMin; + Target.getiOSVersion(Major, Minor, Update); + } else if (Target.isMacOSX()) { + VersionType = MCVM_OSXVersionMin; + if (!Target.getMacOSXVersion(Major, Minor, Update)) + Major = 0; + } else { + VersionType = MCVM_IOSVersionMin; + Target.getiOSVersion(Major, Minor, Update); + } + if (Major != 0) + EmitVersionMin(VersionType, Major, Minor, Update); +} |

