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