/// in them, so mangle them as appropriate.
///
std::string Mangler::makeNameProper(const std::string &X,
- bool hasPrivateLinkage) {
+ ManglerPrefixTy PrefixTy) {
assert(!X.empty() && "Cannot mangle empty strings");
if (!UseQuotes) {
if (NeedPrefix) {
Result = Prefix + Result;
- if (hasPrivateLinkage)
+
+ if (PrefixTy == PrivatePrefixTy)
Result = PrivatePrefix + Result;
+ else if (PrefixTy == LinkerPrivatePrefixTy)
+ Result = LinkerPrivatePrefix + Result;
}
+
return Result;
}
return X.substr(1); // Strip off the \001.
Result = Prefix + X;
- if (hasPrivateLinkage)
+
+ if (PrefixTy == PrivatePrefixTy)
Result = PrivatePrefix + Result;
+ else if (PrefixTy == LinkerPrivatePrefixTy)
+ Result = LinkerPrivatePrefix + Result;
+
return Result;
}
if (NeedPrefix) {
Result = Prefix + Result;
- if (hasPrivateLinkage)
+
+ if (PrefixTy == PrivatePrefixTy)
Result = PrivatePrefix + Result;
+ else if (PrefixTy == LinkerPrivatePrefixTy)
+ Result = LinkerPrivatePrefix + Result;
}
+
Result = '"' + Result + '"';
return Result;
}
bool ForcePrivate) {
assert((!isa<Function>(GV) || !cast<Function>(GV)->isIntrinsic()) &&
"Intrinsic functions cannot be mangled by Mangler");
-
+
+ ManglerPrefixTy PrefixTy =
+ (GV->hasPrivateLinkage() || ForcePrivate) ? PrivatePrefixTy :
+ GV->hasLinkerPrivateLinkage() ? LinkerPrivatePrefixTy : DefaultPrefixTy;
+
if (GV->hasName())
- return makeNameProper(GV->getName() + Suffix,
- GV->hasPrivateLinkage() | ForcePrivate);
+ return makeNameProper(GV->getName() + Suffix, PrefixTy);
// Get the ID for the global, assigning a new one if we haven't got one
// already.
if (ID == 0) ID = NextAnonGlobalID++;
// Must mangle the global into a unique ID.
- return makeNameProper("__unnamed_" + utostr(ID) + Suffix,
- GV->hasPrivateLinkage() | ForcePrivate);
+ return makeNameProper("__unnamed_" + utostr(ID) + Suffix, PrefixTy);
}
-Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix)
- : Prefix(prefix), PrivatePrefix (privatePrefix), UseQuotes(false),
+Mangler::Mangler(Module &M, const char *prefix, const char *privatePrefix,
+ const char *linkerPrivatePrefix)
+ : Prefix(prefix), PrivatePrefix(privatePrefix),
+ LinkerPrivatePrefix(linkerPrivatePrefix), UseQuotes(false),
NextAnonGlobalID(1) {
std::fill(AcceptableChars, array_endof(AcceptableChars), 0);