• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ llvm类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中llvm的典型用法代码示例。如果您正苦于以下问题:C++ llvm类的具体用法?C++ llvm怎么用?C++ llvm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了llvm类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: maybe_print_statistics

static void maybe_print_statistics(llvm::Module *M, const char *prefix = nullptr)
{
    if (!statistics)
        return;

    using namespace llvm;
    uint64_t inum, bnum, fnum, gnum;
    inum = bnum = fnum = gnum = 0;

    for (auto I = M->begin(), E = M->end(); I != E; ++I) {
        // don't count in declarations
        if (I->size() == 0)
            continue;

        ++fnum;

        for (const BasicBlock& B : *I) {
            ++bnum;
            inum += B.size();
        }
    }

    for (auto I = M->global_begin(), E = M->global_end(); I != E; ++I)
        ++gnum;

    if (prefix)
        errs() << prefix;

    errs() << "Globals/Functions/Blocks/Instr.: "
           << gnum << " " << fnum << " " << bnum << " " << inum << "\n";
}
开发者ID:tomsik68,项目名称:dg,代码行数:31,代码来源:llvm-slicer.cpp


示例2: utostr

std::string RewriteBlocks::SynthesizeBlockHelperFuncs(BlockExpr *CE, int i,
                                                   const char *funcName,
                                                   std::string Tag) {
  std::string StructRef = "struct " + Tag;
  std::string S = "static void __";
  
  S += funcName;
  S += "_block_copy_" + utostr(i);
  S += "(" + StructRef;
  S += "*dst, " + StructRef;
  S += "*src) {";
  for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = ImportedBlockDecls.begin(), 
      E = ImportedBlockDecls.end(); I != E; ++I) {
    S += "_Block_copy_assign(&dst->";
    S += (*I)->getNameAsString();
    S += ", src->";
    S += (*I)->getNameAsString();
    S += ");}";
  }
  S += "\nstatic void __";
  S += funcName;
  S += "_block_dispose_" + utostr(i);
  S += "(" + StructRef;
  S += "*src) {";
  for (llvm::SmallPtrSet<ValueDecl*,8>::iterator I = ImportedBlockDecls.begin(), 
      E = ImportedBlockDecls.end(); I != E; ++I) {
    S += "_Block_destroy(src->";
    S += (*I)->getNameAsString();
    S += ");";
  }
  S += "}\n";  
  return S;
}
开发者ID:,项目名称:,代码行数:33,代码来源:


示例3: switch

Interval FlatStoreManager::RegionToInterval(const MemRegion *R) { 
  switch (R->getKind()) {
  case MemRegion::VarRegionKind: {
    QualType T = cast<VarRegion>(R)->getValueType(Ctx);
    uint64_t Size = Ctx.getTypeSize(T);
    return Interval(0, Size-1);
  }
  default:
    llvm_unreachable("Region kind unhandled.");
    return Interval(0, 0);
  }
}
开发者ID:jhoush,项目名称:dist-clang,代码行数:12,代码来源:FlatStore.cpp


示例4: InitializeNativeTarget

CodeGenerator::CodeGenerator() {
	InitializeNativeTarget();
	builder_=new IRBuilder<>(llvm::getGlobalContext());
	module_=new Module("my cool jit", llvm::getGlobalContext());
   fpm_=new FunctionPassManager (module_);
	fpm_->add(llvm::createCFGSimplificationPass());
	fpm_->add(llvm::createDeadCodeEliminationPass());
	fpm_->add(llvm::createMemCpyOptPass());
	engine_ = EngineBuilder(module_).create();
	assert(engine_);

}
开发者ID:wangli1426,项目名称:Claims,代码行数:12,代码来源:CodeGenerator.cpp


示例5: hash_value

uint64_t ExternalCommand::getSignature() {
  // FIXME: Use a more appropriate hashing infrastructure.
  using llvm::hash_combine;
  llvm::hash_code code = hash_value(getName());
  for (const auto* input: inputs) {
    code = hash_combine(code, input->getName());
  }
  for (const auto* output: outputs) {
    code = hash_combine(code, output->getName());
  }
  code = hash_combine(code, allowMissingInputs);
  code = hash_combine(code, allowModifiedOutputs);
  code = hash_combine(code, alwaysOutOfDate);
  return size_t(code);
}
开发者ID:aciidb0mb3r,项目名称:swift-build-tool,代码行数:15,代码来源:ExternalCommand.cpp


示例6: input

 static StringRef input(StringRef scalar, void*, VMProtect &value) {
   value = 0;
   if (scalar.size() != 3)
     return "segment access protection must be three chars (e.g. \"r-x\")";
   switch (scalar[0]) {
   case 'r':
     value = llvm::MachO::VM_PROT_READ;
     break;
   case '-':
     break;
   default:
     return "segment access protection first char must be 'r' or '-'";
   }
   switch (scalar[1]) {
   case 'w':
     value = value | llvm::MachO::VM_PROT_WRITE;
     break;
   case '-':
     break;
   default:
     return "segment access protection second char must be 'w' or '-'";
   }
   switch (scalar[2]) {
   case 'x':
     value = value | llvm::MachO::VM_PROT_EXECUTE;
     break;
   case '-':
     break;
   default:
     return "segment access protection third char must be 'x' or '-'";
   }
   // Return the empty string on success,
   return StringRef();
 }
开发者ID:cheloizaguirre,项目名称:lld,代码行数:34,代码来源:MachONormalizedFileYAML.cpp


示例7: addExportInfo

void Util::addExportInfo(const lld::File &atomFile, NormalizedFile &nFile) {
  if (_ctx.outputMachOType() == llvm::MachO::MH_OBJECT)
    return;

  for (SectionInfo *sect : _sectionInfos) {
    for (const AtomInfo &info : sect->atomsAndOffsets) {
      const DefinedAtom *atom = info.atom;
      if (atom->scope() != Atom::scopeGlobal)
        continue;
      if (_ctx.exportRestrictMode()) {
        if (!_ctx.exportSymbolNamed(atom->name()))
          continue;
      }
      Export exprt;
      exprt.name = atom->name();
      exprt.offset = _atomToAddress[atom] - _ctx.baseAddress();
      exprt.kind = EXPORT_SYMBOL_FLAGS_KIND_REGULAR;
      if (atom->merge() == DefinedAtom::mergeAsWeak)
        exprt.flags = EXPORT_SYMBOL_FLAGS_WEAK_DEFINITION;
      else
        exprt.flags = 0;
      exprt.otherOffset = 0;
      exprt.otherName = StringRef();
      nFile.exportInfo.push_back(exprt);
    }
  }
}
开发者ID:sas,项目名称:lld,代码行数:27,代码来源:MachONormalizedFileFromAtoms.cpp


示例8: writeModule

    bool writeModule() {
        // compose name if not given
        std::string fl;
        if (!options.outputFile.empty()) {
            fl = options.outputFile;
        } else {
            fl = options.inputFile;
            replace_suffix(fl, ".sliced");
        }

        // open stream to write to
        std::ofstream ofs(fl);
        llvm::raw_os_ostream ostream(ofs);

        // write the module
        errs() << "INFO: saving sliced module to: " << fl.c_str() << "\n";

    #if (LLVM_VERSION_MAJOR > 6)
        llvm::WriteBitcodeToFile(*M, ostream);
    #else
        llvm::WriteBitcodeToFile(M, ostream);
    #endif

        return true;
    }
开发者ID:tomsik68,项目名称:dg,代码行数:25,代码来源:llvm-slicer.cpp


示例9: printArg

void Command::Print(raw_ostream &OS, const char *Terminator, bool Quote,
                    CrashReportInfo *CrashInfo) const {
  // Always quote the exe.
  OS << ' ';
  printArg(OS, Executable, /*Quote=*/true);

  llvm::ArrayRef<const char *> Args = Arguments;
  llvm::SmallVector<const char *, 128> ArgsRespFile;
  if (ResponseFile != nullptr) {
    buildArgvForResponseFile(ArgsRespFile);
    Args = ArrayRef<const char *>(ArgsRespFile).slice(1); // no executable name
  }

  bool HaveCrashVFS = CrashInfo && !CrashInfo->VFSPath.empty();
  for (size_t i = 0, e = Args.size(); i < e; ++i) {
    const char *const Arg = Args[i];

    if (CrashInfo) {
      if (int Skip = skipArgs(Arg, HaveCrashVFS)) {
        i += Skip - 1;
        continue;
      }
      auto Found = std::find_if(InputFilenames.begin(), InputFilenames.end(),
                                [&Arg](StringRef IF) { return IF == Arg; });
      if (Found != InputFilenames.end() &&
          (i == 0 || StringRef(Args[i - 1]) != "-main-file-name")) {
        // Replace the input file name with the crashinfo's file name.
        OS << ' ';
        StringRef ShortName = llvm::sys::path::filename(CrashInfo->Filename);
        printArg(OS, ShortName.str().c_str(), Quote);
        continue;
      }
    }

    OS << ' ';
    printArg(OS, Arg, Quote);
  }

  if (CrashInfo && HaveCrashVFS) {
    OS << ' ';
    printArg(OS, "-ivfsoverlay", Quote);
    OS << ' ';
    printArg(OS, CrashInfo->VFSPath.str().c_str(), Quote);
  }

  if (ResponseFile != nullptr) {
    OS << "\n Arguments passed via response file:\n";
    writeResponseFile(OS);
    // Avoiding duplicated newline terminator, since FileLists are
    // newline-separated.
    if (Creator.getResponseFilesSupport() != Tool::RF_FileList)
      OS << "\n";
    OS << " (end of response file)";
  }

  OS << Terminator;
}
开发者ID:apurtell,项目名称:llvm-clang,代码行数:57,代码来源:Job.cpp


示例10: mapping

 static void mapping(IO &io, Export &exp) {
   io.mapRequired("name",         exp.name);
   io.mapOptional("offset",       exp.offset);
   io.mapOptional("kind",         exp.kind,
                               llvm::MachO::EXPORT_SYMBOL_FLAGS_KIND_REGULAR);
   if (!io.outputting() || exp.flags)
     io.mapOptional("flags",      exp.flags);
   io.mapOptional("other",        exp.otherOffset, Hex32(0));
   io.mapOptional("other-name",   exp.otherName, StringRef());
 }
开发者ID:cheloizaguirre,项目名称:lld,代码行数:10,代码来源:MachONormalizedFileYAML.cpp


示例11: annotate

    void annotate(const std::set<LLVMNode *> *criteria = nullptr)
    {
        // compose name
        std::string fl(options.inputFile);
        fl.replace(fl.end() - 3, fl.end(), "-debug.ll");

        // open stream to write to
        std::ofstream ofs(fl);
        llvm::raw_os_ostream outputstream(ofs);

        std::string module_comment =
        "; -- Generated by llvm-slicer --\n"
        ";   * slicing criteria: '" + options.slicingCriteria + "'\n" +
        ";   * forward slice: '" + std::to_string(options.forwardSlicing) + "'\n" +
        ";   * remove slicing criteria: '"
             + std::to_string(options.removeSlicingCriteria) + "'\n" +
        ";   * undefined are pure: '"
             + std::to_string(options.dgOptions.RDAOptions.undefinedArePure) + "'\n" +
        ";   * pointer analysis: ";
        if (options.dgOptions.PTAOptions.analysisType
                == LLVMPointerAnalysisOptions::AnalysisType::fi)
            module_comment += "flow-insensitive\n";
        else if (options.dgOptions.PTAOptions.analysisType
                    == LLVMPointerAnalysisOptions::AnalysisType::fs)
            module_comment += "flow-sensitive\n";
        else if (options.dgOptions.PTAOptions.analysisType
                    == LLVMPointerAnalysisOptions::AnalysisType::inv)
            module_comment += "flow-sensitive with invalidate\n";

        module_comment+= ";   * PTA field sensitivity: ";
        if (options.dgOptions.PTAOptions.fieldSensitivity == Offset::UNKNOWN)
            module_comment += "full\n\n";
        else
            module_comment
                += std::to_string(*options.dgOptions.PTAOptions.fieldSensitivity)
                   + "\n\n";

        errs() << "INFO: Saving IR with annotations to " << fl << "\n";
        auto annot
            = new dg::debug::LLVMDGAssemblyAnnotationWriter(annotationOptions,
                                                            dg->getPTA(),
                                                            dg->getRDA(),
                                                            criteria);
        annot->emitModuleComment(std::move(module_comment));
        llvm::Module *M = dg->getModule();
        M->print(outputstream, annot);

        delete annot;
    }
开发者ID:tomsik68,项目名称:dg,代码行数:49,代码来源:llvm-slicer.cpp


示例12: main

int main(int argc, char *argv[]) {
  PROGRAM_START(argc, argv);
  llvm::cl::ParseCommandLineOptions(argc, argv, "Swift Syntax Test\n");

  int ExitCode = EXIT_SUCCESS;

  if (options::InputSourceFilename.empty() &&
      options::InputSourceDirectory.empty()) {
    llvm::errs() << "input source file is required\n";
    ExitCode = EXIT_FAILURE;
  }
  
  if (!options::InputSourceFilename.empty() &&
      !options::InputSourceDirectory.empty()) {
    llvm::errs() << "input-source-filename and input-source-directory cannot "
                    "be used together\n\n";
    ExitCode = EXIT_FAILURE;
  }
  
  if (options::Action == ActionType::None) {
    llvm::errs() << "an action is required\n";
    ExitCode = EXIT_FAILURE;
  }

  if (ExitCode == EXIT_FAILURE) {
    llvm::cl::PrintHelpMessage();
    return ExitCode;
  }

  if (!options::InputSourceFilename.empty()) {
    ExitCode = invokeCommand(argv[0], options::InputSourceFilename);
  } else {
    assert(!options::InputSourceDirectory.empty());
    std::error_code errorCode;
    llvm::sys::fs::recursive_directory_iterator DI(options::InputSourceDirectory, errorCode);
    llvm::sys::fs::recursive_directory_iterator endIterator;
    for (; DI != endIterator; DI.increment(errorCode)) {
      auto entry = *DI;
      auto path = entry.path();
      if (!llvm::sys::fs::is_directory(path) &&
          StringRef(path).endswith(".swift")) {
        ExitCode = invokeCommand(argv[0], path);
      }
    }
  }

  return ExitCode;
}
开发者ID:etDev24,项目名称:swift,代码行数:48,代码来源:swift-syntax-test.cpp


示例13: hash_value

std::string CompilerInvocation::getPCHHash() const {
  using llvm::hash_code;
  using llvm::hash_value;
  using llvm::hash_combine;

  auto Code = hash_value(LangOpts.getPCHHashComponents());
  Code = hash_combine(Code, FrontendOpts.getPCHHashComponents());
  Code = hash_combine(Code, ClangImporterOpts.getPCHHashComponents());
  Code = hash_combine(Code, SearchPathOpts.getPCHHashComponents());
  Code = hash_combine(Code, DiagnosticOpts.getPCHHashComponents());
  Code = hash_combine(Code, SILOpts.getPCHHashComponents());
  Code = hash_combine(Code, IRGenOpts.getPCHHashComponents());

  return llvm::APInt(64, Code).toString(36, /*Signed=*/false);
}
开发者ID:norio-nomura,项目名称:swift,代码行数:15,代码来源:Frontend.cpp


示例14: format

void
BinMapOutput::InnerSectionsSymbols(const BinGroups& groups)
{
    for (BinGroups::const_iterator group = groups.begin(), end=groups.end();
         group != end; ++group)
    {
        if (CountSymbols(m_object, &group->m_section) > 0)
        {
            StringRef name = group->m_section.getName();
            m_os << "---- Section " << name << ' ';
            for (size_t i=0; i<65-name.size(); ++i)
                m_os << '-';

            m_os << "\n\n";
            m_os << format("%-*s", m_bytes*2+2, (const char*)"Real");
            m_os << format("%-*s", m_bytes*2+2, (const char*)"Virtual");
            m_os << "Name\n";
            OutputSymbols(&group->m_section);
            m_os << "\n\n";
        }

        // Recurse to loop through follow groups
        InnerSectionsSymbols(group->m_follow_groups);
    }
}
开发者ID:8l,项目名称:yasm-nextgen,代码行数:25,代码来源:BinMapOutput.cpp


示例15: ShortName

std::string tesla::ShortName(const Location& Loc) {
  return (Twine()
    + Loc.filename()
    + ":"
    + Twine(Loc.line())
    + "#"
    + Twine(Loc.counter())
  ).str();
}
开发者ID:CTSRD-TESLA,项目名称:TESLA,代码行数:9,代码来源:Names.cpp


示例16: verifyAndWriteModule

    int verifyAndWriteModule()
    {
        if (!verifyModule()) {
            errs() << "ERR: Verifying module failed, the IR is not valid\n";
            errs() << "INFO: Saving anyway so that you can check it\n";
            return 1;
        }

        if (!writeModule()) {
            errs() << "Saving sliced module failed\n";
            return 1;
        }

        // exit code
        return 0;
    }
开发者ID:tomsik68,项目名称:dg,代码行数:16,代码来源:llvm-slicer.cpp


示例17: SynthesizeBlockLiterals

void RewriteBlocks::SynthesizeBlockLiterals(SourceLocation FunLocStart,
                                                const char *FunName) {
  // Insert closures that were part of the function.
  for (unsigned i = 0; i < Blocks.size(); i++) {

    CollectBlockDeclRefInfo(Blocks[i]);

    std::string Tag = "__" + std::string(FunName) + "_block_impl_" + utostr(i);
                      
    std::string CI = SynthesizeBlockImpl(Blocks[i], Tag, 
                                         ImportedBlockDecls.size() > 0);

    InsertText(FunLocStart, CI.c_str(), CI.size());

    std::string CF = SynthesizeBlockFunc(Blocks[i], i, FunName, Tag);
    
    InsertText(FunLocStart, CF.c_str(), CF.size());

    if (ImportedBlockDecls.size()) {
      std::string HF = SynthesizeBlockHelperFuncs(Blocks[i], i, FunName, Tag);
      InsertText(FunLocStart, HF.c_str(), HF.size());
    }
    
    BlockDeclRefs.clear();
    BlockByRefDecls.clear();
    BlockByCopyDecls.clear();
    BlockCallExprs.clear();
    ImportedBlockDecls.clear();
  }
  Blocks.clear();
  RewrittenBlockExprs.clear();
}
开发者ID:,项目名称:,代码行数:32,代码来源:


示例18: optimize

void optimize( shared_ptr<module_vmcode> code, vector<optimization_options> opt_options )
{
	Module* mod = code->get_vm_module();

	FunctionPassManager fpm(mod);

	for( optimization_options opt_option: opt_options ){
		switch ( opt_option ){
			case opt_verify:
				for( Function& f: mod->getFunctionList() ){
					if(!f.empty()){
						verifyFunction(f, PrintMessageAction);
					}
				}
				break;
			case opt_preset_std_for_function:
				// createStandardFunctionPasses( &fpm, 1 );
				break;
		}
	}

	fpm.doInitialization();

	for( Function& f: mod->getFunctionList() ){
		if(!f.empty()){
			fpm.run(f);
		}
	}
}
开发者ID:2007750219,项目名称:softart,代码行数:29,代码来源:cg_opt.cpp


示例19: Twine

static std::string ConstantName(const tesla::Argument* A) {
  assert(A->type() == tesla::Argument::Constant);

  if (A->has_name())
      return A->name();

  else
    return Twine(A->value()).str();
}
开发者ID:CTSRD-TESLA,项目名称:TESLA,代码行数:9,代码来源:Names.cpp


示例20: readString

 bool readString(RemoteAddress address, std::string &dest) override {
   if (!isAddressValid(address, 1))
     return false;
   // TODO: Account for running off the edge of an object, offset in ELF
   // binaries
   auto cString = StringRef((const char*)address.getAddressData());
   dest.append(cString.begin(), cString.end());
   return true;
 }
开发者ID:shingt,项目名称:swift,代码行数:9,代码来源:swift-reflection-dump.cpp



注:本文中的llvm类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ local类代码示例发布时间:2022-05-31
下一篇:
C++ literalt类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap