[Sparc] Add initial implementation of MC Code emitter for sparc.
[oota-llvm.git] / lib / Target / Sparc / MCTargetDesc / SparcAsmBackend.cpp
1 //===-- SparcAsmBackend.cpp - Sparc 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/MC/MCAsmBackend.h"
11 #include "MCTargetDesc/SparcMCTargetDesc.h"
12 #include "MCTargetDesc/SparcFixupKinds.h"
13 #include "llvm/MC/MCFixupKindInfo.h"
14 #include "llvm/MC/MCObjectWriter.h"
15 #include "llvm/Support/TargetRegistry.h"
16
17 using namespace llvm;
18
19 namespace {
20   class SparcAsmBackend : public MCAsmBackend {
21
22   public:
23     SparcAsmBackend(const Target &T) : MCAsmBackend() {}
24
25     unsigned getNumFixupKinds() const {
26       return Sparc::NumTargetFixupKinds;
27     }
28
29     const MCFixupKindInfo &getFixupKindInfo(MCFixupKind Kind) const {
30       const static MCFixupKindInfo Infos[Sparc::NumTargetFixupKinds] = {
31         // name                    offset bits  flags
32         { "fixup_sparc_call30",     0,     30,  MCFixupKindInfo::FKF_IsPCRel },
33         { "fixup_sparc_br22",       0,     22,  MCFixupKindInfo::FKF_IsPCRel },
34         { "fixup_sparc_br19",       0,     19,  MCFixupKindInfo::FKF_IsPCRel }
35       };
36
37       if (Kind < FirstTargetFixupKind)
38         return MCAsmBackend::getFixupKindInfo(Kind);
39
40       assert(unsigned(Kind - FirstTargetFixupKind) < getNumFixupKinds() &&
41              "Invalid kind!");
42       return Infos[Kind - FirstTargetFixupKind];
43     }
44
45     bool mayNeedRelaxation(const MCInst &Inst) const {
46       // FIXME.
47       return false;
48     }
49
50     /// fixupNeedsRelaxation - Target specific predicate for whether a given
51     /// fixup requires the associated instruction to be relaxed.
52     bool fixupNeedsRelaxation(const MCFixup &Fixup,
53                               uint64_t Value,
54                               const MCRelaxableFragment *DF,
55                               const MCAsmLayout &Layout) const {
56       // FIXME.
57       assert(0 && "fixupNeedsRelaxation() unimplemented");
58       return false;
59     }
60     void relaxInstruction(const MCInst &Inst, MCInst &Res) const {
61       // FIXME.
62       assert(0 && "relaxInstruction() unimplemented");
63     }
64
65     bool writeNopData(uint64_t Count, MCObjectWriter *OW) const {
66       // FIXME: Zero fill for now.
67       for (uint64_t i = 0; i != Count; ++i)
68         OW->Write8(0);
69       return true;
70     }
71   };
72
73   class ELFSparcAsmBackend : public SparcAsmBackend {
74   public:
75     ELFSparcAsmBackend(const Target &T, Triple::OSType OSType) :
76       SparcAsmBackend(T) { }
77
78     void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
79                     uint64_t Value) const {
80       assert(0 && "applyFixup not implemented yet");
81     }
82
83     MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
84       assert(0 && "Object Writer not implemented yet");
85       return 0;
86     }
87
88     virtual bool doesSectionRequireSymbols(const MCSection &Section) const {
89       return false;
90     }
91   };
92
93 } // end anonymous namespace
94
95
96 MCAsmBackend *llvm::createSparcAsmBackend(const Target &T,
97                                           const MCRegisterInfo &MRI,
98                                           StringRef TT,
99                                           StringRef CPU) {
100   return new ELFSparcAsmBackend(T, Triple(TT).getOS());
101 }