Change from alignof to llvm::alignOf to appease Visual Studio
[oota-llvm.git] / lib / MC / MCSymbol.cpp
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/MC/MCAsmInfo.h"
12 #include "llvm/MC/MCContext.h"
13 #include "llvm/MC/MCExpr.h"
14 #include "llvm/Support/Debug.h"
15 #include "llvm/Support/ErrorHandling.h"
16 #include "llvm/Support/raw_ostream.h"
17 using namespace llvm;
18
19 // Sentinel value for the absolute pseudo section.
20 MCSection *MCSymbol::AbsolutePseudoSection = reinterpret_cast<MCSection *>(1);
21
22 void *MCSymbol::operator new(size_t s, NameEntryTy *Name, MCContext &Ctx) {
23   size_t Size = s + (Name ? sizeof(Name) : 0);
24
25   // For safety, ensure that the alignment of a pointer is enough for an
26   // MCSymbol.  This also ensures we don't need padding between the name and
27   // symbol.
28   assert(alignOf<MCSymbol>() <= alignOf<NameEntryTy *>() &&
29          "Bad alignment of MCSymbol");
30   void *Storage = Ctx.allocate(Size, alignOf<NameEntryTy *>());
31   NameEntryTy **Start = static_cast<NameEntryTy**>(Storage);
32   NameEntryTy **End = Start + (Name ? 1 : 0);
33   return End;
34 }
35
36 void MCSymbol::setVariableValue(const MCExpr *Value) {
37   assert(!IsUsed && "Cannot set a variable that has already been used.");
38   assert(Value && "Invalid variable value!");
39   this->Value = Value;
40   SectionOrFragment = nullptr;
41 }
42
43 void MCSymbol::print(raw_ostream &OS, const MCAsmInfo *MAI) const {
44   // The name for this MCSymbol is required to be a valid target name.  However,
45   // some targets support quoting names with funny characters.  If the name
46   // contains a funny character, then print it quoted.
47   StringRef Name = getName();
48   if (!MAI || MAI->isValidUnquotedName(Name)) {
49     OS << Name;
50     return;
51   }
52
53   if (MAI && !MAI->supportsNameQuoting())
54     report_fatal_error("Symbol name with unsupported characters");
55
56   OS << '"';
57   for (char C : Name) {
58     if (C == '\n')
59       OS << "\\n";
60     else if (C == '"')
61       OS << "\\\"";
62     else
63       OS << C;
64   }
65   OS << '"';
66 }
67
68 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
69 void MCSymbol::dump() const { dbgs() << *this; }
70 #endif