blob: 46eb02f32cc1f26373a412e6267763ad4aa104f7 [file] [log] [blame]
Daniel Dunbarba1da8a2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarecc63f82009-06-23 22:01:43 +00002//
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"
Daniel Dunbarecc63f82009-06-23 22:01:43 +000011#include "llvm/MC/MCSection.h"
12#include "llvm/MC/MCSymbol.h"
Chris Lattner7c5b0212009-10-19 22:49:00 +000013#include "llvm/ADT/SmallString.h"
14#include "llvm/ADT/Twine.h"
Daniel Dunbarecc63f82009-06-23 22:01:43 +000015using namespace llvm;
16
Chris Lattnerc18409a2010-03-11 22:53:35 +000017MCContext::MCContext(const MCAsmInfo &mai) : MAI(mai), NextUniqueID(0) {
Daniel Dunbarecc63f82009-06-23 22:01:43 +000018}
19
20MCContext::~MCContext() {
Chris Lattnerc9d31522009-08-13 00:21:53 +000021 // NOTE: The sections are all allocated out of a bump pointer allocator,
22 // we don't need to free them here.
Daniel Dunbarecc63f82009-06-23 22:01:43 +000023}
24
Daniel Dunbar2928c832009-11-06 10:58:06 +000025MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) {
Chris Lattner00685bb2010-03-10 01:29:27 +000026 assert(!Name.empty() && "Normal symbols cannot be unnamed!");
Chris Lattnerc69485e2009-06-24 04:31:49 +000027 MCSymbol *&Entry = Symbols[Name];
28 if (Entry) return Entry;
29
Daniel Dunbar71d259b2009-06-24 17:00:42 +000030 return Entry = new (*this) MCSymbol(Name, false);
Chris Lattnerc69485e2009-06-24 04:31:49 +000031}
32
Chris Lattner7c5b0212009-10-19 22:49:00 +000033MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) {
34 SmallString<128> NameSV;
35 Name.toVector(NameSV);
36 return GetOrCreateSymbol(NameSV.str());
37}
38
39
Chris Lattner00685bb2010-03-10 01:29:27 +000040MCSymbol *MCContext::GetOrCreateTemporarySymbol(StringRef Name) {
Daniel Dunbarecc63f82009-06-23 22:01:43 +000041 // Otherwise create as usual.
42 MCSymbol *&Entry = Symbols[Name];
Chris Lattner00685bb2010-03-10 01:29:27 +000043 if (Entry) return Entry;
Daniel Dunbar71d259b2009-06-24 17:00:42 +000044 return Entry = new (*this) MCSymbol(Name, true);
Daniel Dunbarecc63f82009-06-23 22:01:43 +000045}
46
Chris Lattner00685bb2010-03-10 01:29:27 +000047MCSymbol *MCContext::GetOrCreateTemporarySymbol(const Twine &Name) {
48 SmallString<128> NameSV;
49 Name.toVector(NameSV);
50 return GetOrCreateTemporarySymbol(NameSV.str());
51}
52
53
Daniel Dunbar2928c832009-11-06 10:58:06 +000054MCSymbol *MCContext::LookupSymbol(StringRef Name) const {
Daniel Dunbarecc63f82009-06-23 22:01:43 +000055 return Symbols.lookup(Name);
56}