annotate lib/MC/MCSectionWasm.cpp @ 134:3a76565eade5 LLVM5.0.1

update 5.0.1
author mir3636
date Sat, 17 Feb 2018 09:57:20 +0900
parents 803732b1fca8
children c2174574ed3a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===- lib/MC/MCSectionWasm.cpp - Wasm Code Section Representation --------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 #include "llvm/MC/MCSectionWasm.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 #include "llvm/MC/MCAsmInfo.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 #include "llvm/MC/MCExpr.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13 #include "llvm/MC/MCSymbol.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "llvm/Support/raw_ostream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 MCSectionWasm::~MCSectionWasm() {} // anchor.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20 // Decides whether a '.section' directive
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 // should be printed before the section name.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 bool MCSectionWasm::ShouldOmitSectionDirective(StringRef Name,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23 const MCAsmInfo &MAI) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 return MAI.shouldOmitSectionDirective(Name);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 static void printName(raw_ostream &OS, StringRef Name) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 if (Name.find_first_not_of("0123456789_."
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 "abcdefghijklmnopqrstuvwxyz"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 OS << Name;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 OS << '"';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 if (*B == '"') // Unquoted "
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 OS << "\\\"";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 else if (*B != '\\') // Neither " or backslash
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 OS << *B;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 else if (B + 1 == E) // Trailing backslash
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 OS << "\\\\";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 else {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43 OS << B[0] << B[1]; // Quoted character
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 ++B;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 OS << '"';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 void MCSectionWasm::PrintSwitchToSection(const MCAsmInfo &MAI, const Triple &T,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 raw_ostream &OS,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52 const MCExpr *Subsection) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 if (ShouldOmitSectionDirective(SectionName, MAI)) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 OS << '\t' << getSectionName();
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56 if (Subsection) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 OS << '\t';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 Subsection->print(OS, &MAI);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60 OS << '\n';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 return;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 OS << "\t.section\t";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 printName(OS, getSectionName());
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 OS << ",\"";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 // TODO: Print section flags.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 OS << '"';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 OS << ',';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 // If comment string is '@', e.g. as on ARM - use '%' instead
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 if (MAI.getCommentString()[0] == '@')
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76 OS << '%';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 else
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 OS << '@';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80 // TODO: Print section type.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 if (isUnique())
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 OS << ",unique," << UniqueID;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 OS << '\n';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 if (Subsection) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 OS << "\t.subsection\t";
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 Subsection->print(OS, &MAI);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 OS << '\n';
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 bool MCSectionWasm::UseCodeAlign() const { return false; }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 bool MCSectionWasm::isVirtualSection() const { return false; }