blob: db59f7f505c6d39976fb8ca2809eb31071c43899 [file] [log] [blame]
Daniel Dunbarbadeace2009-06-23 23:39:15 +00001//===- lib/MC/MCContext.cpp - Machine Code Context ------------------------===//
Daniel Dunbarca29e4d2009-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"
11
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000012#include "llvm/MC/MCSection.h"
13#include "llvm/MC/MCSymbol.h"
Daniel Dunbarbadeace2009-06-23 23:39:15 +000014#include "llvm/MC/MCValue.h"
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000015using namespace llvm;
16
Chris Lattnerb37f29b2009-07-31 16:43:49 +000017MCContext::MCContext() {
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000018}
19
20MCContext::~MCContext() {
Chris Lattnerb6913162009-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 Dunbarca29e4d2009-06-23 22:01:43 +000023}
24
Daniel Dunbara87555a2009-07-27 21:22:30 +000025MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000026 assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
27
28 // Create and bind the symbol, and ensure that names are unique.
29 MCSymbol *&Entry = Symbols[Name];
30 assert(!Entry && "Duplicate symbol definition!");
Daniel Dunbarf782ebc2009-06-24 17:00:42 +000031 return Entry = new (*this) MCSymbol(Name, false);
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000032}
33
Daniel Dunbara87555a2009-07-27 21:22:30 +000034MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) {
Chris Lattner3f5738d2009-06-24 04:31:49 +000035 MCSymbol *&Entry = Symbols[Name];
36 if (Entry) return Entry;
37
Daniel Dunbarf782ebc2009-06-24 17:00:42 +000038 return Entry = new (*this) MCSymbol(Name, false);
Chris Lattner3f5738d2009-06-24 04:31:49 +000039}
40
Daniel Dunbara87555a2009-07-27 21:22:30 +000041MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) {
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000042 // If unnamed, just create a symbol.
Daniel Dunbara87555a2009-07-27 21:22:30 +000043 if (Name.empty())
Daniel Dunbarf782ebc2009-06-24 17:00:42 +000044 new (*this) MCSymbol("", true);
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000045
46 // Otherwise create as usual.
47 MCSymbol *&Entry = Symbols[Name];
48 assert(!Entry && "Duplicate symbol definition!");
Daniel Dunbarf782ebc2009-06-24 17:00:42 +000049 return Entry = new (*this) MCSymbol(Name, true);
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000050}
51
Daniel Dunbara87555a2009-07-27 21:22:30 +000052MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const {
Daniel Dunbarca29e4d2009-06-23 22:01:43 +000053 return Symbols.lookup(Name);
54}