llvm.org GIT mirror llvm / de9a1a2
Remove AllowQuotesInName and friends from MCAsmInfo. Accepting quotes is a property of an assembler, not of an object file. For example, ELF can support any names for sections and symbols, but the gnu assembler only accepts quotes in some contexts and llvm-mc in a few more. LLVM should not produce different symbols based on a guess about which assembler will be reading the code it is printing. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194575 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 6 years ago
11 changed file(s) with 48 addition(s) and 132 deletion(s). Raw diff Collapse all Expand all
143143 /// AssemblerDialect - Which dialect of an assembler variant to use.
144144 unsigned AssemblerDialect; // Defaults to 0
145145
146 /// AllowQuotesInName - This is true if the assembler allows for complex
147 /// symbol names to be surrounded in quotes. This defaults to false.
148 bool AllowQuotesInName;
149
150 /// AllowNameToStartWithDigit - This is true if the assembler allows symbol
151 /// names to start with a digit (e.g., "0x0021"). This defaults to false.
152 bool AllowNameToStartWithDigit;
153
154 /// AllowPeriodsInName - This is true if the assembler allows periods in
155 /// symbol names. This defaults to true.
156 bool AllowPeriodsInName;
157
158146 /// \brief This is true if the assembler allows @ characters in symbol
159147 /// names. Defaults to false.
160148 bool AllowAtInName;
466454 unsigned getAssemblerDialect() const {
467455 return AssemblerDialect;
468456 }
469 bool doesAllowQuotesInName() const {
470 return AllowQuotesInName;
471 }
472 bool doesAllowNameToStartWithDigit() const {
473 return AllowNameToStartWithDigit;
474 }
475 bool doesAllowPeriodsInName() const {
476 return AllowPeriodsInName;
477 }
478457 bool doesAllowAtInName() const {
479458 return AllowAtInName;
480459 }
4949 Code32Directive = ".code32";
5050 Code64Directive = ".code64";
5151 AssemblerDialect = 0;
52 AllowQuotesInName = false;
53 AllowNameToStartWithDigit = false;
54 AllowPeriodsInName = true;
5552 AllowAtInName = false;
5653 UseDataRegionDirectives = false;
5754 ZeroDirective = "\t.zero\t";
4242 void MCAsmInfoMicrosoft::anchor() { }
4343
4444 MCAsmInfoMicrosoft::MCAsmInfoMicrosoft() {
45 AllowQuotesInName = true;
4645 }
4746
4847 void MCAsmInfoGNUCOFF::anchor() { }
2525 GlobalPrefix = "_";
2626 PrivateGlobalPrefix = "L";
2727 LinkerPrivateGlobalPrefix = "l";
28 AllowQuotesInName = true;
2928 HasSingleParameterDotFile = false;
3029 HasSubsectionsViaSymbols = true;
3130
3131 return false;
3232 }
3333
34 static void printName(raw_ostream &OS, StringRef Name) {
35 if (Name.find_first_not_of("0123456789_."
36 "abcdefghijklmnopqrstuvwxyz"
37 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == Name.npos) {
38 OS << Name;
39 return;
40 }
41 OS << '"';
42 for (const char *B = Name.begin(), *E = Name.end(); B < E; ++B) {
43 if (*B == '"') // Unquoted "
44 OS << "\\\"";
45 else if (*B != '\\') // Neither " or backslash
46 OS << *B;
47 else if (B + 1 == E) // Trailing backslash
48 OS << "\\\\";
49 else {
50 OS << B[0] << B[1]; // Quoted character
51 ++B;
52 }
53 }
54 OS << '"';
55 }
56
3457 void MCSectionELF::PrintSwitchToSection(const MCAsmInfo &MAI,
3558 raw_ostream &OS,
3659 const MCExpr *Subsection) const {
4366 return;
4467 }
4568
46 StringRef name = getSectionName();
47 if (name.find_first_not_of("0123456789_."
48 "abcdefghijklmnopqrstuvwxyz"
49 "ABCDEFGHIJKLMNOPQRSTUVWXYZ") == name.npos) {
50 OS << "\t.section\t" << name;
51 } else {
52 OS << "\t.section\t\"";
53 for (const char *b = name.begin(), *e = name.end(); b < e; ++b) {
54 if (*b == '"') // Unquoted "
55 OS << "\\\"";
56 else if (*b != '\\') // Neither " or backslash
57 OS << *b;
58 else if (b + 1 == e) // Trailing backslash
59 OS << "\\\\";
60 else {
61 OS << b[0] << b[1]; // Quoted character
62 ++b;
63 }
64 }
65 OS << '"';
66 }
69 OS << "\t.section\t";
70 printName(OS, getSectionName());
6771
6872 // Handle the weird solaris syntax if desired.
6973 if (MAI.usesSunStyleELFSectionSwitchSyntax() &&
134138 OS << "," << EntrySize;
135139 }
136140
137 if (Flags & ELF::SHF_GROUP)
138 OS << "," << Group->getName() << ",comdat";
141 if (Flags & ELF::SHF_GROUP) {
142 OS << ",";
143 printName(OS, Group->getName());
144 OS << ",comdat";
145 }
139146 OS << '\n';
140147
141148 if (Subsection)
2323 CommentString = ";";
2424
2525 AlignmentIsInBytes = false;
26 AllowNameToStartWithDigit = true;
2726 UsesELFSectionDirectiveForBSS = true;
2827 }
2222 #include "llvm/Support/raw_ostream.h"
2323 using namespace llvm;
2424
25 static bool isAcceptableChar(char C, bool AllowPeriod) {
26 if ((C < 'a' || C > 'z') &&
27 (C < 'A' || C > 'Z') &&
28 (C < '0' || C > '9') &&
29 C != '_' && C != '$' && C != '@' &&
30 !(AllowPeriod && C == '.') &&
31 !(C & 0x80))
32 return false;
33 return true;
34 }
35
3625 static char HexDigit(int V) {
3726 return V < 10 ? V+'0' : V+'A'-10;
3827 }
4332 OutName.push_back(HexDigit(C & 15));
4433 OutName.push_back('_');
4534 }
46
47 /// NameNeedsEscaping - Return true if the identifier \p Str needs quotes
48 /// for this assembler.
49 static bool NameNeedsEscaping(StringRef Str, const MCAsmInfo *MAI) {
50 assert(!Str.empty() && "Cannot create an empty MCSymbol");
51
52 // If the first character is a number and the target does not allow this, we
53 // need quotes.
54 if (!MAI->doesAllowNameToStartWithDigit() && Str[0] >= '0' && Str[0] <= '9')
55 return true;
56
57 // If any of the characters in the string is an unacceptable character, force
58 // quotes.
59 bool AllowPeriod = MAI->doesAllowPeriodsInName();
60 for (unsigned i = 0, e = Str.size(); i != e; ++i)
61 if (!isAcceptableChar(Str[i], AllowPeriod))
62 return true;
63 return false;
64 }
65
66 /// appendMangledName - Add the specified string in mangled form if it uses
67 /// any unusual characters.
68 static void appendMangledName(SmallVectorImpl &OutName, StringRef Str,
69 const MCAsmInfo *MAI) {
70 // The first character is not allowed to be a number unless the target
71 // explicitly allows it.
72 if (!MAI->doesAllowNameToStartWithDigit() && Str[0] >= '0' && Str[0] <= '9') {
73 MangleLetter(OutName, Str[0]);
74 Str = Str.substr(1);
75 }
76
77 bool AllowPeriod = MAI->doesAllowPeriodsInName();
78 for (unsigned i = 0, e = Str.size(); i != e; ++i) {
79 if (!isAcceptableChar(Str[i], AllowPeriod))
80 MangleLetter(OutName, Str[i]);
81 else
82 OutName.push_back(Str[i]);
83 }
84 }
85
8635
8736 /// appendMangledQuotedName - On systems that support quoted symbols, we still
8837 /// have to escape some (obscure) characters like " and \n which would break the
13382 OutName.append(Prefix, Prefix+strlen(Prefix));
13483 }
13584 }
136
85
13786 // If this is a simple string that doesn't need escaping, just append it.
138 if (!NameNeedsEscaping(Name, MAI) ||
139 // If quotes are supported, they can be used unless the string contains
140 // a quote or newline.
141 (MAI->doesAllowQuotesInName() &&
142 Name.find_first_of("\n\"") == StringRef::npos)) {
87 // Quotes can be used unless the string contains a quote or newline.
88 if (Name.find_first_of("\n\"") == StringRef::npos) {
14389 OutName.append(Name.begin(), Name.end());
14490 return;
14591 }
146
147 // On systems that do not allow quoted names, we need to mangle most
148 // strange characters.
149 if (!MAI->doesAllowQuotesInName())
150 return appendMangledName(OutName, Name, MAI);
151
92
15293 // Okay, the system allows quoted strings. We can quote most anything, the
15394 // only characters that need escaping are " and \n.
15495 assert(Name.find_first_of("\n\"") != StringRef::npos);
3434
3535 PrivateGlobalPrefix = "$L__";
3636
37 AllowPeriodsInName = false;
38
3937 HasSetDirective = false;
4038
4139 HasSingleParameterDotFile = false;
3030 InlineAsmStart = ";#ASMSTART";
3131 InlineAsmEnd = ";#ASMEND";
3232 AssemblerDialect = 0;
33 AllowQuotesInName = false;
34 AllowNameToStartWithDigit = false;
35 AllowPeriodsInName = false;
3633
3734 //===--- Data Emission Directives -------------------------------------===//
3835 ZeroDirective = ".zero";
11
22 define i32 @main(i32 %x) nounwind gc "ocaml" {
33 ; CHECK: .text
4 ; CHECK-NEXT: .globl caml_3C_stdin_3E___code_begin
5 ; CHECK-NEXT: caml_3C_stdin_3E___code_begin:
4 ; CHECK-NEXT: .globl "caml__code_begin"
5 ; CHECK-NEXT: "caml__code_begin":
66 ; CHECK-NEXT: .data
7 ; CHECK-NEXT: .globl caml_3C_stdin_3E___data_begin
8 ; CHECK-NEXT: caml_3C_stdin_3E___data_begin:
7 ; CHECK-NEXT: .globl "caml__data_begin"
8 ; CHECK-NEXT: "caml__data_begin":
99
1010 %puts = tail call i32 @foo(i32 %x)
1111 ret i32 0
1212
13 ; CHECK: .globl caml_3C_stdin_3E___code_end
14 ; CHECK-NEXT: caml_3C_stdin_3E___code_end:
13 ; CHECK: .globl "caml__code_end"
14 ; CHECK-NEXT: "caml__code_end":
1515 ; CHECK-NEXT: .data
16 ; CHECK-NEXT: .globl caml_3C_stdin_3E___data_end
17 ; CHECK-NEXT: caml_3C_stdin_3E___data_end:
16 ; CHECK-NEXT: .globl "caml__data_end"
17 ; CHECK-NEXT: "caml__data_end":
1818 ; CHECK-NEXT: .quad 0
19 ; CHECK-NEXT: .globl caml_3C_stdin_3E___frametable
20 ; CHECK-NEXT: caml_3C_stdin_3E___frametable:
19 ; CHECK-NEXT: .globl "caml__frametable"
20 ; CHECK-NEXT: "caml__frametable":
2121 ; CHECK-NEXT: .short 1
2222 ; CHECK-NEXT: .align 8
2323 ; CHECK-NEXT: # live roots for main
6464 ; PR4584
6565 @"foo bar" = linkonce global i32 42
6666
67 ; LINUX: .type foo_20_bar,@object
68 ; LINUX: .section .data.foo_20_bar,"aGw",@progbits,foo_20_bar,comdat
69 ; LINUX: .weak foo_20_bar
70 ; LINUX: foo_20_bar:
67 ; LINUX: .type "foo bar",@object
68 ; LINUX: .section ".data.foo bar","aGw",@progbits,"foo bar",comdat
69 ; LINUX: .weak "foo bar"
70 ; LINUX: "foo bar":
7171
7272 ; DARWIN: .section __DATA,__datacoal_nt,coalesced
7373 ; DARWIN: .globl "_foo bar"