Refactor SourceInfo into Source.

A Script object is associated with a Source object (HAS-A relation.)

A Source object describes the source code (more specifically, the LLVM
module) that is going to be compiled.

BCCContext contains the context used in a Source object.

BCCContext is now managed by the user not the libbcc itself. That is,
user should supply the context object when they create a Source object.

Change-Id: Icb8980d6f15cf30aa0415e69e3ae585d990dc156
diff --git a/lib/ExecutionEngine/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
index 58a49c5..100f54b 100644
--- a/lib/ExecutionEngine/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -226,27 +226,27 @@
     mRSExecutable(NULL),
     mpSymbolLookupFn(NULL),
     mpSymbolLookupContext(NULL),
-    mModule(NULL),
-    mHasLinked(false) /* Turn off linker */ {
+    mModule(NULL) {
   llvm::remove_fatal_error_handler();
   llvm::install_fatal_error_handler(LLVMErrorHandler, &mError);
   return;
 }
 
-
-int Compiler::linkModule(llvm::Module *moduleWith) {
-  if (llvm::Linker::LinkModules(mModule, moduleWith,
-                                llvm::Linker::PreserveSource,
-                                &mError) != 0) {
-    return hasError();
+int Compiler::readModule(llvm::Module &pModule) {
+  mModule = &pModule;
+  if (pModule.getMaterializer() != NULL) {
+    // A module with non-null materializer means that it is a lazy-load module.
+    // Materialize it now via invoking MaterializeAllPermanently(). This
+    // function returns false when the materialization is successful.
+    if (pModule.MaterializeAllPermanently(&mError)) {
+      setError("Failed to materialize the module `" +
+               pModule.getModuleIdentifier() + "'! (" + mError + ")");
+      mModule = NULL;
+    }
   }
-
-  // Everything for linking should be settled down here with no error occurs
-  mHasLinked = true;
   return hasError();
 }
 
-
 int Compiler::compile(const CompilerOption &option) {
   llvm::Target const *Target = NULL;
   llvm::TargetData *TD = NULL;
@@ -390,7 +390,7 @@
   runInternalPasses(ForEachNameList, ForEachSigList);
 
   // Perform link-time optimization if we have multiple modules
-  if (mHasLinked) {
+  if (option.RunLTO) {
     runLTO(new llvm::TargetData(*TD), ExportSymbols, CodeGenOptLevel);
   }