Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
MCAsmInfoWasm.cpp
Go to the documentation of this file.
1//===-- MCAsmInfoWasm.cpp - Wasm asm properties -----------------*- C++ -*-===//
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//
9// This file defines target asm properties related what form asm statements
10// should take in general on Wasm-based targets
11//
12//===----------------------------------------------------------------------===//
13
18
19using namespace llvm;
20
28
29static void printName(raw_ostream &OS, StringRef Name) {
30 if (Name.find_first_not_of("0123456789_."
31 "abcdefghijklmnopqrstuvwxyz"
32 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
33 OS << Name;
34 return;
35 }
36 OS << '"';
37 for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
38 if (*B == '"') // Unquoted "
39 OS << "\\\"";
40 else if (*B != '\\') // Neither " or backslash
41 OS << *B;
42 else if (B + 1 == E) // Trailing backslash
43 OS << "\\\\";
44 else {
45 OS << B[0] << B[1]; // Quoted character
46 ++B;
47 }
48 }
49 OS << '"';
50}
51
52void MCAsmInfoWasm::printSwitchToSection(const MCSection &Section,
53 uint32_t Subsection, const Triple &T,
54 raw_ostream &OS) const {
55 auto &Sec = static_cast<const MCSectionWasm &>(Section);
56 if (shouldOmitSectionDirective(Sec.getName())) {
57 OS << '\t' << Sec.getName();
58 if (Subsection)
59 OS << '\t' << Subsection;
60 OS << '\n';
61 return;
62 }
63
64 OS << "\t.section\t";
65 printName(OS, Sec.getName());
66 OS << ",\"";
67
68 if (Sec.IsPassive)
69 OS << 'p';
70 if (Sec.Group)
71 OS << 'G';
72 if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
73 OS << 'S';
74 if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
75 OS << 'T';
76 if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN)
77 OS << 'R';
78
79 OS << '"';
80
81 OS << ',';
82
83 // If comment string is '@', e.g. as on ARM - use '%' instead
84 if (getCommentString()[0] == '@')
85 OS << '%';
86 else
87 OS << '@';
88
89 // TODO: Print section type.
90
91 if (Sec.Group) {
92 OS << ",";
93 printName(OS, Sec.Group->getName());
94 OS << ",comdat";
95 }
96
97 if (Sec.isUnique())
98 OS << ",unique," << Sec.UniqueID;
99
100 OS << '\n';
101
102 if (Subsection)
103 OS << "\t.subsection\t" << Subsection << '\n';
104}
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static void printName(raw_ostream &OS, StringRef Name)
#define T
bool HasNoDeadStrip
True if this target supports the MachO .no_dead_strip directive.
Definition MCAsmInfo.h:318
StringRef PrivateGlobalPrefix
This prefix is used for globals like constant pool entries that are completely private to the ....
Definition MCAsmInfo.h:160
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:325
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks.
Definition MCAsmInfo.h:164
StringRef getCommentString() const
Definition MCAsmInfo.h:538
virtual bool shouldOmitSectionDirective(StringRef SectionName) const
Return true if the .section directive should be omitted when emitting SectionName.
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition MCAsmInfo.h:314
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:521
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:47
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition raw_ostream.h:53
@ WASM_SEG_FLAG_RETAIN
Definition Wasm.h:231
@ WASM_SEG_FLAG_TLS
Definition Wasm.h:230
@ WASM_SEG_FLAG_STRINGS
Definition Wasm.h:229
This is an optimization pass for GlobalISel generic memory operations.