Daniel Dunbar | ba1da8a | 2009-06-23 23:39:15 +0000 | [diff] [blame] | 1 | //===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===// |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 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" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 11 | #include "llvm/MC/MCSection.h" |
| 12 | #include "llvm/MC/MCSymbol.h" |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 13 | #include "llvm/ADT/SmallString.h" |
| 14 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 15 | using namespace llvm; |
| 16 | |
Chris Lattner | c18409a | 2010-03-11 22:53:35 +0000 | [diff] [blame^] | 17 | MCContext::MCContext(const MCAsmInfo &mai) : MAI(mai), NextUniqueID(0) { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | MCContext::~MCContext() { |
Chris Lattner | c9d3152 | 2009-08-13 00:21:53 +0000 | [diff] [blame] | 21 | // NOTE: The sections are all allocated out of a bump pointer allocator, |
| 22 | // we don't need to free them here. |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 23 | } |
| 24 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 25 | MCSymbol *MCContext::GetOrCreateSymbol(StringRef Name) { |
Chris Lattner | 00685bb | 2010-03-10 01:29:27 +0000 | [diff] [blame] | 26 | assert(!Name.empty() && "Normal symbols cannot be unnamed!"); |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 27 | MCSymbol *&Entry = Symbols[Name]; |
| 28 | if (Entry) return Entry; |
| 29 | |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 30 | return Entry = new (*this) MCSymbol(Name, false); |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 33 | MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) { |
| 34 | SmallString<128> NameSV; |
| 35 | Name.toVector(NameSV); |
| 36 | return GetOrCreateSymbol(NameSV.str()); |
| 37 | } |
| 38 | |
| 39 | |
Chris Lattner | 00685bb | 2010-03-10 01:29:27 +0000 | [diff] [blame] | 40 | MCSymbol *MCContext::GetOrCreateTemporarySymbol(StringRef Name) { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 41 | // Otherwise create as usual. |
| 42 | MCSymbol *&Entry = Symbols[Name]; |
Chris Lattner | 00685bb | 2010-03-10 01:29:27 +0000 | [diff] [blame] | 43 | if (Entry) return Entry; |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 44 | return Entry = new (*this) MCSymbol(Name, true); |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Chris Lattner | 00685bb | 2010-03-10 01:29:27 +0000 | [diff] [blame] | 47 | MCSymbol *MCContext::GetOrCreateTemporarySymbol(const Twine &Name) { |
| 48 | SmallString<128> NameSV; |
| 49 | Name.toVector(NameSV); |
| 50 | return GetOrCreateTemporarySymbol(NameSV.str()); |
| 51 | } |
| 52 | |
| 53 | |
Daniel Dunbar | 2928c83 | 2009-11-06 10:58:06 +0000 | [diff] [blame] | 54 | MCSymbol *MCContext::LookupSymbol(StringRef Name) const { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 55 | return Symbols.lookup(Name); |
| 56 | } |