LLVM  4.0.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"
14 #include "llvm/Support/COFF.h"
16 using namespace llvm;
17 
19 
20 // ShouldOmitSectionDirective - Decides whether a '.section' directive
21 // should be printed before the section name
23  const MCAsmInfo &MAI) const {
24  if (COMDATSymbol)
25  return false;
26 
27  // FIXME: Does .section .bss/.data/.text work everywhere??
28  if (Name == ".text" || Name == ".data" || Name == ".bss")
29  return true;
30 
31  return false;
32 }
33 
34 void MCSectionCOFF::setSelection(int Selection) const {
35  assert(Selection != 0 && "invalid COMDAT selection type");
36  this->Selection = Selection;
37  Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
38 }
39 
41  raw_ostream &OS,
42  const MCExpr *Subsection) const {
43 
44  // standard sections don't require the '.section'
45  if (ShouldOmitSectionDirective(SectionName, MAI)) {
46  OS << '\t' << getSectionName() << '\n';
47  return;
48  }
49 
50  OS << "\t.section\t" << getSectionName() << ",\"";
52  OS << 'd';
54  OS << 'b';
56  OS << 'x';
58  OS << 'w';
60  OS << 'r';
61  else
62  OS << 'y';
64  OS << 'n';
66  OS << 's';
68  !isImplicitlyDiscardable(SectionName))
69  OS << 'D';
70  OS << '"';
71 
73  OS << ",";
74  switch (Selection) {
76  OS << "one_only,";
77  break;
79  OS << "discard,";
80  break;
82  OS << "same_size,";
83  break;
85  OS << "same_contents,";
86  break;
88  OS << "associative,";
89  break;
91  OS << "largest,";
92  break;
94  OS << "newest,";
95  break;
96  default:
97  assert (0 && "unsupported COFF selection type");
98  break;
99  }
100  assert(COMDATSymbol);
101  COMDATSymbol->print(OS, &MAI);
102  }
103  OS << '\n';
104 }
105 
107  return getKind().isText();
108 }
109 
112 }
void print(raw_ostream &OS, const MCAsmInfo *MAI) const
print - Print the value to the stream OS.
Definition: MCSymbol.cpp:53
void setSelection(int Selection) const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:34
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
Decides whether a '.section' directive should be printed before the section name. ...
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:57
void PrintSwitchToSection(const MCAsmInfo &MAI, raw_ostream &OS, const MCExpr *Subsection) const override
bool isText() const
Definition: SectionKind.h:119
unsigned getCharacteristics() const
Definition: MCSectionCOFF.h:70
SectionKind getKind() const
Definition: MCSection.h:102
StringRef getSectionName() const
Definition: MCSectionCOFF.h:69
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
static bool isImplicitlyDiscardable(StringRef Name)
Definition: MCSectionCOFF.h:87
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:47