Add MCSymbolCOFF class and use it to get and set the COFF type field.
authorPete Cooper <peter_cooper@apple.com>
Mon, 8 Jun 2015 17:17:12 +0000 (17:17 +0000)
committerPete Cooper <peter_cooper@apple.com>
Mon, 8 Jun 2015 17:17:12 +0000 (17:17 +0000)
Reviewed by Rafael EspĂ­ndola.

llvm-svn: 239312

llvm/include/llvm/MC/MCSymbolCOFF.h [new file with mode: 0644]
llvm/lib/MC/MCContext.cpp
llvm/lib/MC/WinCOFFObjectWriter.cpp
llvm/lib/MC/WinCOFFStreamer.cpp

diff --git a/llvm/include/llvm/MC/MCSymbolCOFF.h b/llvm/include/llvm/MC/MCSymbolCOFF.h
new file mode 100644 (file)
index 0000000..c7636e3
--- /dev/null
@@ -0,0 +1,33 @@
+//===- MCSymbolCOFF.h -  ----------------------------------------*- C++ -*-===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#ifndef LLVM_MC_MCSYMBOLCOFF_H
+#define LLVM_MC_MCSYMBOLCOFF_H
+
+#include "llvm/MC/MCSymbol.h"
+#include "llvm/Support/COFF.h"
+
+namespace llvm {
+class MCSymbolCOFF : public MCSymbol {
+
+public:
+  MCSymbolCOFF(const StringMapEntry<bool> *Name, bool isTemporary)
+      : MCSymbol(SymbolKindCOFF, Name, isTemporary) {}
+
+  uint16_t getType() const {
+    return (getFlags() & COFF::SF_TypeMask) >> COFF::SF_TypeShift;
+  }
+  void setType(uint16_t Type) const {
+    modifyFlags(Type << COFF::SF_TypeShift, COFF::SF_TypeMask);
+  }
+
+  static bool classof(const MCSymbol *S) { return S->isCOFF(); }
+};
+}
+
+#endif
index b44cbc0..6e67e69 100644 (file)
@@ -20,6 +20,7 @@
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
+#include "llvm/MC/MCSymbolCOFF.h"
 #include "llvm/MC/MCSymbolELF.h"
 #include "llvm/Support/ELF.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -159,9 +160,16 @@ MCSymbol *MCContext::getOrCreateLSDASymbol(StringRef FuncName) {
 
 MCSymbol *MCContext::createSymbolImpl(const StringMapEntry<bool> *Name,
                                       bool IsTemporary) {
-  bool IsELF = MOFI && MOFI->getObjectFileType() == MCObjectFileInfo::IsELF;
-  if (IsELF)
-    return new (*this) MCSymbolELF(Name, IsTemporary);
+  if (MOFI) {
+    switch (MOFI->getObjectFileType()) {
+    case MCObjectFileInfo::IsCOFF:
+      return new (*this) MCSymbolCOFF(Name, IsTemporary);
+    case MCObjectFileInfo::IsELF:
+      return new (*this) MCSymbolELF(Name, IsTemporary);
+    case MCObjectFileInfo::IsMachO:
+      return new (*this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
+    }
+  }
   return new (*this) MCSymbol(MCSymbol::SymbolKindUnset, Name, IsTemporary);
 }
 
index ccc791e..3aabce6 100644 (file)
@@ -25,7 +25,7 @@
 #include "llvm/MC/MCObjectWriter.h"
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSectionCOFF.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolCOFF.h"
 #include "llvm/MC/MCValue.h"
 #include "llvm/MC/StringTableBuilder.h"
 #include "llvm/Support/COFF.h"
@@ -428,8 +428,8 @@ void WinCOFFObjectWriter::DefineSymbol(const MCSymbol &Symbol,
     const MCSymbol *Base = Layout.getBaseSymbol(Symbol);
     coff_symbol->Data.Value = getSymbolValue(Symbol, Layout);
 
-    coff_symbol->Data.Type =
-        (Symbol.getFlags() & COFF::SF_TypeMask) >> COFF::SF_TypeShift;
+    const MCSymbolCOFF &SymbolCOFF = cast<MCSymbolCOFF>(Symbol);
+    coff_symbol->Data.Type = SymbolCOFF.getType();
     coff_symbol->Data.StorageClass =
         (Symbol.getFlags() & COFF::SF_ClassMask) >> COFF::SF_ClassShift;
 
@@ -675,8 +675,8 @@ bool WinCOFFObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
   // MS LINK expects to be able to replace all references to a function with a
   // thunk to implement their /INCREMENTAL feature.  Make sure we don't optimize
   // away any relocations to functions.
-  if ((((SymA.getFlags() & COFF::SF_TypeMask) >> COFF::SF_TypeShift) >>
-       COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
+  uint16_t Type = cast<MCSymbolCOFF>(SymA).getType();
+  if ((Type >> COFF::SCT_COMPLEX_TYPE_SHIFT) == COFF::IMAGE_SYM_DTYPE_FUNCTION)
     return false;
   return MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(Asm, SymA, FB,
                                                                 InSet, IsPCRel);
index c53a1a6..8f33c78 100644 (file)
@@ -22,7 +22,7 @@
 #include "llvm/MC/MCSection.h"
 #include "llvm/MC/MCSectionCOFF.h"
 #include "llvm/MC/MCStreamer.h"
-#include "llvm/MC/MCSymbol.h"
+#include "llvm/MC/MCSymbolCOFF.h"
 #include "llvm/MC/MCValue.h"
 #include "llvm/MC/MCWinCOFFStreamer.h"
 #include "llvm/Support/COFF.h"
@@ -149,7 +149,7 @@ void MCWinCOFFStreamer::EmitCOFFSymbolType(int Type) {
     FatalError("type value '" + Twine(Type) + "' out of range");
 
   getAssembler().registerSymbol(*CurSymbol);
-  CurSymbol->modifyFlags(Type << COFF::SF_TypeShift, COFF::SF_TypeMask);
+  cast<MCSymbolCOFF>(CurSymbol)->setType((uint16_t)Type);
 }
 
 void MCWinCOFFStreamer::EndCOFFSymbolDef() {