Move immediate constant predicate templates from the Blackfin target to MathExtras.h
[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 }
22
23 MCSection *MCContext::GetSection(const StringRef &Name) const {
24   StringMap<MCSection*>::const_iterator I = Sections.find(Name);
25   return I != Sections.end() ? I->second : 0;
26 }
27
28 MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
29   assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
30
31   // Create and bind the symbol, and ensure that names are unique.
32   MCSymbol *&Entry = Symbols[Name];
33   assert(!Entry && "Duplicate symbol definition!");
34   return Entry = new (*this) MCSymbol(Name, false);
35 }
36
37 MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
38   MCSymbol *&Entry = Symbols[Name];
39   if (Entry) return Entry;
40
41   return Entry = new (*this) MCSymbol(Name, false);
42 }
43
44
45 MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
46   // If unnamed, just create a symbol.
47   if (Name.empty())
48     new (*this) MCSymbol("", true);
49     
50   // Otherwise create as usual.
51   MCSymbol *&Entry = Symbols[Name];
52   assert(!Entry && "Duplicate symbol definition!");
53   return Entry = new (*this) MCSymbol(Name, true);
54 }
55
56 MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const {
57   return Symbols.lookup(Name);
58 }
59
60 void MCContext::ClearSymbolValue(MCSymbol *Sym) {
61   SymbolValues.erase(Sym);
62 }
63
64 void MCContext::SetSymbolValue(MCSymbol *Sym, const MCValue &Value) {
65   SymbolValues[Sym] = Value;
66 }
67
68 const MCValue *MCContext::GetSymbolValue(MCSymbol *Sym) const {
69   DenseMap<MCSymbol*, MCValue>::iterator it = SymbolValues.find(Sym);
70
71   if (it == SymbolValues.end())
72     return 0;
73
74   return &it->second;
75 }