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"
11 #include "llvm/MC/MCSection.h"
12 #include "llvm/MC/MCSymbol.h"
13 #include "llvm/MC/MCValue.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/ADT/Twine.h"
18 MCContext::MCContext() {
21 MCContext::~MCContext() {
22 // NOTE: The sections are all allocated out of a bump pointer allocator,
23 // we don't need to free them here.
26 MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
27 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
28 MCSymbol *&Entry = Symbols[Name];
29 if (Entry) return Entry;
31 return Entry = new (*this) MCSymbol(Name, false);
34 MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
35 SmallString<128> NameSV;
36 Name.toVector(NameSV);
37 return GetOrCreateSymbol(NameSV.str());
41 MCSymbol *MCContext::GetOrCreateTemporarySymbol(StringRef Name) {
42 // If unnamed, just create a symbol.
44 new (*this) MCSymbol("", true);
46 // Otherwise create as usual.
47 MCSymbol *&Entry = Symbols[Name];
48 if (Entry) return Entry;
49 return Entry = new (*this) MCSymbol(Name, true);
52 MCSymbol *MCContext::GetOrCreateTemporarySymbol(const Twine &Name) {
53 SmallString<128> NameSV;
54 Name.toVector(NameSV);
55 return GetOrCreateTemporarySymbol(NameSV.str());
59 MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
60 return Symbols.lookup(Name);