diff options
author | Jush Lu <jush.msn@gmail.com> | 2011-03-09 19:39:16 +0800 |
---|---|---|
committer | Jush Lu <jush.msn@gmail.com> | 2011-03-09 19:39:16 +0800 |
commit | b5530586d68bd25831a6796b5d3199cb0769a35c (patch) | |
tree | fac4a03b53b6a64b0c00f433e4d8b3c9f2bc67cd /lib/Target/PowerPC/PPCAsmBackend.cpp | |
parent | b4e17c5bf4361bbdeced39aa071150d7fa9c3c10 (diff) | |
parent | d01f50f42ce60207ed6d27fb1778e456d83be06c (diff) | |
download | external_llvm-b5530586d68bd25831a6796b5d3199cb0769a35c.zip external_llvm-b5530586d68bd25831a6796b5d3199cb0769a35c.tar.gz external_llvm-b5530586d68bd25831a6796b5d3199cb0769a35c.tar.bz2 |
Merge upstream r127116
Diffstat (limited to 'lib/Target/PowerPC/PPCAsmBackend.cpp')
-rw-r--r-- | lib/Target/PowerPC/PPCAsmBackend.cpp | 119 |
1 files changed, 67 insertions, 52 deletions
diff --git a/lib/Target/PowerPC/PPCAsmBackend.cpp b/lib/Target/PowerPC/PPCAsmBackend.cpp index a6d1426..c4d4ac9 100644 --- a/lib/Target/PowerPC/PPCAsmBackend.cpp +++ b/lib/Target/PowerPC/PPCAsmBackend.cpp @@ -10,78 +10,93 @@ #include "llvm/Target/TargetAsmBackend.h" #include "PPC.h" #include "PPCFixupKinds.h" +#include "llvm/MC/MCMachObjectWriter.h" #include "llvm/MC/MCSectionMachO.h" -#include "llvm/MC/MCObjectFormat.h" #include "llvm/MC/MCObjectWriter.h" +#include "llvm/Object/MachOFormat.h" #include "llvm/Target/TargetRegistry.h" -#include "llvm/Support/MachO.h" using namespace llvm; namespace { - class PPCAsmBackend : public TargetAsmBackend { - public: - PPCAsmBackend(const Target &T) : TargetAsmBackend(T) {} - - bool MayNeedRelaxation(const MCInst &Inst) const { - // FIXME. - return false; - } - - void RelaxInstruction(const MCInst &Inst, MCInst &Res) const { - // FIXME. - assert(0 && "RelaxInstruction() unimplemented"); - } - - bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const { - // FIXME: Zero fill for now. That's not right, but at least will get the - // section size right. - for (uint64_t i = 0; i != Count; ++i) - OW->Write8(0); - return true; - } - - unsigned getPointerSize() const { - StringRef Name = TheTarget.getName(); - if (Name == "ppc64") return 8; - assert(Name == "ppc32" && "Unknown target name!"); - return 4; - } - }; +class PPCMachObjectWriter : public MCMachObjectTargetWriter { +public: + PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType, + uint32_t CPUSubtype) + : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {} +}; + +class PPCAsmBackend : public TargetAsmBackend { +const Target &TheTarget; +public: + PPCAsmBackend(const Target &T) : TargetAsmBackend(), TheTarget(T) {} + + unsigned getNumFixupKinds() const { return PPC::NumTargetFixupKinds; } + + const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const { + const static MCFixupKindInfo Infos[PPC::NumTargetFixupKinds] = { + // name offset bits flags + { "fixup_ppc_br24", 6, 24, MCFixupKindInfo::FKF_IsPCRel }, + { "fixup_ppc_brcond14", 16, 14, MCFixupKindInfo::FKF_IsPCRel }, + { "fixup_ppc_lo16", 16, 16, 0 }, + { "fixup_ppc_ha16", 16, 16, 0 }, + { "fixup_ppc_lo14", 16, 14, 0 } + }; + + if (Kind < FirstTargetFixupKind) + return TargetAsmBackend::getFixupKindInfo(Kind); + + assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() && + "Invalid kind!"); + return Infos[Kind - FirstTargetFixupKind]; + } + + bool MayNeedRelaxation(const MCInst &Inst) const { + // FIXME. + return false; + } + + void RelaxInstruction(const MCInst &Inst, MCInst &Res) const { + // FIXME. + assert(0 && "RelaxInstruction() unimplemented"); + } + + bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const { + // FIXME: Zero fill for now. That's not right, but at least will get the + // section size right. + for (uint64_t i = 0; i != Count; ++i) + OW->Write8(0); + return true; + } + + unsigned getPointerSize() const { + StringRef Name = TheTarget.getName(); + if (Name == "ppc64") return 8; + assert(Name == "ppc32" && "Unknown target name!"); + return 4; + } +}; } // end anonymous namespace // FIXME: This should be in a separate file. namespace { class DarwinPPCAsmBackend : public PPCAsmBackend { - MCMachOObjectFormat Format; public: - DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) { - HasScatteredSymbols = true; - } - - virtual const MCObjectFormat &getObjectFormat() const { - return Format; - } + DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) { } - void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF, + void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize, uint64_t Value) const { assert(0 && "UNIMP"); } - bool isVirtualSection(const MCSection &Section) const { - const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section); - return (SMO.getType() == MCSectionMachO::S_ZEROFILL || - SMO.getType() == MCSectionMachO::S_GB_ZEROFILL || - SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL); - } - MCObjectWriter *createObjectWriter(raw_ostream &OS) const { bool is64 = getPointerSize() == 8; - return createMachObjectWriter(OS, /*Is64Bit=*/is64, - is64 ? MachO::CPUTypePowerPC64 : - MachO::CPUTypePowerPC64, - MachO::CPUSubType_POWERPC_ALL, - /*IsLittleEndian=*/false); + return createMachObjectWriter(new PPCMachObjectWriter( + /*Is64Bit=*/is64, + (is64 ? object::mach::CTM_PowerPC64 : + object::mach::CTM_PowerPC), + object::mach::CSPPC_ALL), + OS, /*IsLittleEndian=*/false); } virtual bool doesSectionRequireSymbols(const MCSection &Section) const { |