Chris Lattner | b46443a | 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 | |
| 10 | #include "llvm/Target/TargetAsmBackend.h" |
| 11 | #include "PPC.h" |
| 12 | #include "PPCFixupKinds.h" |
| 13 | #include "llvm/MC/MCSectionMachO.h" |
| 14 | #include "llvm/MC/MCObjectFormat.h" |
| 15 | #include "llvm/MC/MCObjectWriter.h" |
Daniel Dunbar | 36d76a8 | 2010-11-27 04:38:36 +0000 | [diff] [blame^] | 16 | #include "llvm/Object/MachOFormat.h" |
Chris Lattner | b46443a | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 17 | #include "llvm/Target/TargetRegistry.h" |
Chris Lattner | b46443a | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 18 | using namespace llvm; |
| 19 | |
| 20 | namespace { |
| 21 | class PPCAsmBackend : public TargetAsmBackend { |
Rafael Espindola | fd46797 | 2010-11-26 04:24:21 +0000 | [diff] [blame] | 22 | const Target &TheTarget; |
Chris Lattner | b46443a | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 23 | public: |
Rafael Espindola | fd46797 | 2010-11-26 04:24:21 +0000 | [diff] [blame] | 24 | PPCAsmBackend(const Target &T) : TargetAsmBackend(), TheTarget(T) {} |
Chris Lattner | b46443a | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 25 | |
| 26 | bool MayNeedRelaxation(const MCInst &Inst) const { |
| 27 | // FIXME. |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | void RelaxInstruction(const MCInst &Inst, MCInst &Res) const { |
| 32 | // FIXME. |
| 33 | assert(0 && "RelaxInstruction() unimplemented"); |
| 34 | } |
| 35 | |
| 36 | bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const { |
| 37 | // FIXME: Zero fill for now. That's not right, but at least will get the |
| 38 | // section size right. |
| 39 | for (uint64_t i = 0; i != Count; ++i) |
| 40 | OW->Write8(0); |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | unsigned getPointerSize() const { |
| 45 | StringRef Name = TheTarget.getName(); |
| 46 | if (Name == "ppc64") return 8; |
| 47 | assert(Name == "ppc32" && "Unknown target name!"); |
| 48 | return 4; |
| 49 | } |
| 50 | }; |
| 51 | } // end anonymous namespace |
| 52 | |
| 53 | |
| 54 | // FIXME: This should be in a separate file. |
| 55 | namespace { |
| 56 | class DarwinPPCAsmBackend : public PPCAsmBackend { |
| 57 | MCMachOObjectFormat Format; |
| 58 | public: |
| 59 | DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) { |
| 60 | HasScatteredSymbols = true; |
| 61 | } |
| 62 | |
| 63 | virtual const MCObjectFormat &getObjectFormat() const { |
| 64 | return Format; |
| 65 | } |
| 66 | |
| 67 | void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF, |
| 68 | uint64_t Value) const { |
| 69 | assert(0 && "UNIMP"); |
| 70 | } |
| 71 | |
Chris Lattner | b46443a | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 72 | MCObjectWriter *createObjectWriter(raw_ostream &OS) const { |
| 73 | bool is64 = getPointerSize() == 8; |
| 74 | return createMachObjectWriter(OS, /*Is64Bit=*/is64, |
Daniel Dunbar | 36d76a8 | 2010-11-27 04:38:36 +0000 | [diff] [blame^] | 75 | (is64 ? object::mach::CTM_PowerPC64 : |
| 76 | object::mach::CTM_PowerPC), |
| 77 | object::mach::CSPPC_ALL, |
Chris Lattner | b46443a | 2010-11-15 08:49:58 +0000 | [diff] [blame] | 78 | /*IsLittleEndian=*/false); |
| 79 | } |
| 80 | |
| 81 | virtual bool doesSectionRequireSymbols(const MCSection &Section) const { |
| 82 | return false; |
| 83 | } |
| 84 | }; |
| 85 | } // end anonymous namespace |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T, |
| 91 | const std::string &TT) { |
| 92 | switch (Triple(TT).getOS()) { |
| 93 | case Triple::Darwin: |
| 94 | return new DarwinPPCAsmBackend(T); |
| 95 | default: |
| 96 | return 0; |
| 97 | } |
| 98 | } |