1 //===-- PPCAsmBackend.cpp - PPC Assembler Backend -------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/Target/TargetAsmBackend.h"
12 #include "PPCFixupKinds.h"
13 #include "llvm/MC/MCMachObjectWriter.h"
14 #include "llvm/MC/MCSectionMachO.h"
15 #include "llvm/MC/MCObjectWriter.h"
16 #include "llvm/Object/MachOFormat.h"
17 #include "llvm/Target/TargetRegistry.h"
21 class PPCMachObjectWriter : public MCMachObjectTargetWriter {
23 PPCMachObjectWriter(bool Is64Bit, uint32_t CPUType,
25 : MCMachObjectTargetWriter(Is64Bit, CPUType, CPUSubtype) {}
28 class PPCAsmBackend : public TargetAsmBackend {
29 const Target &TheTarget;
31 PPCAsmBackend(const Target &T) : TargetAsmBackend(), TheTarget(T) {}
33 unsigned getNumFixupKinds() const { return PPC::NumTargetFixupKinds; }
35 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
36 const static MCFixupKindInfo Infos[PPC::NumTargetFixupKinds] = {
37 // name offset bits flags
38 { "fixup_ppc_br24", 6, 24, MCFixupKindInfo::FKF_IsPCRel },
39 { "fixup_ppc_brcond14", 16, 14, MCFixupKindInfo::FKF_IsPCRel },
40 { "fixup_ppc_lo16", 16, 16, 0 },
41 { "fixup_ppc_ha16", 16, 16, 0 },
42 { "fixup_ppc_lo14", 16, 14, 0 }
45 if (Kind < FirstTargetFixupKind)
46 return TargetAsmBackend::getFixupKindInfo(Kind);
48 assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
50 return Infos[Kind - FirstTargetFixupKind];
53 bool MayNeedRelaxation(const MCInst &Inst) const {
58 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
60 assert(0 && "RelaxInstruction() unimplemented");
63 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
64 // FIXME: Zero fill for now. That's not right, but at least will get the
65 // section size right.
66 for (uint64_t i = 0; i != Count; ++i)
71 unsigned getPointerSize() const {
72 StringRef Name = TheTarget.getName();
73 if (Name == "ppc64") return 8;
74 assert(Name == "ppc32" && "Unknown target name!");
78 } // end anonymous namespace
81 // FIXME: This should be in a separate file.
83 class DarwinPPCAsmBackend : public PPCAsmBackend {
85 DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) { }
87 void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
88 uint64_t Value) const {
92 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
93 bool is64 = getPointerSize() == 8;
94 return createMachObjectWriter(new PPCMachObjectWriter(
96 (is64 ? object::mach::CTM_PowerPC64 :
97 object::mach::CTM_PowerPC),
98 object::mach::CSPPC_ALL),
99 OS, /*IsLittleEndian=*/false);
102 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
106 } // end anonymous namespace
111 TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T,
112 const std::string &TT) {
113 if (Triple(TT).isOSDarwin())
114 return new DarwinPPCAsmBackend(T);