/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/MC/MCAsmInfo.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- MCAsmInfo.cpp - Asm Info -------------------------------------------===// |
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. |
11 | | // |
12 | | //===----------------------------------------------------------------------===// |
13 | | |
14 | | #include "llvm/MC/MCAsmInfo.h" |
15 | | #include "llvm/BinaryFormat/Dwarf.h" |
16 | | #include "llvm/MC/MCContext.h" |
17 | | #include "llvm/MC/MCExpr.h" |
18 | | #include "llvm/MC/MCStreamer.h" |
19 | | #include "llvm/Support/CommandLine.h" |
20 | | |
21 | | using namespace llvm; |
22 | | |
23 | | enum DefaultOnOff { Default, Enable, Disable }; |
24 | | static cl::opt<DefaultOnOff> DwarfExtendedLoc( |
25 | | "dwarf-extended-loc", cl::Hidden, |
26 | | cl::desc("Disable emission of the extended flags in .loc directives."), |
27 | | cl::values(clEnumVal(Default, "Default for platform"), |
28 | | clEnumVal(Enable, "Enabled"), clEnumVal(Disable, "Disabled")), |
29 | | cl::init(Default)); |
30 | | |
31 | 68.0k | MCAsmInfo::MCAsmInfo() { |
32 | 68.0k | SeparatorString = ";"; |
33 | 68.0k | CommentString = "#"; |
34 | 68.0k | LabelSuffix = ":"; |
35 | 68.0k | PrivateGlobalPrefix = "L"; |
36 | 68.0k | PrivateLabelPrefix = PrivateGlobalPrefix; |
37 | 68.0k | LinkerPrivateGlobalPrefix = ""; |
38 | 68.0k | InlineAsmStart = "APP"; |
39 | 68.0k | InlineAsmEnd = "NO_APP"; |
40 | 68.0k | Code16Directive = ".code16"; |
41 | 68.0k | Code32Directive = ".code32"; |
42 | 68.0k | Code64Directive = ".code64"; |
43 | 68.0k | ZeroDirective = "\t.zero\t"; |
44 | 68.0k | AsciiDirective = "\t.ascii\t"; |
45 | 68.0k | AscizDirective = "\t.asciz\t"; |
46 | 68.0k | Data8bitsDirective = "\t.byte\t"; |
47 | 68.0k | Data16bitsDirective = "\t.short\t"; |
48 | 68.0k | Data32bitsDirective = "\t.long\t"; |
49 | 68.0k | Data64bitsDirective = "\t.quad\t"; |
50 | 68.0k | GlobalDirective = "\t.globl\t"; |
51 | 68.0k | WeakDirective = "\t.weak\t"; |
52 | 68.0k | if (DwarfExtendedLoc != Default) |
53 | 2 | SupportsExtendedDwarfLocDirective = DwarfExtendedLoc == Enable; |
54 | 68.0k | |
55 | 68.0k | // FIXME: Clang's logic should be synced with the logic used to initialize |
56 | 68.0k | // this member and the two implementations should be merged. |
57 | 68.0k | // For reference: |
58 | 68.0k | // - Solaris always enables the integrated assembler by default |
59 | 68.0k | // - SparcELFMCAsmInfo and X86ELFMCAsmInfo are handling this case |
60 | 68.0k | // - Windows always enables the integrated assembler by default |
61 | 68.0k | // - MCAsmInfoCOFF is handling this case, should it be MCAsmInfoMicrosoft? |
62 | 68.0k | // - MachO targets always enables the integrated assembler by default |
63 | 68.0k | // - MCAsmInfoDarwin is handling this case |
64 | 68.0k | // - Generic_GCC toolchains enable the integrated assembler on a per |
65 | 68.0k | // architecture basis. |
66 | 68.0k | // - The target subclasses for AArch64, ARM, and X86 handle these cases |
67 | 68.0k | UseIntegratedAssembler = false; |
68 | 68.0k | PreserveAsmComments = true; |
69 | 68.0k | } |
70 | | |
71 | 55.1k | MCAsmInfo::~MCAsmInfo() = default; |
72 | | |
73 | 89.6k | void MCAsmInfo::addInitialFrameState(const MCCFIInstruction &Inst) { |
74 | 89.6k | InitialFrameState.push_back(Inst); |
75 | 89.6k | } |
76 | | |
77 | 0 | bool MCAsmInfo::isSectionAtomizableBySymbols(const MCSection &Section) const { |
78 | 0 | return false; |
79 | 0 | } |
80 | | |
81 | | const MCExpr * |
82 | | MCAsmInfo::getExprForPersonalitySymbol(const MCSymbol *Sym, |
83 | | unsigned Encoding, |
84 | 62 | MCStreamer &Streamer) const { |
85 | 62 | return getExprForFDESymbol(Sym, Encoding, Streamer); |
86 | 62 | } |
87 | | |
88 | | const MCExpr * |
89 | | MCAsmInfo::getExprForFDESymbol(const MCSymbol *Sym, |
90 | | unsigned Encoding, |
91 | 25.8k | MCStreamer &Streamer) const { |
92 | 25.8k | if (!(Encoding & dwarf::DW_EH_PE_pcrel)) |
93 | 364 | return MCSymbolRefExpr::create(Sym, Streamer.getContext()); |
94 | 25.5k | |
95 | 25.5k | MCContext &Context = Streamer.getContext(); |
96 | 25.5k | const MCExpr *Res = MCSymbolRefExpr::create(Sym, Context); |
97 | 25.5k | MCSymbol *PCSym = Context.createTempSymbol(); |
98 | 25.5k | Streamer.EmitLabel(PCSym); |
99 | 25.5k | const MCExpr *PC = MCSymbolRefExpr::create(PCSym, Context); |
100 | 25.5k | return MCBinaryExpr::createSub(Res, PC, Context); |
101 | 25.5k | } |
102 | | |
103 | 25.9M | static bool isAcceptableChar(char C) { |
104 | 25.9M | return (C >= 'a' && C <= 'z'16.2M ) || (9.68M C >= 'A'9.68M && C <= 'Z'4.65M ) || |
105 | 25.9M | (8.41M C >= '0'8.41M && C <= '9'7.77M ) || C == '_'4.02M || C == '$'644k || C == '.'613k || C == '@'7.13k ; |
106 | 25.9M | } |
107 | | |
108 | 1.82M | bool MCAsmInfo::isValidUnquotedName(StringRef Name) const { |
109 | 1.82M | if (Name.empty()) |
110 | 0 | return false; |
111 | 1.82M | |
112 | 1.82M | // If any of the characters in the string is an unacceptable character, force |
113 | 1.82M | // quotes. |
114 | 25.9M | for (char C : Name)1.82M { |
115 | 25.9M | if (!isAcceptableChar(C)) |
116 | 4.34k | return false; |
117 | 25.9M | } |
118 | 1.82M | |
119 | 1.82M | return true1.81M ; |
120 | 1.82M | } |
121 | | |
122 | 195k | bool MCAsmInfo::shouldOmitSectionDirective(StringRef SectionName) const { |
123 | 195k | // FIXME: Does .section .bss/.data/.text work everywhere?? |
124 | 195k | return SectionName == ".text" || SectionName == ".data"112k || |
125 | 195k | (110k SectionName == ".bss"110k && !usesELFSectionDirectiveForBSS()1.85k ); |
126 | 195k | } |