LLVM  3.7.0
MCSectionCOFF.cpp
Go to the documentation of this file.
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"
15 using namespace llvm;
16 
17 MCSectionCOFF::~MCSectionCOFF() {} // anchor.
18 
19 // ShouldOmitSectionDirective - Decides whether a '.section' directive
20 // should be printed before the section name
22  const MCAsmInfo &MAI) const {
23  if (COMDATSymbol)
24  return false;
25 
26  // FIXME: Does .section .bss/.data/.text work everywhere??
27  if (Name == ".text" || Name == ".data" || Name == ".bss")
28  return true;
29 
30  return false;
31 }
32 
33 void MCSectionCOFF::setSelection(int Selection) const {
34  assert(Selection != 0 && "invalid COMDAT selection type");
35  this->Selection = Selection;
36  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
37 }
38 
40  raw_ostream &OS,
41  const MCExpr *Subsection) const {
42 
43  // standard sections don't require the '.section'
44  if (ShouldOmitSectionDirective(SectionName, MAI)) {
45  OS << '\t' << getSectionName() << '\n';
46  return;
47  }
48 
49  OS << "\t.section\t" << getSectionName() << ",\"";
51  OS << 'd';
53  OS << 'b';
55  OS << 'x';
57  OS << 'w';
59  OS << 'r';
60  else
61  OS << 'y';
63  OS << 'n';
65  OS << 's';
66  OS << '"';
67 
69  OS << ",";
70  switch (Selection) {
72  OS << "one_only,";
73  break;
75  OS << "discard,";
76  break;
78  OS << "same_size,";
79  break;
81  OS << "same_contents,";
82  break;
84  OS << "associative,";
85  break;
87  OS << "largest,";
88  break;
90  OS << "newest,";
91  break;
92  default:
93  assert (0 && "unsupported COFF selection type");
94  break;
95  }
96  assert(COMDATSymbol);
97  COMDATSymbol->print(OS, &MAI);
98  }
99  OS << '\n';
100 }
101 
103  return getKind().isText();
104 }
105 
108 }
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:51
void setSelection(int Selection) const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:33
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
ShouldOmitSectionDirective - Decides whether a '.section' directive should be printed before the sect...
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:58
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const override
bool isText() const
Definition: SectionKind.h:137
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:64
SectionKind getKind() const
Definition: MCSection.h:109
StringRef getSectionName() const
Definition: MCSectionCOFF.h:63
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:38
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:40