Fix NDEBUG build.
[oota-llvm.git] / lib / MC / MCSection.cpp
index 523c53787ce17879ef239cfa0402adee093c2bc0..04f932bfeec07903c7786f185a4c7edb50f07c2b 100644 (file)
@@ -19,6 +19,9 @@ using namespace llvm;
 // MCSection
 //===----------------------------------------------------------------------===//
 
+MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
+    : Begin(Begin), HasInstructions(false), Variant(V), Kind(K) {}
+
 MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
   if (!End)
     End = Ctx.createTempSymbol("sec_end", true);
@@ -49,18 +52,57 @@ void MCSection::setBundleLockState(BundleLockStateType NewState) {
   ++BundleLockNestingDepth;
 }
 
-MCSectionData::iterator MCSectionData::begin() { return Fragments.begin(); }
+MCSection::iterator
+MCSection::getSubsectionInsertionPoint(unsigned Subsection) {
+  if (Subsection == 0 && SubsectionFragmentMap.empty())
+    return end();
 
-MCSectionData::iterator MCSectionData::end() { return Fragments.end(); }
+  SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI =
+      std::lower_bound(SubsectionFragmentMap.begin(),
+                       SubsectionFragmentMap.end(),
+                       std::make_pair(Subsection, (MCFragment *)nullptr));
+  bool ExactMatch = false;
+  if (MI != SubsectionFragmentMap.end()) {
+    ExactMatch = MI->first == Subsection;
+    if (ExactMatch)
+      ++MI;
+  }
+  iterator IP;
+  if (MI == SubsectionFragmentMap.end())
+    IP = end();
+  else
+    IP = MI->second;
+  if (!ExactMatch && Subsection != 0) {
+    // The GNU as documentation claims that subsections have an alignment of 4,
+    // although this appears not to be the case.
+    MCFragment *F = new MCDataFragment();
+    SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
+    getFragmentList().insert(IP, F);
+    F->setParent(this);
+  }
 
-MCSectionData::reverse_iterator MCSectionData::rbegin() {
-  return Fragments.rbegin();
+  return IP;
 }
 
-MCSectionData::reverse_iterator MCSectionData::rend() {
-  return Fragments.rend();
+#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
+void MCSection::dump() {
+  raw_ostream &OS = llvm::errs();
+
+  OS << "<MCSection";
+  OS << " Fragments:[\n      ";
+  for (auto it = begin(), ie = end(); it != ie; ++it) {
+    if (it != begin())
+      OS << ",\n      ";
+    it->dump();
+  }
+  OS << "]>";
 }
+#endif
+
+MCSection::iterator MCSection::begin() { return Fragments.begin(); }
+
+MCSection::iterator MCSection::end() { return Fragments.end(); }
 
-size_t MCSectionData::size() const { return Fragments.size(); }
+MCSection::reverse_iterator MCSection::rbegin() { return Fragments.rbegin(); }
 
-bool MCSectionData::empty() const { return Fragments.empty(); }
+MCSection::reverse_iterator MCSection::rend() { return Fragments.rend(); }