LLVM  9.0.0svn
MCSectionWasm.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCSectionWasm.cpp - Wasm Code Section Representation --------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCSymbol.h"
14 
15 using namespace llvm;
16 
17 // Decides whether a '.section' directive
18 // should be printed before the section name.
20  const MCAsmInfo &MAI) const {
21  return MAI.shouldOmitSectionDirective(Name);
22 }
23 
24 static void printName(raw_ostream &OS, StringRef Name) {
25  if (Name.find_first_not_of("0123456789_."
26  "abcdefghijklmnopqrstuvwxyz"
27  "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
28  OS << Name;
29  return;
30  }
31  OS << '"';
32  for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
33  if (*B == '"') // Unquoted "
34  OS << "\\\"";
35  else if (*B != '\\') // Neither " or backslash
36  OS << *B;
37  else if (B + 1 == E) // Trailing backslash
38  OS << "\\\\";
39  else {
40  OS << B[0] << B[1]; // Quoted character
41  ++B;
42  }
43  }
44  OS << '"';
45 }
46 
48  raw_ostream &OS,
49  const MCExpr *Subsection) const {
50 
52  OS << '\t' << getSectionName();
53  if (Subsection) {
54  OS << '\t';
55  Subsection->print(OS, &MAI);
56  }
57  OS << '\n';
58  return;
59  }
60 
61  OS << "\t.section\t";
63  OS << ",\"";
64 
65  if (IsPassive)
66  OS << "passive";
67 
68  OS << '"';
69 
70  OS << ',';
71 
72  // If comment string is '@', e.g. as on ARM - use '%' instead
73  if (MAI.getCommentString()[0] == '@')
74  OS << '%';
75  else
76  OS << '@';
77 
78  // TODO: Print section type.
79 
80  if (isUnique())
81  OS << ",unique," << UniqueID;
82 
83  OS << '\n';
84 
85  if (Subsection) {
86  OS << "\t.subsection\t";
87  Subsection->print(OS, &MAI);
88  OS << '\n';
89  }
90 }
91 
92 bool MCSectionWasm::UseCodeAlign() const { return false; }
93 
94 bool MCSectionWasm::isVirtualSection() const { return false; }
This class represents lattice values for constants.
Definition: AllocatorList.h:23
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
StringRef getSectionName() const
Definition: MCSectionWasm.h:59
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:35
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:118
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:55
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:41
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:249
StringRef getCommentString() const
Definition: MCAsmInfo.h:485
bool isUnique() const
Definition: MCSectionWasm.h:72
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:43
void PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T, raw_ostream &OS, const MCExpr *Subsection) const override
iterator begin() const
Definition: StringRef.h:101
static const size_t npos
Definition: StringRef.h:50
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:45
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool shouldOmitSectionDirective(StringRef Name, const MCAsmInfo &MAI) const
Decides whether a &#39;.section&#39; directive should be printed before the section name. ...
bool isVirtualSection() const override
Check whether this section is "virtual", that is has no actual object file contents.
iterator end() const
Definition: StringRef.h:103