summaryrefslogtreecommitdiff
path: root/lib/MC/MCSection.cpp
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-08-08 22:41:53 +0000
committerChris Lattner <sabre@nondot.org>2009-08-08 22:41:53 +0000
commit892e18239308f8a02a4c83758616be84a459c19d (patch)
tree84b7cceebedea3e4afd191e06686054be73baf22 /lib/MC/MCSection.cpp
parent0aac30195c8f3f7066d4d069693e5d91f054f081 (diff)
downloadllvm-892e18239308f8a02a4c83758616be84a459c19d.tar.gz
llvm-892e18239308f8a02a4c83758616be84a459c19d.tar.bz2
llvm-892e18239308f8a02a4c83758616be84a459c19d.tar.xz
1. Make MCSection an abstract class.
2. Move section switch printing to MCSection virtual method which takes a TAI. This eliminates textual formatting stuff from TLOF. 3. Eliminate SwitchToSectionDirective, getSectionFlagsAsString, and TLOFELF::AtIsCommentChar. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78510 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCSection.cpp')
-rw-r--r--lib/MC/MCSection.cpp114
1 files changed, 109 insertions, 5 deletions
diff --git a/lib/MC/MCSection.cpp b/lib/MC/MCSection.cpp
index ec6078ea37..a1f5664859 100644
--- a/lib/MC/MCSection.cpp
+++ b/lib/MC/MCSection.cpp
@@ -9,8 +9,14 @@
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCContext.h"
+#include "llvm/Target/TargetAsmInfo.h"
+#include "llvm/Support/raw_ostream.h"
using namespace llvm;
+//===----------------------------------------------------------------------===//
+// MCSection
+//===----------------------------------------------------------------------===//
+
MCSection::~MCSection() {
}
@@ -22,26 +28,124 @@ MCSection::MCSection(const StringRef &N, bool isDirective, SectionKind K,
Entry = this;
}
-MCSection *MCSection::
-Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
- return new (Ctx) MCSection(Name, IsDirective, K, Ctx);
-}
-
+//===----------------------------------------------------------------------===//
+// MCSectionELF
+//===----------------------------------------------------------------------===//
MCSectionELF *MCSectionELF::
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
}
+void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
+ raw_ostream &OS) const {
+ if (isDirective()) {
+ OS << getName() << '\n';
+ return;
+ }
+
+ OS << "\t.section\t" << getName();
+
+ // Handle the weird solaris syntax if desired.
+ if (TAI.usesSunStyleELFSectionSwitchSyntax() &&
+ !getKind().isMergeableConst() && !getKind().isMergeableCString()) {
+ if (!getKind().isMetadata())
+ OS << ",#alloc";
+ if (getKind().isText())
+ OS << ",#execinstr";
+ if (getKind().isWriteable())
+ OS << ",#write";
+ if (getKind().isThreadLocal())
+ OS << ",#tls";
+ } else {
+ OS << ",\"";
+
+ if (!getKind().isMetadata())
+ OS << 'a';
+ if (getKind().isText())
+ OS << 'x';
+ if (getKind().isWriteable())
+ OS << 'w';
+ if (getKind().isMergeable1ByteCString() ||
+ getKind().isMergeable2ByteCString() ||
+ getKind().isMergeable4ByteCString() ||
+ getKind().isMergeableConst4() ||
+ getKind().isMergeableConst8() ||
+ getKind().isMergeableConst16())
+ OS << 'M';
+ if (getKind().isMergeable1ByteCString() ||
+ getKind().isMergeable2ByteCString() ||
+ getKind().isMergeable4ByteCString())
+ OS << 'S';
+ if (getKind().isThreadLocal())
+ OS << 'T';
+
+ OS << "\",";
+
+ // If comment string is '@', e.g. as on ARM - use '%' instead
+ if (TAI.getCommentString()[0] == '@')
+ OS << '%';
+ else
+ OS << '@';
+
+ if (getKind().isBSS() || getKind().isThreadBSS())
+ OS << "nobits";
+ else
+ OS << "progbits";
+
+ if (getKind().isMergeable1ByteCString()) {
+ OS << ",1";
+ } else if (getKind().isMergeable2ByteCString()) {
+ OS << ",2";
+ } else if (getKind().isMergeable4ByteCString()) {
+ OS << ",4";
+ } else if (getKind().isMergeableConst4()) {
+ OS << ",4";
+ } else if (getKind().isMergeableConst8()) {
+ OS << ",8";
+ } else if (getKind().isMergeableConst16()) {
+ OS << ",16";
+ }
+ }
+}
+
+//===----------------------------------------------------------------------===//
+// MCSectionMachO
+//===----------------------------------------------------------------------===//
MCSectionMachO *MCSectionMachO::
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionMachO(Name, IsDirective, K, Ctx);
}
+void MCSectionMachO::PrintSwitchToSection(const TargetAsmInfo &TAI,
+ raw_ostream &OS) const {
+ if (!isDirective())
+ OS << "\t.section\t" << getName() << '\n';
+ else
+ OS << getName() << '\n';
+}
+
+//===----------------------------------------------------------------------===//
+// MCSectionCOFF
+//===----------------------------------------------------------------------===//
MCSectionCOFF *MCSectionCOFF::
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
}
+void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
+ raw_ostream &OS) const {
+
+ if (isDirective()) {
+ OS << getName() << '\n';
+ return;
+ }
+ OS << "\t.section\t" << getName() << ",\"";
+ if (getKind().isText())
+ OS << 'x';
+ if (getKind().isWriteable())
+ OS << 'w';
+ OS << "\"\n";
+}