Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 1 | //===-- PPCAsmBackend.cpp - PPC Assembler Backend -------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Evan Cheng | 61d4a20 | 2011-07-25 19:53:23 +0000 | [diff] [blame] | 10 | #include "MCTargetDesc/PPCFixupKinds.h" |
Chandler Carruth | 6bda14b | 2017-06-06 11:49:48 +0000 | [diff] [blame] | 11 | #include "MCTargetDesc/PPCMCTargetDesc.h" |
Zachary Turner | 264b5d9 | 2017-06-07 03:48:56 +0000 | [diff] [blame] | 12 | #include "llvm/BinaryFormat/ELF.h" |
| 13 | #include "llvm/BinaryFormat/MachO.h" |
Craig Topper | b25fda9 | 2012-03-17 18:46:09 +0000 | [diff] [blame] | 14 | #include "llvm/MC/MCAsmBackend.h" |
Chandler Carruth | d990388 | 2015-01-14 11:23:27 +0000 | [diff] [blame] | 15 | #include "llvm/MC/MCAssembler.h" |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 16 | #include "llvm/MC/MCELFObjectWriter.h" |
Craig Topper | 6e80c28 | 2012-03-26 06:58:25 +0000 | [diff] [blame] | 17 | #include "llvm/MC/MCFixupKindInfo.h" |
Daniel Dunbar | 73b8713 | 2010-12-16 16:08:33 +0000 | [diff] [blame] | 18 | #include "llvm/MC/MCMachObjectWriter.h" |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 19 | #include "llvm/MC/MCObjectWriter.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/MC/MCSectionMachO.h" |
Alex Bradbury | b22f751 | 2018-01-03 08:53:05 +0000 | [diff] [blame] | 21 | #include "llvm/MC/MCSubtargetInfo.h" |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 22 | #include "llvm/MC/MCSymbolELF.h" |
Jim Grosbach | 28fcafb | 2011-06-24 23:44:37 +0000 | [diff] [blame] | 23 | #include "llvm/MC/MCValue.h" |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 24 | #include "llvm/Support/ErrorHandling.h" |
Evan Cheng | 2bb4035 | 2011-08-24 18:08:43 +0000 | [diff] [blame] | 25 | #include "llvm/Support/TargetRegistry.h" |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 26 | using namespace llvm; |
| 27 | |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 28 | static uint64_t adjustFixupValue(unsigned Kind, uint64_t Value) { |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 29 | switch (Kind) { |
| 30 | default: |
| 31 | llvm_unreachable("Unknown fixup kind!"); |
| 32 | case FK_Data_1: |
| 33 | case FK_Data_2: |
| 34 | case FK_Data_4: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 35 | case FK_Data_8: |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 36 | case PPC::fixup_ppc_nofixup: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 37 | return Value; |
| 38 | case PPC::fixup_ppc_brcond14: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 39 | case PPC::fixup_ppc_brcond14abs: |
Adhemerval Zanella | f2aceda | 2012-10-25 12:27:42 +0000 | [diff] [blame] | 40 | return Value & 0xfffc; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 41 | case PPC::fixup_ppc_br24: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 42 | case PPC::fixup_ppc_br24abs: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 43 | return Value & 0x3fffffc; |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 44 | case PPC::fixup_ppc_half16: |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 45 | return Value & 0xffff; |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 46 | case PPC::fixup_ppc_half16ds: |
Ulrich Weigand | 3e18601 | 2013-03-26 10:56:47 +0000 | [diff] [blame] | 47 | return Value & 0xfffc; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 48 | } |
| 49 | } |
| 50 | |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 51 | static unsigned getFixupKindNumBytes(unsigned Kind) { |
| 52 | switch (Kind) { |
| 53 | default: |
| 54 | llvm_unreachable("Unknown fixup kind!"); |
| 55 | case FK_Data_1: |
| 56 | return 1; |
| 57 | case FK_Data_2: |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 58 | case PPC::fixup_ppc_half16: |
| 59 | case PPC::fixup_ppc_half16ds: |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 60 | return 2; |
| 61 | case FK_Data_4: |
| 62 | case PPC::fixup_ppc_brcond14: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 63 | case PPC::fixup_ppc_brcond14abs: |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 64 | case PPC::fixup_ppc_br24: |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 65 | case PPC::fixup_ppc_br24abs: |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 66 | return 4; |
| 67 | case FK_Data_8: |
| 68 | return 8; |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 69 | case PPC::fixup_ppc_nofixup: |
| 70 | return 0; |
| 71 | } |
| 72 | } |
| 73 | |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 74 | namespace { |
Daniel Dunbar | 8888a96 | 2010-12-16 16:09:19 +0000 | [diff] [blame] | 75 | |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 76 | class PPCAsmBackend : public MCAsmBackend { |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 77 | const Target &TheTarget; |
| 78 | bool IsLittleEndian; |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 79 | public: |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 80 | PPCAsmBackend(const Target &T, bool isLittle) : MCAsmBackend(), TheTarget(T), |
| 81 | IsLittleEndian(isLittle) {} |
Daniel Dunbar | 0c9d9fd | 2010-12-16 03:20:06 +0000 | [diff] [blame] | 82 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 83 | unsigned getNumFixupKinds() const override { |
| 84 | return PPC::NumTargetFixupKinds; |
| 85 | } |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 86 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 87 | const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override { |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 88 | const static MCFixupKindInfo InfosBE[PPC::NumTargetFixupKinds] = { |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 89 | // name offset bits flags |
| 90 | { "fixup_ppc_br24", 6, 24, MCFixupKindInfo::FKF_IsPCRel }, |
| 91 | { "fixup_ppc_brcond14", 16, 14, MCFixupKindInfo::FKF_IsPCRel }, |
Ulrich Weigand | b6a30d1 | 2013-06-24 11:03:33 +0000 | [diff] [blame] | 92 | { "fixup_ppc_br24abs", 6, 24, 0 }, |
| 93 | { "fixup_ppc_brcond14abs", 16, 14, 0 }, |
Ulrich Weigand | 6e23ac6 | 2013-05-17 12:37:21 +0000 | [diff] [blame] | 94 | { "fixup_ppc_half16", 0, 16, 0 }, |
| 95 | { "fixup_ppc_half16ds", 0, 14, 0 }, |
Bill Schmidt | 24b8dd6 | 2012-12-12 19:29:35 +0000 | [diff] [blame] | 96 | { "fixup_ppc_nofixup", 0, 0, 0 } |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 97 | }; |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 98 | const static MCFixupKindInfo InfosLE[PPC::NumTargetFixupKinds] = { |
| 99 | // name offset bits flags |
| 100 | { "fixup_ppc_br24", 2, 24, MCFixupKindInfo::FKF_IsPCRel }, |
| 101 | { "fixup_ppc_brcond14", 2, 14, MCFixupKindInfo::FKF_IsPCRel }, |
| 102 | { "fixup_ppc_br24abs", 2, 24, 0 }, |
| 103 | { "fixup_ppc_brcond14abs", 2, 14, 0 }, |
| 104 | { "fixup_ppc_half16", 0, 16, 0 }, |
| 105 | { "fixup_ppc_half16ds", 2, 14, 0 }, |
| 106 | { "fixup_ppc_nofixup", 0, 0, 0 } |
| 107 | }; |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 108 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 109 | if (Kind < FirstTargetFixupKind) |
Evan Cheng | 5928e69 | 2011-07-25 23:24:55 +0000 | [diff] [blame] | 110 | return MCAsmBackend::getFixupKindInfo(Kind); |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 111 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 112 | assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() && |
| 113 | "Invalid kind!"); |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 114 | return (IsLittleEndian? InfosLE : InfosBE)[Kind - FirstTargetFixupKind]; |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 115 | } |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 116 | |
Rafael Espindola | 801b42d | 2017-06-23 22:52:36 +0000 | [diff] [blame] | 117 | void applyFixup(const MCAssembler &Asm, const MCFixup &Fixup, |
| 118 | const MCValue &Target, MutableArrayRef<char> Data, |
Rafael Espindola | 1beb702 | 2017-07-11 23:18:25 +0000 | [diff] [blame] | 119 | uint64_t Value, bool IsResolved) const override { |
Benjamin Kramer | 8abfec3 | 2012-11-24 13:18:17 +0000 | [diff] [blame] | 120 | Value = adjustFixupValue(Fixup.getKind(), Value); |
| 121 | if (!Value) return; // Doesn't change encoding. |
| 122 | |
| 123 | unsigned Offset = Fixup.getOffset(); |
Ulrich Weigand | 56f5b28 | 2013-05-15 15:01:46 +0000 | [diff] [blame] | 124 | unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind()); |
Benjamin Kramer | 8abfec3 | 2012-11-24 13:18:17 +0000 | [diff] [blame] | 125 | |
| 126 | // For each byte of the fragment that the fixup touches, mask in the bits |
| 127 | // from the fixup value. The Value has been "split up" into the appropriate |
| 128 | // bitfields above. |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 129 | for (unsigned i = 0; i != NumBytes; ++i) { |
| 130 | unsigned Idx = IsLittleEndian ? i : (NumBytes - 1 - i); |
| 131 | Data[Offset + i] |= uint8_t((Value >> (Idx * 8)) & 0xff); |
| 132 | } |
Benjamin Kramer | 8abfec3 | 2012-11-24 13:18:17 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 135 | bool shouldForceRelocation(const MCAssembler &Asm, const MCFixup &Fixup, |
| 136 | const MCValue &Target) override { |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 137 | switch ((PPC::Fixups)Fixup.getKind()) { |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 138 | default: |
| 139 | return false; |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 140 | case PPC::fixup_ppc_br24: |
| 141 | case PPC::fixup_ppc_br24abs: |
| 142 | // If the target symbol has a local entry point we must not attempt |
| 143 | // to resolve the fixup directly. Emit a relocation and leave |
| 144 | // resolution of the final target address to the linker. |
| 145 | if (const MCSymbolRefExpr *A = Target.getSymA()) { |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 146 | if (const auto *S = dyn_cast<MCSymbolELF>(&A->getSymbol())) { |
| 147 | // The "other" values are stored in the last 6 bits of the second |
| 148 | // byte. The traditional defines for STO values assume the full byte |
| 149 | // and thus the shift to pack it. |
| 150 | unsigned Other = S->getOther() << 2; |
| 151 | if ((Other & ELF::STO_PPC64_LOCAL_MASK) != 0) |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 152 | return true; |
Rafael Espindola | 95fb9b9 | 2015-06-02 20:38:46 +0000 | [diff] [blame] | 153 | } |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 154 | } |
Rafael Espindola | 76287ab | 2017-06-30 22:47:27 +0000 | [diff] [blame] | 155 | return false; |
Ulrich Weigand | bb68610 | 2014-07-20 23:06:03 +0000 | [diff] [blame] | 156 | } |
| 157 | } |
| 158 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 159 | bool mayNeedRelaxation(const MCInst &Inst) const override { |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 160 | // FIXME. |
| 161 | return false; |
| 162 | } |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 163 | |
| 164 | bool fixupNeedsRelaxation(const MCFixup &Fixup, |
| 165 | uint64_t Value, |
Eli Bendersky | 4d9ada0 | 2013-01-08 00:22:56 +0000 | [diff] [blame] | 166 | const MCRelaxableFragment *DF, |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 167 | const MCAsmLayout &Layout) const override { |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 168 | // FIXME. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 169 | llvm_unreachable("relaxInstruction() unimplemented"); |
Jim Grosbach | 25b63fa | 2011-12-06 00:47:03 +0000 | [diff] [blame] | 170 | } |
| 171 | |
Nirav Dave | 8603062 | 2016-07-11 14:23:53 +0000 | [diff] [blame] | 172 | void relaxInstruction(const MCInst &Inst, const MCSubtargetInfo &STI, |
| 173 | MCInst &Res) const override { |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 174 | // FIXME. |
Craig Topper | e55c556 | 2012-02-07 02:50:20 +0000 | [diff] [blame] | 175 | llvm_unreachable("relaxInstruction() unimplemented"); |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 176 | } |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 177 | |
Craig Topper | 0d3fa92 | 2014-04-29 07:57:37 +0000 | [diff] [blame] | 178 | bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override { |
Ulrich Weigand | d3ac7c0 | 2013-07-04 18:28:46 +0000 | [diff] [blame] | 179 | uint64_t NumNops = Count / 4; |
| 180 | for (uint64_t i = 0; i != NumNops; ++i) |
Jim Grosbach | 36e60e9 | 2015-06-04 22:24:41 +0000 | [diff] [blame] | 181 | OW->write32(0x60000000); |
Ulrich Weigand | d3ac7c0 | 2013-07-04 18:28:46 +0000 | [diff] [blame] | 182 | |
Benjamin Kramer | 97fbdd5 | 2015-04-17 11:12:43 +0000 | [diff] [blame] | 183 | OW->WriteZeros(Count % 4); |
David Majnemer | 7137420 | 2013-09-26 09:18:48 +0000 | [diff] [blame] | 184 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 185 | return true; |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 186 | } |
| 187 | |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 188 | unsigned getPointerSize() const { |
| 189 | StringRef Name = TheTarget.getName(); |
Bill Schmidt | 0a9170d | 2013-07-26 01:35:43 +0000 | [diff] [blame] | 190 | if (Name == "ppc64" || Name == "ppc64le") return 8; |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 191 | assert(Name == "ppc32" && "Unknown target name!"); |
| 192 | return 4; |
| 193 | } |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 194 | |
| 195 | bool isLittleEndian() const { |
| 196 | return IsLittleEndian; |
| 197 | } |
Daniel Dunbar | 7ee2181 | 2010-12-16 16:08:43 +0000 | [diff] [blame] | 198 | }; |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 199 | } // end anonymous namespace |
| 200 | |
| 201 | |
| 202 | // FIXME: This should be in a separate file. |
| 203 | namespace { |
| 204 | class DarwinPPCAsmBackend : public PPCAsmBackend { |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 205 | public: |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 206 | DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T, false) { } |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 207 | |
Lang Hames | 60fbc7c | 2017-10-10 16:28:07 +0000 | [diff] [blame] | 208 | std::unique_ptr<MCObjectWriter> |
| 209 | createObjectWriter(raw_pwrite_stream &OS) const override { |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 210 | bool is64 = getPointerSize() == 8; |
David Fang | b88cdf6 | 2013-08-08 20:14:40 +0000 | [diff] [blame] | 211 | return createPPCMachObjectWriter( |
| 212 | OS, |
| 213 | /*Is64Bit=*/is64, |
Charles Davis | 8bdfafd | 2013-09-01 04:28:48 +0000 | [diff] [blame] | 214 | (is64 ? MachO::CPU_TYPE_POWERPC64 : MachO::CPU_TYPE_POWERPC), |
| 215 | MachO::CPU_SUBTYPE_POWERPC_ALL); |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 216 | } |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 217 | }; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 218 | |
| 219 | class ELFPPCAsmBackend : public PPCAsmBackend { |
Rafael Espindola | 1ad4095 | 2011-12-21 17:00:36 +0000 | [diff] [blame] | 220 | uint8_t OSABI; |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 221 | public: |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 222 | ELFPPCAsmBackend(const Target &T, bool IsLittleEndian, uint8_t OSABI) : |
| 223 | PPCAsmBackend(T, IsLittleEndian), OSABI(OSABI) { } |
Jim Grosbach | e2d2981 | 2012-01-18 18:52:20 +0000 | [diff] [blame] | 224 | |
Lang Hames | 60fbc7c | 2017-10-10 16:28:07 +0000 | [diff] [blame] | 225 | std::unique_ptr<MCObjectWriter> |
| 226 | createObjectWriter(raw_pwrite_stream &OS) const override { |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 227 | bool is64 = getPointerSize() == 8; |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 228 | return createPPCELFObjectWriter(OS, is64, isLittleEndian(), OSABI); |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 229 | } |
Roman Divacky | 038c1a1 | 2011-08-02 15:51:38 +0000 | [diff] [blame] | 230 | }; |
| 231 | |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 232 | } // end anonymous namespace |
| 233 | |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 234 | MCAsmBackend *llvm::createPPCAsmBackend(const Target &T, |
Alex Bradbury | b22f751 | 2018-01-03 08:53:05 +0000 | [diff] [blame] | 235 | const MCSubtargetInfo &STI, |
Bill Wendling | 58e2d3d | 2013-09-09 02:37:14 +0000 | [diff] [blame] | 236 | const MCRegisterInfo &MRI, |
Joel Jones | 373d7d3 | 2016-07-25 17:18:28 +0000 | [diff] [blame] | 237 | const MCTargetOptions &Options) { |
Alex Bradbury | b22f751 | 2018-01-03 08:53:05 +0000 | [diff] [blame] | 238 | const Triple &TT = STI.getTargetTriple(); |
Daniel Sanders | 418caf5 | 2015-06-10 10:35:34 +0000 | [diff] [blame] | 239 | if (TT.isOSDarwin()) |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 240 | return new DarwinPPCAsmBackend(T); |
Daniel Dunbar | 2b9b0e3 | 2011-04-19 21:14:45 +0000 | [diff] [blame] | 241 | |
Daniel Sanders | 418caf5 | 2015-06-10 10:35:34 +0000 | [diff] [blame] | 242 | uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS()); |
Daniel Sanders | 50f1723 | 2015-09-15 16:17:27 +0000 | [diff] [blame] | 243 | bool IsLittleEndian = TT.getArch() == Triple::ppc64le; |
Ulrich Weigand | cae3a17 | 2014-03-24 18:16:09 +0000 | [diff] [blame] | 244 | return new ELFPPCAsmBackend(T, IsLittleEndian, OSABI); |
Chris Lattner | aac9fa7 | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 245 | } |