Chris Lattner | ed47a04 | 2009-07-31 17:02:00 +0000 | [diff] [blame] | 1 | //===- 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 Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 12 | #include "llvm/Target/TargetAsmInfo.h" |
| 13 | #include "llvm/Support/raw_ostream.h" |
Chris Lattner | ed47a04 | 2009-07-31 17:02:00 +0000 | [diff] [blame] | 14 | using namespace llvm; |
| 15 | |
Chris Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 16 | //===----------------------------------------------------------------------===// |
| 17 | // MCSection |
| 18 | //===----------------------------------------------------------------------===// |
| 19 | |
Chris Lattner | ed47a04 | 2009-07-31 17:02:00 +0000 | [diff] [blame] | 20 | MCSection::~MCSection() { |
| 21 | } |
| 22 | |
Chris Lattner | ed47a04 | 2009-07-31 17:02:00 +0000 | [diff] [blame] | 23 | |
Chris Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 24 | //===----------------------------------------------------------------------===// |
| 25 | // MCSectionELF |
| 26 | //===----------------------------------------------------------------------===// |
Chris Lattner | a1c31b7 | 2009-08-08 20:50:49 +0000 | [diff] [blame] | 27 | |
| 28 | MCSectionELF *MCSectionELF:: |
| 29 | Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) { |
Chris Lattner | 38cff38 | 2009-08-13 00:37:15 +0000 | [diff] [blame^] | 30 | return new (Ctx) MCSectionELF(Name, IsDirective, K); |
Chris Lattner | a1c31b7 | 2009-08-08 20:50:49 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Chris Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 33 | void 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 Lattner | 1f8e8db | 2009-08-09 15:31:10 +0000 | [diff] [blame] | 103 | |
| 104 | OS << '\n'; |
Chris Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Chris Lattner | ff4bc46 | 2009-08-10 01:39:42 +0000 | [diff] [blame] | 107 | |
Chris Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 108 | //===----------------------------------------------------------------------===// |
| 109 | // MCSectionCOFF |
| 110 | //===----------------------------------------------------------------------===// |
Chris Lattner | a1c31b7 | 2009-08-08 20:50:49 +0000 | [diff] [blame] | 111 | |
Chris Lattner | 7c599d0 | 2009-08-08 20:52:13 +0000 | [diff] [blame] | 112 | MCSectionCOFF *MCSectionCOFF:: |
Chris Lattner | a1c31b7 | 2009-08-08 20:50:49 +0000 | [diff] [blame] | 113 | Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) { |
Chris Lattner | 38cff38 | 2009-08-13 00:37:15 +0000 | [diff] [blame^] | 114 | return new (Ctx) MCSectionCOFF(Name, IsDirective, K); |
Chris Lattner | a1c31b7 | 2009-08-08 20:50:49 +0000 | [diff] [blame] | 115 | } |
| 116 | |
Chris Lattner | 892e182 | 2009-08-08 22:41:53 +0000 | [diff] [blame] | 117 | void 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 | } |