From b5261ebabb215330d6549048b825d236fb3c9b6b Mon Sep 17 00:00:00 2001 From: Daniel Dunbar Date: Mon, 27 Jul 2009 21:22:30 +0000 Subject: [PATCH] Move MCContext and friends to StringRef based APIs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77251 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/MC/MCContext.h | 11 ++++++----- include/llvm/MC/MCSection.h | 3 ++- include/llvm/MC/MCSymbol.h | 3 ++- lib/MC/MCContext.cpp | 12 ++++++------ 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/include/llvm/MC/MCContext.h b/include/llvm/MC/MCContext.h index 846e195139d..24dbc40479b 100644 --- a/include/llvm/MC/MCContext.h +++ b/include/llvm/MC/MCContext.h @@ -18,6 +18,7 @@ namespace llvm { class MCValue; class MCSection; class MCSymbol; + class StringRef; /// MCContext - Context object for machine code objects. class MCContext { @@ -46,19 +47,19 @@ namespace llvm { ~MCContext(); /// GetSection - Get or create a new section with the given @param Name. - MCSection *GetSection(const char *Name); + MCSection *GetSection(const StringRef &Name); /// CreateSymbol - Create a new symbol with the specified @param Name. /// /// @param Name - The symbol name, which must be unique across all symbols. - MCSymbol *CreateSymbol(const char *Name); + MCSymbol *CreateSymbol(const StringRef &Name); /// GetOrCreateSymbol - Lookup the symbol inside with the specified /// @param Name. If it exists, return it. If not, create a forward /// reference and return it. /// /// @param Name - The symbol name, which must be unique across all symbols. - MCSymbol *GetOrCreateSymbol(const char *Name); + MCSymbol *GetOrCreateSymbol(const StringRef &Name); /// CreateTemporarySymbol - Create a new temporary symbol with the specified /// @param Name. @@ -66,10 +67,10 @@ namespace llvm { /// @param Name - The symbol name, for debugging purposes only, temporary /// symbols do not surive assembly. If non-empty the name must be unique /// across all symbols. - MCSymbol *CreateTemporarySymbol(const char *Name = ""); + MCSymbol *CreateTemporarySymbol(const StringRef &Name = ""); /// LookupSymbol - Get the symbol for @param Name, or null. - MCSymbol *LookupSymbol(const char *Name) const; + MCSymbol *LookupSymbol(const StringRef &Name) const; /// ClearSymbolValue - Erase a value binding for @param Symbol, if one /// exists. diff --git a/include/llvm/MC/MCSection.h b/include/llvm/MC/MCSection.h index 1b127b52e1c..48ffa2facd6 100644 --- a/include/llvm/MC/MCSection.h +++ b/include/llvm/MC/MCSection.h @@ -15,6 +15,7 @@ #define LLVM_MC_MCSECTION_H #include +#include "llvm/ADT/StringRef.h" namespace llvm { @@ -25,7 +26,7 @@ namespace llvm { std::string Name; private: friend class MCContext; - MCSection(const char *_Name) : Name(_Name) {} + MCSection(const StringRef &_Name) : Name(_Name) {} MCSection(const MCSection&); // DO NOT IMPLEMENT void operator=(const MCSection&); // DO NOT IMPLEMENT diff --git a/include/llvm/MC/MCSymbol.h b/include/llvm/MC/MCSymbol.h index 235e6614f97..de6dc5fcb87 100644 --- a/include/llvm/MC/MCSymbol.h +++ b/include/llvm/MC/MCSymbol.h @@ -15,6 +15,7 @@ #define LLVM_MC_MCSYMBOL_H #include +#include "llvm/ADT/StringRef.h" namespace llvm { class MCSection; @@ -46,7 +47,7 @@ namespace llvm { private: // MCContext creates and uniques these. friend class MCContext; - MCSymbol(const char *_Name, bool _IsTemporary) + MCSymbol(const StringRef &_Name, bool _IsTemporary) : Name(_Name), Section(0), IsTemporary(_IsTemporary), IsExternal(false) {} MCSymbol(const MCSymbol&); // DO NOT IMPLEMENT diff --git a/lib/MC/MCContext.cpp b/lib/MC/MCContext.cpp index 6c6019c76ff..6c74dcd9ecf 100644 --- a/lib/MC/MCContext.cpp +++ b/lib/MC/MCContext.cpp @@ -21,7 +21,7 @@ MCContext::MCContext() MCContext::~MCContext() { } -MCSection *MCContext::GetSection(const char *Name) { +MCSection *MCContext::GetSection(const StringRef &Name) { MCSection *&Entry = Sections[Name]; if (!Entry) @@ -30,7 +30,7 @@ MCSection *MCContext::GetSection(const char *Name) { return Entry; } -MCSymbol *MCContext::CreateSymbol(const char *Name) { +MCSymbol *MCContext::CreateSymbol(const StringRef &Name) { assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!"); // Create and bind the symbol, and ensure that names are unique. @@ -39,7 +39,7 @@ MCSymbol *MCContext::CreateSymbol(const char *Name) { return Entry = new (*this) MCSymbol(Name, false); } -MCSymbol *MCContext::GetOrCreateSymbol(const char *Name) { +MCSymbol *MCContext::GetOrCreateSymbol(const StringRef &Name) { MCSymbol *&Entry = Symbols[Name]; if (Entry) return Entry; @@ -47,9 +47,9 @@ MCSymbol *MCContext::GetOrCreateSymbol(const char *Name) { } -MCSymbol *MCContext::CreateTemporarySymbol(const char *Name) { +MCSymbol *MCContext::CreateTemporarySymbol(const StringRef &Name) { // If unnamed, just create a symbol. - if (Name[0] == '\0') + if (Name.empty()) new (*this) MCSymbol("", true); // Otherwise create as usual. @@ -58,7 +58,7 @@ MCSymbol *MCContext::CreateTemporarySymbol(const char *Name) { return Entry = new (*this) MCSymbol(Name, true); } -MCSymbol *MCContext::LookupSymbol(const char *Name) const { +MCSymbol *MCContext::LookupSymbol(const StringRef &Name) const { return Symbols.lookup(Name); } -- 2.34.1