• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===-- AMDGPUAsmBackend.cpp - AMDGPU 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 "MCTargetDesc/AMDGPUMCTargetDesc.h"
11 #include "llvm/ADT/StringRef.h"
12 #include "llvm/MC/MCAsmBackend.h"
13 #include "llvm/MC/MCAssembler.h"
14 #include "llvm/MC/MCObjectWriter.h"
15 #include "llvm/MC/MCValue.h"
16 #include "llvm/Support/TargetRegistry.h"
17 
18 using namespace llvm;
19 
20 namespace {
21 
22 class AMDGPUMCObjectWriter : public MCObjectWriter {
23 public:
AMDGPUMCObjectWriter(raw_ostream & OS)24   AMDGPUMCObjectWriter(raw_ostream &OS) : MCObjectWriter(OS, true) { }
ExecutePostLayoutBinding(MCAssembler & Asm,const MCAsmLayout & Layout)25   virtual void ExecutePostLayoutBinding(MCAssembler &Asm,
26                                         const MCAsmLayout &Layout) {
27     //XXX: Implement if necessary.
28   }
RecordRelocation(const MCAssembler & Asm,const MCAsmLayout & Layout,const MCFragment * Fragment,const MCFixup & Fixup,MCValue Target,uint64_t & FixedValue)29   virtual void RecordRelocation(const MCAssembler &Asm,
30                                 const MCAsmLayout &Layout,
31                                 const MCFragment *Fragment,
32                                 const MCFixup &Fixup,
33                                 MCValue Target, uint64_t &FixedValue) {
34     assert(!"Not implemented");
35   }
36 
37   virtual void WriteObject(MCAssembler &Asm, const MCAsmLayout &Layout);
38 
39 };
40 
41 class AMDGPUAsmBackend : public MCAsmBackend {
42 public:
AMDGPUAsmBackend(const Target & T)43   AMDGPUAsmBackend(const Target &T)
44     : MCAsmBackend() {}
45 
46   virtual AMDGPUMCObjectWriter *createObjectWriter(raw_ostream &OS) const;
getNumFixupKinds() const47   virtual unsigned getNumFixupKinds() const { return 0; };
applyFixup(const MCFixup & Fixup,char * Data,unsigned DataSize,uint64_t Value) const48   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
49                           uint64_t Value) const { assert(!"Not implemented"); }
fixupNeedsRelaxation(const MCFixup & Fixup,uint64_t Value,const MCInstFragment * DF,const MCAsmLayout & Layout) const50   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
51                                     const MCInstFragment *DF,
52                                     const MCAsmLayout &Layout) const {
53     return false;
54   }
relaxInstruction(const MCInst & Inst,MCInst & Res) const55   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const {
56     assert(!"Not implemented");
57   }
mayNeedRelaxation(const MCInst & Inst) const58   virtual bool mayNeedRelaxation(const MCInst &Inst) const { return false; }
writeNopData(uint64_t Count,MCObjectWriter * OW) const59   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const {
60     return true;
61   }
62 };
63 
64 } //End anonymous namespace
65 
WriteObject(MCAssembler & Asm,const MCAsmLayout & Layout)66 void AMDGPUMCObjectWriter::WriteObject(MCAssembler &Asm,
67                                        const MCAsmLayout &Layout) {
68   for (MCAssembler::iterator I = Asm.begin(), E = Asm.end(); I != E; ++I) {
69     Asm.writeSectionData(I, Layout);
70   }
71 }
72 
createAMDGPUAsmBackend(const Target & T,StringRef TT)73 MCAsmBackend *llvm::createAMDGPUAsmBackend(const Target &T, StringRef TT) {
74   return new AMDGPUAsmBackend(T);
75 }
76 
createObjectWriter(raw_ostream & OS) const77 AMDGPUMCObjectWriter * AMDGPUAsmBackend::createObjectWriter(
78                                                         raw_ostream &OS) const {
79   return new AMDGPUMCObjectWriter(OS);
80 }
81