ADT/Triple: Move a variety of clients to using isOSDarwin() and isOSWindows()
[oota-llvm.git] / lib / Target / MBlaze / MBlazeAsmBackend.cpp
index 56c04199cff223889b43f2f6894a8ad378291b3f..08f14c3659571306b9f203e78760539f7e37f4dd 100644 (file)
@@ -13,9 +13,9 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/MC/MCAssembler.h"
 #include "llvm/MC/MCAsmLayout.h"
+#include "llvm/MC/MCELFObjectWriter.h"
 #include "llvm/MC/MCELFSymbolFlags.h"
 #include "llvm/MC/MCExpr.h"
-#include "llvm/MC/MCObjectFormat.h"
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCSectionMachO.h"
@@ -41,12 +41,23 @@ static unsigned getFixupKindSize(unsigned Kind) {
 
 
 namespace {
+class MBlazeELFObjectWriter : public MCELFObjectTargetWriter {
+public:
+  MBlazeELFObjectWriter(Triple::OSType OSType)
+    : MCELFObjectTargetWriter(/*is64Bit*/ false, OSType, ELF::EM_MBLAZE,
+                              /*HasRelocationAddend*/ true) {}
+};
+
 class MBlazeAsmBackend : public TargetAsmBackend {
 public:
   MBlazeAsmBackend(const Target &T)
     : TargetAsmBackend() {
   }
 
+  unsigned getNumFixupKinds() const {
+    return 2;
+  }
+
   bool MayNeedRelaxation(const MCInst &Inst) const;
 
   void RelaxInstruction(const MCInst &Inst, MCInst &Res) const;
@@ -61,7 +72,7 @@ public:
 static unsigned getRelaxedOpcode(unsigned Op) {
     switch (Op) {
     default:            return Op;
-    case MBlaze::ADDI:  return MBlaze::ADDI32;
+    case MBlaze::ADDIK: return MBlaze::ADDIK32;
     case MBlaze::ORI:   return MBlaze::ORI32;
     case MBlaze::BRLID: return MBlaze::BRLID32;
     }
@@ -96,39 +107,28 @@ bool MBlazeAsmBackend::WriteNopData(uint64_t Count, MCObjectWriter *OW) const {
 
 namespace {
 class ELFMBlazeAsmBackend : public MBlazeAsmBackend {
-  MCELFObjectFormat Format;
-
 public:
   Triple::OSType OSType;
   ELFMBlazeAsmBackend(const Target &T, Triple::OSType _OSType)
-    : MBlazeAsmBackend(T), OSType(_OSType) {
-    HasScatteredSymbols = true;
-  }
+    : MBlazeAsmBackend(T), OSType(_OSType) { }
 
-  virtual const MCObjectFormat &getObjectFormat() const {
-    return Format;
-  }
-
-
-  void ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
+  void ApplyFixup(const MCFixup &Fixup, char *Data, unsigned DataSize,
                   uint64_t Value) const;
 
   MCObjectWriter *createObjectWriter(raw_ostream &OS) const {
-    return createELFObjectWriter(OS,/*Is64Bit=*/false,
-                                 OSType, ELF::EM_MBLAZE,
-                                 /*IsLittleEndian=*/false,
-                                 /*HasRelocationAddend=*/true);
+    return createELFObjectWriter(new MBlazeELFObjectWriter(OSType), OS,
+                                 /*IsLittleEndian*/ false);
   }
 };
 
-void ELFMBlazeAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
-                                     uint64_t Value) const {
+void ELFMBlazeAsmBackend::ApplyFixup(const MCFixup &Fixup, char *Data,
+                                     unsigned DataSize, uint64_t Value) const {
   unsigned Size = getFixupKindSize(Fixup.getKind());
 
-  assert(Fixup.getOffset() + Size <= DF.getContents().size() &&
+  assert(Fixup.getOffset() + Size <= DataSize &&
          "Invalid fixup offset!");
 
-  char *data = DF.getContents().data() + Fixup.getOffset();
+  char *data = Data + Fixup.getOffset();
   switch (Size) {
   default: llvm_unreachable("Cannot fixup unknown value.");
   case 1:  llvm_unreachable("Cannot fixup 1 byte value.");
@@ -150,14 +150,13 @@ void ELFMBlazeAsmBackend::ApplyFixup(const MCFixup &Fixup, MCDataFragment &DF,
 
 TargetAsmBackend *llvm::createMBlazeAsmBackend(const Target &T,
                                             const std::string &TT) {
-  switch (Triple(TT).getOS()) {
-  case Triple::Darwin:
+  Triple TheTriple(TT);
+
+  if (TheTriple.isOSDarwin())
     assert(0 && "Mac not supported on MBlaze");
-  case Triple::MinGW32:
-  case Triple::Cygwin:
-  case Triple::Win32:
+
+  if (TheTriple.isOSWindows())
     assert(0 && "Windows not supported on MBlaze");
-  default:
-    return new ELFMBlazeAsmBackend(T, Triple(TT).getOS());
-  }
+
+  return new ELFMBlazeAsmBackend(T, TheTriple.getOS());
 }