LLVM 24.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
21static void printName(raw_ostream &OS, StringRef Name) {
22 if (Name.find_first_not_of("0123456789_."
23 "abcdefghijklmnopqrstuvwxyz"
24 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
25 OS << Name;
26 return;
27 }
28 OS << '"';
29 for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
30 if (*B == '"') // Unquoted "
31 OS << "\\\"";
32 else if (*B != '\\') // Neither " or backslash
33 OS << *B;
34 else if (B + 1 == E) // Trailing backslash
35 OS << "\\\\";
36 else {
37 OS << B[0] << B[1]; // Quoted character
38 ++B;
39 }
40 }
41 OS << '"';
42}
43
44static void printSwitchToSection(const MCAsmInfo &MAI, const MCSection &Section,
45 uint32_t Subsection, const Triple &T,
46 raw_ostream &OS) {
47 auto &Sec = static_cast<const MCSectionWasm &>(Section);
48 if (MAI.isSectionDirective(Sec.getName())) {
49 OS << '\t' << Sec.getName();
50 if (Subsection)
51 OS << '\t' << Subsection;
52 OS << '\n';
53 return;
54 }
55
56 OS << "\t.section\t";
57 printName(OS, Sec.getName());
58 OS << ",\"";
59
60 unsigned SegmentFlags = Sec.getSegmentFlags();
61
62 if (Sec.isWasmData() && Sec.getPassive())
63 OS << 'p';
64 if (Sec.getGroup())
65 OS << 'G';
66 if (SegmentFlags & wasm::WASM_SEG_FLAG_STRINGS)
67 OS << 'S';
68 if (SegmentFlags & wasm::WASM_SEG_FLAG_TLS)
69 OS << 'T';
70 if (SegmentFlags & wasm::WASM_SEG_FLAG_RETAIN)
71 OS << 'R';
72
73 OS << '"';
74
75 OS << ',';
76
77 // If comment string is '@', e.g. as on ARM - use '%' instead
78 if (MAI.getCommentString()[0] == '@')
79 OS << '%';
80 else
81 OS << '@';
82
83 // TODO: Print section type.
84
85 if (const MCSymbolWasm *Group = Sec.getGroup()) {
86 OS << ",";
87 printName(OS, Group->getName());
88 OS << ",comdat";
89 }
90
91 if (Sec.isUnique())
92 OS << ",unique," << Sec.getUniqueID();
93
94 OS << '\n';
95
96 if (Subsection)
97 OS << "\t.subsection\t" << Subsection << '\n';
98}
99
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 printSwitchToSection(const MCAsmInfo &MAI, const MCSection &Section, uint32_t Subsection, const Triple &T, raw_ostream &OS)
static void printName(raw_ostream &OS, StringRef Name)
#define T
MCAsmInfoWasm(const MCTargetOptions &Options)
This class is intended to be used as a base class for asm properties and features specific to the tar...
Definition MCAsmInfo.h:69
StringRef InternalSymbolPrefix
For internal use by compiler and assembler, not meant to be visible externally.
Definition MCAsmInfo.h:169
bool HasNoDeadStrip
True if this target supports the MachO .no_dead_strip directive.
Definition MCAsmInfo.h:334
MCAsmInfo(const MCTargetOptions &Options)
Definition MCAsmInfo.cpp:28
void printSwitchToSection(const MCSection &Sec, uint32_t Subsection, const Triple &T, raw_ostream &OS) const
Definition MCAsmInfo.h:555
const char * WeakRefDirective
This directive, if non-null, is used to declare a global as being a weak undefined symbol.
Definition MCAsmInfo.h:341
StringRef getCommentString() const
Definition MCAsmInfo.h:587
bool HasIdentDirective
True if the target has a .ident directive, this is true for ELF targets.
Definition MCAsmInfo.h:330
void(* PrintSwitchToSectionFn)(const MCAsmInfo &, const MCSection &, uint32_t Subsection, const Triple &, raw_ostream &)
Definition MCAsmInfo.h:276
bool isSectionDirective(StringRef SecName) const
Definition MCAsmInfo.h:551
This represents a section on wasm.
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:577
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Triple - Helper class for working with autoconf configuration names.
Definition Triple.h:48
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:242
@ WASM_SEG_FLAG_TLS
Definition Wasm.h:241
@ WASM_SEG_FLAG_STRINGS
Definition Wasm.h:240
This is an optimization pass for GlobalISel generic memory operations.