Add target hook for setting symbol prefix and section of unicode

string literals.

llvm-svn: 68363
This commit is contained in:
Daniel Dunbar
2009-04-03 00:57:44 +00:00
parent 0fc36ca69d
commit fd6cfcffa2
4 changed files with 52 additions and 5 deletions

View File

@@ -257,6 +257,18 @@ public:
return "";
}
/// getUnicodeStringSymbolPrefix - Get the default symbol prefix to
/// use for string literals.
virtual const char *getUnicodeStringSymbolPrefix() const {
return ".str";
}
/// getUnicodeStringSymbolPrefix - Get the default symbol prefix to
/// use for string literals.
virtual const char *getUnicodeStringSection() const {
return 0;
}
/// getCFStringSection - Return the section to use for the CFString
/// literals, or 0 if no special section is used.
virtual const char *getCFStringSection() const {

View File

@@ -658,6 +658,14 @@ public:
return IsConstant ? "\01LC" : "\01lC";
}
virtual const char *getUnicodeStringSymbolPrefix() const {
return "__utf16_string_";
}
virtual const char *getUnicodeStringSection() const {
return "__TEXT,__ustring";
}
virtual const char *getCFStringSymbolPrefix() const {
return "\01LC";
}
@@ -810,6 +818,14 @@ public:
return IsConstant ? "\01LC" : "\01lC";
}
virtual const char *getUnicodeStringSymbolPrefix() const {
return "__utf16_string_";
}
virtual const char *getUnicodeStringSection() const {
return "__TEXT,__ustring";
}
virtual const char *getCFStringSymbolPrefix() const {
return "\01L_unnamed_cfstring_";
}

View File

@@ -1082,13 +1082,31 @@ GetAddrOfConstantCFString(const StringLiteral *Literal) {
CurField = NextField;
NextField = *Field++;
llvm::Constant *C = llvm::ConstantArray::get(str);
const char *Sect, *Prefix;
bool isConstant;
if (isUTF16) {
Prefix = getContext().Target.getUnicodeStringSymbolPrefix();
Sect = getContext().Target.getUnicodeStringSection();
// FIXME: Why does GCC not set constant here?
isConstant = false;
} else {
Prefix = getContext().Target.getStringSymbolPrefix(true);
Sect = getContext().Target.getCFStringDataSection();
// FIXME: -fwritable-strings should probably affect this, but we
// are following gcc here.
isConstant = true;
}
llvm::GlobalVariable *GV =
new llvm::GlobalVariable(C->getType(), true,
new llvm::GlobalVariable(C->getType(), isConstant,
llvm::GlobalValue::InternalLinkage,
C, getContext().Target.getStringSymbolPrefix(true),
&getModule());
if (const char *Sect = getContext().Target.getCFStringDataSection())
C, Prefix, &getModule());
if (Sect)
GV->setSection(Sect);
if (isUTF16) {
unsigned Align = getContext().getTypeAlign(getContext().ShortTy)/8;
GV->setAlignment(Align);
}
appendFieldAndPadding(*this, Fields, CurField, NextField,
llvm::ConstantExpr::getGetElementPtr(GV, Zeros, 2),
CFRD, STy);

View File

@@ -2,8 +2,9 @@
// RUN: grep -F '@"\01LC" = internal constant [8 x i8] c"string0\00"' %t &&
// RUN: grep -F '@"\01LC1" = internal constant [8 x i8] c"string1\00", section "__TEXT,__cstring,cstring_literals"' %t &&
// RUN: grep -F '@__utf16_string_ = internal global [35 x i8] c"h\00e\00l\00l\00o\00 \00\92! \00\03& \00\90! \00w\00o\00r\00l\00d\00\00", section "__TEXT,__ustring", align 2' %t &&
// RUN: true
const char *g0 = "string0";
const void *g1 = __builtin___CFStringMakeConstantString("string1");
const void *g2 = __builtin___CFStringMakeConstantString("hello \u2192 \u2603 \u2190 world");