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, Ctx);
33 MCSectionELF::MCSectionELF(const StringRef &name, bool isDirective,
34 SectionKind K, MCContext &Ctx)
35 : MCSection(K), Name(name), IsDirective(isDirective) {
36 Ctx.SetSection(Name, this);
40 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
41 raw_ostream &OS) const {
43 OS << getName() << '\n';
47 OS << "\t.section\t" << getName();
49 // Handle the weird solaris syntax if desired.
50 if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
51 !getKind().isMergeableConst() && !getKind().isMergeableCString()) {
52 if (!getKind().isMetadata())
54 if (getKind().isText())
56 if (getKind().isWriteable())
58 if (getKind().isThreadLocal())
63 if (!getKind().isMetadata())
65 if (getKind().isText())
67 if (getKind().isWriteable())
69 if (getKind().isMergeable1ByteCString() ||
70 getKind().isMergeable2ByteCString() ||
71 getKind().isMergeable4ByteCString() ||
72 getKind().isMergeableConst4() ||
73 getKind().isMergeableConst8() ||
74 getKind().isMergeableConst16())
76 if (getKind().isMergeable1ByteCString() ||
77 getKind().isMergeable2ByteCString() ||
78 getKind().isMergeable4ByteCString())
80 if (getKind().isThreadLocal())
85 // If comment string is '@', e.g. as on ARM - use '%' instead
86 if (TAI.getCommentString()[0] == '@')
91 if (getKind().isBSS() || getKind().isThreadBSS())
96 if (getKind().isMergeable1ByteCString()) {
98 } else if (getKind().isMergeable2ByteCString()) {
100 } else if (getKind().isMergeable4ByteCString()) {
102 } else if (getKind().isMergeableConst4()) {
104 } else if (getKind().isMergeableConst8()) {
106 } else if (getKind().isMergeableConst16()) {
112 //===----------------------------------------------------------------------===//
114 //===----------------------------------------------------------------------===//
116 MCSectionMachO *MCSectionMachO::
117 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
118 return new (Ctx) MCSectionMachO(Name, IsDirective, K, Ctx);
121 MCSectionMachO::MCSectionMachO(const StringRef &name, bool isDirective,
122 SectionKind K, MCContext &Ctx)
123 : MCSection(K), Name(name), IsDirective(isDirective) {
124 Ctx.SetSection(Name, this);
127 void MCSectionMachO::PrintSwitchToSection(const TargetAsmInfo &TAI,
128 raw_ostream &OS) const {
130 OS << "\t.section\t" << getName() << '\n';
132 OS << getName() << '\n';
135 //===----------------------------------------------------------------------===//
137 //===----------------------------------------------------------------------===//
139 MCSectionCOFF *MCSectionCOFF::
140 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
141 return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
144 MCSectionCOFF::MCSectionCOFF(const StringRef &name, bool isDirective,
145 SectionKind K, MCContext &Ctx)
146 : MCSection(K), Name(name), IsDirective(isDirective) {
147 Ctx.SetSection(Name, this);
151 void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
152 raw_ostream &OS) const {
155 OS << getName() << '\n';
158 OS << "\t.section\t" << getName() << ",\"";
159 if (getKind().isText())
161 if (getKind().isWriteable())