本文整理汇总了C++中Mangler类的典型用法代码示例。如果您正苦于以下问题:C++ Mangler类的具体用法?C++ Mangler怎么用?C++ Mangler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Mangler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: locked
std::string ExecutionEngine::getMangledName(const GlobalValue *GV) {
MutexGuard locked(lock);
Mangler Mang;
SmallString<128> FullName;
Mang.getNameWithPrefix(FullName, GV, false);
return FullName.str();
}
示例2: emitLinkerFlagsForGlobal
void TargetLoweringObjectFileCOFF::emitLinkerFlagsForGlobal(
raw_ostream &OS, const GlobalValue *GV, const Mangler &Mang) const {
if (!GV->hasDLLExportStorageClass() || GV->isDeclaration())
return;
const Triple &TT = getTargetTriple();
if (TT.isKnownWindowsMSVCEnvironment())
OS << " /EXPORT:";
else
OS << " -export:";
if (TT.isWindowsGNUEnvironment() || TT.isWindowsCygwinEnvironment()) {
std::string Flag;
raw_string_ostream FlagOS(Flag);
Mang.getNameWithPrefix(FlagOS, GV, false);
FlagOS.flush();
if (Flag[0] == GV->getParent()->getDataLayout().getGlobalPrefix())
OS << Flag.substr(1);
else
OS << Flag;
} else {
Mang.getNameWithPrefix(OS, GV, false);
}
if (!GV->getValueType()->isFunctionTy()) {
if (TT.isKnownWindowsMSVCEnvironment())
OS << ",DATA";
else
OS << ",data";
}
}
示例3: getSILLinkage
/// Get or create SILGlobalVariable for a given global VarDecl.
SILGlobalVariable *SILGenModule::getSILGlobalVariable(VarDecl *gDecl,
ForDefinition_t forDef) {
// First, get a mangled name for the declaration.
std::string mangledName;
if (auto SILGenName = gDecl->getAttrs().getAttribute<SILGenNameAttr>()) {
mangledName = SILGenName->Name;
} else {
Mangler mangler;
mangler.mangleGlobalVariableFull(gDecl);
mangledName = mangler.finalize();
}
// Check if it is already created, and update linkage if necessary.
if (auto gv = M.lookUpGlobalVariable(mangledName)) {
// Update the SILLinkage here if this is a definition.
if (forDef == ForDefinition) {
gv->setLinkage(getSILLinkage(getDeclLinkage(gDecl), ForDefinition));
gv->setDeclaration(false);
}
return gv;
}
// Get the linkage for SILGlobalVariable.
SILLinkage link = getSILLinkage(getDeclLinkage(gDecl), forDef);
SILType silTy = M.Types.getLoweredTypeOfGlobal(gDecl);
auto *silGlobal = SILGlobalVariable::create(M, link,
makeModuleFragile ? IsFragile : IsNotFragile,
mangledName, silTy,
None, gDecl);
silGlobal->setDeclaration(!forDef);
return silGlobal;
}
示例4: mangleSubstitution
static void mangleSubstitution(Mangler &M, Substitution Sub) {
M.mangleType(Sub.getReplacement()->getCanonicalType(), 0);
for (auto C : Sub.getConformances()) {
if (C.isAbstract())
return;
M.mangleProtocolConformance(C.getConcrete());
}
}
示例5: mangleSubstitution
static void mangleSubstitution(Mangler &M, Substitution Sub) {
M.mangleType(Sub.getReplacement()->getCanonicalType(),
ResilienceExpansion::Minimal, 0);
for (auto C : Sub.getConformances()) {
if (!C)
return;
M.mangleProtocolConformance(C);
}
}
示例6: getBehaviorInitStorageFn
static SILValue getBehaviorInitStorageFn(SILGenFunction &gen,
VarDecl *behaviorVar) {
std::string behaviorInitName;
{
Mangler m;
m.mangleBehaviorInitThunk(behaviorVar);
std::string Old = m.finalize();
NewMangling::ASTMangler NewMangler;
std::string New = NewMangler.mangleBehaviorInitThunk(behaviorVar);
behaviorInitName = NewMangling::selectMangling(Old, New);
}
SILFunction *thunkFn;
// Skip out early if we already emitted this thunk.
if (auto existing = gen.SGM.M.lookUpFunction(behaviorInitName)) {
thunkFn = existing;
} else {
auto init = behaviorVar->getBehavior()->InitStorageDecl.getDecl();
auto initFn = gen.SGM.getFunction(SILDeclRef(init), NotForDefinition);
// Emit a thunk to inject the `self` metatype and implode tuples.
auto storageVar = behaviorVar->getBehavior()->StorageDecl;
auto selfTy = behaviorVar->getDeclContext()->getDeclaredInterfaceType();
auto initTy = gen.getLoweredType(selfTy).getFieldType(behaviorVar,
gen.SGM.M);
auto storageTy = gen.getLoweredType(selfTy).getFieldType(storageVar,
gen.SGM.M);
auto initConstantTy = initFn->getLoweredType().castTo<SILFunctionType>();
auto param = SILParameterInfo(initTy.getSwiftRValueType(),
initTy.isAddress() ? ParameterConvention::Indirect_In
: ParameterConvention::Direct_Owned);
auto result = SILResultInfo(storageTy.getSwiftRValueType(),
storageTy.isAddress() ? ResultConvention::Indirect
: ResultConvention::Owned);
initConstantTy = SILFunctionType::get(initConstantTy->getGenericSignature(),
initConstantTy->getExtInfo(),
ParameterConvention::Direct_Unowned,
param,
result,
// TODO: throwing initializer?
None,
gen.getASTContext());
// TODO: Generate the body of the thunk.
thunkFn = gen.SGM.M.getOrCreateFunction(SILLocation(behaviorVar),
behaviorInitName,
SILLinkage::PrivateExternal,
initConstantTy,
IsBare, IsTransparent, IsFragile);
}
return gen.B.createFunctionRef(behaviorVar, thunkFn);
}
示例7: mangle
std::string mangle(const GlobalValue *GV) {
std::string MangledName;
{
Mangler Mang;
raw_string_ostream MangledNameStream(MangledName);
Mang.getNameWithPrefix(MangledNameStream, GV, false);
}
return MangledName;
}
示例8: mangleConstant
static std::string mangleConstant(NormalProtocolConformance *C) {
using namespace Mangle;
Mangler mangler;
// mangled-name ::= '_T' global
// global ::= 'WP' protocol-conformance
mangler.append("_TWP");
mangler.mangleProtocolConformance(C);
return mangler.finalize();
}
示例9: applyScopeRestrictions
void LTOCodeGenerator::applyScopeRestrictions() {
if (ScopeRestrictionsDone)
return;
// Declare a callback for the internalize pass that will ask for every
// candidate GlobalValue if it can be internalized or not.
Mangler Mang;
SmallString<64> MangledName;
auto mustPreserveGV = [&](const GlobalValue &GV) -> bool {
// Unnamed globals can't be mangled, but they can't be preserved either.
if (!GV.hasName())
return false;
// Need to mangle the GV as the "MustPreserveSymbols" StringSet is filled
// with the linker supplied name, which on Darwin includes a leading
// underscore.
MangledName.clear();
MangledName.reserve(GV.getName().size() + 1);
Mang.getNameWithPrefix(MangledName, &GV, /*CannotUsePrivateLabel=*/false);
return MustPreserveSymbols.count(MangledName);
};
// Preserve linkonce value on linker request
preserveDiscardableGVs(*MergedModule, mustPreserveGV);
if (!ShouldInternalize)
return;
if (ShouldRestoreGlobalsLinkage) {
// Record the linkage type of non-local symbols so they can be restored
// prior
// to module splitting.
auto RecordLinkage = [&](const GlobalValue &GV) {
if (!GV.hasAvailableExternallyLinkage() && !GV.hasLocalLinkage() &&
GV.hasName())
ExternalSymbols.insert(std::make_pair(GV.getName(), GV.getLinkage()));
};
for (auto &GV : *MergedModule)
RecordLinkage(GV);
for (auto &GV : MergedModule->globals())
RecordLinkage(GV);
for (auto &GV : MergedModule->aliases())
RecordLinkage(GV);
}
// Update the llvm.compiler_used globals to force preserving libcalls and
// symbols referenced from asm
updateCompilerUsed(*MergedModule, *TargetMach, AsmUndefinedRefs);
internalizeModule(*MergedModule, mustPreserveGV);
ScopeRestrictionsDone = true;
}
示例10: assert
bool ide::printDeclUSR(const ValueDecl *D, raw_ostream &OS) {
using namespace Mangle;
if (!isa<FuncDecl>(D) && !D->hasName())
return true; // Ignore.
if (D->getModuleContext()->isBuiltinModule())
return true; // Ignore.
ValueDecl *VD = const_cast<ValueDecl *>(D);
if (ClangNode ClangN = VD->getClangNode()) {
llvm::SmallString<128> Buf;
if (auto ClangD = ClangN.getAsDecl()) {
bool Ignore = clang::index::generateUSRForDecl(ClangD, Buf);
if (!Ignore)
OS << Buf.str();
return Ignore;
}
auto &Importer = *D->getASTContext().getClangModuleLoader();
auto ClangMacroInfo = ClangN.getAsMacro();
auto PPRecord = Importer.getClangPreprocessor().getPreprocessingRecord();
assert(PPRecord && "Clang importer should be created with "
"-detailed-preprocessing-record option");
auto ClangMacroDef = PPRecord->findMacroDefinition(ClangMacroInfo);
bool Ignore = clang::index::generateUSRForMacro(
ClangMacroDef, Importer.getClangASTContext().getSourceManager(), Buf);
if (!Ignore)
OS << Buf.str();
return Ignore;
}
if (!D->hasType())
return true;
// FIXME: mangling 'self' in destructors crashes in mangler.
if (isa<ParamDecl>(VD) && isa<DestructorDecl>(VD->getDeclContext()))
return true;
OS << getUSRSpacePrefix();
Mangler Mangler;
if (auto Ctor = dyn_cast<ConstructorDecl>(VD)) {
Mangler.mangleConstructorEntity(Ctor, /*isAllocating=*/false,
/*uncurryingLevel=*/0);
} else if (auto Dtor = dyn_cast<DestructorDecl>(VD)) {
Mangler.mangleDestructorEntity(Dtor, /*isDeallocating=*/false);
} else if (auto NTD = dyn_cast<NominalTypeDecl>(VD)) {
Mangler.mangleNominalType(NTD, Mangler::BindGenerics::None);
} else if (isa<TypeAliasDecl>(VD) || isa<AssociatedTypeDecl>(VD)) {
Mangler.mangleContextOf(VD, Mangler::BindGenerics::None);
Mangler.mangleDeclName(VD);
} else {
Mangler.mangleEntity(VD, /*uncurryingLevel=*/0);
}
Mangler.finalize(OS);
return false;
}
示例11: mangleConstant
static std::string mangleConstant(NormalProtocolConformance *C) {
using namespace Mangle;
Mangler mangler;
// mangled-name ::= '_T' global
// global ::= 'WP' protocol-conformance
mangler.append("_TWP");
mangler.mangleProtocolConformance(C);
std::string Old = mangler.finalize();
NewMangling::ASTMangler NewMangler;
std::string New = NewMangler.mangleWitnessTable(C);
return NewMangling::selectMangling(Old, New);
}
示例12: applyRestriction
void LTOCodeGenerator::
applyRestriction(GlobalValue &GV,
const ArrayRef<StringRef> &Libcalls,
std::vector<const char*> &MustPreserveList,
SmallPtrSet<GlobalValue*, 8> &AsmUsed,
Mangler &Mangler) {
SmallString<64> Buffer;
Mangler.getNameWithPrefix(Buffer, &GV);
if (GV.isDeclaration())
return;
if (MustPreserveSymbols.count(Buffer))
MustPreserveList.push_back(GV.getName().data());
if (AsmUndefinedRefs.count(Buffer))
AsmUsed.insert(&GV);
// Conservatively append user-supplied runtime library functions to
// llvm.compiler.used. These could be internalized and deleted by
// optimizations like -globalopt, causing problems when later optimizations
// add new library calls (e.g., llvm.memset => memset and printf => puts).
// Leave it to the linker to remove any dead code (e.g. with -dead_strip).
if (isa<Function>(GV) &&
std::binary_search(Libcalls.begin(), Libcalls.end(), GV.getName()))
AsmUsed.insert(&GV);
}
示例13: addPotentialUndefinedSymbol
void LTOModule::addPotentialUndefinedSymbol(GlobalValue* decl, Mangler &mangler)
{
const char* name = mangler.getValueName(decl).c_str();
// ignore all llvm.* symbols
if ( strncmp(name, "llvm.", 5) != 0 ) {
_undefines[name] = 1;
}
}
示例14: emitLinkerFlagsForUsedCOFF
void llvm::emitLinkerFlagsForUsedCOFF(raw_ostream &OS, const GlobalValue *GV,
const Triple &T, Mangler &M) {
if (!T.isKnownWindowsMSVCEnvironment())
return;
OS << " /INCLUDE:";
M.getNameWithPrefix(OS, GV, false);
}
示例15: getNameWithPrefix
void TargetLoweringObjectFileMachO::getNameWithPrefix(
SmallVectorImpl<char> &OutName, const GlobalValue *GV, Mangler &Mang,
const TargetMachine &TM) const {
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
const MCSection *TheSection = SectionForGlobal(GV, GVKind, Mang, TM);
bool CannotUsePrivateLabel =
!canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
Mang.getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
}