diff options
| author | Daniel Dunbar <daniel@zuster.org> | 2008-10-17 21:58:32 +0000 |
|---|---|---|
| committer | Daniel Dunbar <daniel@zuster.org> | 2008-10-17 21:58:32 +0000 |
| commit | b35174727fc2d4fb09506d5c8b69d3cb1323001f (patch) | |
| tree | e79df610c4cd2049e61aa42bfaf45da3edb4e52f /clang/lib/CodeGen | |
| parent | dfcf599dfa1257170a2c7ece3d42cc1423c0fbb4 (diff) | |
| download | bcm5719-llvm-b35174727fc2d4fb09506d5c8b69d3cb1323001f.tar.gz bcm5719-llvm-b35174727fc2d4fb09506d5c8b69d3cb1323001f.zip | |
Lift CodeGenFunction::EmitPredefinedFunctioName out of EmitPredefinedLValue.
- Shouldn't assume predefined expr is a function printing one.
- Uses CGM functionality to cache function names per module.
llvm-svn: 57737
Diffstat (limited to 'clang/lib/CodeGen')
| -rw-r--r-- | clang/lib/CodeGen/CGExpr.cpp | 50 | ||||
| -rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.h | 1 |
2 files changed, 28 insertions, 23 deletions
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 872e3d1af4a..34d025d289b 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -531,21 +531,12 @@ LValue CodeGenFunction::EmitStringLiteralLValue(const StringLiteral *E) { return LValue::MakeAddr(CGM.GetAddrOfConstantStringFromLiteral(E), 0); } -LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { - std::string FunctionName; - if(const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) { - FunctionName = FD->getName(); - } else if (isa<ObjCMethodDecl>(CurFuncDecl)) { - // Just get the mangled name. - FunctionName = CurFn->getName(); - } else { - return EmitUnsupportedLValue(E, "predefined expression"); - } +LValue CodeGenFunction::EmitPredefinedFunctionName(unsigned Type) { std::string GlobalVarName; - - switch (E->getIdentType()) { + + switch (Type) { default: - return EmitUnsupportedLValue(E, "predefined expression"); + assert(0 && "Invalid type"); case PredefinedExpr::Func: GlobalVarName = "__func__."; break; @@ -557,17 +548,30 @@ LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { GlobalVarName = "__PRETTY_FUNCTION__."; break; } - + + std::string FunctionName; + if(const FunctionDecl *FD = dyn_cast<FunctionDecl>(CurFuncDecl)) { + FunctionName = FD->getName(); + } else { + // Just get the mangled name. + FunctionName = CurFn->getName(); + } + GlobalVarName += FunctionName; - - // FIXME: Can cache/reuse these within the module. - llvm::Constant *C = llvm::ConstantArray::get(FunctionName); - - // Create a global variable for this. - C = new llvm::GlobalVariable(C->getType(), true, - llvm::GlobalValue::InternalLinkage, - C, GlobalVarName, CurFn->getParent()); - return LValue::MakeAddr(C,0); + llvm::Constant *C = + CGM.GetAddrOfConstantCString(FunctionName, GlobalVarName.c_str()); + return LValue::MakeAddr(C, 0); +} + +LValue CodeGenFunction::EmitPredefinedLValue(const PredefinedExpr *E) { + switch (E->getIdentType()) { + default: + return EmitUnsupportedLValue(E, "predefined expression"); + case PredefinedExpr::Func: + case PredefinedExpr::Function: + case PredefinedExpr::PrettyFunction: + return EmitPredefinedFunctionName(E->getIdentType()); + } } LValue CodeGenFunction::EmitArraySubscriptExpr(const ArraySubscriptExpr *E) { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index ca499d85e4c..c0a5a44b69b 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -375,6 +375,7 @@ public: LValue EmitDeclRefLValue(const DeclRefExpr *E); LValue EmitStringLiteralLValue(const StringLiteral *E); + LValue EmitPredefinedFunctionName(unsigned Type); LValue EmitPredefinedLValue(const PredefinedExpr *E); LValue EmitUnaryOpLValue(const UnaryOperator *E); LValue EmitArraySubscriptExpr(const ArraySubscriptExpr *E); |

