Use the new script to sort the includes of every file under lib.
[oota-llvm.git] / lib / MC / MCParser / DarwinAsmParser.cpp
index 7d8639ea4d81f6f9a17954d6ffe039b7d8d8531e..20c949dbdaaa86cd8002afa3f6add3d65418695e 100644 (file)
@@ -8,14 +8,15 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/MC/MCParser/MCAsmParserExtension.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
 #include "llvm/MC/MCContext.h"
+#include "llvm/MC/MCParser/MCAsmLexer.h"
+#include "llvm/MC/MCParser/MCAsmParser.h"
 #include "llvm/MC/MCSectionMachO.h"
 #include "llvm/MC/MCStreamer.h"
 #include "llvm/MC/MCSymbol.h"
-#include "llvm/MC/MCParser/MCAsmLexer.h"
-#include "llvm/MC/MCParser/MCAsmParser.h"
-#include "llvm/ADT/StringRef.h"
-#include "llvm/ADT/Twine.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 using namespace llvm;
@@ -25,6 +26,12 @@ namespace {
 /// \brief Implementation of directive handling which is shared across all
 /// Darwin targets.
 class DarwinAsmParser : public MCAsmParserExtension {
+  template<bool (DarwinAsmParser::*Handler)(StringRef, SMLoc)>
+  void AddDirectiveHandler(StringRef Directive) {
+    getParser().AddDirectiveHandler(this, Directive,
+                                    HandleDirective<DarwinAsmParser, Handler>);
+  }
+
   bool ParseSectionSwitch(const char *Segment, const char *Section,
                           unsigned TAA = 0, unsigned ImplicitAlign = 0,
                           unsigned StubSize = 0);
@@ -36,173 +43,88 @@ public:
     // Call the base implementation.
     this->MCAsmParserExtension::Initialize(Parser);
 
-    Parser.AddDirectiveHandler(this, ".desc", MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveDesc));
-    Parser.AddDirectiveHandler(this, ".lsym", MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveLsym));
-    Parser.AddDirectiveHandler(this, ".subsections_via_symbols",
-                               MCAsmParser::DirectiveHandler(
-                        &DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols));
-    Parser.AddDirectiveHandler(this, ".dump", MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveDumpOrLoad));
-    Parser.AddDirectiveHandler(this, ".load", MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveDumpOrLoad));
-    Parser.AddDirectiveHandler(this, ".section", MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveSection));
-    Parser.AddDirectiveHandler(this, ".secure_log_unique",
-                               MCAsmParser::DirectiveHandler(
-                             &DarwinAsmParser::ParseDirectiveSecureLogUnique));
-    Parser.AddDirectiveHandler(this, ".secure_log_reset",
-                               MCAsmParser::DirectiveHandler(
-                             &DarwinAsmParser::ParseDirectiveSecureLogReset));
-    Parser.AddDirectiveHandler(this, ".tbss",
-                               MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveTBSS));
-    Parser.AddDirectiveHandler(this, ".zerofill",
-                               MCAsmParser::DirectiveHandler(
-                                 &DarwinAsmParser::ParseDirectiveZerofill));
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDesc>(".desc");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveLsym>(".lsym");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSubsectionsViaSymbols>(
+      ".subsections_via_symbols");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".dump");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDumpOrLoad>(".load");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSection>(".section");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectivePushSection>(".pushsection");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectivePopSection>(".popsection");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectivePrevious>(".previous");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogUnique>(
+      ".secure_log_unique");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveSecureLogReset>(
+      ".secure_log_reset");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveTBSS>(".tbss");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveZerofill>(".zerofill");
+
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDataRegion>(".data_region");
+    AddDirectiveHandler<&DarwinAsmParser::ParseDirectiveDataRegionEnd>(".end_data_region");
 
     // Special section directives.
-    Parser.AddDirectiveHandler(this, ".const",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveConst));
-    Parser.AddDirectiveHandler(this, ".const_data",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveConstData));
-    Parser.AddDirectiveHandler(this, ".constructor",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveConstructor));
-    Parser.AddDirectiveHandler(this, ".cstring",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveCString));
-    Parser.AddDirectiveHandler(this, ".data",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveData));
-    Parser.AddDirectiveHandler(this, ".destructor",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveDestructor));
-    Parser.AddDirectiveHandler(this, ".dyld",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveDyld));
-    Parser.AddDirectiveHandler(this, ".fvmlib_init0",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveFVMLibInit0));
-    Parser.AddDirectiveHandler(this, ".fvmlib_init1",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveFVMLibInit1));
-    Parser.AddDirectiveHandler(this, ".lazy_symbol_pointer",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers));
-    Parser.AddDirectiveHandler(this, ".literal16",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveLiteral16));
-    Parser.AddDirectiveHandler(this, ".literal4",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveLiteral4));
-    Parser.AddDirectiveHandler(this, ".literal8",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveLiteral8));
-    Parser.AddDirectiveHandler(this, ".mod_init_func",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveModInitFunc));
-    Parser.AddDirectiveHandler(this, ".mod_term_func",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveModTermFunc));
-    Parser.AddDirectiveHandler(this, ".non_lazy_symbol_pointer",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveNonLazySymbolPointers));
-    Parser.AddDirectiveHandler(this, ".objc_cat_cls_meth",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCCatClsMeth));
-    Parser.AddDirectiveHandler(this, ".objc_cat_inst_meth",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCCatInstMeth));
-    Parser.AddDirectiveHandler(this, ".objc_category",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCCategory));
-    Parser.AddDirectiveHandler(this, ".objc_class",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCClass));
-    Parser.AddDirectiveHandler(this, ".objc_class_names",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCClassNames));
-    Parser.AddDirectiveHandler(this, ".objc_class_vars",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCClassVars));
-    Parser.AddDirectiveHandler(this, ".objc_cls_meth",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCClsMeth));
-    Parser.AddDirectiveHandler(this, ".objc_cls_refs",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCClsRefs));
-    Parser.AddDirectiveHandler(this, ".objc_inst_meth",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCInstMeth));
-    Parser.AddDirectiveHandler(this, ".objc_instance_vars",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCInstanceVars));
-    Parser.AddDirectiveHandler(this, ".objc_message_refs",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCMessageRefs));
-    Parser.AddDirectiveHandler(this, ".objc_meta_class",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCMetaClass));
-    Parser.AddDirectiveHandler(this, ".objc_meth_var_names",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCMethVarNames));
-    Parser.AddDirectiveHandler(this, ".objc_meth_var_types",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCMethVarTypes));
-    Parser.AddDirectiveHandler(this, ".objc_module_info",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCModuleInfo));
-    Parser.AddDirectiveHandler(this, ".objc_protocol",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCProtocol));
-    Parser.AddDirectiveHandler(this, ".objc_selector_strs",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCSelectorStrs));
-    Parser.AddDirectiveHandler(this, ".objc_string_object",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCStringObject));
-    Parser.AddDirectiveHandler(this, ".objc_symbols",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveObjCSymbols));
-    Parser.AddDirectiveHandler(this, ".picsymbol_stub",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectivePICSymbolStub));
-    Parser.AddDirectiveHandler(this, ".static_const",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveStaticConst));
-    Parser.AddDirectiveHandler(this, ".static_data",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveStaticData));
-    Parser.AddDirectiveHandler(this, ".symbol_stub",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveSymbolStub));
-    Parser.AddDirectiveHandler(this, ".tdata",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveTData));
-    Parser.AddDirectiveHandler(this, ".text",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveText));
-    Parser.AddDirectiveHandler(this, ".thread_init_func",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveThreadInitFunc));
-    Parser.AddDirectiveHandler(this, ".tlv",
-                               MCAsmParser::DirectiveHandler(
-                 &DarwinAsmParser::ParseSectionDirectiveTLV));
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConst>(".const");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstData>(".const_data");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveConstructor>(".constructor");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveCString>(".cstring");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveData>(".data");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDestructor>(".destructor");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveDyld>(".dyld");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit0>(".fvmlib_init0");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveFVMLibInit1>(".fvmlib_init1");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLazySymbolPointers>(".lazy_symbol_pointer");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral16>(".literal16");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral4>(".literal4");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveLiteral8>(".literal8");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModInitFunc>(".mod_init_func");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveModTermFunc>(".mod_term_func");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveNonLazySymbolPointers>(".non_lazy_symbol_pointer");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatClsMeth>(".objc_cat_cls_meth");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCatInstMeth>(".objc_cat_inst_meth");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCCategory>(".objc_category");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClass>(".objc_class");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassNames>(".objc_class_names");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClassVars>(".objc_class_vars");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsMeth>(".objc_cls_meth");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCClsRefs>(".objc_cls_refs");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCInstMeth>(".objc_inst_meth");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCInstanceVars>(".objc_instance_vars");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMessageRefs>(".objc_message_refs");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMetaClass>(".objc_meta_class");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMethVarNames>(".objc_meth_var_names");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCMethVarTypes>(".objc_meth_var_types");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCModuleInfo>(".objc_module_info");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCProtocol>(".objc_protocol");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCSelectorStrs>(".objc_selector_strs");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCStringObject>(".objc_string_object");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveObjCSymbols>(".objc_symbols");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectivePICSymbolStub>(".picsymbol_stub");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticConst>(".static_const");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveStaticData>(".static_data");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveSymbolStub>(".symbol_stub");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTData>(".tdata");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveText>(".text");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveThreadInitFunc>(".thread_init_func");
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveTLV>(".tlv");
+
+    AddDirectiveHandler<&DarwinAsmParser::ParseSectionDirectiveIdent>(".ident");
   }
 
   bool ParseDirectiveDesc(StringRef, SMLoc);
   bool ParseDirectiveDumpOrLoad(StringRef, SMLoc);
   bool ParseDirectiveLsym(StringRef, SMLoc);
-  bool ParseDirectiveSection();
+  bool ParseDirectiveSection(StringRef, SMLoc);
+  bool ParseDirectivePushSection(StringRef, SMLoc);
+  bool ParseDirectivePopSection(StringRef, SMLoc);
+  bool ParseDirectivePrevious(StringRef, SMLoc);
   bool ParseDirectiveSecureLogReset(StringRef, SMLoc);
   bool ParseDirectiveSecureLogUnique(StringRef, SMLoc);
   bool ParseDirectiveSubsectionsViaSymbols(StringRef, SMLoc);
   bool ParseDirectiveTBSS(StringRef, SMLoc);
   bool ParseDirectiveZerofill(StringRef, SMLoc);
+  bool ParseDirectiveDataRegion(StringRef, SMLoc);
+  bool ParseDirectiveDataRegionEnd(StringRef, SMLoc);
 
   // Named Section Directive
   bool ParseSectionDirectiveConst(StringRef, SMLoc) {
@@ -369,6 +291,11 @@ public:
     return ParseSectionSwitch("__DATA", "__thread_vars",
                               MCSectionMachO::S_THREAD_LOCAL_VARIABLES);
   }
+  bool ParseSectionDirectiveIdent(StringRef, SMLoc) {
+    // Darwin silently ignores the .ident directive.
+    getParser().EatToEndOfStatement();
+    return false;
+  }
   bool ParseSectionDirectiveThreadInitFunc(StringRef, SMLoc) {
     return ParseSectionSwitch("__DATA", "__thread_init",
                          MCSectionMachO::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS);
@@ -376,7 +303,7 @@ public:
 
 };
 
-}
+} // end anonymous namespace
 
 bool DarwinAsmParser::ParseSectionSwitch(const char *Segment,
                                          const char *Section,
@@ -397,7 +324,7 @@ bool DarwinAsmParser::ParseSectionSwitch(const char *Segment,
   //
   // FIXME: This isn't really what 'as' does; I think it just uses the implicit
   // alignment on the section (e.g., if one manually inserts bytes into the
-  // section, then just issueing the section switch directive will not realign
+  // section, then just issuing the section switch directive will not realign
   // the section. However, this is arguably more reasonable behavior, and there
   // is no good reason for someone to intentionally emit incorrectly sized
   // values into the implicitly aligned sections.
@@ -454,11 +381,9 @@ bool DarwinAsmParser::ParseDirectiveDumpOrLoad(StringRef Directive,
   // FIXME: If/when .dump and .load are implemented they will be done in the
   // the assembly parser and not have any need for an MCStreamer API.
   if (IsDump)
-    Warning(IDLoc, "ignoring directive .dump for now");
+    return Warning(IDLoc, "ignoring directive .dump for now");
   else
-    Warning(IDLoc, "ignoring directive .load for now");
-
-  return false;
+    return Warning(IDLoc, "ignoring directive .load for now");
 }
 
 /// ParseDirectiveLsym
@@ -493,7 +418,7 @@ bool DarwinAsmParser::ParseDirectiveLsym(StringRef, SMLoc) {
 
 /// ParseDirectiveSection:
 ///   ::= .section identifier (',' identifier)*
-bool DarwinAsmParser::ParseDirectiveSection() {
+bool DarwinAsmParser::ParseDirectiveSection(StringRef, SMLoc) {
   SMLoc Loc = getLexer().getLoc();
 
   StringRef SectionName;
@@ -519,10 +444,12 @@ bool DarwinAsmParser::ParseDirectiveSection() {
 
 
   StringRef Segment, Section;
-  unsigned TAA, StubSize;
+  unsigned StubSize;
+  unsigned TAA;
+  bool TAAParsed;
   std::string ErrorStr =
     MCSectionMachO::ParseSectionSpecifier(SectionSpec, Segment, Section,
-                                          TAA, StubSize);
+                                          TAA, TAAParsed, StubSize);
 
   if (!ErrorStr.empty())
     return Error(Loc, ErrorStr.c_str());
@@ -536,29 +463,54 @@ bool DarwinAsmParser::ParseDirectiveSection() {
   return false;
 }
 
-/// ParseDirectiveSecureLogUnique
-///  ::= .secure_log_unique "log message"
-bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
-  std::string LogMessage;
+/// ParseDirectivePushSection:
+///   ::= .pushsection identifier (',' identifier)*
+bool DarwinAsmParser::ParseDirectivePushSection(StringRef S, SMLoc Loc) {
+  getStreamer().PushSection();
 
-  if (getLexer().isNot(AsmToken::String))
-    LogMessage = "";
-  else{
-    LogMessage = getTok().getString();
-    Lex();
+  if (ParseDirectiveSection(S, Loc)) {
+    getStreamer().PopSection();
+    return true;
   }
 
+  return false;
+}
+
+/// ParseDirectivePopSection:
+///   ::= .popsection
+bool DarwinAsmParser::ParseDirectivePopSection(StringRef, SMLoc) {
+  if (!getStreamer().PopSection())
+    return TokError(".popsection without corresponding .pushsection");
+  return false;
+}
+
+/// ParseDirectivePrevious:
+///   ::= .previous
+bool DarwinAsmParser::ParseDirectivePrevious(StringRef DirName, SMLoc) {
+  const MCSection *PreviousSection = getStreamer().getPreviousSection();
+  if (PreviousSection == NULL)
+      return TokError(".previous without corresponding .section");
+  getStreamer().SwitchSection(PreviousSection);
+  return false;
+}
+
+/// ParseDirectiveSecureLogUnique
+///  ::= .secure_log_unique ... message ...
+bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
+  StringRef LogMessage = getParser().ParseStringToEndOfStatement();
   if (getLexer().isNot(AsmToken::EndOfStatement))
     return TokError("unexpected token in '.secure_log_unique' directive");
 
   if (getContext().getSecureLogUsed() != false)
     return Error(IDLoc, ".secure_log_unique specified multiple times");
 
-  char *SecureLogFile = getContext().getSecureLogFile();
+  // Get the secure log path.
+  const char *SecureLogFile = getContext().getSecureLogFile();
   if (SecureLogFile == NULL)
     return Error(IDLoc, ".secure_log_unique used but AS_SECURE_LOG_FILE "
                  "environment variable unset.");
 
+  // Open the secure log file if we haven't already.
   raw_ostream *OS = getContext().getSecureLog();
   if (OS == NULL) {
     std::string Err;
@@ -571,6 +523,7 @@ bool DarwinAsmParser::ParseDirectiveSecureLogUnique(StringRef, SMLoc IDLoc) {
     getContext().setSecureLog(OS);
   }
 
+  // Write the message.
   int CurBuf = getSourceManager().FindBufferContainingLoc(IDLoc);
   *OS << getSourceManager().getBufferInfo(CurBuf).Buffer->getBufferIdentifier()
       << ":" << getSourceManager().FindLineNumber(IDLoc, CurBuf) << ":"
@@ -749,10 +702,46 @@ bool DarwinAsmParser::ParseDirectiveZerofill(StringRef, SMLoc) {
   return false;
 }
 
+/// ParseDirectiveDataRegion
+///  ::= .data_region [ ( jt8 | jt16 | jt32 ) ]
+bool DarwinAsmParser::ParseDirectiveDataRegion(StringRef, SMLoc) {
+  if (getLexer().is(AsmToken::EndOfStatement)) {
+    Lex();
+    getStreamer().EmitDataRegion(MCDR_DataRegion);
+    return false;
+  }
+  StringRef RegionType;
+  SMLoc Loc = getParser().getTok().getLoc();
+  if (getParser().ParseIdentifier(RegionType))
+    return TokError("expected region type after '.data_region' directive");
+  int Kind = StringSwitch<int>(RegionType)
+    .Case("jt8", MCDR_DataRegionJT8)
+    .Case("jt16", MCDR_DataRegionJT16)
+    .Case("jt32", MCDR_DataRegionJT32)
+    .Default(-1);
+  if (Kind == -1)
+    return Error(Loc, "unknown region type in '.data_region' directive");
+  Lex();
+
+  getStreamer().EmitDataRegion((MCDataRegionType)Kind);
+  return false;
+}
+
+/// ParseDirectiveDataRegionEnd
+///  ::= .end_data_region
+bool DarwinAsmParser::ParseDirectiveDataRegionEnd(StringRef, SMLoc) {
+  if (getLexer().isNot(AsmToken::EndOfStatement))
+    return TokError("unexpected token in '.end_data_region' directive");
+
+  Lex();
+  getStreamer().EmitDataRegion(MCDR_DataRegionEnd);
+  return false;
+}
+
 namespace llvm {
 
 MCAsmParserExtension *createDarwinAsmParser() {
   return new DarwinAsmParser;
 }
 
-}
+} // end llvm namespace