OSDN Git Service

Tentative fix for r351701 and gcc 6.2 build on ubuntu
[android-x86/external-llvm.git] / lib / MC / MCSectionWasm.cpp
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
9 #include "llvm/MC/MCSectionWasm.h"
10 #include "llvm/MC/MCAsmInfo.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCSymbol.h"
13 #include "llvm/Support/raw_ostream.h"
14
15 using namespace llvm;
16
17 MCSectionWasm::~MCSectionWasm() {} // anchor.
18
19 // Decides whether a '.section' directive
20 // should be printed before the section name.
21 bool MCSectionWasm::ShouldOmitSectionDirective(StringRef Name,
22                                                const MCAsmInfo &MAI) const {
23   return MAI.shouldOmitSectionDirective(Name);
24 }
25
26 static void printName(raw_ostream &OS, StringRef Name) {
27   if (Name.find_first_not_of("0123456789_."
28                              "abcdefghijklmnopqrstuvwxyz"
29                              "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
30     OS << Name;
31     return;
32   }
33   OS << '"';
34   for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
35     if (*B == '"') // Unquoted "
36       OS << "\\\"";
37     else if (*B != '\\') // Neither " or backslash
38       OS << *B;
39     else if (B + 1 == E) // Trailing backslash
40       OS << "\\\\";
41     else {
42       OS << B[0] << B[1]; // Quoted character
43       ++B;
44     }
45   }
46   OS << '"';
47 }
48
49 void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
50                                          raw_ostream &OS,
51                                          const MCExpr *Subsection) const {
52
53   if (ShouldOmitSectionDirective(SectionName, MAI)) {
54     OS << '\t' << getSectionName();
55     if (Subsection) {
56       OS << '\t';
57       Subsection->print(OS, &MAI);
58     }
59     OS << '\n';
60     return;
61   }
62
63   OS << "\t.section\t";
64   printName(OS, getSectionName());
65   OS << ",\"";
66
67   // TODO: Print section flags.
68
69   OS << '"';
70
71   OS << ',';
72
73   // If comment string is '@', e.g. as on ARM - use '%' instead
74   if (MAI.getCommentString()[0] == '@')
75     OS << '%';
76   else
77     OS << '@';
78
79   // TODO: Print section type.
80
81   if (isUnique())
82     OS << ",unique," << UniqueID;
83
84   OS << '\n';
85
86   if (Subsection) {
87     OS << "\t.subsection\t";
88     Subsection->print(OS, &MAI);
89     OS << '\n';
90   }
91 }
92
93 bool MCSectionWasm::UseCodeAlign() const { return false; }
94
95 bool MCSectionWasm::isVirtualSection() const { return false; }