LLVM  5.0.0
MCSectionWasm.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCSectionWasm.cpp - Wasm 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/MCSectionWasm.h"
11 #include "llvm/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/MC/MCSymbol.h"
16 
17 using namespace llvm;
18 
20 
21 // Decides whether a '.section' directive
22 // should be printed before the section name.
24  const MCAsmInfo &MAI) const {
25  return MAI.shouldOmitSectionDirective(Name);
26 }
27 
28 static void printName(raw_ostream &OS, StringRef Name) {
29  if (Name.find_first_not_of("0123456789_."
30  "abcdefghijklmnopqrstuvwxyz"
31  "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
32  OS << Name;
33  return;
34  }
35  OS << '"';
36  for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
37  if (*B == '"') // Unquoted "
38  OS << "\\\"";
39  else if (*B != '\\') // Neither " or backslash
40  OS << *B;
41  else if (B + 1 == E) // Trailing backslash
42  OS << "\\\\";
43  else {
44  OS << B[0] << B[1]; // Quoted character
45  ++B;
46  }
47  }
48  OS << '"';
49 }
50 
52  raw_ostream &OS,
53  const MCExpr *Subsection) const {
54 
55  if (ShouldOmitSectionDirective(SectionName, MAI)) {
56  OS << '\t' << getSectionName();
57  if (Subsection) {
58  OS << '\t';
59  Subsection->print(OS, &MAI);
60  }
61  OS << '\n';
62  return;
63  }
64 
65  OS << "\t.section\t";
67  OS << ",\"";
68 
69  // TODO: Print section flags.
70 
71  OS << '"';
72 
73  OS << ',';
74 
75  // If comment string is '@', e.g. as on ARM - use '%' instead
76  if (MAI.getCommentString()[0] == '@')
77  OS << '%';
78  else
79  OS << '@';
80 
81  // TODO: Print section type.
82 
83  if (isUnique())
84  OS << ",unique," << UniqueID;
85 
86  OS << '\n';
87 
88  if (Subsection) {
89  OS << "\t.subsection\t";
90  Subsection->print(OS, &MAI);
91  OS << '\n';
92  }
93 }
94 
95 bool MCSectionWasm::UseCodeAlign() const { return false; }
96 
97 bool MCSectionWasm::isVirtualSection() const { return false; }
StringRef getCommentString() const
Definition: MCAsmInfo.h:470
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
static void printName(raw_ostream &OS, StringRef Name)
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
Definition: MCAsmInfo.cpp:108
StringRef getSectionName() const
Definition: MCSectionWasm.h:65
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
const char * Name
iterator begin() const
Definition: StringRef.h:106
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
bool isUnique() const
Definition: MCSectionWasm.h:77
LLVM_NODISCARD size_t find_first_not_of(char C, size_t From=0) const
Find the first character in the string that is not C or npos if not found.
Definition: StringRef.cpp:265
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a '.section' directive should be printed before the section name. ...
#define E
Definition: LargeTest.cpp:27
#define B
Definition: LargeTest.cpp:24
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
static const size_t npos
Definition: StringRef.h:51
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:40
iterator end() const
Definition: StringRef.h:108
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:44
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.