Home | History | Annotate | Download | only in MCTargetDesc
      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:
     24   AMDGPUMCObjectWriter(raw_ostream &OS) : MCObjectWriter(OS, true) { }
     25   virtual void ExecutePostLayoutBinding(MCAssembler &Asm,
     26                                         const MCAsmLayout &Layout) {
     27     //XXX: Implement if necessary.
     28   }
     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:
     43   AMDGPUAsmBackend(const Target &T)
     44     : MCAsmBackend() {}
     45 
     46   virtual AMDGPUMCObjectWriter *createObjectWriter(raw_ostream &OS) const;
     47   virtual unsigned getNumFixupKinds() const { return 0; };
     48   virtual void applyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
     49                           uint64_t Value) const { assert(!"Not implemented"); }
     50   virtual bool fixupNeedsRelaxation(const MCFixup &Fixup, uint64_t Value,
     51                                     const MCInstFragment *DF,
     52                                     const MCAsmLayout &Layout) const {
     53     return false;
     54   }
     55   virtual void relaxInstruction(const MCInst &Inst, MCInst &Res) const {
     56     assert(!"Not implemented");
     57   }
     58   virtual bool mayNeedRelaxation(const MCInst &Inst) const { return false; }
     59   virtual bool writeNopData(uint64_t Count, MCObjectWriter *OW) const {
     60     return true;
     61   }
     62 };
     63 
     64 } //End anonymous namespace
     65 
     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 
     73 MCAsmBackend *llvm::createAMDGPUAsmBackend(const Target &T, StringRef TT) {
     74   return new AMDGPUAsmBackend(T);
     75 }
     76 
     77 AMDGPUMCObjectWriter * AMDGPUAsmBackend::createObjectWriter(
     78                                                         raw_ostream &OS) const {
     79   return new AMDGPUMCObjectWriter(OS);
     80 }
     81