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/MCObjectFormat.h"
16 #include "llvm/MC/MCObjectWriter.h"
17 #include "llvm/Object/MachOFormat.h"
18 #include "llvm/Target/TargetRegistry.h"
22 class PPCMachObjectWriter : public MCMachObjectTargetWriter {
25 class PPCAsmBackend : public TargetAsmBackend {
26 const Target &TheTarget;
28 PPCAsmBackend(const Target &T) : TargetAsmBackend(), TheTarget(T) {}
30 unsigned getNumFixupKinds() const { return PPC::NumTargetFixupKinds; }
32 const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
33 const static MCFixupKindInfo Infos[PPC::NumTargetFixupKinds] = {
34 // name offset bits flags
35 { "fixup_ppc_br24", 6, 24, MCFixupKindInfo::FKF_IsPCRel },
36 { "fixup_ppc_brcond14", 16, 14, MCFixupKindInfo::FKF_IsPCRel },
37 { "fixup_ppc_lo16", 16, 16, 0 },
38 { "fixup_ppc_ha16", 16, 16, 0 },
39 { "fixup_ppc_lo14", 16, 14, 0 }
42 if (Kind < FirstTargetFixupKind)
43 return TargetAsmBackend::getFixupKindInfo(Kind);
45 assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
47 return Infos[Kind - FirstTargetFixupKind];
50 bool MayNeedRelaxation(const MCInst &Inst) const {
55 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
57 assert(0 && "RelaxInstruction() unimplemented");
60 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
61 // FIXME: Zero fill for now. That's not right, but at least will get the
62 // section size right.
63 for (uint64_t i = 0; i != Count; ++i)
68 unsigned getPointerSize() const {
69 StringRef Name = TheTarget.getName();
70 if (Name == "ppc64") return 8;
71 assert(Name == "ppc32" && "Unknown target name!");
75 } // end anonymous namespace
78 // FIXME: This should be in a separate file.
80 class DarwinPPCAsmBackend : public PPCAsmBackend {
81 MCMachOObjectFormat Format;
83 DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) {
84 HasScatteredSymbols = true;
87 virtual const MCObjectFormat &getObjectFormat() const {
91 void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
92 uint64_t Value) const {
96 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
97 bool is64 = getPointerSize() == 8;
98 return createMachObjectWriter(new PPCMachObjectWriter,
100 (is64 ? object::mach::CTM_PowerPC64 :
101 object::mach::CTM_PowerPC),
102 object::mach::CSPPC_ALL,
103 /*IsLittleEndian=*/false);
106 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
110 } // end anonymous namespace
115 TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T,
116 const std::string &TT) {
117 switch (Triple(TT).getOS()) {
119 return new DarwinPPCAsmBackend(T);