blob: 8b7fcd2815c251a0dc31f2726ab9ea41d7b2280e [file] [log] [blame]
Chris Lattnered47a042009-07-31 17:02:00 +00001//===- lib/MC/MCSection.cpp - Machine 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/MCSection.h"
11#include "llvm/MC/MCContext.h"
Chris Lattner892e1822009-08-08 22:41:53 +000012#include "llvm/Target/TargetAsmInfo.h"
13#include "llvm/Support/raw_ostream.h"
Chris Lattnered47a042009-07-31 17:02:00 +000014using namespace llvm;
15
Chris Lattner892e1822009-08-08 22:41:53 +000016//===----------------------------------------------------------------------===//
17// MCSection
18//===----------------------------------------------------------------------===//
19
Chris Lattnered47a042009-07-31 17:02:00 +000020MCSection::~MCSection() {
21}
22
Chris Lattnered47a042009-07-31 17:02:00 +000023
Chris Lattner892e1822009-08-08 22:41:53 +000024//===----------------------------------------------------------------------===//
25// MCSectionELF
26//===----------------------------------------------------------------------===//
Chris Lattnera1c31b72009-08-08 20:50:49 +000027
28MCSectionELF *MCSectionELF::
29Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
Chris Lattner38cff382009-08-13 00:37:15 +000030 return new (Ctx) MCSectionELF(Name, IsDirective, K);
Chris Lattnera1c31b72009-08-08 20:50:49 +000031}
32
Chris Lattner892e1822009-08-08 22:41:53 +000033void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
34 raw_ostream &OS) const {
35 if (isDirective()) {
36 OS << getName() << '\n';
37 return;
38 }
39
40 OS << "\t.section\t" << getName();
41
42 // Handle the weird solaris syntax if desired.
43 if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
44 !getKind().isMergeableConst() && !getKind().isMergeableCString()) {
45 if (!getKind().isMetadata())
46 OS << ",#alloc";
47 if (getKind().isText())
48 OS << ",#execinstr";
49 if (getKind().isWriteable())
50 OS << ",#write";
51 if (getKind().isThreadLocal())
52 OS << ",#tls";
53 } else {
54 OS << ",\"";
55
56 if (!getKind().isMetadata())
57 OS << 'a';
58 if (getKind().isText())
59 OS << 'x';
60 if (getKind().isWriteable())
61 OS << 'w';
62 if (getKind().isMergeable1ByteCString() ||
63 getKind().isMergeable2ByteCString() ||
64 getKind().isMergeable4ByteCString() ||
65 getKind().isMergeableConst4() ||
66 getKind().isMergeableConst8() ||
67 getKind().isMergeableConst16())
68 OS << 'M';
69 if (getKind().isMergeable1ByteCString() ||
70 getKind().isMergeable2ByteCString() ||
71 getKind().isMergeable4ByteCString())
72 OS << 'S';
73 if (getKind().isThreadLocal())
74 OS << 'T';
75
76 OS << "\",";
77
78 // If comment string is '@', e.g. as on ARM - use '%' instead
79 if (TAI.getCommentString()[0] == '@')
80 OS << '%';
81 else
82 OS << '@';
83
84 if (getKind().isBSS() || getKind().isThreadBSS())
85 OS << "nobits";
86 else
87 OS << "progbits";
88
89 if (getKind().isMergeable1ByteCString()) {
90 OS << ",1";
91 } else if (getKind().isMergeable2ByteCString()) {
92 OS << ",2";
93 } else if (getKind().isMergeable4ByteCString()) {
94 OS << ",4";
95 } else if (getKind().isMergeableConst4()) {
96 OS << ",4";
97 } else if (getKind().isMergeableConst8()) {
98 OS << ",8";
99 } else if (getKind().isMergeableConst16()) {
100 OS << ",16";
101 }
102 }
Chris Lattner1f8e8db2009-08-09 15:31:10 +0000103
104 OS << '\n';
Chris Lattner892e1822009-08-08 22:41:53 +0000105}
106
Chris Lattnerff4bc462009-08-10 01:39:42 +0000107
Chris Lattner892e1822009-08-08 22:41:53 +0000108//===----------------------------------------------------------------------===//
109// MCSectionCOFF
110//===----------------------------------------------------------------------===//
Chris Lattnera1c31b72009-08-08 20:50:49 +0000111
Chris Lattner7c599d02009-08-08 20:52:13 +0000112MCSectionCOFF *MCSectionCOFF::
Chris Lattnera1c31b72009-08-08 20:50:49 +0000113Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
Chris Lattner38cff382009-08-13 00:37:15 +0000114 return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
Chris Lattnera1c31b72009-08-08 20:50:49 +0000115}
116
Chris Lattner892e1822009-08-08 22:41:53 +0000117void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
118 raw_ostream &OS) const {
119
120 if (isDirective()) {
121 OS << getName() << '\n';
122 return;
123 }
124 OS << "\t.section\t" << getName() << ",\"";
125 if (getKind().isText())
126 OS << 'x';
127 if (getKind().isWriteable())
128 OS << 'w';
129 OS << "\"\n";
130}