annotate lib/MC/MCSectionWasm.cpp @ 121:803732b1fca8

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