OSDN Git Service

Simplify the logic for deciding when to initialize the sections.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 24 Jan 2014 03:54:40 +0000 (03:54 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 24 Jan 2014 03:54:40 +0000 (03:54 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199971 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/MC/MCELFStreamer.h
include/llvm/MC/MCStreamer.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/LLVMTargetMachine.cpp
lib/MC/MCAsmStreamer.cpp
lib/MC/MCELFStreamer.cpp
lib/MC/MCStreamer.cpp
lib/MC/WinCOFFStreamer.cpp

index c24119c..7090022 100644 (file)
@@ -45,7 +45,7 @@ public:
   /// @name MCStreamer Interface
   /// @{
 
-  virtual void InitSections();
+  virtual void InitSections(bool Force);
   virtual void ChangeSection(const MCSection *Section,
                              const MCExpr *Subsection);
   virtual void EmitLabel(MCSymbol *Symbol);
index 78491e8..1538a41 100644 (file)
@@ -157,8 +157,6 @@ class MCStreamer {
   /// values saved by PushSection.
   SmallVector<std::pair<MCSectionSubPair, MCSectionSubPair>, 4> SectionStack;
 
-  bool AutoInitSections;
-
 protected:
   MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer);
 
@@ -330,19 +328,11 @@ public:
       SectionStack.back().first = MCSectionSubPair(Section, Subsection);
   }
 
-  /// Initialize the streamer.
-  void InitStreamer() {
-    if (AutoInitSections)
-      InitSections();
-  }
-
-  /// Tell this MCStreamer to call InitSections upon initialization.
-  void setAutoInitSections(bool AutoInitSections) {
-    this->AutoInitSections = AutoInitSections;
-  }
-
-  /// InitSections - Create the default sections and set the initial one.
-  virtual void InitSections();
+  /// Create the default sections and set the initial one.
+  ///
+  /// @param Force - If false, a text streamer implementation can be a nop.
+  /// Used by CodeGen to avoid starting every file with '.text'.
+  virtual void InitSections(bool Force = true);
 
   /// AssignSection - Sets the symbol's section.
   ///
index 45f5f58..cdff074 100644 (file)
@@ -163,7 +163,7 @@ bool AsmPrinter::doInitialization(Module &M) {
   const_cast<TargetLoweringObjectFile&>(getObjFileLowering())
     .Initialize(OutContext, TM);
 
-  OutStreamer.InitStreamer();
+  OutStreamer.InitSections(false);
 
   Mang = new Mangler(TM.getDataLayout());
 
index 2a92e23..f30c515 100644 (file)
@@ -208,7 +208,6 @@ bool LLVMTargetMachine::addPassesToEmitFile(PassManagerBase &PM,
                                                          *Context, *MAB, Out,
                                                          MCE, hasMCRelaxAll(),
                                                          hasMCNoExecStack()));
-    AsmStreamer.get()->setAutoInitSections(true);
     break;
   }
   case CGFT_Null:
index 96e14a9..f586db3 100644 (file)
@@ -128,6 +128,11 @@ public:
   virtual void ChangeSection(const MCSection *Section,
                              const MCExpr *Subsection);
 
+  virtual void InitSections(bool Force) {
+    if (Force)
+      SwitchSection(getContext().getObjectFileInfo()->getTextSection());
+  }
+
   virtual void EmitLabel(MCSymbol *Symbol);
   virtual void EmitDebugLabel(MCSymbol *Symbol);
 
index d2c2395..8c9ad63 100644 (file)
@@ -38,7 +38,7 @@ using namespace llvm;
 MCELFStreamer::~MCELFStreamer() {
 }
 
-void MCELFStreamer::InitSections() {
+void MCELFStreamer::InitSections(bool Force) {
   // This emulates the same behavior of GNU as. This makes it easier
   // to compare the output as the major sections are in the same order.
   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
index 10b2f3f..0b7c906 100644 (file)
@@ -29,8 +29,7 @@ void MCTargetStreamer::emitLabel(MCSymbol *Symbol) {}
 
 MCStreamer::MCStreamer(MCContext &Ctx, MCTargetStreamer *TargetStreamer)
     : Context(Ctx), TargetStreamer(TargetStreamer), EmitEHFrame(true),
-      EmitDebugFrame(false), CurrentW64UnwindInfo(0), LastSymbol(0),
-      AutoInitSections(false) {
+      EmitDebugFrame(false), CurrentW64UnwindInfo(0), LastSymbol(0) {
   SectionStack.push_back(std::pair<MCSectionSubPair, MCSectionSubPair>());
   if (TargetStreamer)
     TargetStreamer->setStreamer(this);
@@ -201,7 +200,7 @@ void MCStreamer::EmitEHSymAttributes(const MCSymbol *Symbol,
                                      MCSymbol *EHSymbol) {
 }
 
-void MCStreamer::InitSections() {
+void MCStreamer::InitSections(bool Force) {
   SwitchSection(getContext().getObjectFileInfo()->getTextSection());
 }
 
index 6dbe518..3f7baf9 100644 (file)
@@ -50,7 +50,7 @@ public:
 
   // MCStreamer interface
 
-  virtual void InitSections();
+  virtual void InitSections(bool Force);
   virtual void EmitLabel(MCSymbol *Symbol);
   virtual void EmitDebugLabel(MCSymbol *Symbol);
   virtual void EmitAssemblerFlag(MCAssemblerFlag Flag);
@@ -123,7 +123,7 @@ void WinCOFFStreamer::AddCommonSymbol(MCSymbol *Symbol, uint64_t Size,
 
 // MCStreamer interface
 
-void WinCOFFStreamer::InitSections() {
+void WinCOFFStreamer::InitSections(bool Force) {
   // FIXME: this is identical to the ELF one.
   // This emulates the same behavior of GNU as. This makes it easier
   // to compare the output as the major sections are in the same order.