/src/keystone/llvm/lib/MC/MCSectionCOFF.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- lib/MC/MCSectionCOFF.cpp - COFF 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/MCSectionCOFF.h" |
11 | | #include "llvm/MC/MCAsmInfo.h" |
12 | | #include "llvm/MC/MCContext.h" |
13 | | #include "llvm/MC/MCSymbol.h" |
14 | | #include "llvm/Support/COFF.h" |
15 | | #include "llvm/Support/raw_ostream.h" |
16 | | using namespace llvm_ks; |
17 | | |
18 | 0 | MCSectionCOFF::~MCSectionCOFF() {} // anchor. |
19 | | |
20 | | // ShouldOmitSectionDirective - Decides whether a '.section' directive |
21 | | // should be printed before the section name |
22 | | bool MCSectionCOFF::ShouldOmitSectionDirective(StringRef Name, |
23 | 0 | const MCAsmInfo &MAI) const { |
24 | 0 | if (COMDATSymbol) |
25 | 0 | return false; |
26 | | |
27 | | // FIXME: Does .section .bss/.data/.text work everywhere?? |
28 | 0 | if (Name == ".text" || Name == ".data" || Name == ".bss") |
29 | 0 | return true; |
30 | | |
31 | 0 | return false; |
32 | 0 | } |
33 | | |
34 | 0 | void MCSectionCOFF::setSelection(int Selection) const { |
35 | 0 | assert(Selection != 0 && "invalid COMDAT selection type"); |
36 | 0 | this->Selection = Selection; |
37 | 0 | Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT; |
38 | 0 | } |
39 | | |
40 | | void MCSectionCOFF::PrintSwitchToSection(const MCAsmInfo &MAI, |
41 | | raw_ostream &OS, |
42 | 0 | const MCExpr *Subsection) const { |
43 | | |
44 | | // standard sections don't require the '.section' |
45 | 0 | if (ShouldOmitSectionDirective(SectionName, MAI)) { |
46 | 0 | OS << '\t' << getSectionName() << '\n'; |
47 | 0 | return; |
48 | 0 | } |
49 | | |
50 | 0 | OS << "\t.section\t" << getSectionName() << ",\""; |
51 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_CNT_INITIALIZED_DATA) |
52 | 0 | OS << 'd'; |
53 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA) |
54 | 0 | OS << 'b'; |
55 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_EXECUTE) |
56 | 0 | OS << 'x'; |
57 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_WRITE) |
58 | 0 | OS << 'w'; |
59 | 0 | else if (getCharacteristics() & COFF::IMAGE_SCN_MEM_READ) |
60 | 0 | OS << 'r'; |
61 | 0 | else |
62 | 0 | OS << 'y'; |
63 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_LNK_REMOVE) |
64 | 0 | OS << 'n'; |
65 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_MEM_SHARED) |
66 | 0 | OS << 's'; |
67 | 0 | OS << '"'; |
68 | |
|
69 | 0 | if (getCharacteristics() & COFF::IMAGE_SCN_LNK_COMDAT) { |
70 | 0 | OS << ","; |
71 | 0 | switch (Selection) { |
72 | 0 | case COFF::IMAGE_COMDAT_SELECT_NODUPLICATES: |
73 | 0 | OS << "one_only,"; |
74 | 0 | break; |
75 | 0 | case COFF::IMAGE_COMDAT_SELECT_ANY: |
76 | 0 | OS << "discard,"; |
77 | 0 | break; |
78 | 0 | case COFF::IMAGE_COMDAT_SELECT_SAME_SIZE: |
79 | 0 | OS << "same_size,"; |
80 | 0 | break; |
81 | 0 | case COFF::IMAGE_COMDAT_SELECT_EXACT_MATCH: |
82 | 0 | OS << "same_contents,"; |
83 | 0 | break; |
84 | 0 | case COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE: |
85 | 0 | OS << "associative,"; |
86 | 0 | break; |
87 | 0 | case COFF::IMAGE_COMDAT_SELECT_LARGEST: |
88 | 0 | OS << "largest,"; |
89 | 0 | break; |
90 | 0 | case COFF::IMAGE_COMDAT_SELECT_NEWEST: |
91 | 0 | OS << "newest,"; |
92 | 0 | break; |
93 | 0 | default: |
94 | 0 | assert (0 && "unsupported COFF selection type"); |
95 | 0 | break; |
96 | 0 | } |
97 | 0 | assert(COMDATSymbol); |
98 | 0 | COMDATSymbol->print(OS, &MAI); |
99 | 0 | } |
100 | 0 | OS << '\n'; |
101 | 0 | } |
102 | | |
103 | 0 | bool MCSectionCOFF::UseCodeAlign() const { |
104 | 0 | return getKind().isText(); |
105 | 0 | } |
106 | | |
107 | 0 | bool MCSectionCOFF::isVirtualSection() const { |
108 | 0 | return getCharacteristics() & COFF::IMAGE_SCN_CNT_UNINITIALIZED_DATA; |
109 | 0 | } |