当前位置: 首页>>代码示例>>C++>>正文


C++ ArrayRef::slice方法代码示例

本文整理汇总了C++中llvm::ArrayRef::slice方法的典型用法代码示例。如果您正苦于以下问题:C++ ArrayRef::slice方法的具体用法?C++ ArrayRef::slice怎么用?C++ ArrayRef::slice使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在llvm::ArrayRef的用法示例。


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

示例1: parse

bool CoreDriver::parse(llvm::ArrayRef<const char *> args,
                       CoreLinkingContext &ctx, raw_ostream &diagnostics) {
  // Parse command line options using CoreOptions.td
  CoreOptTable table;
  unsigned missingIndex;
  unsigned missingCount;
  llvm::opt::InputArgList parsedArgs =
      table.ParseArgs(args.slice(1), missingIndex, missingCount);
  if (missingCount) {
    diagnostics << "error: missing arg value for '"
                << parsedArgs.getArgString(missingIndex) << "' expected "
                << missingCount << " argument(s).\n";
    return false;
  }

  // Set default options
  ctx.setOutputPath("-");
  ctx.setDeadStripping(false);
  ctx.setGlobalsAreDeadStripRoots(false);
  ctx.setPrintRemainingUndefines(false);
  ctx.setAllowRemainingUndefines(true);
  ctx.setSearchArchivesToOverrideTentativeDefinitions(false);

  // Process all the arguments and create input files.
  for (auto inputArg : parsedArgs) {
    switch (inputArg->getOption().getID()) {
    case OPT_mllvm:
      ctx.appendLLVMOption(inputArg->getValue());
      break;

    case OPT_entry:
      ctx.setEntrySymbolName(inputArg->getValue());
      break;

    case OPT_output:
      ctx.setOutputPath(inputArg->getValue());
      break;

    case OPT_dead_strip:
      ctx.setDeadStripping(true);
      break;

    case OPT_keep_globals:
      ctx.setGlobalsAreDeadStripRoots(true);
      break;

    case OPT_undefines_are_errors:
      ctx.setPrintRemainingUndefines(true);
      ctx.setAllowRemainingUndefines(false);
      break;

    case OPT_commons_search_archives:
      ctx.setSearchArchivesToOverrideTentativeDefinitions(true);
      break;

    case OPT_add_pass:
      ctx.addPassNamed(inputArg->getValue());
      break;

    case OPT_INPUT: {
      std::vector<std::unique_ptr<File>> files
        = loadFile(ctx, inputArg->getValue(), false);
      for (std::unique_ptr<File> &file : files)
        ctx.getNodes().push_back(llvm::make_unique<FileNode>(std::move(file)));
      break;
    }

    default:
      break;
    }
  }

  if (ctx.getNodes().empty()) {
    diagnostics << "No input files\n";
    return false;
  }

  // Validate the combination of options used.
  return ctx.validate(diagnostics);
}
开发者ID:8l,项目名称:lld,代码行数:80,代码来源:CoreDriver.cpp

示例2: parse

void BuildSystemInvocation::parse(llvm::ArrayRef<std::string> args,
                                  llvm::SourceMgr& sourceMgr) {
  auto error = [&](const Twine &message) {
    sourceMgr.PrintMessage(llvm::SMLoc{}, llvm::SourceMgr::DK_Error, message);
    hadErrors = true;
  };

  while (!args.empty()) {
    const auto& option = args.front();
    args = args.slice(1);

    if (option == "-") {
      for (const auto& arg: args) {
        positionalArgs.push_back(arg);
      }
      break;
    }

    if (!option.empty() && option[0] != '-') {
      positionalArgs.push_back(option);
      continue;
    }
    
    if (option == "--help") {
      showUsage = true;
      break;
    } else if (option == "--version") {
      showVersion = true;
      break;
    } else if (option == "--no-db") {
      dbPath = "";
    } else if (option == "--db") {
      if (args.empty()) {
        error("missing argument to '" + option + "'");
        break;
      }
      dbPath = args[0];
      args = args.slice(1);
    } else if (option == "-C" || option == "--chdir") {
      if (args.empty()) {
        error("missing argument to '" + option + "'");
        break;
      }
      chdirPath = args[0];
      args = args.slice(1);
    } else if (option == "-f") {
      if (args.empty()) {
        error("missing argument to '" + option + "'");
        break;
      }
      buildFilePath = args[0];
      args = args.slice(1);
    } else if (option == "--serial") {
      useSerialBuild = true;
    } else if (option == "-v" || option == "--verbose") {
      showVerboseStatus = true;
    } else if (option == "--trace") {
      if (args.empty()) {
        error("missing argument to '" + option + "'");
        break;
      }
      traceFilePath = args[0];
      args = args.slice(1);
    } else {
      error("invalid option '" + option + "'");
      break;
    }
  }
}
开发者ID:apple,项目名称:swift-llbuild,代码行数:69,代码来源:BuildSystemFrontend.cpp

示例3: parse

bool GnuLdDriver::parse(llvm::ArrayRef<const char *> args,
                        std::unique_ptr<ELFLinkingContext> &context,
                        raw_ostream &diag) {
  // Parse command line options using GnuLdOptions.td
  GnuLdOptTable table;
  unsigned missingIndex;
  unsigned missingCount;

  llvm::opt::InputArgList parsedArgs =
      table.ParseArgs(args.slice(1), missingIndex, missingCount);
  if (missingCount) {
    diag << "error: missing arg value for '"
         << parsedArgs.getArgString(missingIndex) << "' expected "
         << missingCount << " argument(s).\n";
    return false;
  }

  // Handle --help
  if (parsedArgs.hasArg(OPT_help)) {
    table.PrintHelp(llvm::outs(), args[0], "LLVM Linker", false);
    return true;
  }

  // Use -target or use default target triple to instantiate LinkingContext
  llvm::Triple baseTriple;
  if (auto *arg = parsedArgs.getLastArg(OPT_target)) {
    baseTriple = llvm::Triple(arg->getValue());
  } else {
    baseTriple = getDefaultTarget(args[0]);
  }
  llvm::Triple triple(baseTriple);

  if (!applyEmulation(triple, parsedArgs, diag))
    return false;

  std::unique_ptr<ELFLinkingContext> ctx(createELFLinkingContext(triple));

  if (!ctx) {
    diag << "unknown target triple\n";
    return false;
  }

  // Copy mllvm
  for (auto *arg : parsedArgs.filtered(OPT_mllvm))
    ctx->appendLLVMOption(arg->getValue());

  // Ignore unknown arguments.
  for (auto unknownArg : parsedArgs.filtered(OPT_UNKNOWN))
    diag << "warning: ignoring unknown argument: "
         << unknownArg->getValue() << "\n";

  // Set sys root path.
  if (auto *arg = parsedArgs.getLastArg(OPT_sysroot))
    ctx->setSysroot(arg->getValue());

  // Handle --demangle option(For compatibility)
  if (parsedArgs.hasArg(OPT_demangle))
    ctx->setDemangleSymbols(true);

  // Handle --no-demangle option.
  if (parsedArgs.hasArg(OPT_no_demangle))
    ctx->setDemangleSymbols(false);

  // Figure out output kind (-r, -static, -shared)
  if (parsedArgs.hasArg(OPT_relocatable)) {
    ctx->setOutputELFType(llvm::ELF::ET_REL);
    ctx->setPrintRemainingUndefines(false);
    ctx->setAllowRemainingUndefines(true);
  }

  if (parsedArgs.hasArg(OPT_static)) {
    ctx->setOutputELFType(llvm::ELF::ET_EXEC);
    ctx->setIsStaticExecutable(true);
  }

  if (parsedArgs.hasArg(OPT_shared)) {
    ctx->setOutputELFType(llvm::ELF::ET_DYN);
    ctx->setAllowShlibUndefines(true);
    ctx->setUseShlibUndefines(false);
    ctx->setPrintRemainingUndefines(false);
    ctx->setAllowRemainingUndefines(true);
  }

  // Handle --stats.
  if (parsedArgs.hasArg(OPT_stats)) {
    ctx->setCollectStats(true);
  }

  // Figure out if the output type is nmagic/omagic
  if (auto *arg =
          parsedArgs.getLastArg(OPT_nmagic, OPT_omagic, OPT_no_omagic)) {
    switch (arg->getOption().getID()) {
    case OPT_nmagic:
      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::NMAGIC);
      ctx->setIsStaticExecutable(true);
      break;
    case OPT_omagic:
      ctx->setOutputMagic(ELFLinkingContext::OutputMagic::OMAGIC);
      ctx->setIsStaticExecutable(true);
      break;
//.........这里部分代码省略.........
开发者ID:8l,项目名称:lld,代码行数:101,代码来源:GnuLdDriver.cpp

示例4: dlltoolDriverMain

int llvm::dlltoolDriverMain(llvm::ArrayRef<const char *> ArgsArr) {
  DllOptTable Table;
  unsigned MissingIndex;
  unsigned MissingCount;
  llvm::opt::InputArgList Args =
      Table.ParseArgs(ArgsArr.slice(1), MissingIndex, MissingCount);
  if (MissingCount) {
    llvm::errs() << Args.getArgString(MissingIndex) << ": missing argument\n";
    return 1;
  }

  // Handle when no input or output is specified
  if (Args.hasArgNoClaim(OPT_INPUT) ||
      (!Args.hasArgNoClaim(OPT_d) && !Args.hasArgNoClaim(OPT_l))) {
    Table.PrintHelp(outs(), ArgsArr[0], "dlltool", false);
    llvm::outs() << "\nTARGETS: i386, i386:x86-64, arm\n";
    return 1;
  }

  if (!Args.hasArgNoClaim(OPT_m) && Args.hasArgNoClaim(OPT_d)) {
    llvm::errs() << "error: no target machine specified\n"
                 << "supported targets: i386, i386:x86-64, arm\n";
    return 1;
  }

  for (auto *Arg : Args.filtered(OPT_UNKNOWN))
    llvm::errs() << "ignoring unknown argument: " << Arg->getSpelling() << "\n";

  if (!Args.hasArg(OPT_d)) {
    llvm::errs() << "no definition file specified\n";
    return 1;
  }

  std::unique_ptr<MemoryBuffer> MB =
      openFile(Args.getLastArg(OPT_d)->getValue());
  if (!MB)
    return 1;

  if (!MB->getBufferSize()) {
    llvm::errs() << "definition file empty\n";
    return 1;
  }

  COFF::MachineTypes Machine = IMAGE_FILE_MACHINE_UNKNOWN;
  if (auto *Arg = Args.getLastArg(OPT_m))
    Machine = getEmulation(Arg->getValue());

  if (Machine == IMAGE_FILE_MACHINE_UNKNOWN) {
    llvm::errs() << "unknown target\n";
    return 1;
  }

  Expected<COFFModuleDefinition> Def =
      parseCOFFModuleDefinition(*MB, Machine, true);

  if (!Def) {
    llvm::errs() << "error parsing definition\n"
                 << errorToErrorCode(Def.takeError()).message();
    return 1;
  }

  // Do this after the parser because parseCOFFModuleDefinition sets OutputFile.
  if (auto *Arg = Args.getLastArg(OPT_D))
    Def->OutputFile = Arg->getValue();

  if (Def->OutputFile.empty()) {
    llvm::errs() << "no output file specified\n";
    return 1;
  }

  std::string Path = Args.getLastArgValue(OPT_l);
  if (Path.empty())
    Path = getImplibPath(Def->OutputFile);

  if (Machine == IMAGE_FILE_MACHINE_I386 && Args.getLastArg(OPT_k)) {
    for (COFFShortExport& E : Def->Exports) {
      if (E.isWeak() || (!E.Name.empty() && E.Name[0] == '?'))
        continue;
      E.SymbolName = E.Name;
      // Trim off the trailing decoration. Symbols will always have a
      // starting prefix here (either _ for cdecl/stdcall, @ for fastcall
      // or ? for C++ functions). (Vectorcall functions also will end up having
      // a prefix here, even if they shouldn't.)
      E.Name = E.Name.substr(0, E.Name.find('@', 1));
      // By making sure E.SymbolName != E.Name for decorated symbols,
      // writeImportLibrary writes these symbols with the type
      // IMPORT_NAME_UNDECORATE.
    }
  }

  if (writeImportLibrary(Def->OutputFile, Path, Def->Exports, Machine, true))
    return 1;
  return 0;
}
开发者ID:JaredCJR,项目名称:llvm,代码行数:94,代码来源:DlltoolDriver.cpp


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