[cfe-commits] r57736 - in /cfe/trunk/lib/CodeGen: CodeGenModule.cpp CodeGenModule.h
Daniel Dunbar
daniel at zuster.org
Fri Oct 17 14:56:50 PDT 2008
Author: ddunbar
Date: Fri Oct 17 16:56:50 2008
New Revision: 57736
URL: http://llvm.org/viewvc/llvm-project?rev=57736&view=rev
Log:
Add option argument to GetAddrOfConstantString to use for name of
(first) global holding the string.
- No functionality change.
Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=57736&r1=57735&r2=57736&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Oct 17 16:56:50 2008
@@ -885,14 +885,17 @@
/// GenerateWritableString -- Creates storage for a string literal.
static llvm::Constant *GenerateStringLiteral(const std::string &str,
bool constant,
- CodeGenModule &CGM) {
+ CodeGenModule &CGM,
+ const char *GlobalName) {
// Create Constant for this string literal. Don't add a '\0'.
llvm::Constant *C = llvm::ConstantArray::get(str, false);
// Create a global variable for this string
C = new llvm::GlobalVariable(C->getType(), constant,
llvm::GlobalValue::InternalLinkage,
- C, ".str", &CGM.getModule());
+ C,
+ GlobalName ? GlobalName : ".str",
+ &CGM.getModule());
return C;
}
@@ -905,10 +908,11 @@
/// Feature.WriteableStrings.
///
/// The result has pointer to array type.
-llvm::Constant *CodeGenModule::GetAddrOfConstantString(const std::string &str) {
+llvm::Constant *CodeGenModule::GetAddrOfConstantString(const std::string &str,
+ const char *GlobalName) {
// Don't share any string literals if writable-strings is turned on.
if (Features.WritableStrings)
- return GenerateStringLiteral(str, false, *this);
+ return GenerateStringLiteral(str, false, *this, GlobalName);
llvm::StringMapEntry<llvm::Constant *> &Entry =
ConstantStringMap.GetOrCreateValue(&str[0], &str[str.length()]);
@@ -917,7 +921,7 @@
return Entry.getValue();
// Create a global variable for this.
- llvm::Constant *C = GenerateStringLiteral(str, true, *this);
+ llvm::Constant *C = GenerateStringLiteral(str, true, *this, GlobalName);
Entry.setValue(C);
return C;
}
@@ -925,8 +929,9 @@
/// GetAddrOfConstantCString - Returns a pointer to a character
/// array containing the literal and a terminating '\-'
/// character. The result has pointer to array type.
-llvm::Constant *CodeGenModule::GetAddrOfConstantCString(const std::string &str) {
- return GetAddrOfConstantString(str + "\0");
+llvm::Constant *CodeGenModule::GetAddrOfConstantCString(const std::string &str,
+ const char *GlobalName){
+ return GetAddrOfConstantString(str + "\0", GlobalName);
}
/// EmitObjCPropertyImplementations - Emit information for synthesized
Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=57736&r1=57735&r2=57736&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Fri Oct 17 16:56:50 2008
@@ -179,12 +179,20 @@
/// Feature.WriteableStrings.
///
/// The result has pointer to array type.
- llvm::Constant *GetAddrOfConstantString(const std::string& str);
+ ///
+ /// \param GlobalName If provided, the name to use for the global
+ /// (if one is created).
+ llvm::Constant *GetAddrOfConstantString(const std::string& str,
+ const char *GlobalName=0);
/// GetAddrOfConstantCString - Returns a pointer to a character
- /// array containing the literal and a terminating '\-'
+ /// array containing the literal and a terminating '\0'
/// character. The result has pointer to array type.
- llvm::Constant *GetAddrOfConstantCString(const std::string &str);
+ ///
+ /// \param GlobalName If provided, the name to use for the global
+ /// (if one is created).
+ llvm::Constant *GetAddrOfConstantCString(const std::string &str,
+ const char *GlobalName=0);
/// getBuiltinLibFunction - Given a builtin id for a function like
/// "__builtin_fabsf", return a Function* for "fabsf".
More information about the cfe-commits
mailing list