Refactoring interface.

Change-Id: I7afcd83408d381dcf4d053ffe66150f567e02545
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index 1540967..adccedc 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -202,6 +202,16 @@
 }
 
 
+int Script::prepareSharedObject(char const *cacheDir,
+                                char const *cacheName,
+                                char const *objPath,
+                                char const *dsoPath,
+                                unsigned long flags) {
+  // TODO: Support cached shared object.
+  return 1;
+}
+
+
 int Script::prepareExecutable(char const *cacheDir,
                               char const *cacheName,
                               unsigned long flags) {
diff --git a/lib/ExecutionEngine/Script.h b/lib/ExecutionEngine/Script.h
index 70df516..e9f7b09 100644
--- a/lib/ExecutionEngine/Script.h
+++ b/lib/ExecutionEngine/Script.h
@@ -53,6 +53,7 @@
     enum ObjectType {
       Unknown,
       Relocatable,
+      SharedObject,
       Executable,
     };
   }
@@ -88,6 +89,12 @@
           objPath.append(".o");
           break;
         }
+
+        case ScriptObject::SharedObject: {
+          objPath.append(".so");
+          break;
+        }
+
         default: {
           assert(false && "Unknown object type!");
         }
@@ -158,6 +165,27 @@
                           char const *cacheName,
                           unsigned long flags);
 
+    /*
+     * Link the given bitcodes in mSourceList to shared object (.so).
+     *
+     * Currently, it requires one to provide the relocatable object files with
+     * given bitcodes to output a shared object.
+     *
+     * The usage of this function is flexible. You can have a relocatable object
+     * compiled before and pass it in objPath to generate shared object. If the
+     * objPath is NULL, we'll invoke prepareRelocatable() to get .o first (if
+     * you haven't done that yet) and then link the output relocatable object
+     * file. The latter case will have libbcc compile with USE_CACHE enabled.
+     *
+     * TODO: Currently, we only support to link the bitcodes in mSourceList[0].
+     *
+     */
+    int prepareSharedObject(char const *cacheDir,
+                            char const *cacheName,
+                            char const *objPath,
+                            char const *dsoPath,
+                            unsigned long flags);
+
     int prepareRelocatable(char const *cacheDir,
                            char const *cacheName,
                            llvm::Reloc::Model RelocModel,
diff --git a/lib/ExecutionEngine/bcc.cpp b/lib/ExecutionEngine/bcc.cpp
index 45ab1ee..6f858fa 100644
--- a/lib/ExecutionEngine/bcc.cpp
+++ b/lib/ExecutionEngine/bcc.cpp
@@ -160,6 +160,18 @@
 }
 
 
+extern "C" int bccPrepareSharedObject(BCCScriptRef script,
+                                      char const *cacheDir,
+                                      char const *cacheName,
+                                      char const *objPath,
+                                      char const *dsoPath,
+                                      unsigned long flags) {
+  BCC_FUNC_LOGGER();
+  return unwrap(script)->prepareSharedObject(cacheDir, cacheName,
+                                             objPath, dsoPath, flags);
+}
+
+
 extern "C" int bccPrepareExecutable(BCCScriptRef script,
                                     char const *cacheDir,
                                     char const *cacheName,