blob: 6a6177063f5ff92fe36645ac9d33f82595ec6272 [file] [log] [blame]
Chris Lattnerb46443a2010-11-15 08:49:58 +00001//===-- PPCAsmBackend.cpp - PPC Assembler Backend -------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#include "llvm/Target/TargetAsmBackend.h"
11#include "PPC.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"
18using namespace llvm;
19
20namespace {
21 class PPCAsmBackend : public TargetAsmBackend {
22 public:
23 PPCAsmBackend(const Target &T) : TargetAsmBackend(T) {}
24
25 bool MayNeedRelaxation(const MCInst &Inst) const {
26 // FIXME.
27 return false;
28 }
29
30 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
31 // FIXME.
32 assert(0 && "RelaxInstruction() unimplemented");
33 }
34
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)
39 OW->Write8(0);
40 return true;
41 }
42
43 unsigned getPointerSize() const {
44 StringRef Name = TheTarget.getName();
45 if (Name == "ppc64") return 8;
46 assert(Name == "ppc32" && "Unknown target name!");
47 return 4;
48 }
49 };
50} // end anonymous namespace
51
52
53// FIXME: This should be in a separate file.
54namespace {
55 class DarwinPPCAsmBackend : public PPCAsmBackend {
56 MCMachOObjectFormat Format;
57 public:
58 DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) {
59 HasScatteredSymbols = true;
60 }
61
62 virtual const MCObjectFormat &getObjectFormat() const {
63 return Format;
64 }
65
66 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
67 uint64_t Value) const {
68 assert(0 && "UNIMP");
69 }
70
Chris Lattnerb46443a2010-11-15 08:49:58 +000071 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
72 bool is64 = getPointerSize() == 8;
73 return createMachObjectWriter(OS, /*Is64Bit=*/is64,
74 is64 ? MachO::CPUTypePowerPC64 :
75 MachO::CPUTypePowerPC64,
76 MachO::CPUSubType_POWERPC_ALL,
77 /*IsLittleEndian=*/false);
78 }
79
80 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
81 return false;
82 }
83 };
84} // end anonymous namespace
85
86
87
88
89TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T,
90 const std::string &TT) {
91 switch (Triple(TT).getOS()) {
92 case Triple::Darwin:
93 return new DarwinPPCAsmBackend(T);
94 default:
95 return 0;
96 }
97}