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" |
Daniel Dunbar | ba1da8a | 2009-06-23 23:39:15 +0000 | [diff] [blame] | 13 | #include "llvm/MC/MCValue.h" |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 14 | #include "llvm/ADT/SmallString.h" |
| 15 | #include "llvm/ADT/Twine.h" |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 16 | using namespace llvm; |
| 17 | |
Chris Lattner | fcdbf4e | 2009-07-31 16:43:49 +0000 | [diff] [blame] | 18 | MCContext::MCContext() { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | MCContext::~MCContext() { |
Chris Lattner | c9d3152 | 2009-08-13 00:21:53 +0000 | [diff] [blame] | 22 | // NOTE: The sections are all allocated out of a bump pointer allocator, |
| 23 | // we don't need to free them here. |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Daniel Dunbar | b5261eb | 2009-07-27 21:22:30 +0000 | [diff] [blame] | 26 | MCSymbol *MCContext::CreateSymbol(const StringRef &Name) { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 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!"); |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 32 | return Entry = new (*this) MCSymbol(Name, false); |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 33 | } |
| 34 | |
Daniel Dunbar | b5261eb | 2009-07-27 21:22:30 +0000 | [diff] [blame] | 35 | MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) { |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 36 | MCSymbol *&Entry = Symbols[Name]; |
| 37 | if (Entry) return Entry; |
| 38 | |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 39 | return Entry = new (*this) MCSymbol(Name, false); |
Chris Lattner | c69485e | 2009-06-24 04:31:49 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Chris Lattner | 7c5b021 | 2009-10-19 22:49:00 +0000 | [diff] [blame] | 42 | MCSymbol *MCContext::GetOrCreateSymbol(const Twine &Name) { |
| 43 | SmallString<128> NameSV; |
| 44 | Name.toVector(NameSV); |
| 45 | return GetOrCreateSymbol(NameSV.str()); |
| 46 | } |
| 47 | |
| 48 | |
Daniel Dunbar | b5261eb | 2009-07-27 21:22:30 +0000 | [diff] [blame] | 49 | MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 50 | // If unnamed, just create a symbol. |
Daniel Dunbar | b5261eb | 2009-07-27 21:22:30 +0000 | [diff] [blame] | 51 | if (Name.empty()) |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 52 | new (*this) MCSymbol("", true); |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 53 | |
| 54 | // Otherwise create as usual. |
| 55 | MCSymbol *&Entry = Symbols[Name]; |
| 56 | assert(!Entry && "Duplicate symbol definition!"); |
Daniel Dunbar | 71d259b | 2009-06-24 17:00:42 +0000 | [diff] [blame] | 57 | return Entry = new (*this) MCSymbol(Name, true); |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 58 | } |
| 59 | |
Daniel Dunbar | b5261eb | 2009-07-27 21:22:30 +0000 | [diff] [blame] | 60 | MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const { |
Daniel Dunbar | ecc63f8 | 2009-06-23 22:01:43 +0000 | [diff] [blame] | 61 | return Symbols.lookup(Name); |
| 62 | } |