[cfe-commits] r57737 - in /cfe/trunk/lib/CodeGen: CGExpr.cpp CodeGenFunction.h
Daniel Dunbar
daniel at zuster.org
Fri Oct 17 14:58:33 PDT 2008
Author: ddunbar
Date: Fri Oct 17 16:58:32 2008
New Revision: 57737
URL: http://llvm.org/viewvc/llvm-project?rev=57737&view=rev
Log:
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.
Modified:
cfe/trunk/lib/CodeGen/CGExpr.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=57737&r1=57736&r2=57737&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Fri Oct 17 16:58:32 2008
@@ -531,21 +531,12 @@
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 @@
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) {
Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=57737&r1=57736&r2=57737&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Fri Oct 17 16:58:32 2008
@@ -375,6 +375,7 @@
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);
More information about the cfe-commits
mailing list