コード例 #1
0
bool Compiler::CreateEngine() {
    auto module = cs_.module_.get();
    auto engine = llvm::EngineBuilder(cs_.module_.release())
            .setErrorStr(&error_)
            .setOptLevel(OPT_LEVEL)
            .setEngineKind(llvm::EngineKind::JIT)
#ifdef LLL_USE_MCJIT
            .setUseMCJIT(true)
#else
            .setUseMCJIT(false)
#endif
            .create();

    if (engine) {
        engine->finalizeObject();
        engine_.reset(new Engine(engine, module, cs_.function_));
        return true;
    } else {
        return false;
    }
}
コード例 #2
0
ファイル: memory.c プロジェクト: TimurTarasenko/robovm
static void _finalizeObject(GC_PTR addr, GC_PTR client_data) {
    Object* obj = (Object*) addr;
    Env* env = rvmGetEnv();
    assert(env != NULL);
    finalizeObject(env, obj);
}
コード例 #3
0
ファイル: main-chain.cpp プロジェクト: PragashSiva/bamql
/**
 * Compile many queries, then arrange them into a chain and squirt reads
 * through it.
 */
int main(int argc, char *const *argv) {
  const char *input_filename = nullptr;
  bool binary = false;
  ChainPattern chain = known_chains["parallel"];
  bool help = false;
  bool ignore_index = false;
  int c;

  while ((c = getopt(argc, argv, "bc:f:hI")) != -1) {
    switch (c) {
    case 'b':
      binary = true;
      break;
    case 'c':
      if (known_chains.find(optarg) == known_chains.end()) {
        std::cerr << "Unknown chaining method: " << optarg << std::endl;
        return 1;
      } else {
        chain = known_chains[optarg];
      }
      break;
    case 'h':
      help = true;
      break;
    case 'I':
      ignore_index = true;
      break;
    case 'f':
      input_filename = optarg;
      break;
    case '?':
      fprintf(stderr, "Option -%c is not valid.\n", optopt);
      return 1;
    default:
      abort();
    }
  }
  if (help) {
    std::cout << argv[0] << " [-b] [-c] [-I] [-v] -f input.bam "
                            " query1 output1.bam ..." << std::endl;
    std::cout << "Filter a BAM/SAM file based on the provided query. For "
                 "details, see the man page." << std::endl;
    std::cout << "\t-b\tThe input file is binary (BAM) not text (SAM)."
              << std::endl;
    std::cout << "\t-c\tChain the queries, rather than use them independently."
              << std::endl;
    std::cout << "\t-I\tDo not use the index, even if it exists." << std::endl;
    std::cout << "\t-v\tPrint some information along the way." << std::endl;
    return 0;
  }

  if (optind >= argc) {
    std::cout << "Need a query and a BAM file." << std::endl;
    return 1;
  }
  if ((argc - optind) % 2 != 0) {
    std::cout << "Queries and BAM files must be paired." << std::endl;
    return 1;
  }
  if (input_filename == nullptr) {
    std::cout << "An input file is required." << std::endl;
    return 1;
  }
  // Create a new LLVM module and JIT
  LLVMInitializeNativeTarget();
  llvm::InitializeNativeTargetAsmParser();
  llvm::InitializeNativeTargetAsmPrinter();
  std::unique_ptr<llvm::Module> module(
      new llvm::Module("bamql", llvm::getGlobalContext()));
  auto generator = std::make_shared<bamql::Generator>(module.get(), nullptr);
  auto engine = bamql::createEngine(std::move(module));
  if (!engine) {
    return 1;
  }

  // Prepare a chain of wranglers.
  std::shared_ptr<OutputWrangler> output;
  for (auto it = argc - 2; it >= optind; it -= 2) {
    // Prepare the output file.
    std::shared_ptr<htsFile> output_file;
    if (strcmp("-", argv[it + 1]) != 0) {
      output_file =
          std::shared_ptr<htsFile>(hts_open(argv[it + 1], "wb"), hts_close);
      if (!output_file) {
        perror(optarg);
        return 1;
      }
    }
    // Parse the input query.
    std::string query(argv[it]);
    auto ast =
        bamql::AstNode::parseWithLogging(query, bamql::getDefaultPredicates());
    if (!ast) {
      return 1;
    }

    // Add the link to the chain.
    std::stringstream function_name;
    function_name << "filter" << it;
    output = std::make_shared<OutputWrangler>(engine,
                                              generator,
                                              query,
                                              ast,
                                              function_name.str(),
                                              chain,
                                              std::string(argv[it + 1]),
                                              output_file,
                                              output);
  }
  engine->finalizeObject();
  output->prepareExecution();

  // Run the chain.
  if (output->processFile(input_filename, binary, ignore_index)) {
    output->write_summary();
    return 0;
  } else {
    return 1;
  }
}