1b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner//===-- PPCAsmBackend.cpp - PPC Assembler Backend -------------------------===// 2b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// 3b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// The LLVM Compiler Infrastructure 4b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// 5b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// This file is distributed under the University of Illinois Open Source 6b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// License. See LICENSE.TXT for details. 7b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// 8b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner//===----------------------------------------------------------------------===// 9b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner 10966aeb5788c242cfaca35c56c0ddc0ff778d4376Evan Cheng#include "MCTargetDesc/PPCMCTargetDesc.h" 11966aeb5788c242cfaca35c56c0ddc0ff778d4376Evan Cheng#include "MCTargetDesc/PPCFixupKinds.h" 1279aa3417eb6f58d668aadfedf075240a41d35a26Craig Topper#include "llvm/MC/MCAsmBackend.h" 13ebe69fe11e48d322045d5949c83283927a0d790bStephen Hines#include "llvm/MC/MCAssembler.h" 142c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky#include "llvm/MC/MCELFObjectWriter.h" 15f1d0f7781e766df878bec4e7977fa3204374f394Craig Topper#include "llvm/MC/MCFixupKindInfo.h" 16aa4b7dd13ba83152473950d7014a29686dc7eef6Daniel Dunbar#include "llvm/MC/MCMachObjectWriter.h" 17b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner#include "llvm/MC/MCObjectWriter.h" 18d04a8d4b33ff316ca4cf961e06c9e312eff8e64fChandler Carruth#include "llvm/MC/MCSectionMachO.h" 196948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar#include "llvm/MC/MCSymbolELF.h" 20ba8297ec08cdf7ae0c1e0c18ce07922e1f822643Jim Grosbach#include "llvm/MC/MCValue.h" 212c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky#include "llvm/Support/ELF.h" 222c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky#include "llvm/Support/ErrorHandling.h" 235510728d28bb1ee04abc32da3d21b7df12948053Charles Davis#include "llvm/Support/MachO.h" 243e74d6fdd248e20a280f1dff3da9a6c689c2c4c3Evan Cheng#include "llvm/Support/TargetRegistry.h" 25b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattnerusing namespace llvm; 26b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner 27b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigandstatic uint64_t adjustFixupValue(unsigned Kind, uint64_t Value) { 282c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky switch (Kind) { 292c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky default: 302c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky llvm_unreachable("Unknown fixup kind!"); 312c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky case FK_Data_1: 322c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky case FK_Data_2: 332c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky case FK_Data_4: 34aa71428378c1cb491ca60041d8ba7aa110bc963dAdhemerval Zanella case FK_Data_8: 35349c2787cf9e174c8aa955bf8e3b09a405b2aeceBill Schmidt case PPC::fixup_ppc_nofixup: 362c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky return Value; 372c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky case PPC::fixup_ppc_brcond14: 389679c47a07386cbf3547a0927609c7ee080b2aabUlrich Weigand case PPC::fixup_ppc_brcond14abs: 39aa71428378c1cb491ca60041d8ba7aa110bc963dAdhemerval Zanella return Value & 0xfffc; 402c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky case PPC::fixup_ppc_br24: 419679c47a07386cbf3547a0927609c7ee080b2aabUlrich Weigand case PPC::fixup_ppc_br24abs: 422c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky return Value & 0x3fffffc; 43e152eac63efa836cbb109d79e4307516fa16f1a6Ulrich Weigand case PPC::fixup_ppc_half16: 442c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky return Value & 0xffff; 45e152eac63efa836cbb109d79e4307516fa16f1a6Ulrich Weigand case PPC::fixup_ppc_half16ds: 4665e90c036472380bba160c349412f37128608e1cUlrich Weigand return Value & 0xfffc; 472c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky } 482c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky} 492c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky 50b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigandstatic unsigned getFixupKindNumBytes(unsigned Kind) { 51b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand switch (Kind) { 52b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand default: 53b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand llvm_unreachable("Unknown fixup kind!"); 54b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case FK_Data_1: 55b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand return 1; 56b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case FK_Data_2: 57e152eac63efa836cbb109d79e4307516fa16f1a6Ulrich Weigand case PPC::fixup_ppc_half16: 58e152eac63efa836cbb109d79e4307516fa16f1a6Ulrich Weigand case PPC::fixup_ppc_half16ds: 59b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand return 2; 60b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case FK_Data_4: 61b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case PPC::fixup_ppc_brcond14: 629679c47a07386cbf3547a0927609c7ee080b2aabUlrich Weigand case PPC::fixup_ppc_brcond14abs: 63b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case PPC::fixup_ppc_br24: 649679c47a07386cbf3547a0927609c7ee080b2aabUlrich Weigand case PPC::fixup_ppc_br24abs: 65b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand return 4; 66b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case FK_Data_8: 67b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand return 8; 68b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand case PPC::fixup_ppc_nofixup: 69b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand return 0; 70b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand } 71b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand} 72b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand 73b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattnernamespace { 74ae5abd595f5442767313a4c8a24008ad19323cebDaniel Dunbar 7578c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Chengclass PPCAsmBackend : public MCAsmBackend { 7636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const Target &TheTarget; 7736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool IsLittleEndian; 78297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbarpublic: 7936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines PPCAsmBackend(const Target &T, bool isLittle) : MCAsmBackend(), TheTarget(T), 8036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines IsLittleEndian(isLittle) {} 812761fc427082215c2affcc9d8db8491400bc9e5dDaniel Dunbar 82dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines unsigned getNumFixupKinds() const override { 83dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines return PPC::NumTargetFixupKinds; 84dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines } 85297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar 86dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const override { 8736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const static MCFixupKindInfo InfosBE[PPC::NumTargetFixupKinds] = { 88297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar // name offset bits flags 89297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar { "fixup_ppc_br24", 6, 24, MCFixupKindInfo::FKF_IsPCRel }, 90297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar { "fixup_ppc_brcond14", 16, 14, MCFixupKindInfo::FKF_IsPCRel }, 919679c47a07386cbf3547a0927609c7ee080b2aabUlrich Weigand { "fixup_ppc_br24abs", 6, 24, 0 }, 929679c47a07386cbf3547a0927609c7ee080b2aabUlrich Weigand { "fixup_ppc_brcond14abs", 16, 14, 0 }, 93e152eac63efa836cbb109d79e4307516fa16f1a6Ulrich Weigand { "fixup_ppc_half16", 0, 16, 0 }, 94e152eac63efa836cbb109d79e4307516fa16f1a6Ulrich Weigand { "fixup_ppc_half16ds", 0, 14, 0 }, 95349c2787cf9e174c8aa955bf8e3b09a405b2aeceBill Schmidt { "fixup_ppc_nofixup", 0, 0, 0 } 96297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar }; 9736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines const static MCFixupKindInfo InfosLE[PPC::NumTargetFixupKinds] = { 9836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines // name offset bits flags 9936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_br24", 2, 24, MCFixupKindInfo::FKF_IsPCRel }, 10036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_brcond14", 2, 14, MCFixupKindInfo::FKF_IsPCRel }, 10136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_br24abs", 2, 24, 0 }, 10236b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_brcond14abs", 2, 14, 0 }, 10336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_half16", 0, 16, 0 }, 10436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_half16ds", 2, 14, 0 }, 10536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines { "fixup_ppc_nofixup", 0, 0, 0 } 10636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines }; 107bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 108297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar if (Kind < FirstTargetFixupKind) 10978c10eeaa57d1c6c4b7781d3c0bcb0cfbbc43b5cEvan Cheng return MCAsmBackend::getFixupKindInfo(Kind); 110bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 111297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() && 112297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar "Invalid kind!"); 11336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return (IsLittleEndian? InfosLE : InfosBE)[Kind - FirstTargetFixupKind]; 114297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar } 115bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 116e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, 117dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines uint64_t Value, bool IsPCRel) const override { 118e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer Value = adjustFixupValue(Fixup.getKind(), Value); 119e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer if (!Value) return; // Doesn't change encoding. 120e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer 121e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer unsigned Offset = Fixup.getOffset(); 122b1cf8de85af10ff3d4ded6431be1cebd6133fd54Ulrich Weigand unsigned NumBytes = getFixupKindNumBytes(Fixup.getKind()); 123e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer 124e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer // For each byte of the fragment that the fixup touches, mask in the bits 125e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer // from the fixup value. The Value has been "split up" into the appropriate 126e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer // bitfields above. 12736b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines for (unsigned i = 0; i != NumBytes; ++i) { 12836b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines unsigned Idx = IsLittleEndian ? i : (NumBytes - 1 - i); 12936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines Data[Offset + i] |= uint8_t((Value >> (Idx * 8)) & 0xff); 13036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 131e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer } 132e8ca482c9734a556f3b66d44ba27e23a1d00b1e0Benjamin Kramer 13337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines void processFixupValue(const MCAssembler &Asm, const MCAsmLayout &Layout, 13437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines const MCFixup &Fixup, const MCFragment *DF, 13537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines const MCValue &Target, uint64_t &Value, 13637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines bool &IsResolved) override { 13737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines switch ((PPC::Fixups)Fixup.getKind()) { 13837ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines default: break; 13937ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case PPC::fixup_ppc_br24: 14037ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines case PPC::fixup_ppc_br24abs: 14137ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // If the target symbol has a local entry point we must not attempt 14237ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // to resolve the fixup directly. Emit a relocation and leave 14337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines // resolution of the final target address to the linker. 14437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines if (const MCSymbolRefExpr *A = Target.getSymA()) { 1456948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar if (const auto *S = dyn_cast<MCSymbolELF>(&A->getSymbol())) { 1466948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar // The "other" values are stored in the last 6 bits of the second 1476948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar // byte. The traditional defines for STO values assume the full byte 1486948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar // and thus the shift to pack it. 1496948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar unsigned Other = S->getOther() << 2; 1506948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar if ((Other & ELF::STO_PPC64_LOCAL_MASK) != 0) 1516948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar IsResolved = false; 1526948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar } 15337ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines } 15437ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines break; 15537ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines } 15637ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines } 15737ed9c199ca639565f6ce88105f9e39e898d82d0Stephen Hines 158dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines bool mayNeedRelaxation(const MCInst &Inst) const override { 159297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar // FIXME. 160297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar return false; 161297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar } 162370b78d795154899a22ca2b4674e890661ff1d59Jim Grosbach 163370b78d795154899a22ca2b4674e890661ff1d59Jim Grosbach bool fixupNeedsRelaxation(const MCFixup &Fixup, 164370b78d795154899a22ca2b4674e890661ff1d59Jim Grosbach uint64_t Value, 165251040bc18eedfa56d01fe92836e55cfd8c5d990Eli Bendersky const MCRelaxableFragment *DF, 166dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines const MCAsmLayout &Layout) const override { 167370b78d795154899a22ca2b4674e890661ff1d59Jim Grosbach // FIXME. 168bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("relaxInstruction() unimplemented"); 169370b78d795154899a22ca2b4674e890661ff1d59Jim Grosbach } 170370b78d795154899a22ca2b4674e890661ff1d59Jim Grosbach 171bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 172dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines void relaxInstruction(const MCInst &Inst, MCInst &Res) const override { 173297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar // FIXME. 174bc2198133a1836598b54b943420748e75d5dea94Craig Topper llvm_unreachable("relaxInstruction() unimplemented"); 175297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar } 176bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 177dce4a407a24b04eebc6a376f8e62b41aaa7b071fStephen Hines bool writeNopData(uint64_t Count, MCObjectWriter *OW) const override { 178972befb3f281f0f9ce08d7cf27b4e879327676b0Ulrich Weigand uint64_t NumNops = Count / 4; 179972befb3f281f0f9ce08d7cf27b4e879327676b0Ulrich Weigand for (uint64_t i = 0; i != NumNops; ++i) 1806948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar OW->write32(0x60000000); 181972befb3f281f0f9ce08d7cf27b4e879327676b0Ulrich Weigand 1826948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar OW->WriteZeros(Count % 4); 1839637da60835a60f8ccd8289d04c60b2dcd4b9b5aDavid Majnemer 184297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar return true; 185bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach } 186bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 187297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar unsigned getPointerSize() const { 188297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar StringRef Name = TheTarget.getName(); 189f38cc38fa647d4e72c053c39bbe0cdec1342535fBill Schmidt if (Name == "ppc64" || Name == "ppc64le") return 8; 190297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar assert(Name == "ppc32" && "Unknown target name!"); 191297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar return 4; 192297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar } 19336b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines 19436b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines bool isLittleEndian() const { 19536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return IsLittleEndian; 19636b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines } 197297ed28bf9c633db52ff31115d439a0133b00efbDaniel Dunbar}; 198b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner} // end anonymous namespace 199b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner 200b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner 201b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner// FIXME: This should be in a separate file. 202b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattnernamespace { 203b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner class DarwinPPCAsmBackend : public PPCAsmBackend { 204b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner public: 20536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T, false) { } 206bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 2070c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override { 208b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner bool is64 = getPointerSize() == 8; 209d4f9d05fde4b2cfd202a5852ec1ec3e960ef53edDavid Fang return createPPCMachObjectWriter( 210d4f9d05fde4b2cfd202a5852ec1ec3e960ef53edDavid Fang OS, 211d4f9d05fde4b2cfd202a5852ec1ec3e960ef53edDavid Fang /*Is64Bit=*/is64, 2125510728d28bb1ee04abc32da3d21b7df12948053Charles Davis (is64 ? MachO::CPU_TYPE_POWERPC64 : MachO::CPU_TYPE_POWERPC), 2135510728d28bb1ee04abc32da3d21b7df12948053Charles Davis MachO::CPU_SUBTYPE_POWERPC_ALL); 214b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner } 215b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner }; 2162c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky 2172c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky class ELFPPCAsmBackend : public PPCAsmBackend { 218dc9a8a378daf432d8dcfc178507afe149706f9a6Rafael Espindola uint8_t OSABI; 2192c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky public: 22036b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines ELFPPCAsmBackend(const Target &T, bool IsLittleEndian, uint8_t OSABI) : 22136b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines PPCAsmBackend(T, IsLittleEndian), OSABI(OSABI) { } 222bc3af9b618c061294c7df00f3313f9c5234b8450Jim Grosbach 2230c7f116bb6950ef819323d855415b2f2b0aad987Pirama Arumuga Nainar MCObjectWriter *createObjectWriter(raw_pwrite_stream &OS) const override { 2242c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky bool is64 = getPointerSize() == 8; 22536b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return createPPCELFObjectWriter(OS, is64, isLittleEndian(), OSABI); 2262c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky } 2272c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky }; 2282c0d69fad0e658117922f3d96d9b732bedf9fd47Roman Divacky 229b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner} // end anonymous namespace 230b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner 231c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill WendlingMCAsmBackend *llvm::createPPCAsmBackend(const Target &T, 232c3cee57f7d20f69a84fd88464ed8cf050e63c7adBill Wendling const MCRegisterInfo &MRI, 2336948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar const Triple &TT, StringRef CPU) { 2346948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar if (TT.isOSDarwin()) 235b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner return new DarwinPPCAsmBackend(T); 236912225e18559a73228099330a4c253fdccf9fa3dDaniel Dunbar 2376948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TT.getOS()); 2386948897e478cbd66626159776a8017b3c18579b9Pirama Arumuga Nainar bool IsLittleEndian = TT.getArch() == Triple::ppc64le; 23936b56886974eae4f9c5ebc96befd3e7bfe5de338Stephen Hines return new ELFPPCAsmBackend(T, IsLittleEndian, OSABI); 240b46443a686c29a1aa8f881c48c35d3f61a35f7acChris Lattner} 241