llvm-mc/Mach-O: Don't put assembler temporary labels in the symbol table.
[oota-llvm.git] / lib / MC / MCContext.cpp
1 //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
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/MCContext.h"
11
12 #include "llvm/MC/MCSection.h"
13 #include "llvm/MC/MCSymbol.h"
14 #include "llvm/MC/MCValue.h"
15 using namespace llvm;
16
17 MCContext::MCContext() {
18 }
19
20 MCContext::~MCContext() {
21   // NOTE: The sections are all allocated out of a bump pointer allocator,
22   // we don't need to free them here.
23 }
24
25 MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
26   assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
27
28   // Create and bind the symbol, and ensure that names are unique.
29   MCSymbol *&Entry = Symbols[Name];
30   assert(!Entry && "Duplicate symbol definition!");
31   return Entry = new (*this) MCSymbol(Name, false);
32 }
33
34 MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
35   MCSymbol *&Entry = Symbols[Name];
36   if (Entry) return Entry;
37
38   return Entry = new (*this) MCSymbol(Name, false);
39 }
40
41 MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
42   // If unnamed, just create a symbol.
43   if (Name.empty())
44     new (*this) MCSymbol("", true);
45     
46   // Otherwise create as usual.
47   MCSymbol *&Entry = Symbols[Name];
48   assert(!Entry && "Duplicate symbol definition!");
49   return Entry = new (*this) MCSymbol(Name, true);
50 }
51
52 MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const {
53   return Symbols.lookup(Name);
54 }
55
56 void MCContext::ClearSymbolValue(const MCSymbol *Sym) {
57   SymbolValues.erase(Sym);
58 }
59
60 void MCContext::SetSymbolValue(const MCSymbol *Sym, const MCValue &Value) {
61   SymbolValues[Sym] = Value;
62 }
63
64 const MCValue *MCContext::GetSymbolValue(const MCSymbol *Sym) const {
65   DenseMap<const MCSymbol*, MCValue>::iterator it = SymbolValues.find(Sym);
66
67   if (it == SymbolValues.end())
68     return 0;
69
70   return &it->second;
71 }