-// LoadFile - Read the specified bitcode file in and return it. This routine
-// searches the link path for the specified file to try to find it...
-//
-static inline std::auto_ptr<Module> LoadFile(const std::string &FN,
- LLVMContext& Context) {
- sys::Path Filename;
- if (!Filename.set(FN)) {
- errs() << "Invalid file name: '" << FN << "'\n";
- return std::auto_ptr<Module>();
- }
-
- std::string ErrorMessage;
- if (Filename.exists()) {
- if (Verbose) errs() << "Loading '" << Filename.c_str() << "'\n";
- Module* Result = 0;
-
- const std::string &FNStr = Filename.str();
- if (MemoryBuffer *Buffer = MemoryBuffer::getFileOrSTDIN(FNStr,
- &ErrorMessage)) {
- Result = ParseBitcodeFile(Buffer, Context, &ErrorMessage);
- delete Buffer;
- }
- if (Result) return std::auto_ptr<Module>(Result); // Load successful!
-
- if (Verbose) {
- errs() << "Error opening bitcode file: '" << Filename.c_str() << "'";
- if (ErrorMessage.size()) errs() << ": " << ErrorMessage;
- errs() << "\n";
- }
- } else {
- errs() << "Bitcode file: '" << Filename.c_str() << "' does not exist.\n";
- }