本文整理汇总了C++中OwningPtr::get方法的典型用法代码示例。如果您正苦于以下问题:C++ OwningPtr::get方法的具体用法?C++ OwningPtr::get怎么用?C++ OwningPtr::get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OwningPtr
的用法示例。
在下文中一共展示了OwningPtr::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: runOnModule
bool DebugIR::runOnModule(Module &M) {
OwningPtr<int> fd;
if (isMissingPath() && !getSourceInfo(M)) {
if (!WriteSourceToDisk)
report_fatal_error("DebugIR unable to determine file name in input. "
"Ensure Module contains an identifier, a valid "
"DICompileUnit, or construct DebugIR with "
"non-empty Filename/Directory parameters.");
else
generateFilename(fd);
}
if (!GeneratedPath && WriteSourceToDisk)
updateExtension(".debug-ll");
// Clear line numbers. Keep debug info (if any) if we were able to read the
// file name from the DICompileUnit descriptor.
DebugMetadataRemover::process(M, !ParsedPath);
OwningPtr<Module> DisplayM;
createDebugInfo(M, DisplayM);
if (WriteSourceToDisk) {
Module *OutputM = DisplayM.get() ? DisplayM.get() : &M;
writeDebugBitcode(OutputM, fd.get());
}
DEBUG(M.dump());
return true;
}
示例2: run
bool ToolInvocation::run() {
std::vector<const char*> Argv;
for (int I = 0, E = CommandLine.size(); I != E; ++I)
Argv.push_back(CommandLine[I].c_str());
const char *const BinaryName = Argv[0];
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts = new DiagnosticOptions();
TextDiagnosticPrinter DiagnosticPrinter(
llvm::errs(), &*DiagOpts);
DiagnosticsEngine Diagnostics(
IntrusiveRefCntPtr<clang::DiagnosticIDs>(new DiagnosticIDs()),
&*DiagOpts, &DiagnosticPrinter, false);
const OwningPtr<clang::driver::Driver> Driver(
newDriver(&Diagnostics, BinaryName));
// Since the input might only be virtual, don't check whether it exists.
Driver->setCheckInputsExist(false);
const OwningPtr<clang::driver::Compilation> Compilation(
Driver->BuildCompilation(llvm::makeArrayRef(Argv)));
const clang::driver::ArgStringList *const CC1Args = getCC1Arguments(
&Diagnostics, Compilation.get());
if (CC1Args == NULL) {
return false;
}
OwningPtr<clang::CompilerInvocation> Invocation(
newInvocation(&Diagnostics, *CC1Args));
return runInvocation(BinaryName, Compilation.get(), Invocation.take());
}
示例3: clang_indexTranslationUnit_Impl
static void clang_indexTranslationUnit_Impl(void *UserData) {
IndexTranslationUnitInfo *ITUI =
static_cast<IndexTranslationUnitInfo*>(UserData);
CXTranslationUnit TU = ITUI->TU;
CXClientData client_data = ITUI->client_data;
IndexerCallbacks *client_index_callbacks = ITUI->index_callbacks;
unsigned index_callbacks_size = ITUI->index_callbacks_size;
unsigned index_options = ITUI->index_options;
ITUI->result = 1; // init as error.
if (!TU)
return;
if (!client_index_callbacks || index_callbacks_size == 0)
return;
CIndexer *CXXIdx = (CIndexer*)TU->CIdx;
if (CXXIdx->isOptEnabled(CXGlobalOpt_ThreadBackgroundPriorityForIndexing))
setThreadBackgroundPriority();
IndexerCallbacks CB;
memset(&CB, 0, sizeof(CB));
unsigned ClientCBSize = index_callbacks_size < sizeof(CB)
? index_callbacks_size : sizeof(CB);
memcpy(&CB, client_index_callbacks, ClientCBSize);
OwningPtr<IndexingContext> IndexCtx;
IndexCtx.reset(new IndexingContext(client_data, CB, index_options, TU));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<IndexingContext>
IndexCtxCleanup(IndexCtx.get());
OwningPtr<IndexingConsumer> IndexConsumer;
IndexConsumer.reset(new IndexingConsumer(*IndexCtx));
// Recover resources if we crash before exiting this method.
llvm::CrashRecoveryContextCleanupRegistrar<IndexingConsumer>
IndexConsumerCleanup(IndexConsumer.get());
ASTUnit *Unit = static_cast<ASTUnit *>(TU->TUData);
if (!Unit)
return;
ASTUnit::ConcurrencyCheck Check(*Unit);
FileManager &FileMgr = Unit->getFileManager();
if (Unit->getOriginalSourceFileName().empty())
IndexCtx->enteredMainFile(0);
else
IndexCtx->enteredMainFile(FileMgr.getFile(Unit->getOriginalSourceFileName()));
IndexConsumer->Initialize(Unit->getASTContext());
indexPreprocessingRecord(*Unit, *IndexCtx);
indexTranslationUnit(*Unit, *IndexCtx);
indexDiagnostics(TU, *IndexCtx);
ITUI->result = 0;
}
示例4: format
// Returns true on error.
static bool format(std::string FileName) {
FileManager Files((FileSystemOptions()));
DiagnosticsEngine Diagnostics(
IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
new DiagnosticOptions);
SourceManager Sources(Diagnostics, Files);
OwningPtr<MemoryBuffer> Code;
if (error_code ec = MemoryBuffer::getFileOrSTDIN(FileName, Code)) {
llvm::errs() << ec.message() << "\n";
return true;
}
if (Code->getBufferSize() == 0)
return true; // Empty files are formatted correctly.
FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files);
std::vector<CharSourceRange> Ranges;
if (fillRanges(Sources, ID, Code.get(), Ranges))
return true;
FormatStyle FormatStyle = getStyle(Style, FileName);
Lexer Lex(ID, Sources.getBuffer(ID), Sources,
getFormattingLangOpts(FormatStyle.Standard));
tooling::Replacements Replaces = reformat(FormatStyle, Lex, Sources, Ranges);
if (OutputXML) {
llvm::outs()
<< "<?xml version='1.0'?>\n<replacements xml:space='preserve'>\n";
for (tooling::Replacements::const_iterator I = Replaces.begin(),
E = Replaces.end();
I != E; ++I) {
llvm::outs() << "<replacement "
<< "offset='" << I->getOffset() << "' "
<< "length='" << I->getLength() << "'>"
<< I->getReplacementText() << "</replacement>\n";
}
llvm::outs() << "</replacements>\n";
} else {
Rewriter Rewrite(Sources, LangOptions());
tooling::applyAllReplacements(Replaces, Rewrite);
if (Inplace) {
if (Replaces.size() == 0)
return false; // Nothing changed, don't touch the file.
std::string ErrorInfo;
llvm::raw_fd_ostream FileStream(FileName.c_str(), ErrorInfo,
llvm::sys::fs::F_Binary);
if (!ErrorInfo.empty()) {
llvm::errs() << "Error while writing file: " << ErrorInfo << "\n";
return true;
}
Rewrite.getEditBuffer(ID).write(FileStream);
FileStream.flush();
} else {
if (Cursor.getNumOccurrences() != 0)
outs() << "{ \"Cursor\": " << tooling::shiftedCodePosition(
Replaces, Cursor) << " }\n";
Rewrite.getEditBuffer(ID).write(outs());
}
}
return false;
}
示例5: HandleTranslationUnit
virtual void HandleTranslationUnit(ASTContext &C) {
{
PrettyStackTraceString CrashInfo("Per-file LLVM IR generation");
if (llvm::TimePassesIsEnabled)
LLVMIRGeneration.startTimer();
Gen->HandleTranslationUnit(C);
if (llvm::TimePassesIsEnabled)
LLVMIRGeneration.stopTimer();
}
// Silently ignore if we weren't initialized for some reason.
if (!TheModule)
return;
// Make sure IR generation is happy with the module. This is released by
// the module provider.
llvm::Module *M = Gen->ReleaseModule();
if (!M) {
// The module has been released by IR gen on failures, do not double
// free.
TheModule.take();
return;
}
assert(TheModule.get() == M &&
"Unexpected module change during IR generation");
// Link LinkModule into this module if present, preserving its validity.
if (LinkModule) {
std::string ErrorMsg;
if (Linker::LinkModules(M, LinkModule.get(), Linker::PreserveSource,
&ErrorMsg)) {
Diags.Report(diag::err_fe_cannot_link_module)
<< LinkModule->getModuleIdentifier() << ErrorMsg;
return;
}
}
// Install an inline asm handler so that diagnostics get printed through
// our diagnostics hooks.
LLVMContext &Ctx = TheModule->getContext();
LLVMContext::InlineAsmDiagHandlerTy OldHandler =
Ctx.getInlineAsmDiagnosticHandler();
void *OldContext = Ctx.getInlineAsmDiagnosticContext();
Ctx.setInlineAsmDiagnosticHandler(InlineAsmDiagHandler, this);
EmitBackendOutput(Diags, CodeGenOpts, TargetOpts, LangOpts,
TheModule.get(), Action, AsmOutStream);
Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
}
示例6: main
int main()
{
InitializeNativeTarget();
llvm_start_multithreaded();
LLVMContext context;
string error;
OwningPtr<llvm::MemoryBuffer> fileBuf;
MemoryBuffer::getFile("hw.bc", fileBuf);
ErrorOr<Module*> m = parseBitcodeFile(fileBuf.get(), context);
ExecutionEngine *ee = ExecutionEngine::create(m.get());
Function* func = ee->FindFunctionNamed("main");
std::cout << "hop " << m.get() << " ee " << ee << " f " << func << std::endl;
typedef void (*PFN)();
PFN pfn = reinterpret_cast<PFN>(ee->getPointerToFunction(func));
pfn();
Function* f = ee->FindFunctionNamed("fib");
std::cout << "big " << f << std::endl;
// typedef std::function<int(int)> fibType;
typedef int (*fibType)(int);
fibType ffib = reinterpret_cast<fibType>(ee->getPointerToFunction(f));
std::cout << "fib " << ffib(7) << std::endl;
delete ee;
}
示例7: create
image* create(const char* data, std::size_t size) {
StringRef data_ref(data, size);
MemoryBuffer* buff(MemoryBuffer::getMemBufferCopy(data_ref, "binary"));
OwningPtr<object::Binary> binary;
if (error_code ec = createBinary(buff, binary))
llvm_binary_fail(ec);
return create_image(binary.get());
}
示例8: main
int main(int argc, char **argv) {
atexit(llvm_shutdown); // Call llvm_shutdown() on exit.
lav::parseArguments(argc, argv);
sys::PrintStackTraceOnErrorSignal();
// Load the bytecode...
// std::cout << std::endl << "Loading the bytecode..." << std::endl;
std::string ErrorMsg;
Module *mainModule = 0;
OwningPtr<MemoryBuffer> BufferPtr;
llvm::error_code ec =
MemoryBuffer::getFileOrSTDIN(InputFileName.c_str(), BufferPtr);
if (ec) {
lav::exit_error((std::string) "error loading program '%s': %s" +
InputFileName.c_str() + ec.message().c_str());
}
mainModule =
getLazyBitcodeModule(BufferPtr.get(), getGlobalContext(), &ErrorMsg);
if (mainModule) {
if (mainModule->MaterializeAllPermanently(&ErrorMsg)) {
delete mainModule;
mainModule = 0;
}
}
if (!mainModule)
lav::exit_error((std::string) "error loading program '%s': %s" +
InputFileName.c_str() + ErrorMsg.c_str());
std::cout << "Loading the bytecode... Completed " << std::endl << std::endl;
PassManager Passes;
Passes.add(new llvm::DataLayout(mainModule));
Passes.add(createFCFGSimplificationPass()); // Clean up after IPCP & DAE
// Passes.add(createLoopInfoPass()); //
Passes.add(llvm::createLoopSimplifyPass());
Passes.add(lav::createPetljePass()); //
if (EnableInline)
Passes.add(createAllInlinerPass(
Threshold)); //Inline malo vece funkcije, parametar inlininga od 200 do
//milijardu, ako je bez argumenta postavljeno je na
//milijardu
Passes.run(*mainModule);
Podaci p(mainModule);
p.UradiPosao();
BufferPtr.take();
std::cout << "Finished " << std::endl << std::endl;
return 0;
}
示例9: main
int main(int argc, const char *argv[]) {
cl::ParseCommandLineOptions(argc, argv, "SPIR verifier");
if (InputFilename.empty()) {
errs() << HelpMessage;
return 1;
}
StringRef Path = InputFilename;
LLVMContext Ctx;
OwningPtr<MemoryBuffer> result;
// Parse the bitcode file into a module.
error_code ErrCode = MemoryBuffer::getFile(Path, result);
if (!result.get()) {
errs() << "Buffer Creation Error. " << ErrCode.message() << "\n";
return 1;
}
std::string ErrMsg;
Module *M = ParseBitcodeFile(result.get(), Ctx, &ErrMsg);
if (!M) {
outs() << "According to this SPIR Verifier, " << Path << " is an invalid SPIR module.\n";
errs() << "Bitcode parsing error. " << ErrMsg << "\n";
return 1;
}
// Run the verification pass, and report errors if necessary.
SpirValidation Validation;
Validation.runOnModule(*M);
const ErrorPrinter *EP = Validation.getErrorPrinter();
if (EP->hasErrors()) {
outs() << "According to this SPIR Verifier, " << Path << " is an invalid SPIR module.\n";
errs() << "The module contains the following errors:\n\n";
EP->print(errs(), LITMode.getValue());
return 1;
}
outs() << "According to this SPIR Verifier, " << Path << " is a valid SPIR module.\n";
return 0;
}
示例10: SpecialCaseList
SpecialCaseList *SpecialCaseList::create(
const StringRef Path, std::string &Error) {
if (Path.empty())
return new SpecialCaseList();
OwningPtr<MemoryBuffer> File;
if (error_code EC = MemoryBuffer::getFile(Path, File)) {
Error = (Twine("Can't open file '") + Path + "': " + EC.message()).str();
return 0;
}
return create(File.get(), Error);
}
示例11: createDebugInfo
void DebugIR::createDebugInfo(Module &M, OwningPtr<Module> &DisplayM) {
if (M.getFunctionList().size() == 0)
// no functions -- no debug info needed
return;
OwningPtr<ValueToValueMapTy> VMap;
if (WriteSourceToDisk && (HideDebugIntrinsics || HideDebugMetadata)) {
VMap.reset(new ValueToValueMapTy);
DisplayM.reset(CloneModule(&M, *VMap));
if (HideDebugIntrinsics)
DebugIntrinsicsRemover::process(*DisplayM);
if (HideDebugMetadata)
DebugMetadataRemover::process(*DisplayM);
}
DIUpdater R(M, Filename, Directory, DisplayM.get(), VMap.get());
}
示例12: dumpInput
/// @brief Opens \a File and dumps it.
static void dumpInput(StringRef File) {
// If file isn't stdin, check that it exists.
if (File != "-" && !sys::fs::exists(File)) {
reportError(File, readobj_error::file_not_found);
return;
}
// Attempt to open the binary.
OwningPtr<Binary> Binary;
if (error_code EC = createBinary(File, Binary)) {
reportError(File, EC);
return;
}
if (Archive *Arc = dyn_cast<Archive>(Binary.get()))
dumpArchive(Arc);
else if (ObjectFile *Obj = dyn_cast<ObjectFile>(Binary.get()))
dumpObject(Obj);
else
reportError(File, readobj_error::unrecognized_file_format);
}
示例13: PrintFileSectionSizes
/// @brief Print the section sizes for @p file. If @p file is an archive, print
/// the section sizes for each archive member.
static void PrintFileSectionSizes(StringRef file) {
// If file is not stdin, check that it exists.
if (file != "-") {
bool exists;
if (sys::fs::exists(file, exists) || !exists) {
errs() << ToolName << ": '" << file << "': " << "No such file\n";
return;
}
}
// Attempt to open the binary.
ErrorOr<Binary *> BinaryOrErr = createBinary(file);
if (error_code EC = BinaryOrErr.getError()) {
errs() << ToolName << ": " << file << ": " << EC.message() << ".\n";
return;
}
OwningPtr<Binary> binary(BinaryOrErr.get());
if (Archive *a = dyn_cast<Archive>(binary.get())) {
// This is an archive. Iterate over each member and display its sizes.
for (object::Archive::child_iterator i = a->child_begin(),
e = a->child_end(); i != e; ++i) {
OwningPtr<Binary> child;
if (error_code ec = i->getAsBinary(child)) {
errs() << ToolName << ": " << file << ": " << ec.message() << ".\n";
continue;
}
if (ObjectFile *o = dyn_cast<ObjectFile>(child.get())) {
if (OutputFormat == sysv)
outs() << o->getFileName() << " (ex " << a->getFileName()
<< "):\n";
PrintObjectSectionSizes(o);
if (OutputFormat == berkeley)
outs() << o->getFileName() << " (ex " << a->getFileName() << ")\n";
}
}
} else if (ObjectFile *o = dyn_cast<ObjectFile>(binary.get())) {
if (OutputFormat == sysv)
outs() << o->getFileName() << " :\n";
PrintObjectSectionSizes(o);
if (OutputFormat == berkeley)
outs() << o->getFileName() << "\n";
} else {
errs() << ToolName << ": " << file << ": " << "Unrecognized file type.\n";
}
// System V adds an extra newline at the end of each file.
if (OutputFormat == sysv)
outs() << "\n";
}
示例14: fname
Module *LoadModule(const char *filename)
{
LLVMContext &Context = getGlobalContext();
std::string ErrMsg;
OwningPtr<MemoryBuffer> Buffer;
std::string fname(filename);
if (error_code ec = MemoryBuffer::getFile(fname, Buffer)) {
std::cout << "Could not open file" << ec.message() << std::endl;
}
Module *m = ParseBitcodeFile(Buffer.get(), Context, &ErrMsg);
if (!m) {
std::cout << "error" << ErrMsg << std::endl;
}
return m;
}
示例15: createPCHExternalASTSource
void CompilerInstance::createPCHExternalASTSource(StringRef Path,
bool DisablePCHValidation,
bool AllowPCHWithCompilerErrors,
void *DeserializationListener){
OwningPtr<ExternalASTSource> Source;
bool Preamble = getPreprocessorOpts().PrecompiledPreambleBytes.first != 0;
Source.reset(createPCHExternalASTSource(Path, getHeaderSearchOpts().Sysroot,
DisablePCHValidation,
AllowPCHWithCompilerErrors,
getPreprocessor(), getASTContext(),
DeserializationListener,
Preamble));
ModuleManager = static_cast<ASTReader*>(Source.get());
getASTContext().setExternalSource(Source);
}