blob: de0ee4ebe9caf03c6a5dc334673fd647139d28c9 [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"
Daniel Dunbar36d76a82010-11-27 04:38:36 +000016#include "llvm/Object/MachOFormat.h"
Chris Lattnerb46443a2010-11-15 08:49:58 +000017#include "llvm/Target/TargetRegistry.h"
Chris Lattnerb46443a2010-11-15 08:49:58 +000018using namespace llvm;
19
20namespace {
21 class PPCAsmBackend : public TargetAsmBackend {
Rafael Espindolafd467972010-11-26 04:24:21 +000022 const Target &TheTarget;
Chris Lattnerb46443a2010-11-15 08:49:58 +000023 public:
Rafael Espindolafd467972010-11-26 04:24:21 +000024 PPCAsmBackend(const Target &T) : TargetAsmBackend(), TheTarget(T) {}
Chris Lattnerb46443a2010-11-15 08:49:58 +000025
26 bool MayNeedRelaxation(const MCInst &Inst) const {
27 // FIXME.
28 return false;
29 }
30
31 void RelaxInstruction(const MCInst &Inst, MCInst &Res) const {
32 // FIXME.
33 assert(0 && "RelaxInstruction() unimplemented");
34 }
35
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)
40 OW->Write8(0);
41 return true;
42 }
43
44 unsigned getPointerSize() const {
45 StringRef Name = TheTarget.getName();
46 if (Name == "ppc64") return 8;
47 assert(Name == "ppc32" && "Unknown target name!");
48 return 4;
49 }
50 };
51} // end anonymous namespace
52
53
54// FIXME: This should be in a separate file.
55namespace {
56 class DarwinPPCAsmBackend : public PPCAsmBackend {
57 MCMachOObjectFormat Format;
58 public:
59 DarwinPPCAsmBackend(const Target &T) : PPCAsmBackend(T) {
60 HasScatteredSymbols = true;
61 }
62
63 virtual const MCObjectFormat &getObjectFormat() const {
64 return Format;
65 }
66
67 void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
68 uint64_t Value) const {
69 assert(0 && "UNIMP");
70 }
71
Chris Lattnerb46443a2010-11-15 08:49:58 +000072 MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
73 bool is64 = getPointerSize() == 8;
74 return createMachObjectWriter(OS, /*Is64Bit=*/is64,
Daniel Dunbar36d76a82010-11-27 04:38:36 +000075 (is64 ? object::mach::CTM_PowerPC64 :
76 object::mach::CTM_PowerPC),
77 object::mach::CSPPC_ALL,
Chris Lattnerb46443a2010-11-15 08:49:58 +000078 /*IsLittleEndian=*/false);
79 }
80
81 virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
82 return false;
83 }
84 };
85} // end anonymous namespace
86
87
88
89
90TargetAsmBackend *llvm::createPPCAsmBackend(const Target &T,
91 const std::string &TT) {
92 switch (Triple(TT).getOS()) {
93 case Triple::Darwin:
94 return new DarwinPPCAsmBackend(T);
95 default:
96 return 0;
97 }
98}