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/MCSectionMachO.h"
14 #include "llvm/MC/MCObjectFormat.h"
15 #include "llvm/MC/MCObjectWriter.h"
16 #include "llvm/Target/TargetRegistry.h"
17 #include "llvm/Support/MachO.h"
21 class PPCAsmBackend : public TargetAsmBackend {
23 PPCAsmBackend(const Target &T) : TargetAsmBackend(T) {}
25 bool MayNeedRelaxation(const MCInst &Inst) const {
30 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
32 assert(0 && "RelaxInstruction() unimplemented");
35 bool WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
36 // FIXME: Zero fill for now. That's not right, but at least will get the
37 // section size right.
38 for (uint64_t i = 0; i != Count; ++i)
43 unsigned getPointerSize() const {
44 StringRef Name = TheTarget.getName();
45 if (Name == "ppc64") return 8;
46 assert(Name == "ppc32" && "Unknown target name!");
50 } // end anonymous namespace
53 // FIXME: This should be in a separate file.
55 class DarwinPPCAsmBackend : public PPCAsmBackend {
56 MCMachOObjectFormat Format;
58 DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) {
59 HasScatteredSymbols = true;
62 virtual const MCObjectFormat &getObjectFormat() const {
66 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
67 uint64_t Value) const {
71 bool isVirtualSection(const MCSection &Section) const {
72 const MCSectionMachO &SMO = static_cast<const MCSectionMachO&>(Section);
73 return (SMO.getType() == MCSectionMachO::S_ZEROFILL ||
74 SMO.getType() == MCSectionMachO::S_GB_ZEROFILL ||
75 SMO.getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
78 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
79 bool is64 = getPointerSize() == 8;
80 return createMachObjectWriter(OS, /*Is64Bit=*/is64,
81 is64 ? MachO::CPUTypePowerPC64 :
82 MachO::CPUTypePowerPC64,
83 MachO::CPUSubType_POWERPC_ALL,
84 /*IsLittleEndian=*/false);
87 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
91 } // end anonymous namespace
96 TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T,
97 const std::string &TT) {
98 switch (Triple(TT).getOS()) {
100 return new DarwinPPCAsmBackend(T);