/Users/buildslave/jenkins/sharedspace/clang-stage2-coverage-R@2/llvm/lib/MC/MCSymbol.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | //===- lib/MC/MCSymbol.cpp - MCSymbol implementation ----------------------===// |
2 | | // |
3 | | // The LLVM Compiler Infrastructure |
4 | | // |
5 | | // This file is distributed under the University of Illinois Open Source |
6 | | // License. See LICENSE.TXT for details. |
7 | | // |
8 | | //===----------------------------------------------------------------------===// |
9 | | |
10 | | #include "llvm/MC/MCSymbol.h" |
11 | | #include "llvm/ADT/StringRef.h" |
12 | | #include "llvm/MC/MCAsmInfo.h" |
13 | | #include "llvm/MC/MCContext.h" |
14 | | #include "llvm/MC/MCExpr.h" |
15 | | #include "llvm/MC/MCFragment.h" |
16 | | #include "llvm/Support/Compiler.h" |
17 | | #include "llvm/Support/Debug.h" |
18 | | #include "llvm/Support/ErrorHandling.h" |
19 | | #include "llvm/Support/raw_ostream.h" |
20 | | #include <cassert> |
21 | | #include <cstddef> |
22 | | |
23 | | using namespace llvm; |
24 | | |
25 | | // Only the address of this fragment is ever actually used. |
26 | | static MCDummyFragment SentinelFragment(nullptr); |
27 | | |
28 | | // Sentinel value for the absolute pseudo fragment. |
29 | | MCFragment *MCSymbol::AbsolutePseudoFragment = &SentinelFragment; |
30 | | |
31 | | void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name, |
32 | 8.63M | MCContext &Ctx) { |
33 | 8.63M | // We may need more space for a Name to account for alignment. So allocate |
34 | 8.63M | // space for the storage type and not the name pointer. |
35 | 8.63M | size_t Size = s + (Name ? sizeof(NameEntryStorageTy)4.94M : 03.68M ); |
36 | 8.63M | |
37 | 8.63M | // For safety, ensure that the alignment of a pointer is enough for an |
38 | 8.63M | // MCSymbol. This also ensures we don't need padding between the name and |
39 | 8.63M | // symbol. |
40 | 8.63M | static_assert((unsigned)alignof(MCSymbol) <= alignof(NameEntryStorageTy), |
41 | 8.63M | "Bad alignment of MCSymbol"); |
42 | 8.63M | void *Storage = Ctx.allocate(Size, alignof(NameEntryStorageTy)); |
43 | 8.63M | NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage); |
44 | 8.63M | NameEntryStorageTy *End = Start + (Name ? 14.94M : 03.68M ); |
45 | 8.63M | return End; |
46 | 8.63M | } |
47 | | |
48 | 174k | void MCSymbol::setVariableValue(const MCExpr *Value) { |
49 | 174k | assert(!IsUsed && "Cannot set a variable that has already been used."); |
50 | 174k | assert(Value && "Invalid variable value!"); |
51 | 174k | assert((SymbolContents == SymContentsUnset || |
52 | 174k | SymbolContents == SymContentsVariable) && |
53 | 174k | "Cannot give common/offset symbol a variable value"); |
54 | 174k | this->Value = Value; |
55 | 174k | SymbolContents = SymContentsVariable; |
56 | 174k | setUndefined(); |
57 | 174k | } |
58 | | |
59 | 1.13M | void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const { |
60 | 1.13M | // The name for this MCSymbol is required to be a valid target name. However, |
61 | 1.13M | // some targets support quoting names with funny characters. If the name |
62 | 1.13M | // contains a funny character, then print it quoted. |
63 | 1.13M | StringRef Name = getName(); |
64 | 1.13M | if (!MAI || 1.13M MAI->isValidUnquotedName(Name)1.13M ) { |
65 | 1.13M | OS << Name; |
66 | 1.13M | return; |
67 | 1.13M | } |
68 | 2.31k | |
69 | 2.31k | if (2.31k MAI && 2.31k !MAI->supportsNameQuoting()2.31k ) |
70 | 0 | report_fatal_error("Symbol name with unsupported characters"); |
71 | 2.31k | |
72 | 2.31k | OS << '"'; |
73 | 48.8k | for (char C : Name) { |
74 | 48.8k | if (C == '\n') |
75 | 4 | OS << "\\n"; |
76 | 48.8k | else if (48.8k C == '"'48.8k ) |
77 | 4 | OS << "\\\""; |
78 | 48.8k | else |
79 | 48.8k | OS << C; |
80 | 48.8k | } |
81 | 1.13M | OS << '"'; |
82 | 1.13M | } |
83 | | |
84 | | #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) |
85 | | LLVM_DUMP_METHOD void MCSymbol::dump() const { |
86 | | dbgs() << *this; |
87 | | } |
88 | | #endif |