LLVM  3.7.0
MCSection.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/MC/MCSection.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCAsmInfo.h"
13 #include "llvm/MC/MCContext.h"
14 #include "llvm/MC/MCSymbol.h"
16 using namespace llvm;
17 
18 //===----------------------------------------------------------------------===//
19 // MCSection
20 //===----------------------------------------------------------------------===//
21 
22 MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
23  : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false),
24  IsRegistered(false), Variant(V), Kind(K) {}
25 
27  if (!End)
28  End = Ctx.createTempSymbol("sec_end", true);
29  return End;
30 }
31 
32 bool MCSection::hasEnded() const { return End && End->isInSection(); }
33 
35 }
36 
38  if (NewState == NotBundleLocked) {
39  if (BundleLockNestingDepth == 0) {
40  report_fatal_error("Mismatched bundle_lock/unlock directives");
41  }
42  if (--BundleLockNestingDepth == 0) {
43  BundleLockState = NotBundleLocked;
44  }
45  return;
46  }
47 
48  // If any of the directives is an align_to_end directive, the whole nested
49  // group is align_to_end. So don't downgrade from align_to_end to just locked.
50  if (BundleLockState != BundleLockedAlignToEnd) {
51  BundleLockState = NewState;
52  }
53  ++BundleLockNestingDepth;
54 }
55 
58  if (Subsection == 0 && SubsectionFragmentMap.empty())
59  return end();
60 
62  std::lower_bound(SubsectionFragmentMap.begin(),
63  SubsectionFragmentMap.end(),
64  std::make_pair(Subsection, (MCFragment *)nullptr));
65  bool ExactMatch = false;
66  if (MI != SubsectionFragmentMap.end()) {
67  ExactMatch = MI->first == Subsection;
68  if (ExactMatch)
69  ++MI;
70  }
71  iterator IP;
72  if (MI == SubsectionFragmentMap.end())
73  IP = end();
74  else
75  IP = MI->second;
76  if (!ExactMatch && Subsection != 0) {
77  // The GNU as documentation claims that subsections have an alignment of 4,
78  // although this appears not to be the case.
79  MCFragment *F = new MCDataFragment();
80  SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
81  getFragmentList().insert(IP, F);
82  F->setParent(this);
83  }
84 
85  return IP;
86 }
87 
88 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
90  raw_ostream &OS = llvm::errs();
91 
92  OS << "<MCSection";
93  OS << " Fragments:[\n ";
94  for (auto it = begin(), ie = end(); it != ie; ++it) {
95  if (it != begin())
96  OS << ",\n ";
97  it->dump();
98  }
99  OS << "]>";
100 }
101 #endif
102 
103 MCSection::iterator MCSection::begin() { return Fragments.begin(); }
104 
105 MCSection::iterator MCSection::end() { return Fragments.end(); }
106 
108 
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:39
bool hasEnded() const
Definition: MCSection.cpp:32
reverse_iterator rend()
Definition: ilist.h:379
void setBundleLockState(BundleLockStateType NewState)
Definition: MCSection.cpp:37
MCSection::reverse_iterator rbegin()
Definition: MCSection.cpp:107
F(f)
iterator begin()
Definition: ilist.h:359
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(const char *reason, bool gen_crash_diag=true)
Reports a serious error, calling any installed error handler.
reverse_iterator rbegin()
Definition: ilist.h:377
BundleLockStateType
Express the state of bundle locked groups while emitting code.
Definition: MCSection.h:53
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: APInt.h:33
MCSection::reverse_iterator rend()
Definition: MCSection.cpp:109
#define false
Definition: ConvertUTF.c:65
MCSymbol * getEndSymbol(MCContext &Ctx)
Definition: MCSection.cpp:26
Context object for machine code objects.
Definition: MCContext.h:48
bool isInSection() const
isInSection - Check if this symbol is defined in some section (i.e., it is defined but not absolute)...
Definition: MCSymbol.h:255
MCSection::iterator end()
Definition: MCSection.cpp:105
MCSymbol * createTempSymbol(bool CanBeUnnamed=true)
Create and return a new assembler temporary symbol with a unique but unspecified name.
Definition: MCContext.cpp:222
FragmentListType::reverse_iterator reverse_iterator
Definition: MCSection.h:65
iterator insert(iterator where, NodeTy *New)
Definition: ilist.h:412
SectionKind - This is a simple POD value that classifies the properties of a section.
Definition: SectionKind.h:28
MCSection::iterator begin()
Definition: MCSection.cpp:103
Fragment for data and encoded instructions.
Definition: MCAssembler.h:228
const ARM::ArchExtKind Kind
iterator end()
Definition: ilist.h:367
MCSection::iterator getSubsectionInsertionPoint(unsigned Subsection)
Definition: MCSection.cpp:57
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
virtual ~MCSection()
Definition: MCSection.cpp:34
void setParent(MCSection *Value)
Definition: MCAssembler.h:119
MCSection::FragmentListType & getFragmentList()
Definition: MCSection.h:150