LLVM API Documentation

MCContext.cpp

Go to the documentation of this file.
00001 //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "llvm/MC/MCContext.h"
00011 
00012 #include "llvm/MC/MCSection.h"
00013 #include "llvm/MC/MCSymbol.h"
00014 #include "llvm/MC/MCValue.h"
00015 using namespace llvm;
00016 
00017 MCContext::MCContext() {
00018 }
00019 
00020 MCContext::~MCContext() {
00021   // NOTE: The sections are all allocated out of a bump pointer allocator,
00022   // we don't need to free them here.
00023 }
00024 
00025 MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
00026   assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
00027 
00028   // Create and bind the symbol, and ensure that names are unique.
00029   MCSymbol *&Entry = Symbols[Name];
00030   assert(!Entry && "Duplicate symbol definition!");
00031   return Entry = new (*this) MCSymbol(Name, false);
00032 }
00033 
00034 MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
00035   MCSymbol *&Entry = Symbols[Name];
00036   if (Entry) return Entry;
00037 
00038   return Entry = new (*this) MCSymbol(Name, false);
00039 }
00040 
00041 
00042 MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
00043   // If unnamed, just create a symbol.
00044   if (Name.empty())
00045     new (*this) MCSymbol("", true);
00046     
00047   // Otherwise create as usual.
00048   MCSymbol *&Entry = Symbols[Name];
00049   assert(!Entry && "Duplicate symbol definition!");
00050   return Entry = new (*this) MCSymbol(Name, true);
00051 }
00052 
00053 MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const {
00054   return Symbols.lookup(Name);
00055 }
00056 
00057 void MCContext::ClearSymbolValue(MCSymbol *Sym) {
00058   SymbolValues.erase(Sym);
00059 }
00060 
00061 void MCContext::SetSymbolValue(MCSymbol *Sym, const MCValue &Value) {
00062   SymbolValues[Sym] = Value;
00063 }
00064 
00065 const MCValue *MCContext::GetSymbolValue(MCSymbol *Sym) const {
00066   DenseMap<MCSymbol*, MCValue>::iterator it = SymbolValues.find(Sym);
00067 
00068   if (it == SymbolValues.end())
00069     return 0;
00070 
00071   return &it->second;
00072 }