Ejemplo n.º 1
0
  IR JIT(IR code)
  {
    SMDiagnostic errors;
    string parser_errors;
    ParseAssemblyString(code.assembly.c_str(),master.Program,errors,Context);
	if(master.debug)
	{
	  cerr << "Code:\n" << code.assembly << endl;
	}
    llvm::Function* entryfn = master.Engine->FindFunctionNamed("entry");
    if(entryfn == NULL)
      nerror("ERROR: Couldn't find program entry point.");
    if(!errors.getMessage().empty())
    {
      entryfn->eraseFromParent();
      nerror("IR Parsed with errors: ",errors.getMessage(),"\nCode: \n",code.assembly);
    }
    if(verifyModule(*master.Program,ReturnStatusAction,&parser_errors))
    {
      entryfn->eraseFromParent();
      nerror("IR Parser Error: ",parser_errors);
    }
    master.Passes.run(*master.Program);
	if(master.debug)
	{
	  cerr << "\nIR:" << endl;
	  master.Program->dump();
	}
    return code;
  }
Ejemplo n.º 2
0
SMDiagnostic MIRParserImpl::diagFromLLVMAssemblyDiag(const SMDiagnostic &Error,
                                                     SMRange SourceRange) {
  assert(SourceRange.isValid());

  // Translate the location of the error from the location in the llvm IR string
  // to the corresponding location in the MIR file.
  auto LineAndColumn = SM.getLineAndColumn(SourceRange.Start);
  unsigned Line = LineAndColumn.first + Error.getLineNo() - 1;
  unsigned Column = Error.getColumnNo();
  StringRef LineStr = Error.getLineContents();
  SMLoc Loc = Error.getLoc();

  // Get the full line and adjust the column number by taking the indentation of
  // LLVM IR into account.
  for (line_iterator L(*SM.getMemoryBuffer(SM.getMainFileID()), false), E;
       L != E; ++L) {
    if (L.line_number() == Line) {
      LineStr = *L;
      Loc = SMLoc::getFromPointer(LineStr.data());
      auto Indent = LineStr.find(Error.getLineContents());
      if (Indent != StringRef::npos)
        Column += Indent;
      break;
    }
  }

  return SMDiagnostic(SM, Loc, Filename, Line, Column, Error.getKind(),
                      Error.getMessage(), LineStr, Error.getRanges(),
                      Error.getFixIts());
}
Ejemplo n.º 3
0
CodeGenContext::CodeGenContext():
  mainFunction(0),
  builder(getGlobalContext())
{
  module = new Module("main", getGlobalContext());
  linker=new llvm::Linker("phc", module);

  char * externLibDir=getenv(PHC_ROOT_ENV);
  if(externLibDir==0){
    std::cout<<"Need Enviroment Variable "<<PHC_ROOT_ENV<<"\n";
    return;
  }
  std::cout << "Parse print function\n";
  SMDiagnostic Err;
  std::string dir(externLibDir, strlen(externLibDir));
  std::string filename("/extern/print.s");
  filename = dir + filename;
  libs = llvm::ParseIRFile(filename.c_str(), Err, getGlobalContext());
  std::cout << "Status: " << Err.getMessage() << "\n";
  if (libs == 0) {
    std::cout << "Error: cannot parse module " << filename << "\n";
    return;
  }

  std::cout << "Link print function\n";
  std::string errorMsg;
  linker->LinkModules(module, libs, llvm::Linker::DestroySource, &errorMsg);
  std::cout << "Status: " << errorMsg << "\n";

}
Ejemplo n.º 4
0
 Code* jit_ir(Code* code, const char* ir) {
     SMDiagnostic errors;
     string parser_errors;
     ParseAssemblyString(ir,code->program,errors,Context);
     Function* entryfn = code->program->getFunction(StringRef("entry"));
     if(entryfn == NULL) {
         return hylas_error_code("ERROR: Couldn't find program entry point.");
     }
     if(!errors.getMessage().empty()) {
         entryfn->eraseFromParent();
         return hylas_error_code(errors.getMessage().data());
     }
     if(verifyModule(*code->program,ReturnStatusAction,&parser_errors)) {
         entryfn->eraseFromParent();
         return hylas_error_code(parser_errors.data());
     }
     code->passes.run(*code->program);
     return code;
 }
Ejemplo n.º 5
0
extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) {
  SMDiagnostic d;
  Module *m = ParseAssemblyFile(Filename, d, getGlobalContext());
  if (m) {
    return wrap(m);
  } else {
    LLVMRustError = d.getMessage().str().c_str();
    return NULL;
  }
}
void LLVMGenerator::linkLibrary(const std::string& path)
{
    SMDiagnostic diag;

    Module* mod = ParseIRFile(path, diag, getGlobalContext());

    if(!mod)
        throw std::runtime_error("could not load library '" + path + "': " + diag.getMessage());

    linkLibrary(*mod);
}
Ejemplo n.º 7
0
static std::unique_ptr<Module> getModule(
    StringRef ProgramName, LLVMContext &Context,
    StreamingMemoryObject *StreamingObject) {
  std::unique_ptr<Module> M;
  SMDiagnostic Err;
  std::string VerboseBuffer;
  raw_string_ostream VerboseStrm(VerboseBuffer);
  if (LazyBitcode) {
    std::string StrError;
    switch (InputFileFormat) {
    case PNaClFormat: {
      std::unique_ptr<StreamingMemoryObject> Cache(
          new ThreadedStreamingCache(StreamingObject));
      M.reset(getNaClStreamedBitcodeModule(
          InputFilename, Cache.release(), Context, &VerboseStrm, &StrError));
      break;
    }
    case LLVMFormat: {
      std::unique_ptr<StreamingMemoryObject> Cache(
          new ThreadedStreamingCache(StreamingObject));
      ErrorOr<std::unique_ptr<Module>> MOrErr =
          getStreamedBitcodeModule(
          InputFilename, Cache.release(), Context);
      M = std::move(*MOrErr);
      break;
    }
    case AutodetectFileFormat:
      report_fatal_error("Command can't autodetect file format!");
    }
    if (!StrError.empty())
      Err = SMDiagnostic(InputFilename, SourceMgr::DK_Error, StrError);
  } else {
#if defined(PNACL_BROWSER_TRANSLATOR)
    llvm_unreachable("native client SRPC only supports streaming");
#else
    // Parses binary bitcode as well as textual assembly
    // (so pulls in more code into pnacl-llc).
    M = NaClParseIRFile(InputFilename, InputFileFormat, Err, &VerboseStrm,
                        Context);
#endif
  }
  if (!M) {
#if defined(PNACL_BROWSER_TRANSLATOR)
    report_fatal_error(VerboseStrm.str() + Err.getMessage());
#else
    // Err.print is prettier, so use it for the non-sandboxed translator.
    Err.print(ProgramName.data(), errs());
    errs() << VerboseStrm.str();
    return nullptr;
#endif
  }
  return std::move(M);
}
Ejemplo n.º 8
0
SMDiagnostic MIRParserImpl::diagFromMIStringDiag(const SMDiagnostic &Error,
                                                 SMRange SourceRange) {
  assert(SourceRange.isValid() && "Invalid source range");
  SMLoc Loc = SourceRange.Start;
  bool HasQuote = Loc.getPointer() < SourceRange.End.getPointer() &&
                  *Loc.getPointer() == '\'';
  // Translate the location of the error from the location in the MI string to
  // the corresponding location in the MIR file.
  Loc = Loc.getFromPointer(Loc.getPointer() + Error.getColumnNo() +
                           (HasQuote ? 1 : 0));

  // TODO: Translate any source ranges as well.
  return SM.GetMessage(Loc, Error.getKind(), Error.getMessage(), None,
                       Error.getFixIts());
}
Ejemplo n.º 9
0
bool ArchiveImporter::load(StringRef qualifiedName, Module *& module) {
  if (!valid_) {
    return false;
  }

  if (archive_ == NULL) {
    SMDiagnostic smErr;
    archive_ = ParseIRFile(path_.str(), smErr, getGlobalContext());
    if (archive_ == NULL) {
      bool exists = false;
      if (fs::exists(path_.str(), exists) == errc::success && exists) {
        diag.error() << "Cannot load library " << path_;
        diag.info() << smErr.getMessage();
      }
      valid_ = false;
      return false;
    }

    archiveSource_ = new ArchiveFile(path_);
  }

  Twine mdName("tart.xdef.");
  NamedMDNode * md = archive_->getNamedMetadata(mdName.concat(qualifiedName));
  if (md != NULL) {
    // Convert the qualified name of the module to a relative path.
    SmallString<128> relpath(path_);
    relpath.reserve(path_.size() + qualifiedName.size() + 1);
    relpath.push_back('#');
    for (size_t i = 0; i < qualifiedName.size(); ++i) {
      if (qualifiedName[i] == '.') {
        relpath.push_back('/');
      } else {
        relpath.push_back(qualifiedName[i]);
      }
    }

    // Create the module and read the header.
    module = new Module(qualifiedName, &Builtins::module);
    module->setModuleSource(new ArchiveEntry(relpath, archiveSource_));
    return MDReader(module, module).read(md);
  }

  return false;
}
Module* LinkExternalBitcode(Module* module, std::string bc)
{
    LLVMContext &Context = getGlobalContext();
    SMDiagnostic smdiagnostic;
    std::string InputFile = GetRootPath() + "/" + bc;
    Module* LoadBitcode = ParseIRFile(InputFile, smdiagnostic, Context);

    if (!LoadBitcode) {
        std::cerr << InputFile << " : " << smdiagnostic.getMessage() <<'\n';
    }

    std::string err;
    bool result = Linker::LinkModules(module, LoadBitcode,
                         Linker::DestroySource, &err);
    if (result) {
        std::cerr << "Module Linking Error : "<< err << '\n';
    }
    return module;
};
Ejemplo n.º 11
0
void LoadLLRuntime()
{
#ifdef HSPWIN
	HRSRC hrc;
	HGLOBAL hgb;
	LPVOID p;
	LLVMContext& context = getGlobalContext();

	hrc = FindResource(NULL, MAKEINTRESOURCEA(256), "TEXT");
	hgb = LoadResource(NULL, hrc);
	p = LockResource(hgb);

	SMDiagnostic err;
	rtModule.reset(ParseAssemblyString((char*)p, nullptr, err, context));
	FreeResource(hrc);
	if (!rtModule)
		Alert(err.getMessage().data());
#else
#error
#endif
}
Ejemplo n.º 12
0
//////////////////////////////////////////////////////////////////////////
/// @brief Create new LLVM module from IR.
bool JitManager::SetupModuleFromIR(const uint8_t *pIR)
{
    std::unique_ptr<MemoryBuffer> pMem = MemoryBuffer::getMemBuffer(StringRef((const char*)pIR), "");

    SMDiagnostic Err;
    std::unique_ptr<Module> newModule = parseIR(pMem.get()->getMemBufferRef(), Err, mContext);

    SWR_REL_ASSERT(
        !(newModule == nullptr),
        "Parse failed!\n"
        "%s", Err.getMessage().data());
    if (newModule == nullptr)
    {
        return false;
    }

#if HAVE_LLVM == 0x307
    // llvm-3.7 has mismatched setDataLyout/getDataLayout APIs
    newModule->setDataLayout(*mpExec->getDataLayout());
#else
    newModule->setDataLayout(mpExec->getDataLayout());
#endif

    mpCurrentModule = newModule.get();
#if defined(_WIN32)
    // Needed for MCJIT on windows
    Triple hostTriple(sys::getProcessTriple());
    hostTriple.setObjectFormat(Triple::ELF);
    newModule->setTargetTriple(hostTriple.getTriple());
#endif // _WIN32

    mpExec->addModule(std::move(newModule));
    mIsModuleFinalized = false;

    return true;
}
Ejemplo n.º 13
0
static llvm::Module* jitCompile(const std::string& String)
{
    // Create some module to put our function into it.
    using namespace llvm;
    legacy::PassManager* PM = extemp::EXTLLVM::PM;
    legacy::PassManager* PM_NO = extemp::EXTLLVM::PM_NO;

    char modname[256];
    sprintf(modname, "xtmmodule_%lld", ++llvm_emitcounter);

    std::string asmcode(String);
    SMDiagnostic pa;

    static std::string sInlineString; // This is a hack for now, but it *WORKS*
    static std::string sInlineBitcode;
    static std::unordered_set<std::string> sInlineSyms;
    if (sInlineString.empty()) {
        {
            std::ifstream inStream(UNIV::SHARE_DIR + "/runtime/bitcode.ll");
            std::stringstream inString;
            inString << inStream.rdbuf();
            sInlineString = inString.str();
        }
        std::copy(std::sregex_token_iterator(sInlineString.begin(), sInlineString.end(), sGlobalSymRegex, 1),
                std::sregex_token_iterator(), std::inserter(sInlineSyms, sInlineSyms.begin()));
        {
            std::ifstream inStream(UNIV::SHARE_DIR + "/runtime/inline.ll");
            std::stringstream inString;
            inString << inStream.rdbuf();
            std::string tString = inString.str();
            std::copy(std::sregex_token_iterator(tString.begin(), tString.end(), sGlobalSymRegex, 1),
                    std::sregex_token_iterator(), std::inserter(sInlineSyms, sInlineSyms.begin()));
        }
    }
    if (sInlineBitcode.empty()) {
        // need to avoid parsing the types twice
        static bool first(true);
        if (!first) {
            auto newModule(parseAssemblyString(sInlineString, pa, getGlobalContext()));
            if (newModule) {
                std::string bitcode;
                llvm::raw_string_ostream bitstream(sInlineBitcode);
                llvm::WriteBitcodeToFile(newModule.get(), bitstream);
                std::ifstream inStream(UNIV::SHARE_DIR + "/runtime/inline.ll");
                std::stringstream inString;
                inString << inStream.rdbuf();
                sInlineString = inString.str();
            } else {
std::cout << pa.getMessage().str() << std::endl;
                abort();
            }
        } else {
            first = false;
        }
    }
    std::unique_ptr<llvm::Module> newModule;
    std::vector<std::string> symbols;
    std::copy(std::sregex_token_iterator(asmcode.begin(), asmcode.end(), sGlobalSymRegex, 1),
            std::sregex_token_iterator(), std::inserter(symbols, symbols.begin()));
    std::sort(symbols.begin(), symbols.end());
    auto end(std::unique(symbols.begin(), symbols.end()));
    std::unordered_set<std::string> ignoreSyms;
    std::copy(std::sregex_token_iterator(asmcode.begin(), asmcode.end(), sDefineSymRegex, 1),
            std::sregex_token_iterator(), std::inserter(ignoreSyms, ignoreSyms.begin()));
    std::string declarations;
    llvm::raw_string_ostream dstream(declarations);
    for (auto iter = symbols.begin(); iter != end; ++iter) {
        const char* sym(iter->c_str());
        if (sInlineSyms.find(sym) != sInlineSyms.end() || ignoreSyms.find(sym) != ignoreSyms.end()) {
            continue;
        }
        auto gv = extemp::EXTLLVM::getGlobalValue(sym);
        if (!gv) {
            continue;
        }
        auto func(llvm::dyn_cast<llvm::Function>(gv));
        if (func) {
            dstream << "declare " << SanitizeType(func->getReturnType()) << " @" << sym << " (";
            bool first(true);
            for (const auto& arg : func->getArgumentList()) {
                if (!first) {
                    dstream << ", ";
                } else {
                    first = false;
                }
                dstream << SanitizeType(arg.getType());
            }
            if (func->isVarArg()) {
                dstream << ", ...";
            }
            dstream << ")\n";
        } else {
            auto str(SanitizeType(gv->getType()));
            dstream << '@' << sym << " = external global " << str.substr(0, str.length() - 1) << '\n';
        }
    }
// std::cout << "**** DECL ****\n" << dstream.str() << "**** ENDDECL ****\n" << std::endl;
    if (!sInlineBitcode.empty()) {
        auto modOrErr(parseBitcodeFile(llvm::MemoryBufferRef(sInlineBitcode, "<string>"), getGlobalContext()));
        if (likely(modOrErr)) {
            newModule = std::move(modOrErr.get());
            asmcode = sInlineString + dstream.str() + asmcode;
            if (parseAssemblyInto(llvm::MemoryBufferRef(asmcode, "<string>"), *newModule, pa)) {
std::cout << "**** DECL ****\n" << dstream.str() << "**** ENDDECL ****\n" << std::endl;
                newModule.reset();
            }
        }
    } else {
       newModule = parseAssemblyString(asmcode, pa, getGlobalContext());
    }
    if (newModule) {
        if (unlikely(!extemp::UNIV::ARCH.empty())) {
            newModule->setTargetTriple(extemp::UNIV::ARCH);
        }
        if (EXTLLVM::OPTIMIZE_COMPILES) {
            PM->run(*newModule);
        } else {
            PM_NO->run(*newModule);
        }
    }
    //std::stringstream ss;
    if (unlikely(!newModule))
    {
// std::cout << "**** CODE ****\n" << asmcode << " **** ENDCODE ****" << std::endl;
// std::cout << pa.getMessage().str() << std::endl << pa.getLineNo() << std::endl;
        std::string errstr;
        llvm::raw_string_ostream ss(errstr);
        pa.print("LLVM IR",ss);
        printf("%s\n",ss.str().c_str());
        return nullptr;
    } else if (extemp::EXTLLVM::VERIFY_COMPILES && verifyModule(*newModule)) {
        std::cout << "\nInvalid LLVM IR\n";
        return nullptr;
    }

    llvm::Module *modulePtr = newModule.get();
    extemp::EXTLLVM::EE->addModule(std::move(newModule));
    extemp::EXTLLVM::EE->finalizeObject();
    return modulePtr;
}
Ejemplo n.º 14
0
static bool valueIsOnlyCalled(const Value *v) {
#if LLVM_VERSION_CODE < LLVM_VERSION(3, 5)
  for (auto it = v->use_begin(), ie = v->use_end(); it != ie; ++it) {
    auto user = *it;
#else
  for (auto user : v->users()) {
#endif
    if (const auto *instr = dyn_cast<Instruction>(user)) {
      // Make sure the instruction is a call or invoke.
      CallSite cs(const_cast<Instruction *>(instr));
      if (!cs) return false;

      // Make sure that the value is only the target of this call and
      // not an argument.
      if (cs.hasArgument(v))
        return false;
    } else if (const auto *ce = dyn_cast<ConstantExpr>(user)) {
      if (ce->getOpcode() == Instruction::BitCast)
        if (valueIsOnlyCalled(ce))
          continue;
      return false;
    } else if (const auto *ga = dyn_cast<GlobalAlias>(user)) {
      if (v == ga->getAliasee() && !valueIsOnlyCalled(ga))
        return false;
    } else if (isa<BlockAddress>(user)) {
      // only valid as operand to indirectbr or comparison against null
      continue;
    } else {
      return false;
    }
  }

  return true;
}

bool klee::functionEscapes(const Function *f) {
  return !valueIsOnlyCalled(f);
}

bool klee::loadFile(const std::string &fileName, LLVMContext &context,
                    std::vector<std::unique_ptr<llvm::Module>> &modules,
                    std::string &errorMsg) {
  KLEE_DEBUG_WITH_TYPE("klee_loader", dbgs()
                                          << "Load file " << fileName << "\n");

#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
  ErrorOr<std::unique_ptr<MemoryBuffer>> bufferErr =
      MemoryBuffer::getFileOrSTDIN(fileName);
  std::error_code ec = bufferErr.getError();
#else
  OwningPtr<MemoryBuffer> Buffer;
  error_code ec = MemoryBuffer::getFileOrSTDIN(fileName, Buffer);
#endif
  if (ec) {
    klee_error("Loading file %s failed: %s", fileName.c_str(),
               ec.message().c_str());
  }

#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
  MemoryBufferRef Buffer = bufferErr.get()->getMemBufferRef();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
  MemoryBuffer *Buffer = bufferErr->get();
#endif

#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
  sys::fs::file_magic magic = sys::fs::identify_magic(Buffer.getBuffer());
#else
  sys::fs::file_magic magic = sys::fs::identify_magic(Buffer->getBuffer());
#endif

  if (magic == sys::fs::file_magic::bitcode) {
    SMDiagnostic Err;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
    std::unique_ptr<llvm::Module> module(parseIR(Buffer, Err, context));
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
    std::unique_ptr<llvm::Module> module(ParseIR(Buffer, Err, context));
#else
    std::unique_ptr<llvm::Module> module(ParseIR(Buffer.take(), Err, context));
#endif
    if (!module) {
      klee_error("Loading file %s failed: %s", fileName.c_str(),
                 Err.getMessage().str().c_str());
    }
    modules.push_back(std::move(module));
    return true;
  }

  if (magic == sys::fs::file_magic::archive) {
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
    ErrorOr<std::unique_ptr<object::Binary>> archOwner =
        object::createBinary(Buffer, &context);
    ec = archOwner.getError();
    llvm::object::Binary *arch = archOwner.get().get();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
    ErrorOr<object::Binary *> archOwner =
        object::createBinary(std::move(bufferErr.get()), &context);
    ec = archOwner.getError();
    llvm::object::Binary *arch = archOwner.get();
#else
    OwningPtr<object::Binary> archOwner;
    ec = object::createBinary(Buffer.take(), archOwner);
    llvm::object::Binary *arch = archOwner.get();
#endif
    if (ec)
      klee_error("Loading file %s failed: %s", fileName.c_str(),
                 ec.message().c_str());

    if (auto archive = dyn_cast<object::Archive>(arch)) {
// Load all bitcode files into memory
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
      for (object::Archive::child_iterator AI = archive->child_begin(),
                                           AE = archive->child_end();
           AI != AE; ++AI)
#else
      for (object::Archive::child_iterator AI = archive->begin_children(),
                                           AE = archive->end_children();
           AI != AE; ++AI)
#endif
      {

        StringRef memberName;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
        std::error_code ec;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 8)
        ErrorOr<object::Archive::Child> childOrErr = *AI;
        ec = childOrErr.getError();
        if (ec) {
                errorMsg = ec.message();
                return false;
        }
#else
	object::Archive::child_iterator childOrErr = AI;
#endif
        ErrorOr<StringRef> memberNameErr = childOrErr->getName();
        ec = memberNameErr.getError();
        if (!ec) {
          memberName = memberNameErr.get();
#else
        error_code ec = AI->getName(memberName);

        if (ec == errc::success) {
#endif
          KLEE_DEBUG_WITH_TYPE("klee_linker", dbgs()
                                                  << "Loading archive member "
                                                  << memberName << "\n");
        } else {
          errorMsg = "Archive member does not have a name!\n";
          return false;
        }

#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
        ErrorOr<std::unique_ptr<llvm::object::Binary>> child =
            childOrErr->getAsBinary();
        ec = child.getError();
#else
        OwningPtr<object::Binary> child;
        ec = AI->getAsBinary(child);
#endif
        if (ec) {
// If we can't open as a binary object file its hopefully a bitcode file
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
          ErrorOr<MemoryBufferRef> buff = childOrErr->getMemoryBufferRef();
          ec = buff.getError();
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
          ErrorOr<std::unique_ptr<MemoryBuffer>> buffErr =
              AI->getMemoryBuffer();
          std::unique_ptr<MemoryBuffer> buff = nullptr;
          ec = buffErr.getError();
          if (!ec)
            buff = std::move(buffErr.get());
#else
        OwningPtr<MemoryBuffer> buff;
        ec = AI->getMemoryBuffer(buff);
#endif
          if (ec) {
            errorMsg = "Failed to get MemoryBuffer: " + ec.message();
            return false;
          }

          if (buff) {
            // FIXME: Maybe load bitcode file lazily? Then if we need to link,
            // materialise
            // the module
            SMDiagnostic Err;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
            std::unique_ptr<llvm::Module> module =
                parseIR(buff.get(), Err, context);
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
            std::unique_ptr<llvm::Module> module(
                ParseIR(buff.get(), Err, context));
#else
          std::unique_ptr<llvm::Module> module(
              ParseIR(buff.take(), Err, context));
#endif
            if (!module) {
              klee_error("Loading file %s failed: %s", fileName.c_str(),
                         Err.getMessage().str().c_str());
            }

            modules.push_back(std::move(module));
          } else {
            errorMsg = "Buffer was NULL!";
            return false;
          }

        } else if (child.get()->isObject()) {
          errorMsg = "Object file " + child.get()->getFileName().str() +
                     " in archive is not supported";
          return false;
        } else {
          errorMsg = "Loading archive child with error " + ec.message();
          return false;
        }
      }
    }
    return true;
  }
  if (magic.is_object()) {
    errorMsg = "Loading file " + fileName +
               " Object file as input is currently not supported";
    return false;
  }
  // This might still be an assembly file. Let's try to parse it.
  SMDiagnostic Err;
#if LLVM_VERSION_CODE >= LLVM_VERSION(3, 6)
  std::unique_ptr<llvm::Module> module(parseIR(Buffer, Err, context));
#elif LLVM_VERSION_CODE >= LLVM_VERSION(3, 5)
  std::unique_ptr<llvm::Module> module(ParseIR(Buffer, Err, context));
#else
std::unique_ptr<llvm::Module> module(ParseIR(Buffer.take(), Err, context));
#endif
  if (!module) {
    klee_error("Loading file %s failed: Unrecognized file type.",
               fileName.c_str());
  }
  modules.push_back(std::move(module));
  return true;
}

void klee::checkModule(llvm::Module *m) {
  LegacyLLVMPassManagerTy pm;
  pm.add(createVerifierPass());
  pm.run(*m);
}