1 //===- lib/MC/MCSection.cpp - Machine Code Section Representation ---------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
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"
15 #include "llvm/Support/raw_ostream.h"
18 //===----------------------------------------------------------------------===//
20 //===----------------------------------------------------------------------===//
22 MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin)
23 : Begin(Begin), HasInstructions(false), Data(*this), Variant(V), Kind(K) {}
25 MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) {
27 End = Ctx.createTempSymbol("sec_end", true);
31 bool MCSection::hasEnded() const { return End && End->isInSection(); }
33 MCSection::~MCSection() {
36 void MCSection::setBundleLockState(BundleLockStateType NewState) {
37 if (NewState == NotBundleLocked) {
38 if (BundleLockNestingDepth == 0) {
39 report_fatal_error("Mismatched bundle_lock/unlock directives");
41 if (--BundleLockNestingDepth == 0) {
42 BundleLockState = NotBundleLocked;
47 // If any of the directives is an align_to_end directive, the whole nested
48 // group is align_to_end. So don't downgrade from align_to_end to just locked.
49 if (BundleLockState != BundleLockedAlignToEnd) {
50 BundleLockState = NewState;
52 ++BundleLockNestingDepth;
55 MCSectionData::iterator
56 MCSection::getSubsectionInsertionPoint(unsigned Subsection) {
57 if (Subsection == 0 && Data.SubsectionFragmentMap.empty())
60 SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI =
61 std::lower_bound(Data.SubsectionFragmentMap.begin(),
62 Data.SubsectionFragmentMap.end(),
63 std::make_pair(Subsection, (MCFragment *)nullptr));
64 bool ExactMatch = false;
65 if (MI != Data.SubsectionFragmentMap.end()) {
66 ExactMatch = MI->first == Subsection;
70 MCSectionData::iterator IP;
71 if (MI == Data.SubsectionFragmentMap.end())
75 if (!ExactMatch && Subsection != 0) {
76 // The GNU as documentation claims that subsections have an alignment of 4,
77 // although this appears not to be the case.
78 MCFragment *F = new MCDataFragment();
79 Data.SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F));
80 getFragmentList().insert(IP, F);
87 MCSectionData::iterator MCSection::begin() { return Data.begin(); }
89 MCSectionData::iterator MCSection::end() { return Data.end(); }
91 MCSectionData::reverse_iterator MCSection::rbegin() { return Data.rbegin(); }
93 MCSectionData::FragmentListType &MCSection::getFragmentList() {
94 return Data.getFragmentList();
97 MCSectionData::iterator MCSectionData::begin() { return Fragments.begin(); }
99 MCSectionData::iterator MCSectionData::end() { return Fragments.end(); }
101 MCSectionData::reverse_iterator MCSectionData::rbegin() {
102 return Fragments.rbegin();
105 MCSectionData::reverse_iterator MCSectionData::rend() {
106 return Fragments.rend();