1 //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCContext.h"
12 #include "llvm/MC/MCAtom.h"
13 #include "llvm/MC/MCSection.h"
14 #include "llvm/MC/MCSymbol.h"
15 #include "llvm/MC/MCValue.h"
18 MCContext::MCContext()
22 MCContext::~MCContext() {
25 MCSection *MCContext::GetSection(const char *Name) {
26 MCSection *&Entry = Sections[Name];
29 Entry = new (this) MCSection(Name);
34 MCAtom *MCContext::CreateAtom(MCSection *Section) {
35 return new (this) MCAtom(Section);
38 MCSymbol *MCContext::CreateSymbol(MCAtom *Atom, const char *Name) {
39 assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
41 // Create and bind the symbol, and ensure that names are unique.
42 MCSymbol *&Entry = Symbols[Name];
43 assert(!Entry && "Duplicate symbol definition!");
44 return Entry = new (this) MCSymbol(Atom, Name, false);
47 MCSymbol *MCContext::CreateTemporarySymbol(MCAtom *Atom, const char *Name) {
48 // If unnamed, just create a symbol.
50 new (this) MCSymbol(Atom, "", true);
52 // Otherwise create as usual.
53 MCSymbol *&Entry = Symbols[Name];
54 assert(!Entry && "Duplicate symbol definition!");
55 return Entry = new (this) MCSymbol(Atom, Name, true);
58 MCSymbol *MCContext::LookupSymbol(const char *Name) const {
59 return Symbols.lookup(Name);
62 void MCContext::ClearSymbolValue(MCSymbol *Sym) {
63 SymbolValues.erase(Sym);
66 void MCContext::SetSymbolValue(MCSymbol *Sym, const MCValue &Value) {
67 SymbolValues[Sym] = Value;
70 const MCValue *MCContext::GetSymbolValue(MCSymbol *Sym) const {
71 DenseMap<MCSymbol*, MCValue>::iterator it = SymbolValues.find(Sym);
73 if (it == SymbolValues.end())