Return an error_code from materializeAllPermanently.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 14 Jan 2014 23:51:27 +0000 (23:51 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 14 Jan 2014 23:51:27 +0000 (23:51 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@199275 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Module.h
lib/Bitcode/Reader/BitcodeReader.cpp
lib/ExecutionEngine/Interpreter/Interpreter.cpp
lib/IR/Module.cpp
lib/LTO/LTOModule.cpp
tools/lli/lli.cpp
tools/llvm-dis/llvm-dis.cpp

index 4bfa9e68aa897f9f02b8b9fec67c592f8bcf1fdd..b965c9ee5650bb398dc369d5629b8a3a426efc1b 100644 (file)
@@ -454,12 +454,10 @@ public:
   /// Make sure all GlobalValues in this Module are fully read.
   error_code materializeAll();
 
-  /// MaterializeAllPermanently - Make sure all GlobalValues in this Module are
-  /// fully read and clear the Materializer.  If the module is corrupt, this
-  /// returns true, fills in the optional string with information about the
-  /// problem, and DOES NOT clear the old Materializer.  If successful, this
-  /// returns false.
-  bool MaterializeAllPermanently(std::string *ErrInfo = 0);
+  /// Make sure all GlobalValues in this Module are fully read and clear the
+  /// Materializer. If the module is corrupt, this DOES NOT clear the old
+  /// Materializer.
+  error_code materializeAllPermanently();
 
 /// @}
 /// @name Direct access to the globals list, functions list, and symbol table
index 81ed803ba04985ad32dc65547438d120fe8e8a62..c36dae892c919c29127596a859110916116a57b8 100644 (file)
@@ -3359,7 +3359,9 @@ Module *llvm::ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
   static_cast<BitcodeReader*>(M->getMaterializer())->setBufferOwned(false);
 
   // Read in the entire module, and destroy the BitcodeReader.
-  if (M->MaterializeAllPermanently(ErrMsg)) {
+  if (error_code EC = M->materializeAllPermanently()) {
+    if (ErrMsg)
+      *ErrMsg = EC.message();
     delete M;
     return 0;
   }
index 9ee9d9456d1d2afca744900eecf6c55d224a90e1..6d4f6f716fc4d06a374e1e8c362f34d54a9a9446 100644 (file)
@@ -34,9 +34,12 @@ extern "C" void LLVMLinkInInterpreter() { }
 ///
 ExecutionEngine *Interpreter::create(Module *M, std::string* ErrStr) {
   // Tell this Module to materialize everything and release the GVMaterializer.
-  if (M->MaterializeAllPermanently(ErrStr))
+  if (error_code EC = M->materializeAllPermanently()) {
+    if (ErrStr)
+      *ErrStr = EC.message();
     // We got an error, just return 0
     return 0;
+  }
 
   return new Interpreter(M);
 }
index 06eea7e388a8b9ef9bd5095b0c304d31dcfacefe..d911c7e2b5bf0b0b161a217eaa7664a53391a496 100644 (file)
@@ -383,14 +383,12 @@ error_code Module::materializeAll() {
   return Materializer->MaterializeModule(this);
 }
 
-bool Module::MaterializeAllPermanently(std::string *ErrInfo) {
-  if (error_code EC = materializeAll()) {
-    if (ErrInfo)
-      *ErrInfo = EC.message();
-    return true;
-  }
+error_code Module::materializeAllPermanently() {
+  if (error_code EC = materializeAll())
+    return EC;
+
   Materializer.reset();
-  return false;
+  return error_code::success();
 }
 
 //===----------------------------------------------------------------------===//
index dcfd59e7526f91c148735e82aa964c636c73058e..79cff1f68fe783001fee103b804bc446778c6daa 100644 (file)
@@ -169,7 +169,7 @@ LTOModule *LTOModule::makeLTOModule(MemoryBuffer *buffer,
 
   TargetMachine *target = march->createTargetMachine(TripleStr, CPU, FeatureStr,
                                                      options);
-  m->MaterializeAllPermanently();
+  m->materializeAllPermanently();
 
   LTOModule *Ret = new LTOModule(m.take(), target);
   if (Ret->parseSymbols(errMsg)) {
index c6db51a2b07e0edd23e69ce5ec37a708faebb38a..8e6669221bf834b95f8bf325fa4aabe3b6dd513b 100644 (file)
@@ -413,11 +413,10 @@ int main(int argc, char **argv, char * const *envp) {
   }
 
   // If not jitting lazily, load the whole bitcode file eagerly too.
-  std::string ErrorMsg;
   if (NoLazyCompilation) {
-    if (Mod->MaterializeAllPermanently(&ErrorMsg)) {
+    if (error_code EC = Mod->materializeAllPermanently()) {
       errs() << argv[0] << ": bitcode didn't read correctly.\n";
-      errs() << "Reason: " << ErrorMsg << "\n";
+      errs() << "Reason: " << EC.message() << "\n";
       exit(1);
     }
   }
@@ -433,6 +432,7 @@ int main(int argc, char **argv, char * const *envp) {
     DebugIRPass->runOnModule(*Mod);
   }
 
+  std::string ErrorMsg;
   EngineBuilder builder(Mod);
   builder.setMArch(MArch);
   builder.setMCPU(MCPU);
index 6d471efcc0f4a15e1883fd1f9b07227f394ddb45..9fb056510c007a188a707880cf23649cebdd5b0e 100644 (file)
@@ -135,8 +135,11 @@ int main(int argc, char **argv) {
       DisplayFilename = InputFilename;
     M.reset(getStreamedBitcodeModule(DisplayFilename, streamer, Context,
                                      &ErrorMessage));
-    if(M.get() != 0 && M->MaterializeAllPermanently(&ErrorMessage)) {
-      M.reset();
+    if(M.get() != 0) {
+      if (error_code EC = M->materializeAllPermanently()) {
+        ErrorMessage = EC.message();
+        M.reset();
+      }
     }
   }