MC: Use MachO::SectionType for MCSectionMachO::getType's return type
[oota-llvm.git] / lib / MC / MCSectionMachO.cpp
index 43268e63bbd2925612d75eb930db8d6e66ccaaab..29829463c18ff18cc09c015685979e52fc0e0a2e 100644 (file)
@@ -10,6 +10,7 @@
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCContext.h"
 #include "llvm/Support/raw_ostream.h"
+#include <cctype>
 using namespace llvm;
 
 /// SectionTypeDescriptors - These are strings that describe the various section
@@ -17,7 +18,7 @@ using namespace llvm;
 /// section type list.
 static const struct {
   const char *AssemblerName, *EnumName;
-} SectionTypeDescriptors[MCSectionMachO::LAST_KNOWN_SECTION_TYPE+1] = {
+} SectionTypeDescriptors[MachO::LAST_KNOWN_SECTION_TYPE+1] = {
   { "regular",                  "S_REGULAR" },                    // 0x00
   { 0,                          "S_ZEROFILL" },                   // 0x01
   { "cstring_literals",         "S_CSTRING_LITERALS" },           // 0x02
@@ -54,7 +55,7 @@ static const struct {
   const char *AssemblerName, *EnumName;
 } SectionAttrDescriptors[] = {
 #define ENTRY(ASMNAME, ENUM) \
-  { MCSectionMachO::ENUM, ASMNAME, #ENUM },
+  { MachO::ENUM, ASMNAME, #ENUM },
 ENTRY("pure_instructions",   S_ATTR_PURE_INSTRUCTIONS)
 ENTRY("no_toc",              S_ATTR_NO_TOC)
 ENTRY("strip_static_syms",   S_ATTR_STRIP_STATIC_SYMS)
@@ -67,7 +68,7 @@ ENTRY(0 /*FIXME*/,           S_ATTR_EXT_RELOC)
 ENTRY(0 /*FIXME*/,           S_ATTR_LOC_RELOC)
 #undef ENTRY
   { 0, "none", 0 }, // used if section has no attributes but has a stub size
-#define AttrFlagEnd 0xffffffff // non legal value, multiple attribute bits set
+#define AttrFlagEnd 0xffffffff // non-legal value, multiple attribute bits set
   { AttrFlagEnd, 0, 0 }
 };
 
@@ -90,7 +91,8 @@ MCSectionMachO::MCSectionMachO(StringRef Segment, StringRef Section,
 }
 
 void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI,
-                                          raw_ostream &OS) const {
+                                          raw_ostream &OS,
+                                          const MCExpr *Subsection) const {
   OS << "\t.section\t" << getSegmentName() << ',' << getSectionName();
 
   // Get the section type and attributes.
@@ -100,19 +102,21 @@ void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI,
     return;
   }
 
-  OS << ',';
-
-  unsigned SectionType = TAA & MCSectionMachO::SECTION_TYPE;
-  assert(SectionType <= MCSectionMachO::LAST_KNOWN_SECTION_TYPE &&
+  MachO::SectionType SectionType = getType();
+  assert(SectionType <= MachO::LAST_KNOWN_SECTION_TYPE &&
          "Invalid SectionType specified!");
 
-  if (SectionTypeDescriptors[SectionType].AssemblerName)
+  if (SectionTypeDescriptors[SectionType].AssemblerName) {
+    OS << ',';
     OS << SectionTypeDescriptors[SectionType].AssemblerName;
-  else
-    OS << "<<" << SectionTypeDescriptors[SectionType].EnumName << ">>";
+  } else {
+    // If we have no name for the attribute, stop here.
+    OS << '\n';
+    return;
+  }
 
   // If we don't have any attributes, we're done.
-  unsigned SectionAttrs = TAA & MCSectionMachO::SECTION_ATTRIBUTES;
+  unsigned SectionAttrs = TAA & MachO::SECTION_ATTRIBUTES;
   if (SectionAttrs == 0) {
     // If we have a S_SYMBOL_STUBS size specified, print it along with 'none' as
     // the attribute specifier.
@@ -124,7 +128,9 @@ void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI,
 
   // Check each attribute to see if we have it.
   char Separator = ',';
-  for (unsigned i = 0; SectionAttrDescriptors[i].AttrFlag; ++i) {
+  for (unsigned i = 0;
+       SectionAttrs != 0 && SectionAttrDescriptors[i].AttrFlag;
+       ++i) {
     // Check to see if we have this attribute.
     if ((SectionAttrDescriptors[i].AttrFlag & SectionAttrs) == 0)
       continue;
@@ -149,20 +155,20 @@ void MCSectionMachO::PrintSwitchToSection(const MCAsmInfo &MAI,
 }
 
 bool MCSectionMachO::UseCodeAlign() const {
-  return hasAttribute(MCSectionMachO::S_ATTR_PURE_INSTRUCTIONS);
+  return hasAttribute(MachO::S_ATTR_PURE_INSTRUCTIONS);
 }
 
 bool MCSectionMachO::isVirtualSection() const {
-  return (getType() == MCSectionMachO::S_ZEROFILL ||
-          getType() == MCSectionMachO::S_GB_ZEROFILL ||
-          getType() == MCSectionMachO::S_THREAD_LOCAL_ZEROFILL);
+  return (getType() == MachO::S_ZEROFILL ||
+          getType() == MachO::S_GB_ZEROFILL ||
+          getType() == MachO::S_THREAD_LOCAL_ZEROFILL);
 }
 
 /// StripSpaces - This removes leading and trailing spaces from the StringRef.
 static void StripSpaces(StringRef &Str) {
-  while (!Str.empty() && isspace(Str[0]))
+  while (!Str.empty() && isspace(static_cast<unsigned char>(Str[0])))
     Str = Str.substr(1);
-  while (!Str.empty() && isspace(Str.back()))
+  while (!Str.empty() && isspace(static_cast<unsigned char>(Str.back())))
     Str = Str.substr(0, Str.size()-1);
 }
 
@@ -175,7 +181,9 @@ std::string MCSectionMachO::ParseSectionSpecifier(StringRef Spec,        // In.
                                                   StringRef &Segment,    // Out.
                                                   StringRef &Section,    // Out.
                                                   unsigned  &TAA,        // Out.
+                                                  bool      &TAAParsed,  // Out.
                                                   unsigned  &StubSize) { // Out.
+  TAAParsed = false;
   // Find the first comma.
   std::pair<StringRef, StringRef> Comma = Spec.split(',');
 
@@ -220,22 +228,23 @@ std::string MCSectionMachO::ParseSectionSpecifier(StringRef Spec,        // In.
 
   // Figure out which section type it is.
   unsigned TypeID;
-  for (TypeID = 0; TypeID !=MCSectionMachO::LAST_KNOWN_SECTION_TYPE+1; ++TypeID)
+  for (TypeID = 0; TypeID != MachO::LAST_KNOWN_SECTION_TYPE + 1; ++TypeID)
     if (SectionTypeDescriptors[TypeID].AssemblerName &&
         SectionType == SectionTypeDescriptors[TypeID].AssemblerName)
       break;
 
   // If we didn't find the section type, reject it.
-  if (TypeID > MCSectionMachO::LAST_KNOWN_SECTION_TYPE)
+  if (TypeID > MachO::LAST_KNOWN_SECTION_TYPE)
     return "mach-o section specifier uses an unknown section type";
 
   // Remember the TypeID.
   TAA = TypeID;
+  TAAParsed = true;
 
   // If we have no comma after the section type, there are no attributes.
   if (Comma.second.empty()) {
     // S_SYMBOL_STUBS always require a symbol stub size specifier.
-    if (TAA == MCSectionMachO::S_SYMBOL_STUBS)
+    if (TAA == MachO::S_SYMBOL_STUBS)
       return "mach-o section specifier of type 'symbol_stubs' requires a size "
              "specifier";
     return "";
@@ -272,14 +281,14 @@ std::string MCSectionMachO::ParseSectionSpecifier(StringRef Spec,        // In.
   // Okay, we've parsed the section attributes, see if we have a stub size spec.
   if (Comma.second.empty()) {
     // S_SYMBOL_STUBS always require a symbol stub size specifier.
-    if (TAA == MCSectionMachO::S_SYMBOL_STUBS)
+    if (TAA == MachO::S_SYMBOL_STUBS)
       return "mach-o section specifier of type 'symbol_stubs' requires a size "
       "specifier";
     return "";
   }
 
   // If we have a stub size spec, we must have a sectiontype of S_SYMBOL_STUBS.
-  if ((TAA & MCSectionMachO::SECTION_TYPE) != MCSectionMachO::S_SYMBOL_STUBS)
+  if ((TAA & MachO::SECTION_TYPE) != MachO::S_SYMBOL_STUBS)
     return "mach-o section specifier cannot have a stub size specified because "
            "it does not have type 'symbol_stubs'";