LLVM  8.0.1
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/MCExpr.h"
13 #include "llvm/MC/MCSymbol.h"
15 
16 using namespace llvm;
17 
19 
20 // Decides whether a '.section' directive
21 // should be printed before the section name.
23  const MCAsmInfo &MAI) const {
24  return MAI.shouldOmitSectionDirective(Name);
25 }
26 
27 static void printName(raw_ostream &OS, StringRef Name) {
28  if (Name.find_first_not_of("0123456789_."
29  "abcdefghijklmnopqrstuvwxyz"
30  "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
31  OS << Name;
32  return;
33  }
34  OS << '"';
35  for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
36  if (*B == '"') // Unquoted "
37  OS << "\\\"";
38  else if (*B != '\\') // Neither " or backslash
39  OS << *B;
40  else if (B + 1 == E) // Trailing backslash
41  OS << "\\\\";
42  else {
43  OS << B[0] << B[1]; // Quoted character
44  ++B;
45  }
46  }
47  OS << '"';
48 }
49 
51  raw_ostream &OS,
52  const MCExpr *Subsection) const {
53 
55  OS << '\t' << getSectionName();
56  if (Subsection) {
57  OS << '\t';
58  Subsection->print(OS, &MAI);
59  }
60  OS << '\n';
61  return;
62  }
63 
64  OS << "\t.section\t";
66  OS << ",\"";
67 
68  // TODO: Print section flags.
69 
70  OS << '"';
71 
72  OS << ',';
73 
74  // If comment string is '@', e.g. as on ARM - use '%' instead
75  if (MAI.getCommentString()[0] == '@')
76  OS << '%';
77  else
78  OS << '@';
79 
80  // TODO: Print section type.
81 
82  if (isUnique())
83  OS << ",unique," << UniqueID;
84 
85  OS << '\n';
86 
87  if (Subsection) {
88  OS << "\t.subsection\t";
89  Subsection->print(OS, &MAI);
90  OS << '\n';
91  }
92 }
93 
94 bool MCSectionWasm::UseCodeAlign() const { return false; }
95 
96 bool MCSectionWasm::isVirtualSection() const { return false; }
This class represents lattice values for constants.
Definition: AllocatorList.h:24
StringRef getSectionName() const
Definition: MCSectionWasm.h:61
amdgpu Simplify well known AMD library false Value Value const Twine & Name
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:119
bool ShouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a &#39;.section&#39; directive should be printed before the section name. ...
bool UseCodeAlign() const override
Return true if a .align directive should use "optimized nops" to fill instead of 0s.
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition: MCAsmInfo.h:56
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void print(raw_ostream &OS, const MCAsmInfo *MAI, bool InParens=false) const
Definition: MCExpr.cpp:42
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
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:250
StringRef getCommentString() const
Definition: MCAsmInfo.h:486
bool isUnique() const
Definition: MCSectionWasm.h:74
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
iterator begin() const
Definition: StringRef.h:106
static const size_t npos
Definition: StringRef.h:51
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
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.
iterator end() const
Definition: StringRef.h:108