blob: 45d2c025361dfdf1b0f16029a9cfd1cabdf61e45 [file] [log] [blame]
Shih-wei Liaoe264f622010-02-10 11:10:31 -08001//===- 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#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"
16using namespace llvm;
17
18MCContext::MCContext() {
19}
20
21MCContext::~MCContext() {
22 // NOTE: The sections are all allocated out of a bump pointer allocator,
23 // we don't need to free them here.
24}
25
26MCSymbol *MCContext::CreateSymbol(StringRef Name) {
27 assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
28
29 // Create and bind the symbol, and ensure that names are unique.
30 MCSymbol *&Entry = Symbols[Name];
31 assert(!Entry && "Duplicate symbol definition!");
32 return Entry = new (*this) MCSymbol(Name, false);
33}
34
35MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
36 MCSymbol *&Entry = Symbols[Name];
37 if (Entry) return Entry;
38
39 return Entry = new (*this) MCSymbol(Name, false);
40}
41
42MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
43 SmallString<128> NameSV;
44 Name.toVector(NameSV);
45 return GetOrCreateSymbol(NameSV.str());
46}
47
48
49MCSymbol *MCContext::CreateTemporarySymbol(StringRef Name) {
50 // If unnamed, just create a symbol.
51 if (Name.empty())
52 new (*this) MCSymbol("", true);
53
54 // Otherwise create as usual.
55 MCSymbol *&Entry = Symbols[Name];
56 assert(!Entry && "Duplicate symbol definition!");
57 return Entry = new (*this) MCSymbol(Name, true);
58}
59
60MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
61 return Symbols.lookup(Name);
62}