Make sure to initialize the fpm in the ocaml tutorial.
[oota-llvm.git] / lib / Debugger / Debugger.cpp
index 90741afc8e012115f2030b7fc6b3c609d94c53c2..77fd2ac96bea03ecaced4f74cebedccca08da951 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include "llvm/Debugger/Debugger.h"
 #include "llvm/Module.h"
 #include "llvm/ModuleProvider.h"
-#include "llvm/Bytecode/Reader.h"
 #include "llvm/Bitcode/ReaderWriter.h"
 #include "llvm/Debugger/InferiorProcess.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/ADT/StringExtras.h"
+#include <cstdlib>
 #include <memory>
 using namespace llvm;
 
-static bool Bitcode = false;
-
 /// Debugger constructor - Initialize the debugger to its initial, empty, state.
 ///
 Debugger::Debugger() : Environment(0), Program(0), Process(0) {
@@ -48,25 +46,22 @@ std::string Debugger::getProgramPath() const {
 }
 
 static Module *
-getMaterializedModuleProvider(const std::string &Filename) {
-  if (Bitcode) {
-    return ParseBytecodeFile(Filename);
-  } else {
-    std::auto_ptr<MemoryBuffer> Buffer;
-    Buffer.reset(MemoryBuffer::getFileOrSTDIN(&Filename[0], Filename.size()));
-    if (Buffer.get())
-      return ParseBitcodeFile(Buffer.get());
-    return 0;
-  }
+getMaterializedModuleProvider(const std::string &Filename,
+                              LLVMContext& C) {
+  std::auto_ptr<MemoryBuffer> Buffer;
+  Buffer.reset(MemoryBuffer::getFileOrSTDIN(Filename.c_str()));
+  if (Buffer.get())
+    return ParseBitcodeFile(Buffer.get(), C);
+  return 0;
 }
 
 /// loadProgram - If a program is currently loaded, unload it.  Then search
 /// the PATH for the specified program, loading it when found.  If the
 /// specified program cannot be found, an exception is thrown to indicate the
 /// error.
-void Debugger::loadProgram(const std::string &Filename) {
-  if ((Program = getMaterializedModuleProvider(Filename)) ||
-      (Program = getMaterializedModuleProvider(Filename+".bc")))
+void Debugger::loadProgram(const std::string &Filename, LLVMContext& C) {
+  if ((Program = getMaterializedModuleProvider(Filename, C)) ||
+      (Program = getMaterializedModuleProvider(Filename+".bc", C)))
     return;   // Successfully loaded the program.
 
   // Search the program path for the file...
@@ -75,9 +70,9 @@ void Debugger::loadProgram(const std::string &Filename) {
 
     std::string Directory = getToken(Path, ":");
     while (!Directory.empty()) {
-      if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename)) ||
-          (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
-                                                                      + ".bc")))
+      if ((Program = getMaterializedModuleProvider(Directory +"/"+ Filename, C))
+       || (Program = getMaterializedModuleProvider(Directory +"/"+ Filename
+                                                                   + ".bc", C)))
         return;   // Successfully loaded the program.
 
       Directory = getToken(Path, ":");