[dragonegg] r176265 - Small name handling cleanups. Rename getLLVMAssemblerName to getAssemblerName
Duncan Sands
baldrick at free.fr
Thu Feb 28 08:08:13 PST 2013
Author: baldrick
Date: Thu Feb 28 10:08:13 2013
New Revision: 176265
URL: http://llvm.org/viewvc/llvm-project?rev=176265&view=rev
Log:
Small name handling cleanups. Rename getLLVMAssemblerName to getAssemblerName
and change the file it is defined in. Get rid of some direct uses of DECL_NAME.
Modified:
dragonegg/trunk/include/dragonegg/Internals.h
dragonegg/trunk/include/dragonegg/Trees.h
dragonegg/trunk/src/Backend.cpp
dragonegg/trunk/src/Convert.cpp
dragonegg/trunk/src/Trees.cpp
Modified: dragonegg/trunk/include/dragonegg/Internals.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Internals.h?rev=176265&r1=176264&r2=176265&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Internals.h (original)
+++ dragonegg/trunk/include/dragonegg/Internals.h Thu Feb 28 10:08:13 2013
@@ -136,7 +136,6 @@ void changeLLVMConstant(Constant *Old, C
void register_ctor_dtor(Function *, int, bool);
const char *extractRegisterName(tree_node *);
void handleVisibility(tree_node *decl, GlobalValue *GV);
-std::string getLLVMAssemblerName(tree_node *);
/// Return true if and only if field no. N from struct type T is a padding
/// element added to match llvm struct type size and gcc struct type size.
Modified: dragonegg/trunk/include/dragonegg/Trees.h
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/include/dragonegg/Trees.h?rev=176265&r1=176264&r2=176265&view=diff
==============================================================================
--- dragonegg/trunk/include/dragonegg/Trees.h (original)
+++ dragonegg/trunk/include/dragonegg/Trees.h Thu Feb 28 10:08:13 2013
@@ -72,9 +72,18 @@ template <enum dragonegg_tree_code code>
}
}
+/// getAssemblerName - Return the name to use for the given tree, or an empty
+/// string if it does not have a name. This is the official name that should
+/// be used for everything that will end up with a name in the final assembler.
+/// It should not be used for anything else: GCC will usually crash if you try
+/// to use this with types, function arguments or anything else that doesn't
+/// have a name in the final assembler.
+std::string getAssemblerName(tree t);
+
/// getDescriptiveName - Return a helpful name for the given tree, or an empty
/// string if no sensible name was found. These names are used to make the IR
-/// more readable, and have no official status.
+/// more readable, and have no official status. For example, they can be used
+/// to name types because type names don't end up in the final assembler.
std::string getDescriptiveName(const_tree t);
/// main_type - Return the main variant of the given tree's type.
Modified: dragonegg/trunk/src/Backend.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Backend.cpp?rev=176265&r1=176264&r2=176265&view=diff
==============================================================================
--- dragonegg/trunk/src/Backend.cpp (original)
+++ dragonegg/trunk/src/Backend.cpp Thu Feb 28 10:08:13 2013
@@ -1260,7 +1260,7 @@ Value *make_decl_llvm(tree decl) {
std::string Name;
if (!isa<CONST_DECL>(decl)) // CONST_DECLs do not have assembler names.
- Name = getLLVMAssemblerName(decl);
+ Name = getAssemblerName(decl);
// Now handle ordinary static variables and functions (in memory).
// Also handle vars declared register invalidly.
@@ -1475,20 +1475,6 @@ const char *extractRegisterName(tree dec
return (*Name == '*') ? Name + 1 : Name;
}
-/// getLLVMAssemblerName - Get the assembler name (DECL_ASSEMBLER_NAME) for the
-/// declaration, with any leading star replaced by '\1'.
-std::string getLLVMAssemblerName(tree decl) {
- tree Ident = DECL_ASSEMBLER_NAME(decl);
- if (!Ident)
- return std::string();
-
- const char *Name = IDENTIFIER_POINTER(Ident);
- if (*Name != '*')
- return std::string(Name, IDENTIFIER_LENGTH(Ident));
-
- return "\1" + std::string(Name + 1, IDENTIFIER_LENGTH(Ident) - 1);
-}
-
/// FinalizePlugin - Shutdown the plugin.
static void FinalizePlugin(void) {
static bool Finalized = false;
@@ -1622,7 +1608,7 @@ static void emit_cgraph_aliases(struct c
/// is called once for each function in the compilation unit.
static void emit_current_function() {
if (!quiet_flag && DECL_NAME(current_function_decl))
- errs() << IDENTIFIER_POINTER(DECL_NAME(current_function_decl));
+ errs() << getDescriptiveName(current_function_decl);
// Convert the AST to raw/ugly LLVM code.
Function *Fn;
Modified: dragonegg/trunk/src/Convert.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Convert.cpp?rev=176265&r1=176264&r2=176265&view=diff
==============================================================================
--- dragonegg/trunk/src/Convert.cpp (original)
+++ dragonegg/trunk/src/Convert.cpp Thu Feb 28 10:08:13 2013
@@ -929,7 +929,7 @@ void TreeToLLVM::StartFunctionBody() {
// function. Set to current.
handleVisibility(FnDecl, Fn);
} else {
- std::string Name = getLLVMAssemblerName(FnDecl);
+ std::string Name = getAssemblerName(FnDecl);
Function *FnEntry = TheModule->getFunction(Name);
if (FnEntry) {
assert(FnEntry->getName() == Name && "Same entry, different name?");
@@ -1072,9 +1072,9 @@ void TreeToLLVM::StartFunctionBody() {
// Scalar arguments processed so far.
std::vector<Type *> ScalarArgs;
while (Args) {
- const char *Name = "unnamed_arg";
- if (DECL_NAME(Args))
- Name = IDENTIFIER_POINTER(DECL_NAME(Args));
+ std::string Name = getDescriptiveName(Args);
+ if (Name.empty())
+ Name = "unnamed_arg";
Type *ArgTy = ConvertType(TREE_TYPE(Args));
bool isInvRef = isPassedByInvisibleReference(TREE_TYPE(Args));
@@ -1102,7 +1102,7 @@ void TreeToLLVM::StartFunctionBody() {
// an l-value. On entry to the function, we copy formal argument values
// into the alloca.
Value *Tmp = CreateTemporary(ArgTy, TYPE_ALIGN_UNIT(TREE_TYPE(Args)));
- Tmp->setName(std::string(Name) + "_addr");
+ Tmp->setName(Name + "_addr");
SET_DECL_LOCAL(Args, Tmp);
if (EmitDebugInfo()) {
TheDebugInfo->EmitDeclare(Args, dwarf::DW_TAG_arg_variable, Name,
Modified: dragonegg/trunk/src/Trees.cpp
URL: http://llvm.org/viewvc/llvm-project/dragonegg/trunk/src/Trees.cpp?rev=176265&r1=176264&r2=176265&view=diff
==============================================================================
--- dragonegg/trunk/src/Trees.cpp (original)
+++ dragonegg/trunk/src/Trees.cpp Thu Feb 28 10:08:13 2013
@@ -60,6 +60,23 @@ concatIfNotEmpty(const std::string &Left
return Left + Right;
}
+/// getAssemblerName - Return the name to use for the given tree, or an empty
+/// string if it does not have a name. This is the official name that should
+/// be used for everything that will end up in the final assembler.
+std::string getAssemblerName(tree t) {
+ tree ident = DECL_ASSEMBLER_NAME(t);
+ if (!ident)
+ // Does not have a name.
+ return std::string();
+
+ // Replace any leading star by '\1'.
+ const char *Name = IDENTIFIER_POINTER(ident);
+ if (*Name != '*')
+ return std::string(Name, IDENTIFIER_LENGTH(ident));
+
+ return "\1" + std::string(Name + 1, IDENTIFIER_LENGTH(ident) - 1);
+}
+
/// getDescriptiveName - Return a helpful name for the given tree, or an empty
/// string if no sensible name was found. These names are used to make the IR
/// more readable, and have no official status.
More information about the llvm-commits
mailing list