LLVM 23.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
29
30static void printName(raw_ostream &OS, StringRef Name) {
31 if (Name.find_first_not_of("0123456789_."
32 "abcdefghijklmnopqrstuvwxyz"
33 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
34 OS << Name;
35 return;
36 }
37 OS << '"';
38 for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
39 if (*B == '"') // Unquoted "
40 OS << "\\\"";
41 else if (*B != '\\') // Neither " or backslash
42 OS << *B;
43 else if (B + 1 == E) // Trailing backslash
44 OS << "\\\\";
45 else {
46 OS << B[0] << B[1]; // Quoted character
47 ++B;
48 }
49 }
50 OS << '"';
51}
52
53void MCAsmInfoWasm::printSwitchToSection(const MCSection &Section,
54 uint32_t Subsection, const Triple &T,
55 raw_ostream &OS) const {
56 auto &Sec = static_cast<const MCSectionWasm &>(Section);
57 if (shouldOmitSectionDirective(Sec.getName())) {
58 OS << '\t' << Sec.getName();
59 if (Subsection)
60 OS << '\t' << Subsection;
61 OS << '\n';
62 return;
63 }
64
65 OS << "\t.section\t";
66 printName(OS, Sec.getName());
67 OS << ",\"";
68
69 if (Sec.IsPassive)
70 OS << 'p';
71 if (Sec.Group)
72 OS << 'G';
73 if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
74 OS << 'S';
75 if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
76 OS << 'T';
77 if (Sec.SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN)
78 OS << 'R';
79
80 OS << '"';
81
82 OS << ',';
83
84 // If comment string is '@', e.g. as on ARM - use '%' instead
85 if (getCommentString()[0] == '@')
86 OS << '%';
87 else
88 OS << '@';
89
90 // TODO: Print section type.
91
92 if (Sec.Group) {
93 OS << ",";
94 printName(OS, Sec.Group->getName());
95 OS << ",comdat";
96 }
97
98 if (Sec.isUnique())
99 OS << ",unique," << Sec.UniqueID;
100
101 OS << '\n';
102
103 if (Subsection)
104 OS << "\t.subsection\t" << Subsection << '\n';
105}
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static LVOptions Options
Definition LVOptions.cpp:25
static void printName(raw_ostream &OS, StringRef Name)
#define T
MCAsmInfoWasm(const MCTargetOptions &Options)
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:160
bool HasNoDeadStrip
True if this target supports the MachO .no_dead_strip directive.
Definition MCAsmInfo.h:320
MCAsmInfo(const MCTargetOptions &Options)
Definition MCAsmInfo.cpp:44
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:327
StringRef PrivateLabelPrefix
This prefix is used for labels for basic blocks. Defaults to "L".
Definition MCAsmInfo.h:163
StringRef getCommentString() const
Definition MCAsmInfo.h:544
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:316
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:569
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:240
@ WASM_SEG_FLAG_TLS
Definition Wasm.h:239
@ WASM_SEG_FLAG_STRINGS
Definition Wasm.h:238
This is an optimization pass for GlobalISel generic memory operations.