LCOV - code coverage report
Current view: top level - lib/MC - MCSymbol.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 26 27 96.3 %
Date: 2017-09-14 15:23:50 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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       72330 : static MCDummyFragment SentinelFragment(nullptr);
      27             : 
      28             : // Sentinel value for the absolute pseudo fragment.
      29             : MCFragment *MCSymbol::AbsolutePseudoFragment = &SentinelFragment;
      30             : 
      31     2940426 : void *MCSymbol::operator new(size_t s, const StringMapEntry<bool> *Name,
      32             :                              MCContext &Ctx) {
      33             :   // We may need more space for a Name to account for alignment.  So allocate
      34             :   // space for the storage type and not the name pointer.
      35     2940426 :   size_t Size = s + (Name ? sizeof(NameEntryStorageTy) : 0);
      36             : 
      37             :   // For safety, ensure that the alignment of a pointer is enough for an
      38             :   // MCSymbol.  This also ensures we don't need padding between the name and
      39             :   // symbol.
      40             :   static_assert((unsigned)alignof(MCSymbol) <= alignof(NameEntryStorageTy),
      41             :                 "Bad alignment of MCSymbol");
      42     5880851 :   void *Storage = Ctx.allocate(Size, alignof(NameEntryStorageTy));
      43     2940425 :   NameEntryStorageTy *Start = static_cast<NameEntryStorageTy*>(Storage);
      44     2940425 :   NameEntryStorageTy *End = Start + (Name ? 1 : 0);
      45     2940425 :   return End;
      46             : }
      47             : 
      48        7073 : void MCSymbol::setVariableValue(const MCExpr *Value) {
      49             :   assert(!IsUsed && "Cannot set a variable that has already been used.");
      50             :   assert(Value && "Invalid variable value!");
      51             :   assert((SymbolContents == SymContentsUnset ||
      52             :           SymbolContents == SymContentsVariable) &&
      53             :          "Cannot give common/offset symbol a variable value");
      54        7073 :   this->Value = Value;
      55        7073 :   SymbolContents = SymContentsVariable;
      56        7073 :   setUndefined();
      57        7073 : }
      58             : 
      59     1138292 : void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
      60             :   // The name for this MCSymbol is required to be a valid target name.  However,
      61             :   // some targets support quoting names with funny characters.  If the name
      62             :   // contains a funny character, then print it quoted.
      63     1138292 :   StringRef Name = getName();
      64     1138292 :   if (!MAI || MAI->isValidUnquotedName(Name)) {
      65     1135931 :     OS << Name;
      66     1135931 :     return;
      67             :   }
      68             : 
      69        2361 :   if (MAI && !MAI->supportsNameQuoting())
      70           0 :     report_fatal_error("Symbol name with unsupported characters");
      71             : 
      72        2361 :   OS << '"';
      73       54276 :   for (char C : Name) {
      74       49554 :     if (C == '\n')
      75           4 :       OS << "\\n";
      76       49550 :     else if (C == '"')
      77           4 :       OS << "\\\"";
      78             :     else
      79       49546 :       OS << C;
      80             :   }
      81             :   OS << '"';
      82      216990 : }
      83             : 
      84             : #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
      85             : LLVM_DUMP_METHOD void MCSymbol::dump() const {
      86             :   dbgs() << *this;
      87             : }
      88             : #endif

Generated by: LCOV version 1.13