/src/keystone/llvm/lib/MC/MCSection.cpp
Line | Count | Source (jump to first uncovered line) |
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" |
15 | | #include "llvm/Support/raw_ostream.h" |
16 | | using namespace llvm_ks; |
17 | | |
18 | | //===----------------------------------------------------------------------===// |
19 | | // MCSection |
20 | | //===----------------------------------------------------------------------===// |
21 | | |
22 | | MCSection::MCSection(SectionVariant V, SectionKind K, MCSymbol *Begin) |
23 | 5.69M | : Begin(Begin), BundleGroupBeforeFirstInst(false), HasInstructions(false), |
24 | 5.69M | IsRegistered(false), DummyFragment(this), Variant(V), Kind(K) {} |
25 | | |
26 | 0 | MCSymbol *MCSection::getEndSymbol(MCContext &Ctx) { |
27 | 0 | if (!End) |
28 | 0 | End = Ctx.createTempSymbol("sec_end", true); |
29 | 0 | return End; |
30 | 0 | } |
31 | | |
32 | 148k | bool MCSection::hasEnded() const { return End && End->isInSection(); } |
33 | | |
34 | 5.69M | MCSection::~MCSection() { |
35 | 5.69M | } |
36 | | |
37 | 0 | void MCSection::setBundleLockState(BundleLockStateType NewState) { |
38 | 0 | if (NewState == NotBundleLocked) { |
39 | 0 | if (BundleLockNestingDepth == 0) { |
40 | 0 | report_fatal_error("Mismatched bundle_lock/unlock directives"); |
41 | 0 | } |
42 | 0 | if (--BundleLockNestingDepth == 0) { |
43 | 0 | BundleLockState = NotBundleLocked; |
44 | 0 | } |
45 | 0 | return; |
46 | 0 | } |
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 | 0 | if (BundleLockState != BundleLockedAlignToEnd) { |
51 | 0 | BundleLockState = NewState; |
52 | 0 | } |
53 | 0 | ++BundleLockNestingDepth; |
54 | 0 | } |
55 | | |
56 | | MCSection::iterator |
57 | 148k | MCSection::getSubsectionInsertionPoint(unsigned Subsection) { |
58 | 148k | if (Subsection == 0 && SubsectionFragmentMap.empty()) |
59 | 148k | return end(); |
60 | | |
61 | 0 | SmallVectorImpl<std::pair<unsigned, MCFragment *>>::iterator MI = |
62 | 0 | std::lower_bound(SubsectionFragmentMap.begin(), |
63 | 0 | SubsectionFragmentMap.end(), |
64 | 0 | std::make_pair(Subsection, (MCFragment *)nullptr)); |
65 | 0 | bool ExactMatch = false; |
66 | 0 | if (MI != SubsectionFragmentMap.end()) { |
67 | 0 | ExactMatch = MI->first == Subsection; |
68 | 0 | if (ExactMatch) |
69 | 0 | ++MI; |
70 | 0 | } |
71 | 0 | iterator IP; |
72 | 0 | if (MI == SubsectionFragmentMap.end()) |
73 | 0 | IP = end(); |
74 | 0 | else |
75 | 0 | IP = MI->second->getIterator(); |
76 | 0 | 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 | 0 | MCFragment *F = new MCDataFragment(); |
80 | 0 | SubsectionFragmentMap.insert(MI, std::make_pair(Subsection, F)); |
81 | 0 | getFragmentList().insert(IP, F); |
82 | 0 | F->setParent(this); |
83 | 0 | } |
84 | |
|
85 | 0 | return IP; |
86 | 148k | } |
87 | | |
88 | | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
89 | 0 | LLVM_DUMP_METHOD void MCSection::dump() { |
90 | 0 | raw_ostream &OS = llvm_ks::errs(); |
91 | |
|
92 | 0 | OS << "<MCSection"; |
93 | 0 | OS << " Fragments:[\n "; |
94 | 0 | for (auto it = begin(), ie = end(); it != ie; ++it) { |
95 | 0 | if (it != begin()) |
96 | 0 | OS << ",\n "; |
97 | 0 | it->dump(); |
98 | 0 | } |
99 | 0 | OS << "]>"; |
100 | 0 | } |
101 | | #endif |
102 | | |
103 | 295k | MCSection::iterator MCSection::begin() { return Fragments.begin(); } |
104 | | |
105 | 942k | MCSection::iterator MCSection::end() { return Fragments.end(); } |
106 | | |
107 | 59.8k | MCSection::reverse_iterator MCSection::rbegin() { return Fragments.rbegin(); } |
108 | | |
109 | 0 | MCSection::reverse_iterator MCSection::rend() { return Fragments.rend(); } |