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/Object/MachOFormat.h"
17 #include "llvm/Target/TargetRegistry.h"
21 class PPCAsmBackend : public TargetAsmBackend {
22 const Target &TheTarget;
24 PPCAsmBackend(const Target &T) : TargetAsmBackend(), TheTarget(T) {}
26 bool MayNeedRelaxation(const MCInst &Inst) const {
31 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
33 assert(0 && "RelaxInstruction() unimplemented");
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)
44 unsigned getPointerSize() const {
45 StringRef Name = TheTarget.getName();
46 if (Name == "ppc64") return 8;
47 assert(Name == "ppc32" && "Unknown target name!");
51 } // end anonymous namespace
54 // FIXME: This should be in a separate file.
56 class DarwinPPCAsmBackend : public PPCAsmBackend {
57 MCMachOObjectFormat Format;
59 DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) {
60 HasScatteredSymbols = true;
63 virtual const MCObjectFormat &getObjectFormat() const {
67 void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
68 uint64_t Value) const {
72 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
73 bool is64 = getPointerSize() == 8;
74 return createMachObjectWriter(OS, /*Is64Bit=*/is64,
75 (is64 ? object::mach::CTM_PowerPC64 :
76 object::mach::CTM_PowerPC),
77 object::mach::CSPPC_ALL,
78 /*IsLittleEndian=*/false);
81 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
85 } // end anonymous namespace
90 TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T,
91 const std::string &TT) {
92 switch (Triple(TT).getOS()) {
94 return new DarwinPPCAsmBackend(T);