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/MCContext.h"
12 #include "llvm/Target/TargetAsmInfo.h"
13 #include "llvm/Support/raw_ostream.h"
16 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
20 MCSection::~MCSection() {
24 //===----------------------------------------------------------------------===//
26 //===----------------------------------------------------------------------===//
28 MCSectionELF *MCSectionELF::
29 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
30 return new (Ctx) MCSectionELF(Name, IsDirective, K);
33 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
34 raw_ostream &OS) const {
36 OS << getName() << '\n';
40 OS << "\t.section\t" << getName();
42 // Handle the weird solaris syntax if desired.
43 if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
44 !getKind().isMergeableConst() && !getKind().isMergeableCString()) {
45 if (!getKind().isMetadata())
47 if (getKind().isText())
49 if (getKind().isWriteable())
51 if (getKind().isThreadLocal())
56 if (!getKind().isMetadata())
58 if (getKind().isText())
60 if (getKind().isWriteable())
62 if (getKind().isMergeable1ByteCString() ||
63 getKind().isMergeable2ByteCString() ||
64 getKind().isMergeable4ByteCString() ||
65 getKind().isMergeableConst4() ||
66 getKind().isMergeableConst8() ||
67 getKind().isMergeableConst16())
69 if (getKind().isMergeable1ByteCString() ||
70 getKind().isMergeable2ByteCString() ||
71 getKind().isMergeable4ByteCString())
73 if (getKind().isThreadLocal())
78 // If comment string is '@', e.g. as on ARM - use '%' instead
79 if (TAI.getCommentString()[0] == '@')
84 if (getKind().isBSS() || getKind().isThreadBSS())
89 if (getKind().isMergeable1ByteCString()) {
91 } else if (getKind().isMergeable2ByteCString()) {
93 } else if (getKind().isMergeable4ByteCString()) {
95 } else if (getKind().isMergeableConst4()) {
97 } else if (getKind().isMergeableConst8()) {
99 } else if (getKind().isMergeableConst16()) {
108 //===----------------------------------------------------------------------===//
110 //===----------------------------------------------------------------------===//
112 MCSectionCOFF *MCSectionCOFF::
113 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
114 return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
117 void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
118 raw_ostream &OS) const {
121 OS << getName() << '\n';
124 OS << "\t.section\t" << getName() << ",\"";
125 if (getKind().isText())
127 if (getKind().isWriteable())