本文整理汇总了C++中module::const_global_iterator::isDeclaration方法的典型用法代码示例。如果您正苦于以下问题:C++ const_global_iterator::isDeclaration方法的具体用法?C++ const_global_iterator::isDeclaration怎么用?C++ const_global_iterator::isDeclaration使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类module::const_global_iterator
的用法示例。
在下文中一共展示了const_global_iterator::isDeclaration方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: decorateName
bool X86IntelAsmPrinter::doInitialization(Module &M) {
bool Result = AsmPrinter::doInitialization(M);
Mang->markCharUnacceptable('.');
O << "\t.686\n\t.model flat\n\n";
// Emit declarations for external functions.
for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
if (I->isDeclaration()) {
std::string Name = Mang->getValueName(I);
decorateName(Name, I);
O << "\textern " ;
if (I->hasDLLImportLinkage()) {
O << "__imp_";
}
O << Name << ":near\n";
}
// Emit declarations for external globals. Note that VC++ always declares
// external globals to have type byte, and if that's good enough for VC++...
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (I->isDeclaration()) {
std::string Name = Mang->getValueName(I);
O << "\textern " ;
if (I->hasDLLImportLinkage()) {
O << "__imp_";
}
O << Name << ":byte\n";
}
}
return Result;
}
示例2: if
void PIC16AsmPrinter::EmitExternsAndGlobals (Module &M) {
// Emit declarations for external functions.
O << "section.0" <<"\n";
for (Module::iterator I = M.begin(), E = M.end(); I != E; I++) {
std::string Name = Mang->getValueName(I);
if (Name.compare("abort") == 0)
continue;
if (I->isDeclaration()) {
O << "\textern " <<Name << "\n";
O << "\textern " << Name << ".retval\n";
O << "\textern " << Name << ".args\n";
}
else if (I->hasExternalLinkage()) {
O << "\tglobal " << Name << "\n";
O << "\tglobal " << Name << ".retval\n";
O << "\tglobal " << Name << ".args\n";
}
}
// Emit header file to include declaration of library functions
O << "\t#include C16IntrinsicCalls.INC\n";
// Emit declarations for external globals.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; I++) {
// Any variables reaching here with ".auto." in its name is a local scope
// variable and should not be printed in global data section.
std::string Name = Mang->getValueName(I);
if (isLocalName (Name))
continue;
if (I->isDeclaration())
O << "\textern "<< Name << "\n";
else if (I->hasCommonLinkage() || I->hasExternalLinkage())
O << "\tglobal "<< Name << "\n";
}
}
示例3: emitGlobals
/// EmitGlobals - Emit all of the global variables to memory, storing their
/// addresses into GlobalAddress. This must make sure to copy the contents of
/// their initializers into the memory.
///
void ExecutionEngine::emitGlobals() {
// Loop over all of the global variables in the program, allocating the memory
// to hold them. If there is more than one module, do a prepass over globals
// to figure out how the different modules should link together.
//
std::map<std::pair<std::string, const Type*>,
const GlobalValue*> LinkedGlobalsMap;
if (Modules.size() != 1) {
for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
Module &M = *Modules[m]->getModule();
for (Module::const_global_iterator I = M.global_begin(),
E = M.global_end(); I != E; ++I) {
const GlobalValue *GV = I;
if (GV->hasLocalLinkage() || GV->isDeclaration() ||
GV->hasAppendingLinkage() || !GV->hasName())
continue;// Ignore external globals and globals with internal linkage.
const GlobalValue *&GVEntry =
LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
// If this is the first time we've seen this global, it is the canonical
// version.
if (!GVEntry) {
GVEntry = GV;
continue;
}
// If the existing global is strong, never replace it.
if (GVEntry->hasExternalLinkage() ||
GVEntry->hasDLLImportLinkage() ||
GVEntry->hasDLLExportLinkage())
continue;
// Otherwise, we know it's linkonce/weak, replace it if this is a strong
// symbol. FIXME is this right for common?
if (GV->hasExternalLinkage() || GVEntry->hasExternalWeakLinkage())
GVEntry = GV;
}
}
}
std::vector<const GlobalValue*> NonCanonicalGlobals;
for (unsigned m = 0, e = Modules.size(); m != e; ++m) {
Module &M = *Modules[m]->getModule();
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
// In the multi-module case, see what this global maps to.
if (!LinkedGlobalsMap.empty()) {
if (const GlobalValue *GVEntry =
LinkedGlobalsMap[std::make_pair(I->getName(), I->getType())]) {
// If something else is the canonical global, ignore this one.
if (GVEntry != &*I) {
NonCanonicalGlobals.push_back(I);
continue;
}
}
}
if (!I->isDeclaration()) {
addGlobalMapping(I, getMemoryForGV(I));
} else {
// External variable reference. Try to use the dynamic loader to
// get a pointer to it.
if (void *SymAddr =
sys::DynamicLibrary::SearchForAddressOfSymbol(I->getName().c_str()))
addGlobalMapping(I, SymAddr);
else {
cerr << "Could not resolve external global address: "
<< I->getName() << "\n";
abort();
}
}
}
// If there are multiple modules, map the non-canonical globals to their
// canonical location.
if (!NonCanonicalGlobals.empty()) {
for (unsigned i = 0, e = NonCanonicalGlobals.size(); i != e; ++i) {
const GlobalValue *GV = NonCanonicalGlobals[i];
const GlobalValue *CGV =
LinkedGlobalsMap[std::make_pair(GV->getName(), GV->getType())];
void *Ptr = getPointerToGlobalIfAvailable(CGV);
assert(Ptr && "Canonical global wasn't codegen'd!");
addGlobalMapping(GV, Ptr);
}
}
// Now that all of the globals are set up in memory, loop through them all
// and initialize their contents.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (!I->isDeclaration()) {
if (!LinkedGlobalsMap.empty()) {
if (const GlobalValue *GVEntry =
//.........这里部分代码省略.........
示例4: externalsAndGlobalsCheck
void externalsAndGlobalsCheck(const Module *m) {
std::map<std::string, bool> externals;
std::set<std::string> modelled(modelledExternals,
modelledExternals+NELEMS(modelledExternals));
std::set<std::string> dontCare(dontCareExternals,
dontCareExternals+NELEMS(dontCareExternals));
std::set<std::string> unsafe(unsafeExternals,
unsafeExternals+NELEMS(unsafeExternals));
switch (Libc) {
case KleeLibc:
dontCare.insert(dontCareKlee, dontCareKlee+NELEMS(dontCareKlee));
break;
case UcLibc:
dontCare.insert(dontCareUclibc,
dontCareUclibc+NELEMS(dontCareUclibc));
break;
case NoLibc: /* silence compiler warning */
break;
}
if (WithPOSIXRuntime)
dontCare.insert("syscall");
for (Module::const_iterator fnIt = m->begin(), fn_ie = m->end();
fnIt != fn_ie; ++fnIt) {
if (fnIt->isDeclaration() && !fnIt->use_empty())
externals.insert(std::make_pair(fnIt->getName(), false));
for (Function::const_iterator bbIt = fnIt->begin(), bb_ie = fnIt->end();
bbIt != bb_ie; ++bbIt) {
for (BasicBlock::const_iterator it = bbIt->begin(), ie = bbIt->end();
it != ie; ++it) {
if (const CallInst *ci = dyn_cast<CallInst>(it)) {
if (isa<InlineAsm>(ci->getCalledValue())) {
klee_warning_once(&*fnIt,
"function \"%s\" has inline asm",
fnIt->getName().data());
}
}
}
}
}
for (Module::const_global_iterator
it = m->global_begin(), ie = m->global_end();
it != ie; ++it)
if (it->isDeclaration() && !it->use_empty())
externals.insert(std::make_pair(it->getName(), true));
// and remove aliases (they define the symbol after global
// initialization)
for (Module::const_alias_iterator
it = m->alias_begin(), ie = m->alias_end();
it != ie; ++it) {
std::map<std::string, bool>::iterator it2 =
externals.find(it->getName());
if (it2!=externals.end())
externals.erase(it2);
}
std::map<std::string, bool> foundUnsafe;
for (std::map<std::string, bool>::iterator
it = externals.begin(), ie = externals.end();
it != ie; ++it) {
const std::string &ext = it->first;
if (!modelled.count(ext) && (WarnAllExternals ||
!dontCare.count(ext))) {
if (unsafe.count(ext)) {
foundUnsafe.insert(*it);
} else {
klee_warning("undefined reference to %s: %s",
it->second ? "variable" : "function",
ext.c_str());
}
}
}
for (std::map<std::string, bool>::iterator
it = foundUnsafe.begin(), ie = foundUnsafe.end();
it != ie; ++it) {
const std::string &ext = it->first;
klee_warning("undefined reference to %s: %s (UNSAFE)!",
it->second ? "variable" : "function",
ext.c_str());
}
}
示例5: if
/// Based on GetAllUndefinedSymbols() from LLVM3.2
///
/// GetAllUndefinedSymbols - calculates the set of undefined symbols that still
/// exist in an LLVM module. This is a bit tricky because there may be two
/// symbols with the same name but different LLVM types that will be resolved to
/// each other but aren't currently (thus we need to treat it as resolved).
///
/// Inputs:
/// M - The module in which to find undefined symbols.
///
/// Outputs:
/// UndefinedSymbols - A set of C++ strings containing the name of all
/// undefined symbols.
///
static void
GetAllUndefinedSymbols(Module *M, std::set<std::string> &UndefinedSymbols) {
static const std::string llvmIntrinsicPrefix="llvm.";
std::set<std::string> DefinedSymbols;
UndefinedSymbols.clear();
KLEE_DEBUG_WITH_TYPE("klee_linker",
dbgs() << "*** Computing undefined symbols for "
<< M->getModuleIdentifier() << " ***\n");
for (auto const &Function : *M) {
if (Function.hasName()) {
if (Function.isDeclaration())
UndefinedSymbols.insert(Function.getName());
else if (!Function.hasLocalLinkage()) {
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
assert(!Function.hasDLLImportLinkage() &&
"Found dllimported non-external symbol!");
#else
assert(!Function.hasDLLImportStorageClass() &&
"Found dllimported non-external symbol!");
#endif
DefinedSymbols.insert(Function.getName());
}
}
}
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I)
if (I->hasName()) {
if (I->isDeclaration())
UndefinedSymbols.insert(I->getName());
else if (!I->hasLocalLinkage()) {
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
assert(!I->hasDLLImportLinkage() && "Found dllimported non-external symbol!");
#else
assert(!I->hasDLLImportStorageClass() && "Found dllimported non-external symbol!");
#endif
DefinedSymbols.insert(I->getName());
}
}
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I)
if (I->hasName())
DefinedSymbols.insert(I->getName());
// Prune out any defined symbols from the undefined symbols set
// and other symbols we don't want to treat as an undefined symbol
std::vector<std::string> SymbolsToRemove;
for (std::set<std::string>::iterator I = UndefinedSymbols.begin();
I != UndefinedSymbols.end(); ++I )
{
if (DefinedSymbols.find(*I) != DefinedSymbols.end()) {
SymbolsToRemove.push_back(*I);
continue;
}
// Strip out llvm intrinsics
if ( (I->size() >= llvmIntrinsicPrefix.size() ) &&
(I->compare(0, llvmIntrinsicPrefix.size(), llvmIntrinsicPrefix) == 0) )
{
KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs() << "LLVM intrinsic " << *I <<
" has will be removed from undefined symbols"<< "\n");
SymbolsToRemove.push_back(*I);
continue;
}
// Symbol really is undefined
KLEE_DEBUG_WITH_TYPE("klee_linker",
dbgs() << "Symbol " << *I << " is undefined.\n");
}
// Now remove the symbols from undefined set.
for (auto const &symbol : SymbolsToRemove)
UndefinedSymbols.erase(symbol);
KLEE_DEBUG_WITH_TYPE("klee_linker",
dbgs() << "*** Finished computing undefined symbols ***\n");
}
示例6: switch
bool X86IntelAsmPrinter::doFinalization(Module &M) {
const TargetData *TD = TM.getTargetData();
// Print out module-level global variables here.
for (Module::const_global_iterator I = M.global_begin(), E = M.global_end();
I != E; ++I) {
if (I->isDeclaration()) continue; // External global require no code
// Check to see if this is a special global used by LLVM, if so, emit it.
if (EmitSpecialLLVMGlobal(I))
continue;
std::string name = Mang->getValueName(I);
Constant *C = I->getInitializer();
unsigned Align = TD->getPreferredAlignmentLog(I);
bool bCustomSegment = false;
switch (I->getLinkage()) {
case GlobalValue::CommonLinkage:
case GlobalValue::LinkOnceLinkage:
case GlobalValue::WeakLinkage:
SwitchToDataSection("");
O << name << "?\tsegment common 'COMMON'\n";
bCustomSegment = true;
// FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256
// are also available.
break;
case GlobalValue::AppendingLinkage:
SwitchToDataSection("");
O << name << "?\tsegment public 'DATA'\n";
bCustomSegment = true;
// FIXME: the default alignment is 16 bytes, but 1, 2, 4, and 256
// are also available.
break;
case GlobalValue::DLLExportLinkage:
DLLExportedGVs.insert(name);
// FALL THROUGH
case GlobalValue::ExternalLinkage:
O << "\tpublic " << name << "\n";
// FALL THROUGH
case GlobalValue::InternalLinkage:
SwitchToSection(TAI->getDataSection());
break;
default:
assert(0 && "Unknown linkage type!");
}
if (!bCustomSegment)
EmitAlignment(Align, I);
O << name << ":\t\t\t\t" << TAI->getCommentString()
<< " " << I->getName() << '\n';
EmitGlobalConstant(C);
if (bCustomSegment)
O << name << "?\tends\n";
}
// Output linker support code for dllexported globals
if (!DLLExportedGVs.empty() || !DLLExportedFns.empty()) {
SwitchToDataSection("");
O << "; WARNING: The following code is valid only with MASM v8.x"
<< "and (possible) higher\n"
<< "; This version of MASM is usually shipped with Microsoft "
<< "Visual Studio 2005\n"
<< "; or (possible) further versions. Unfortunately, there is no "
<< "way to support\n"
<< "; dllexported symbols in the earlier versions of MASM in fully "
<< "automatic way\n\n";
O << "_drectve\t segment info alias('.drectve')\n";
}
for (StringSet<>::iterator i = DLLExportedGVs.begin(),
e = DLLExportedGVs.end();
i != e; ++i)
O << "\t db ' /EXPORT:" << i->getKeyData() << ",data'\n";
for (StringSet<>::iterator i = DLLExportedFns.begin(),
e = DLLExportedFns.end();
i != e; ++i)
O << "\t db ' /EXPORT:" << i->getKeyData() << "'\n";
if (!DLLExportedGVs.empty() || !DLLExportedFns.empty())
O << "_drectve\t ends\n";
// Bypass X86SharedAsmPrinter::doFinalization().
bool Result = AsmPrinter::doFinalization(M);
SwitchToDataSection("");
O << "\tend\n";
return Result;
}
示例7: GlobalVariable
std::unique_ptr<Module> llvm::CloneModule(
const Module *M, ValueToValueMapTy &VMap,
function_ref<bool(const GlobalValue *)> ShouldCloneDefinition) {
// First off, we need to create the new module.
std::unique_ptr<Module> New =
llvm::make_unique<Module>(M->getModuleIdentifier(), M->getContext());
New->setDataLayout(M->getDataLayout());
New->setTargetTriple(M->getTargetTriple());
New->setModuleInlineAsm(M->getModuleInlineAsm());
// Loop over all of the global variables, making corresponding globals in the
// new module. Here we add them to the VMap and to the new Module. We
// don't worry about attributes or initializers, they will come later.
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
GlobalVariable *GV = new GlobalVariable(*New,
I->getValueType(),
I->isConstant(), I->getLinkage(),
(Constant*) nullptr, I->getName(),
(GlobalVariable*) nullptr,
I->getThreadLocalMode(),
I->getType()->getAddressSpace());
GV->copyAttributesFrom(&*I);
VMap[&*I] = GV;
}
// Loop over the functions in the module, making external functions as before
for (const Function &I : *M) {
Function *NF = Function::Create(cast<FunctionType>(I.getValueType()),
I.getLinkage(), I.getName(), New.get());
NF->copyAttributesFrom(&I);
VMap[&I] = NF;
}
// Loop over the aliases in the module
for (Module::const_alias_iterator I = M->alias_begin(), E = M->alias_end();
I != E; ++I) {
if (!ShouldCloneDefinition(&*I)) {
// An alias cannot act as an external reference, so we need to create
// either a function or a global variable depending on the value type.
// FIXME: Once pointee types are gone we can probably pick one or the
// other.
GlobalValue *GV;
if (I->getValueType()->isFunctionTy())
GV = Function::Create(cast<FunctionType>(I->getValueType()),
GlobalValue::ExternalLinkage, I->getName(),
New.get());
else
GV = new GlobalVariable(
*New, I->getValueType(), false, GlobalValue::ExternalLinkage,
(Constant *)nullptr, I->getName(), (GlobalVariable *)nullptr,
I->getThreadLocalMode(), I->getType()->getAddressSpace());
VMap[&*I] = GV;
// We do not copy attributes (mainly because copying between different
// kinds of globals is forbidden), but this is generally not required for
// correctness.
continue;
}
auto *GA = GlobalAlias::create(I->getValueType(),
I->getType()->getPointerAddressSpace(),
I->getLinkage(), I->getName(), New.get());
GA->copyAttributesFrom(&*I);
VMap[&*I] = GA;
}
// Now that all of the things that global variable initializer can refer to
// have been created, loop through and copy the global variable referrers
// over... We also set the attributes on the global now.
//
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
I != E; ++I) {
if (I->isDeclaration())
continue;
GlobalVariable *GV = cast<GlobalVariable>(VMap[&*I]);
if (!ShouldCloneDefinition(&*I)) {
// Skip after setting the correct linkage for an external reference.
GV->setLinkage(GlobalValue::ExternalLinkage);
continue;
}
if (I->hasInitializer())
GV->setInitializer(MapValue(I->getInitializer(), VMap));
SmallVector<std::pair<unsigned, MDNode *>, 1> MDs;
I->getAllMetadata(MDs);
for (auto MD : MDs)
GV->addMetadata(MD.first, *MapMetadata(MD.second, VMap));
}
// Similarly, copy over function bodies now...
//
for (const Function &I : *M) {
if (I.isDeclaration())
continue;
Function *F = cast<Function>(VMap[&I]);
if (!ShouldCloneDefinition(&I)) {
// Skip after setting the correct linkage for an external reference.
F->setLinkage(GlobalValue::ExternalLinkage);
//.........这里部分代码省略.........