Revert "Make libbcc public."

This reverts commit 80232dd16c0affb2afae01cde6c94abf23ac1ba8.
diff --git a/lib/Core/Android.mk b/lib/Disassembler/Android.mk
similarity index 74%
rename from lib/Core/Android.mk
rename to lib/Disassembler/Android.mk
index 4448364..3886b33 100644
--- a/lib/Core/Android.mk
+++ b/lib/Disassembler/Android.mk
@@ -1,5 +1,5 @@
 #
-# Copyright (C) 2012 The Android Open Source Project
+# Copyright (C) 2011 The Android Open Source Project
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -17,29 +17,27 @@
 
 LOCAL_PATH := $(call my-dir)
 
-#=====================================================================
-# Common: libbccCore
-#=====================================================================
-
-libbcc_core_SRC_FILES := \
-  BCCContext.cpp \
-  BCCContextImpl.cpp \
-  Compiler.cpp \
-  Script.cpp \
-  Source.cpp \
-  bcc.cpp
+ifeq ($(libbcc_USE_DISASSEMBLER),1)
 
 #=====================================================================
-# Device Static Library: libbccCore
+# Common: libbccDisassembler
+#=====================================================================
+
+libbcc_disassembler_SRC_FILES := \
+  Disassembler.cpp
+
+
+#=====================================================================
+# Device Static Library: libbccDisassembler
 #=====================================================================
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := libbccCore
+LOCAL_MODULE := libbccDisassembler
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
-LOCAL_SRC_FILES := $(libbcc_core_SRC_FILES)
+LOCAL_SRC_FILES := $(libbcc_disassembler_SRC_FILES)
 
 include $(LIBBCC_DEVICE_BUILD_MK)
 include $(LIBBCC_GEN_CONFIG_MK)
@@ -48,18 +46,21 @@
 
 
 #=====================================================================
-# Host Static Library: libbccCore
+# Host Static Library: libbccDisassembler
 #=====================================================================
 
 include $(CLEAR_VARS)
 
-LOCAL_MODULE := libbccCore
+LOCAL_MODULE := libbccDisassembler
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
+LOCAL_IS_HOST_MODULE := true
 
-LOCAL_SRC_FILES := $(libbcc_core_SRC_FILES)
+LOCAL_SRC_FILES := $(libbcc_disassembler_SRC_FILES)
 
 include $(LIBBCC_HOST_BUILD_MK)
 include $(LIBBCC_GEN_CONFIG_MK)
 include $(LLVM_HOST_BUILD_MK)
 include $(BUILD_HOST_STATIC_LIBRARY)
+
+endif # $(libbcc_USE_DISASSEMBLER)
diff --git a/lib/Support/Disassembler.cpp b/lib/Disassembler/Disassembler.cpp
similarity index 84%
rename from lib/Support/Disassembler.cpp
rename to lib/Disassembler/Disassembler.cpp
index b22ff81..d7552cb 100644
--- a/lib/Support/Disassembler.cpp
+++ b/lib/Disassembler/Disassembler.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2011-2012, The Android Open Source Project
+ * Copyright 2011, The Android Open Source Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,26 +14,27 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/Disassembler.h"
+#include "Disassembler.h"
 
-#include <llvm/LLVMContext.h>
+#include "Config.h"
 
-#include <llvm/MC/MCAsmInfo.h>
-#include <llvm/MC/MCDisassembler.h>
-#include <llvm/MC/MCInst.h>
-#include <llvm/MC/MCInstPrinter.h>
+#include "DebugHelper.h"
 
-#include <llvm/Support/MemoryObject.h>
-#include <llvm/Support/TargetRegistry.h>
-#include <llvm/Support/TargetSelect.h>
-#include <llvm/Support/raw_ostream.h>
+#include "llvm/MC/MCAsmInfo.h"
+#include "llvm/MC/MCDisassembler.h"
+#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCInstPrinter.h"
 
-#include <llvm/Target/TargetData.h>
-#include <llvm/Target/TargetMachine.h>
-#include <llvm/Target/TargetOptions.h>
+#include "llvm/Support/MemoryObject.h"
+#include "llvm/Support/raw_ostream.h"
 
-#include "bcc/Config/Config.h"
-#include "bcc/Support/DebugHelper.h"
+#include "llvm/Target/TargetData.h"
+#include "llvm/Target/TargetMachine.h"
+#include "llvm/Target/TargetOptions.h"
+#include "llvm/Support/TargetRegistry.h"
+#include "llvm/Support/TargetSelect.h"
+
+#include "llvm/LLVMContext.h"
 
 #if USE_DISASSEMBLER
 
diff --git a/lib/Disassembler/Disassembler.h b/lib/Disassembler/Disassembler.h
new file mode 100644
index 0000000..d0d924c
--- /dev/null
+++ b/lib/Disassembler/Disassembler.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2011, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_DISASSEMBLER_H
+#define BCC_DISASSEMBLER_H
+
+#include "Config.h"
+
+#if USE_DISASSEMBLER
+
+#include <string>
+
+namespace llvm {
+  class Target;
+  class TargetMachine;
+}
+
+namespace bcc {
+
+  void InitializeDisassembler();
+
+  void Disassemble(char const *OutputFileName,
+                   llvm::Target const *Target,
+                   llvm::TargetMachine *TM,
+                   std::string const &Name,
+                   unsigned char const *Func,
+                   size_t FuncSize);
+
+} // namespace bcc
+
+#endif // USE_DISASSEMBLER
+
+#endif // BCC_DISASSEMBLER_H
diff --git a/lib/ExecutionEngine/Android.mk b/lib/ExecutionEngine/Android.mk
index d5a4573..f3b2c3d 100644
--- a/lib/ExecutionEngine/Android.mk
+++ b/lib/ExecutionEngine/Android.mk
@@ -22,14 +22,36 @@
 #=====================================================================
 
 libbcc_executionengine_SRC_FILES := \
-  BCCRuntimeStub.c \
+  BCCContext.cpp \
+  BCCContextImpl.cpp \
   BCCRuntimeSymbolResolver.cpp \
+  Compiler.cpp \
+  CompilerConfig.cpp \
   ELFObjectLoaderImpl.cpp \
+  FileBase.cpp \
   GDBJIT.cpp \
   GDBJITRegistrar.cpp \
+  Initialization.cpp \
+  InputFile.cpp \
   ObjectLoader.cpp \
+  OutputFile.cpp \
+  RSCompiler.cpp \
+  RSCompilerDriver.cpp \
+  RSExecutable.cpp \
+  RSForEachExpand.cpp \
+  RSInfo.cpp \
+  RSInfoExtractor.cpp \
+  RSInfoReader.cpp \
+  RSInfoWriter.cpp \
+  RSScript.cpp \
+  BCCRuntimeStub.c \
+  Script.cpp \
+  Sha1Helper.cpp \
+  Source.cpp \
   SymbolResolverProxy.cpp \
-  SymbolResolvers.cpp
+  SymbolResolvers.cpp \
+  TargetCompilerConfigs.cpp \
+  bcc.cpp
 
 #=====================================================================
 # Device Static Library: libbccExecutionEngine
@@ -42,11 +64,11 @@
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
 LOCAL_C_INCLUDES := \
-  $(LIBBCC_ROOT_PATH) \
   $(RSLOADER_ROOT_PATH) \
   $(RSLOADER_ROOT_PATH)/include
 
 LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
+LOCAL_SHARED_LIBRARIES := libbcinfo
 
 include $(LIBBCC_DEVICE_BUILD_MK)
 include $(LIBBCC_GEN_CONFIG_MK)
@@ -65,11 +87,11 @@
 LOCAL_MODULE_CLASS := STATIC_LIBRARIES
 
 LOCAL_C_INCLUDES := \
-  $(LIBBCC_ROOT_PATH) \
   $(RSLOADER_ROOT_PATH) \
   $(RSLOADER_ROOT_PATH)/include
 
 LOCAL_SRC_FILES := $(libbcc_executionengine_SRC_FILES)
+LOCAL_SHARED_LIBRARIES := libbcinfo
 
 include $(LIBBCC_HOST_BUILD_MK)
 include $(LIBBCC_GEN_CONFIG_MK)
diff --git a/lib/Core/BCCContext.cpp b/lib/ExecutionEngine/BCCContext.cpp
similarity index 94%
rename from lib/Core/BCCContext.cpp
rename to lib/ExecutionEngine/BCCContext.cpp
index e2284de..62995ed 100644
--- a/lib/Core/BCCContext.cpp
+++ b/lib/ExecutionEngine/BCCContext.cpp
@@ -14,14 +14,13 @@
  * limitations under the License.
  */
 
-#include "bcc/BCCContext.h"
+#include "BCCContext.h"
 
 #include <new>
 
-#include "bcc/Source.h"
-#include "bcc/Support/DebugHelper.h"
-
 #include "BCCContextImpl.h"
+#include "DebugHelper.h"
+#include "Source.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/BCCContext.h b/lib/ExecutionEngine/BCCContext.h
new file mode 100644
index 0000000..56962fe
--- /dev/null
+++ b/lib/ExecutionEngine/BCCContext.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_CONTEXT_H
+#define BCC_EXECUTION_ENGINE_CONTEXT_H
+
+namespace llvm {
+  class LLVMContext;
+}
+
+namespace bcc {
+
+class BCCContextImpl;
+class Source;
+
+/*
+ * class BCCContext manages the global data across the libbcc infrastructure.
+ */
+class BCCContext {
+public:
+  BCCContextImpl *const mImpl;
+
+  BCCContext();
+  ~BCCContext();
+
+  llvm::LLVMContext &getLLVMContext();
+  const llvm::LLVMContext &getLLVMContext() const;
+
+  void addSource(Source &pSource);
+  void removeSource(Source &pSource);
+
+  // Global BCCContext
+  static BCCContext *GetOrCreateGlobalContext();
+  static void DestroyGlobalContext();
+};
+
+} // namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_CONTEXT_H
diff --git a/lib/Core/BCCContextImpl.cpp b/lib/ExecutionEngine/BCCContextImpl.cpp
similarity index 97%
rename from lib/Core/BCCContextImpl.cpp
rename to lib/ExecutionEngine/BCCContextImpl.cpp
index 0a25764..ec865fa 100644
--- a/lib/Core/BCCContextImpl.cpp
+++ b/lib/ExecutionEngine/BCCContextImpl.cpp
@@ -20,7 +20,7 @@
 
 #include <llvm/ADT/STLExtras.h>
 
-#include "bcc/Source.h"
+#include "Source.h"
 
 using namespace bcc;
 
diff --git a/lib/Core/BCCContextImpl.h b/lib/ExecutionEngine/BCCContextImpl.h
similarity index 89%
rename from lib/Core/BCCContextImpl.h
rename to lib/ExecutionEngine/BCCContextImpl.h
index bc397f9..446eb36 100644
--- a/lib/Core/BCCContextImpl.h
+++ b/lib/ExecutionEngine/BCCContextImpl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef BCC_CORE_CONTEXT_IMPL_H
-#define BCC_CORE_CONTEXT_IMPL_H
+#ifndef BCC_EXECUTION_ENGINE_CONTEXT_IMPL_H
+#define BCC_EXECUTION_ENGINE_CONTEXT_IMPL_H
 
 #include <llvm/ADT/SmallPtrSet.h>
 #include <llvm/LLVMContext.h>
@@ -42,4 +42,4 @@
 
 } // namespace bcc
 
-#endif  // BCC_CORE_CONTEXT_IMPL_H
+#endif  // BCC_EXECUTION_ENGINE_CONTEXT_IMPL_H
diff --git a/lib/ExecutionEngine/BCCRuntimeSymbolResolver.cpp b/lib/ExecutionEngine/BCCRuntimeSymbolResolver.cpp
index ddc06fc..1059d85 100644
--- a/lib/ExecutionEngine/BCCRuntimeSymbolResolver.cpp
+++ b/lib/ExecutionEngine/BCCRuntimeSymbolResolver.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/ExecutionEngine/BCCRuntimeSymbolResolver.h"
+#include "BCCRuntimeSymbolResolver.h"
 
 // int_lib.h included by BCCRuntimeStub.h has the following line:
 //
diff --git a/lib/ExecutionEngine/BCCRuntimeSymbolResolver.h b/lib/ExecutionEngine/BCCRuntimeSymbolResolver.h
new file mode 100644
index 0000000..e48a4d8
--- /dev/null
+++ b/lib/ExecutionEngine/BCCRuntimeSymbolResolver.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_BCC_RUNTIME_SYMBOL_RESOLVERS_H
+#define BCC_EXECUTION_ENGINE_BCC_RUNTIME_SYMBOL_RESOLVERS_H
+
+#include "SymbolResolvers.h"
+
+namespace bcc {
+
+class BCCRuntimeSymbolResolver :
+  public ArraySymbolResolver<BCCRuntimeSymbolResolver> {
+  typedef ArraySymbolResolver<BCCRuntimeSymbolResolver> super;
+public:
+  // SymbolArray and NumSymbols are required to be define in the
+  // subclass of ArraySymbolResolver.
+  static const SymbolMap SymbolArray[];
+  static const size_t NumSymbols;
+
+  BCCRuntimeSymbolResolver() : super(/* pSorted */true) { }
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_BCC_RUNTIME_SYMBOL_RESOLVERS_H
diff --git a/lib/Core/Compiler.cpp b/lib/ExecutionEngine/Compiler.cpp
similarity index 98%
rename from lib/Core/Compiler.cpp
rename to lib/ExecutionEngine/Compiler.cpp
index 97b18bc..2348d56 100644
--- a/lib/Core/Compiler.cpp
+++ b/lib/ExecutionEngine/Compiler.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/Compiler.h"
+#include "Compiler.h"
 
 #include <llvm/Analysis/Passes.h>
 #include <llvm/CodeGen/RegAllocRegistry.h>
@@ -27,11 +27,11 @@
 #include <llvm/Transforms/IPO.h>
 #include <llvm/Transforms/Scalar.h>
 
-#include "bcc/Script.h"
-#include "bcc/Source.h"
-#include "bcc/Support/CompilerConfig.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/OutputFile.h"
+#include "CompilerConfig.h"
+#include "DebugHelper.h"
+#include "OutputFile.h"
+#include "Script.h"
+#include "Source.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/Compiler.h b/lib/ExecutionEngine/Compiler.h
new file mode 100644
index 0000000..5e37925
--- /dev/null
+++ b/lib/ExecutionEngine/Compiler.h
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2010-2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_COMPILER_H
+#define BCC_EXECUTION_ENGINE_COMPILER_H
+
+namespace llvm {
+
+class raw_ostream;
+class PassManager;
+class TargetData;
+class TargetMachine;
+
+} // end namespace llvm
+
+namespace bcc {
+
+class CompilerConfig;
+class OutputFile;
+class Script;
+
+//===----------------------------------------------------------------------===//
+// Design of Compiler
+//===----------------------------------------------------------------------===//
+// 1. A compiler instance can be constructed provided an "initial config."
+// 2. A compiler can later be re-configured using config().
+// 3. Once config() is invoked, it'll re-create TargetMachine instance (i.e.,
+//    mTarget) according to the configuration supplied. TargetMachine instance
+//    is *shared* across the different calls to compile() before the next call
+//    to config().
+// 4. Once a compiler instance is created, you can use the compile() service
+//    to compile the file over and over again. Each call uses TargetMachine
+//    instance to construct the compilation passes.
+class Compiler {
+public:
+  enum ErrorCode {
+    kSuccess,
+
+    kInvalidConfigNoTarget,
+    kErrCreateTargetMachine,
+    kErrSwitchTargetMachine,
+    kErrNoTargetMachine,
+    kErrTargetDataNoMemory,
+    kErrMaterialization,
+    kErrInvalidOutputFileState,
+    kErrPrepareOutput,
+    kPrepareCodeGenPass,
+
+    kErrHookBeforeAddLTOPasses,
+    kErrHookAfterAddLTOPasses,
+    kErrHookBeforeExecuteLTOPasses,
+    kErrHookAfterExecuteLTOPasses,
+
+    kErrHookBeforeAddCodeGenPasses,
+    kErrHookAfterAddCodeGenPasses,
+    kErrHookBeforeExecuteCodeGenPasses,
+    kErrHookAfterExecuteCodeGenPasses,
+
+    kMaxErrorCode,
+  };
+
+  static const char *GetErrorString(enum ErrorCode pErrCode);
+
+private:
+  llvm::TargetMachine *mTarget;
+  // LTO is enabled by default.
+  bool mEnableLTO;
+
+  enum ErrorCode runLTO(Script &pScript);
+  enum ErrorCode runCodeGen(Script &pScript, llvm::raw_ostream &pResult);
+
+public:
+  Compiler();
+  Compiler(const CompilerConfig &pConfig);
+
+  enum ErrorCode config(const CompilerConfig &pConfig);
+
+  // Compile a script and output the result to a LLVM stream.
+  enum ErrorCode compile(Script &pScript, llvm::raw_ostream &pResult);
+
+  // Compile a script and output the result to a file.
+  enum ErrorCode compile(Script &pScript, OutputFile &pResult);
+
+  void enableLTO(bool pEnable = true)
+  { mEnableLTO = pEnable; }
+
+  virtual ~Compiler();
+
+protected:
+  //===--------------------------------------------------------------------===//
+  // Plugin callbacks for sub-class.
+  //===--------------------------------------------------------------------===//
+  // Called before adding first pass to code-generation passes.
+  virtual bool beforeAddLTOPasses(Script &pScript, llvm::PassManager &pPM)
+  { return true; }
+
+  // Called after adding last pass to code-generation passes.
+  virtual bool afterAddLTOPasses(Script &pScript, llvm::PassManager &pPM)
+  { return true; }
+
+  // Called before executing code-generation passes.
+  virtual bool beforeExecuteLTOPasses(Script &pScript,
+                                          llvm::PassManager &pPM)
+  { return true; }
+
+  // Called after executing code-generation passes.
+  virtual bool afterExecuteLTOPasses(Script &pScript)
+  { return true; }
+
+  // Called before adding first pass to code-generation passes.
+  virtual bool beforeAddCodeGenPasses(Script &pScript, llvm::PassManager &pPM)
+  { return true; }
+
+  // Called after adding last pass to code-generation passes.
+  virtual bool afterAddCodeGenPasses(Script &pScript, llvm::PassManager &pPM)
+  { return true; }
+
+  // Called before executing code-generation passes.
+  virtual bool beforeExecuteCodeGenPasses(Script &pScript,
+                                          llvm::PassManager &pPM)
+  { return true; }
+
+  // Called after executing code-generation passes.
+  virtual bool afterExecuteCodeGenPasses(Script &pScript)
+  { return true; }
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_COMPILER_H
diff --git a/lib/Support/CompilerConfig.cpp b/lib/ExecutionEngine/CompilerConfig.cpp
similarity index 96%
rename from lib/Support/CompilerConfig.cpp
rename to lib/ExecutionEngine/CompilerConfig.cpp
index f96c8a9..faaaa97 100644
--- a/lib/Support/CompilerConfig.cpp
+++ b/lib/ExecutionEngine/CompilerConfig.cpp
@@ -14,14 +14,14 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/CompilerConfig.h"
+#include "CompilerConfig.h"
 
 #include <llvm/CodeGen/SchedulerRegistry.h>
 #include <llvm/MC/SubtargetFeature.h>
 #include <llvm/Support/TargetRegistry.h>
 
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/TargetCompilerConfigs.h"
+#include "DebugHelper.h"
+#include "TargetCompilerConfigs.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/CompilerConfig.h b/lib/ExecutionEngine/CompilerConfig.h
new file mode 100644
index 0000000..d83086a
--- /dev/null
+++ b/lib/ExecutionEngine/CompilerConfig.h
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_COMPILER_CONFIG_H
+#define BCC_EXECUTION_ENGINE_COMPILER_CONFIG_H
+
+#include <string>
+#include <vector>
+
+#include <llvm/ADT/Triple.h>
+#include <llvm/Support/CodeGen.h>
+#include <llvm/Target/TargetOptions.h>
+
+namespace llvm {
+
+class Target;
+
+} // end namespace llvm
+
+namespace bcc {
+
+class CompilerConfig {
+private:
+  //===--------------------------------------------------------------------===//
+  // Available Configurations
+  //===--------------------------------------------------------------------===//
+  std::string mTriple;
+
+  // Optional. If given, the name of the target CPU to generate code for.
+  std::string mCPU;
+
+  llvm::TargetOptions mTargetOpts;
+
+  llvm::CodeModel::Model mCodeModel;
+
+  llvm::CodeGenOpt::Level mOptLevel;
+
+  llvm::Reloc::Model mRelocModel;
+
+  // The list of target specific features to enable or disable -- this should
+  // be a list of strings starting with '+' (enable) or '-' (disable).
+  std::string mFeatureString;
+
+private:
+  //===--------------------------------------------------------------------===//
+  // These are generated by CompilerConfig during initialize().
+  //===--------------------------------------------------------------------===//
+  const llvm::Target *mTarget;
+  bool initializeTarget();
+
+  llvm::Triple::ArchType mArchType;
+  void initializeArch();
+
+public:
+  //===--------------------------------------------------------------------===//
+  // Getters
+  //===--------------------------------------------------------------------===//
+  inline const std::string &getTriple() const
+  { return mTriple; }
+
+  inline const std::string &getCPU() const
+  { return mCPU; }
+  inline void setCPU(const std::string &pCPU)
+  { mCPU = pCPU; }
+
+  inline const llvm::TargetOptions &getTargetOptions() const
+  { return mTargetOpts; }
+  inline llvm::TargetOptions &getTargetOptions()
+  { return mTargetOpts; }
+
+  inline llvm::CodeModel::Model getCodeModel() const
+  { return mCodeModel; }
+  inline void setCodeModel(llvm::CodeModel::Model pCodeMode)
+  { mCodeModel = pCodeMode; }
+
+  inline llvm::CodeGenOpt::Level getOptimizationLevel() const
+  { return mOptLevel; }
+  inline void setOptimizationLevel(llvm::CodeGenOpt::Level pOptLvl)
+  { mOptLevel = pOptLvl; }
+
+  inline llvm::Reloc::Model getRelocationModel() const
+  { return mRelocModel; }
+  inline void setRelocationModel(llvm::Reloc::Model pRelocModel)
+  { mRelocModel = pRelocModel; }
+
+  inline const llvm::Target *getTarget() const
+  { return mTarget; }
+
+  inline llvm::Triple::ArchType getArchType() const
+  { return mArchType; }
+
+  inline const std::string &getFeatureString() const
+  { return mFeatureString; }
+  void setFeatureString(const std::vector<std::string> &pAttrs);
+
+public:
+  CompilerConfig(const std::string &pTriple);
+
+  virtual ~CompilerConfig() { }
+};
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_COMPILER_CONFIG_H
diff --git a/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp b/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
index 82eac5f..01f613e 100644
--- a/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
+++ b/lib/ExecutionEngine/ELFObjectLoaderImpl.cpp
@@ -24,8 +24,8 @@
 #include "ELFSymbol.h"
 #include "utils/serialize.h"
 
-#include "bcc/ExecutionEngine/SymbolResolverInterface.h"
-#include "bcc/Support/DebugHelper.h"
+#include "DebugHelper.h"
+#include "SymbolResolverInterface.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/File.h b/lib/ExecutionEngine/File.h
new file mode 100644
index 0000000..4b7ad4d
--- /dev/null
+++ b/lib/ExecutionEngine/File.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_FILE_H
+#define BCC_EXECUTION_ENGINE_FILE_H
+
+#include "FileBase.h"
+
+namespace bcc {
+
+template<enum FileBase::OpenModeEnum OpenMode>
+struct FileAttribute {
+  // The flags to the 2nd argument in ::open().
+  enum { kOpenFlags };
+
+  // Default value of LockMode.
+  enum { kDefaultLockMode };
+};
+
+// FileAttribute for accessing read-only file
+template<>
+struct FileAttribute<FileBase::kReadMode> {
+  enum { kOpenFlags       = O_RDONLY };
+  enum { kDefaultLockMode = FileBase::kReadLock };
+};
+
+// FileAttribute for accessing writable file
+template<>
+struct FileAttribute<FileBase::kWriteMode> {
+  enum { kOpenFlags       = O_RDWR | O_CREAT | O_TRUNC };
+  enum { kDefaultLockMode = FileBase::kWriteLock };
+};
+
+template<enum FileBase::OpenModeEnum OpenMode>
+class File : public FileBase {
+public:
+  File(const std::string &pFilename, unsigned pFlags)
+    : FileBase(pFilename, FileAttribute<OpenMode>::kOpenFlags, pFlags) { }
+
+  inline bool lock(enum LockModeEnum pMode = static_cast<enum LockModeEnum>(
+                      FileAttribute<OpenMode>::kDefaultLockMode),
+                   bool pNonblocking = true,
+                   unsigned pMaxRetry = FileBase::kDefaultMaxRetryLock,
+                   useconds_t pRetryInterval =
+                      FileBase::kDefaultRetryLockInterval) {
+    return FileBase::lock(pMode, pNonblocking, pMaxRetry, pRetryInterval);
+  }
+
+  inline android::FileMap *createMap(off_t pOffset, size_t pLength,
+                                     bool pIsReadOnly =
+                                        (OpenMode == FileBase::kReadMode)) {
+    return FileBase::createMap(pOffset, pLength, pIsReadOnly);
+  }
+};
+
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_FILE_H
diff --git a/lib/Support/FileBase.cpp b/lib/ExecutionEngine/FileBase.cpp
similarity index 99%
rename from lib/Support/FileBase.cpp
rename to lib/ExecutionEngine/FileBase.cpp
index 7b6a7c3..379406d 100644
--- a/lib/Support/FileBase.cpp
+++ b/lib/ExecutionEngine/FileBase.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/FileBase.h"
+#include "FileBase.h"
 
 #include <sys/file.h>
 #include <sys/stat.h>
diff --git a/lib/ExecutionEngine/FileBase.h b/lib/ExecutionEngine/FileBase.h
new file mode 100644
index 0000000..62d6504
--- /dev/null
+++ b/lib/ExecutionEngine/FileBase.h
@@ -0,0 +1,149 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_FILE_BASE_H
+#define BCC_EXECUTION_ENGINE_FILE_BASE_H
+
+#include <fcntl.h>
+
+#include <string>
+
+#include <llvm/Support/system_error.h>
+
+namespace android {
+  class FileMap;
+}
+
+namespace bcc {
+
+class FileBase {
+public:
+  enum OpenModeEnum {
+    kReadMode       = 1 << 0,
+    kWriteMode      = 1 << 1,
+    kReadWriteMode  = (kReadMode | kWriteMode),
+  };
+
+  enum FlagEnum {
+    // The openning file is a binary file.
+    kBinary = 1 << 0,
+  };
+
+  enum LockModeEnum {
+    // The shared resource behind the Stream locked in ReadLock mode can be
+    // locked by other processes at the same time.
+    kReadLock,
+
+    // The shared resource behind the Stream locked in WriteLock mode can only
+    // be locked by one process. It's exclusive. That is, the shared resource
+    // cannot have both ReadLock and WriteLock simultaneously.
+    kWriteLock
+  };
+
+  // Default configuration to the lock().
+  enum {
+    kDefaultMaxRetryLock = 4,
+    kDefaultRetryLockInterval = 200000UL,
+  };
+
+protected:
+  // Grant direct access of the internal file descriptor to the sub-class and
+  // error message such that they can implement their own I/O functionality.
+  int mFD;
+
+  llvm::error_code mError;
+
+private:
+  std::string mName;
+
+  // The 2nd argument to the POSIX open().
+  unsigned mOpenFlags;
+
+  // True true if we should call unlock() in destructor.
+  bool mShouldUnlock;
+
+  // Open mName with flag mOpenFlags (using POSIX open().)
+  bool open();
+
+  // Return true if mFD is the corresponded file descriptor to the file named
+  // mName on the filesystem. This check may returns failed, for example,
+  // someone re-create the file with the same name after we openning the file.
+  bool checkFileIntegrity();
+
+  inline bool reopen() {
+    // Don't need to check the object state since this is a private method.
+    close();
+    return open();
+  }
+
+private:
+  FileBase(FileBase &); // Do not implement.
+  void operator=(const FileBase &); // Do not implement.
+
+protected:
+  // pOpenFlags is the 2nd argument to the POSIX open(). pFlags are the flags to
+  // FileBase. It's a bit set composed by the value defined in
+  // FileBase::FlagEnum.
+  FileBase(const std::string &pFilename, unsigned pOpenFlags, unsigned pFlags);
+
+  void detectError();
+
+public:
+  // Lock the file descriptor in given pMode. If pNonblocking is true, the lock
+  // request issued will return immediately when the shared resource is locked.
+  // In this case, it retries pMaxRetry times, each wait pRetryInterval (in
+  // usecs) before the previous retry getting done.
+  //
+  // Only file is allowed to use this API.
+  bool lock(enum LockModeEnum pMode, bool pNonblocking = true,
+            unsigned pMaxRetry = kDefaultMaxRetryLock,
+            useconds_t pRetryInterval = kDefaultRetryLockInterval);
+
+  void unlock();
+
+  // Map the file content to the memory.
+  //
+  // One who gets non-null android::FileMap returned from this API is resposible
+  // for destroying it after the use.
+  android::FileMap *createMap(off_t pOffset, size_t pLength, bool pIsReadOnly);
+
+  size_t getSize();
+
+  off_t seek(off_t pOffset);
+  off_t tell();
+
+  inline bool hasError() const
+  { return (mError.value() != llvm::errc::success); }
+
+  inline const llvm::error_code &getError() const
+  { return mError; }
+
+  // The return value of llvm::error_code::message() is obtained upon the call
+  // and is passed by value (that is, it's not a member of llvm::error_code.)
+  inline std::string getErrorMessage() const
+  { return mError.message(); }
+
+  inline const std::string &getName() const
+  { return mName; }
+
+  void close();
+
+  virtual ~FileBase();
+};
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_FILE_BASE_H
diff --git a/lib/ExecutionEngine/FileMutex.h b/lib/ExecutionEngine/FileMutex.h
new file mode 100644
index 0000000..85c0e84
--- /dev/null
+++ b/lib/ExecutionEngine/FileMutex.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_FILE_MUTEX_H
+#define BCC_EXECUTION_ENGINE_FILE_MUTEX_H
+
+#include <string>
+
+#include "FileBase.h"
+
+namespace bcc {
+
+template<enum FileBase::LockModeEnum LockMode>
+class FileMutex : public FileBase {
+public:
+  FileMutex(const std::string &pFileToLock)
+    : FileBase(pFileToLock + ".lock", O_RDONLY | O_CREAT, 0) { }
+
+  // Provide a lock() interface filled with default configuration.
+  inline bool lock(bool pNonblocking = true,
+                   unsigned pMaxRetry = FileBase::kDefaultMaxRetryLock,
+                   useconds_t pRetryInterval =
+                       FileBase::kDefaultRetryLockInterval) {
+    return FileBase::lock(LockMode, pNonblocking, pMaxRetry, pRetryInterval);
+  }
+};
+
+} // namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_FILE_MUTEX_H
diff --git a/lib/ExecutionEngine/GDBJIT.cpp b/lib/ExecutionEngine/GDBJIT.cpp
index 29944dd..4038098 100644
--- a/lib/ExecutionEngine/GDBJIT.cpp
+++ b/lib/ExecutionEngine/GDBJIT.cpp
@@ -29,7 +29,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include <llvm/Support/Compiler.h>
+#include "llvm/Support/Compiler.h"
 
 // This interface must be kept in sync with gdb/gdb/jit.h .
 extern "C" {
diff --git a/lib/ExecutionEngine/GDBJIT.h b/lib/ExecutionEngine/GDBJIT.h
new file mode 100644
index 0000000..442b666
--- /dev/null
+++ b/lib/ExecutionEngine/GDBJIT.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This file contains portions derived from LLVM, with the original copyright
+// header below:
+//===-------------- GDBJIT.h - Register debug symbols for JIT -------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file defines the data structures used by JIT engines to register object
+// files (ideally containing debug info) with GDB.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef BCC_EXECUTION_ENGINE_GDB_JIT_H
+#define BCC_EXECUTION_ENGINE_GDB_JIT_H
+
+#include "llvm/Support/DataTypes.h"
+#include "llvm/Support/Compiler.h"
+
+// This must be kept in sync with gdb/gdb/jit.h .
+extern "C" {
+
+  typedef enum {
+    JIT_NOACTION = 0,
+    JIT_REGISTER_FN,
+    JIT_UNREGISTER_FN
+  } jit_actions_t;
+
+  struct jit_code_entry {
+    struct jit_code_entry *next_entry;
+    struct jit_code_entry *prev_entry;
+    const char *symfile_addr;
+    uint64_t symfile_size;
+  };
+
+  struct jit_descriptor {
+    uint32_t version;
+    // This should be jit_actions_t, but we want to be specific about the
+    // bit-width.
+    uint32_t action_flag;
+    struct jit_code_entry *relevant_entry;
+    struct jit_code_entry *first_entry;
+  };
+
+  // GDB 7.0+ puts a (silent) breakpoint in this function.
+  LLVM_ATTRIBUTE_NOINLINE void __jit_debug_register_code();
+
+}
+
+#endif // BCC_EXECUTION_ENGINE_GDB_JIT_H
diff --git a/lib/ExecutionEngine/GDBJITRegistrar.cpp b/lib/ExecutionEngine/GDBJITRegistrar.cpp
index 68d6833..5d8428a 100644
--- a/lib/ExecutionEngine/GDBJITRegistrar.cpp
+++ b/lib/ExecutionEngine/GDBJITRegistrar.cpp
@@ -30,15 +30,13 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "bcc/ExecutionEngine/GDBJITRegistrar.h"
-
-#include <llvm/ADT/DenseMap.h>
-#include <llvm/Support/ErrorHandling.h>
-#include <llvm/Support/Memory.h>
-#include <llvm/Support/Mutex.h>
-#include <llvm/Support/MutexGuard.h>
-
-#include "bcc/ExecutionEngine/GDBJIT.h"
+#include "GDBJITRegistrar.h"
+#include "llvm/ADT/DenseMap.h"
+#include "GDBJIT.h"
+#include "llvm/Support/Memory.h"
+#include "llvm/Support/MutexGuard.h"
+#include "llvm/Support/Mutex.h"
+#include "llvm/Support/ErrorHandling.h"
 
 #include <fstream>
 
diff --git a/lib/ExecutionEngine/GDBJITRegistrar.h b/lib/ExecutionEngine/GDBJITRegistrar.h
new file mode 100644
index 0000000..debf503
--- /dev/null
+++ b/lib/ExecutionEngine/GDBJITRegistrar.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// This file contains portions derived from LLVM, with the original copyright
+// header below:
+//===-- GDBJITRegistrar.h - Common Implementation shared by GDB-JIT users --===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains declarations of the interface an ExecutionEngine would use
+// to register an in-memory object file with GDB.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef BCC_GDBJITREGISTRAR_H
+#define BCC_GDBJITREGISTRAR_H
+
+#include <cstddef>
+
+// Buffer for an in-memory object file in executable memory
+typedef char ObjectBuffer;
+
+void registerObjectWithGDB(const ObjectBuffer* Object, std::size_t Size);
+void deregisterObjectWithGDB(const ObjectBuffer* Object);
+
+#endif // BCC_GDBJITREGISTRAR_H
diff --git a/lib/Support/Initialization.cpp b/lib/ExecutionEngine/Initialization.cpp
similarity index 93%
rename from lib/Support/Initialization.cpp
rename to lib/ExecutionEngine/Initialization.cpp
index eb4428c..7cdb938 100644
--- a/lib/Support/Initialization.cpp
+++ b/lib/ExecutionEngine/Initialization.cpp
@@ -14,15 +14,15 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/Initialization.h"
+#include "Initialization.h"
 
 #include <cstdlib>
 
 #include <llvm/Support/ErrorHandling.h>
 #include <llvm/Support/TargetSelect.h>
 
-#include "bcc/Config/Config.h"
-#include "bcc/Support/DebugHelper.h"
+#include "Config.h"
+#include "DebugHelper.h"
 
 namespace {
 
diff --git a/lib/ExecutionEngine/Initialization.h b/lib/ExecutionEngine/Initialization.h
new file mode 100644
index 0000000..9a357bc
--- /dev/null
+++ b/lib/ExecutionEngine/Initialization.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_INITIALIZATION_H
+#define BCC_EXECUTION_ENGINE_INITIALIZATION_H
+
+namespace bcc {
+
+namespace init {
+
+void Initialize();
+
+} // end namespace init
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_INITIALIZATION_H
diff --git a/lib/Support/InputFile.cpp b/lib/ExecutionEngine/InputFile.cpp
similarity index 94%
rename from lib/Support/InputFile.cpp
rename to lib/ExecutionEngine/InputFile.cpp
index 522a71d..a51b09e 100644
--- a/lib/Support/InputFile.cpp
+++ b/lib/ExecutionEngine/InputFile.cpp
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/InputFile.h"
+#include "InputFile.h"
 
-#include "bcc/Support/DebugHelper.h"
+#include "DebugHelper.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/InputFile.h b/lib/ExecutionEngine/InputFile.h
new file mode 100644
index 0000000..a7c22d2
--- /dev/null
+++ b/lib/ExecutionEngine/InputFile.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_INPUT_FILE_H
+#define BCC_EXECUTION_ENGINE_INPUT_FILE_H
+
+#include "File.h"
+#include "FileBase.h"
+
+namespace bcc {
+
+class InputFile : public File<FileBase::kReadMode> {
+  typedef File<FileBase::kReadMode> super;
+public:
+  InputFile(const std::string &pFilename, unsigned pFlags = 0);
+
+  ssize_t read(void *pBuf, size_t count);
+};
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_INPUT_FILE_H
diff --git a/lib/ExecutionEngine/ObjectLoader.cpp b/lib/ExecutionEngine/ObjectLoader.cpp
index 1277e13..708ded3 100644
--- a/lib/ExecutionEngine/ObjectLoader.cpp
+++ b/lib/ExecutionEngine/ObjectLoader.cpp
@@ -14,15 +14,14 @@
  * limitations under the License.
  */
 
-#include "bcc/ExecutionEngine/ObjectLoader.h"
+#include "ObjectLoader.h"
 
 #include <utils/FileMap.h>
 
-#include "bcc/ExecutionEngine/GDBJITRegistrar.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/FileBase.h"
-
+#include "DebugHelper.h"
 #include "ELFObjectLoaderImpl.h"
+#include "FileBase.h"
+#include "GDBJITRegistrar.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/ObjectLoader.h b/lib/ExecutionEngine/ObjectLoader.h
new file mode 100644
index 0000000..6c2bc8c
--- /dev/null
+++ b/lib/ExecutionEngine/ObjectLoader.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_OBJECT_LOADER_H
+#define BCC_EXECUTION_ENGINE_OBJECT_LOADER_H
+
+#include <cstddef>
+
+namespace bcc {
+
+class FileBase;
+class ObjectLoaderImpl;
+class SymbolResolverInterface;
+
+class ObjectLoader {
+private:
+  ObjectLoaderImpl *mImpl;
+
+  void *mDebugImage;
+
+  ObjectLoader() : mImpl(NULL), mDebugImage(0) { }
+
+public:
+  // Load from a in-memory object. pName is a descriptive name of this memory.
+  static ObjectLoader *Load(void *pMemStart, size_t pMemSize, const char *pName,
+                            SymbolResolverInterface &pResolver,
+                            bool pEnableGDBDebug);
+
+  // Load from a file.
+  static ObjectLoader *Load(FileBase &pFile,
+                            SymbolResolverInterface &pResolver,
+                            bool pEnableGDBDebug);
+
+  void *getSymbolAddress(const char *pName) const;
+
+  ~ObjectLoader();
+};
+
+} // namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_OBJECT_LOADER_H
diff --git a/lib/ExecutionEngine/ObjectLoaderImpl.h b/lib/ExecutionEngine/ObjectLoaderImpl.h
index 0e0f2c1..81756f8 100644
--- a/lib/ExecutionEngine/ObjectLoaderImpl.h
+++ b/lib/ExecutionEngine/ObjectLoaderImpl.h
@@ -14,8 +14,8 @@
  * limitations under the License.
  */
 
-#ifndef OBJECT_LOADER_IMPL_H
-#define OBJECT_LOADER_IMPL_H
+#ifndef BCC_EXECUTION_ENGINE_OBJECT_LOADER_IMPL_H
+#define BCC_EXECUTION_ENGINE_OBJECT_LOADER_IMPL_H
 
 #include <cstring>
 
@@ -40,4 +40,4 @@
 
 } // namespace bcc
 
-#endif // OBJECT_LOADER_IMPL_H
+#endif // BCC_EXECUTION_ENGINE_OBJECT_LOADER_IMPL_H
diff --git a/lib/Support/OutputFile.cpp b/lib/ExecutionEngine/OutputFile.cpp
similarity index 97%
rename from lib/Support/OutputFile.cpp
rename to lib/ExecutionEngine/OutputFile.cpp
index 4da52aa..6200617 100644
--- a/lib/Support/OutputFile.cpp
+++ b/lib/ExecutionEngine/OutputFile.cpp
@@ -14,13 +14,13 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/OutputFile.h"
+#include "OutputFile.h"
 
 #include <cstdlib>
 
 #include <llvm/Support/raw_ostream.h>
 
-#include "bcc/Support/DebugHelper.h"
+#include "DebugHelper.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/OutputFile.h b/lib/ExecutionEngine/OutputFile.h
new file mode 100644
index 0000000..4de8863
--- /dev/null
+++ b/lib/ExecutionEngine/OutputFile.h
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_OUTPUT_FILE_H
+#define BCC_EXECUTION_ENGINE_OUTPUT_FILE_H
+
+#include "File.h"
+#include "FileBase.h"
+
+namespace llvm {
+  class raw_fd_ostream;
+}
+
+namespace bcc {
+
+class OutputFile : public File<FileBase::kWriteMode> {
+  typedef File<FileBase::kWriteMode> super;
+public:
+  // Generate a unique temporary filename from pFileTemplate and open it in
+  // an OutputFile returned. The filename will be pFileTemplate with
+  // a dot ('.') plus six random characters appended. Return NULL on error.
+  static OutputFile *CreateTemporary(const std::string &pFileTemplate,
+                                     unsigned pFlags);
+
+  OutputFile(const std::string &pFilename, unsigned pFlags = 0);
+
+  ssize_t write(const void *pBuf, size_t count);
+
+  void truncate();
+
+  // This is similar to the system call dup(). It creates a copy of the file
+  // descriptor it contains and wrap it in llvm::raw_fd_ostream object. It
+  // returns a non-NULL object if everything goes well and user should later
+  // use delete operator to destroy it by itself.
+  llvm::raw_fd_ostream *dup();
+};
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_OUTPUT_FILE_H
diff --git a/lib/RenderScript/RSCompiler.cpp b/lib/ExecutionEngine/RSCompiler.cpp
similarity index 93%
rename from lib/RenderScript/RSCompiler.cpp
rename to lib/ExecutionEngine/RSCompiler.cpp
index cc63904..e431086 100644
--- a/lib/RenderScript/RSCompiler.cpp
+++ b/lib/ExecutionEngine/RSCompiler.cpp
@@ -14,18 +14,18 @@
  * limitations under the License.
  */
 
-#include "bcc/RenderScript/RSCompiler.h"
+#include "RSCompiler.h"
 
 #include <llvm/Module.h>
 #include <llvm/PassManager.h>
 #include <llvm/Transforms/IPO.h>
 
-#include "bcc/RenderScript/RSExecutable.h"
-#include "bcc/RenderScript/RSInfo.h"
-#include "bcc/RenderScript/RSScript.h"
-#include "bcc/RenderScript/RSTransforms.h"
-#include "bcc/Source.h"
-#include "bcc/Support/DebugHelper.h"
+#include "DebugHelper.h"
+#include "RSExecutable.h"
+#include "RSInfo.h"
+#include "RSScript.h"
+#include "RSTransforms.h"
+#include "Source.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/RSCompiler.h b/lib/ExecutionEngine/RSCompiler.h
new file mode 100644
index 0000000..227727b
--- /dev/null
+++ b/lib/ExecutionEngine/RSCompiler.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_RS_COMPILER_H
+#define BCC_EXECUTION_ENGINE_RS_COMPILER_H
+
+#include "Compiler.h"
+
+namespace bcc {
+
+class RSCompiler : public Compiler {
+private:
+  virtual bool beforeAddLTOPasses(Script &pScript, llvm::PassManager &pPM);
+  virtual bool beforeExecuteLTOPasses(Script &pScript, llvm::PassManager &pPM);
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_RS_COMPILER_H
diff --git a/lib/RenderScript/RSCompilerDriver.cpp b/lib/ExecutionEngine/RSCompilerDriver.cpp
similarity index 96%
rename from lib/RenderScript/RSCompilerDriver.cpp
rename to lib/ExecutionEngine/RSCompilerDriver.cpp
index 0089a28..ceb4f93 100644
--- a/lib/RenderScript/RSCompilerDriver.cpp
+++ b/lib/ExecutionEngine/RSCompilerDriver.cpp
@@ -14,16 +14,16 @@
  * limitations under the License.
  */
 
-#include "bcc/RenderScript/RSCompilerDriver.h"
+#include "RSCompilerDriver.h"
 
-#include "bcc/RenderScript/RSExecutable.h"
-#include "bcc/Support/CompilerConfig.h"
-#include "bcc/Support/TargetCompilerConfigs.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/FileMutex.h"
-#include "bcc/Support/InputFile.h"
-#include "bcc/Support/Initialization.h"
-#include "bcc/Support/OutputFile.h"
+#include "CompilerConfig.h"
+#include "TargetCompilerConfigs.h"
+#include "DebugHelper.h"
+#include "FileMutex.h"
+#include "InputFile.h"
+#include "Initialization.h"
+#include "OutputFile.h"
+#include "RSExecutable.h"
 
 #include <cutils/properties.h>
 #include <utils/String8.h>
diff --git a/lib/ExecutionEngine/RSCompilerDriver.h b/lib/ExecutionEngine/RSCompilerDriver.h
new file mode 100644
index 0000000..8bc9298
--- /dev/null
+++ b/lib/ExecutionEngine/RSCompilerDriver.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_RS_COMPILER_DRIVER_H
+#define BCC_EXECUTION_ENGINE_RS_COMPILER_DRIVER_H
+
+#include <string>
+
+#include "BCCRuntimeSymbolResolver.h"
+#include "RSCompiler.h"
+#include "SymbolResolvers.h"
+#include "SymbolResolverProxy.h"
+
+namespace bcc {
+
+class CompilerConfig;
+class RSExecutable;
+class RSScript;
+
+class RSCompilerDriver {
+private:
+  CompilerConfig *mConfig;
+  RSCompiler mCompiler;
+
+  BCCRuntimeSymbolResolver mBCCRuntime;
+  LookupFunctionSymbolResolver<void*> mRSRuntime;
+  SymbolResolverProxy mResolver;
+
+  RSExecutable *loadScriptCache(const RSScript &pScript,
+                                const std::string &pOutputPath);
+
+  // Setup the compiler config for the given script. Return true if mConfig has
+  // been changed and false if it remains unchanged.
+  bool setupConfig(const RSScript &pScript);
+
+  RSExecutable *compileScript(RSScript &pScript,
+                              const std::string &pOutputPath);
+
+public:
+  RSCompilerDriver();
+  ~RSCompilerDriver();
+
+  inline void setRSRuntimeLookupFunction(
+      LookupFunctionSymbolResolver<>::LookupFunctionTy pLookupFunc)
+  { mRSRuntime.setLookupFunction(pLookupFunc); }
+  inline void setRSRuntimeLookupContext(void *pContext)
+  { mRSRuntime.setContext(pContext); }
+
+  // FIXME: This method accompany with loadScriptCache and compileScript should
+  //        all be const-methods. They're not now because the getAddress() in
+  //        SymbolResolverInterface is not a const-method.
+  RSExecutable *build(RSScript &pScript,
+                      const std::string &pOutputPath);
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_RS_COMPILER_DRIVER_H
diff --git a/lib/RenderScript/RSExecutable.cpp b/lib/ExecutionEngine/RSExecutable.cpp
similarity index 95%
rename from lib/RenderScript/RSExecutable.cpp
rename to lib/ExecutionEngine/RSExecutable.cpp
index de730ed..46ec726 100644
--- a/lib/RenderScript/RSExecutable.cpp
+++ b/lib/ExecutionEngine/RSExecutable.cpp
@@ -14,12 +14,12 @@
  * limitations under the License.
  */
 
-#include "bcc/RenderScript/RSExecutable.h"
+#include "RSExecutable.h"
 
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/FileBase.h"
-#include "bcc/Support/OutputFile.h"
-#include "bcc/ExecutionEngine/SymbolResolverProxy.h"
+#include "DebugHelper.h"
+#include "FileBase.h"
+#include "OutputFile.h"
+#include "SymbolResolverProxy.h"
 
 #include <utils/String8.h>
 
diff --git a/lib/ExecutionEngine/RSExecutable.h b/lib/ExecutionEngine/RSExecutable.h
new file mode 100644
index 0000000..12e0f0a
--- /dev/null
+++ b/lib/ExecutionEngine/RSExecutable.h
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_RS_EXECUTABLE_H
+#define BCC_EXECUTION_ENGINE_RS_EXECUTABLE_H
+
+#include <cstddef>
+
+#include "DebugHelper.h"
+#include "ObjectLoader.h"
+#include "RSInfo.h"
+
+#include <utils/Vector.h>
+
+namespace bcc {
+
+class FileBase;
+class SymbolResolverProxy;
+
+/*
+ * RSExecutable holds the build results of a RSScript.
+ */
+class RSExecutable {
+private:
+  RSInfo *mInfo;
+  bool mIsInfoDirty;
+
+  FileBase *mObjFile;
+
+  ObjectLoader *mLoader;
+
+  // Memory address of rs export stuffs
+  android::Vector<void *> mExportVarAddrs;
+  android::Vector<void *> mExportFuncAddrs;
+  android::Vector<void *> mExportForeachFuncAddrs;
+
+  // FIXME: These are designed for RenderScript HAL and is initialized in
+  //        RSExecutable::Create(). Both of them come from RSInfo::getPragmas().
+  //        If possible, read the pragma key/value pairs directly from RSInfo.
+  android::Vector<const char *> mPragmaKeys;
+  android::Vector<const char *> mPragmaValues;
+
+  RSExecutable(RSInfo &pInfo, FileBase &pObjFile, ObjectLoader &pLoader)
+    : mInfo(&pInfo), mIsInfoDirty(false), mObjFile(&pObjFile), mLoader(&pLoader)
+  { }
+
+public:
+  // This is a NULL-terminated string array which specifies "Special" functions
+  // in RenderScript (e.g., root().)
+  static const char *SpecialFunctionNames[];
+
+  // Return NULL on error. If the return object is non-NULL, it claims the
+  // ownership of pInfo and pObjFile.
+  static RSExecutable *Create(RSInfo &pInfo,
+                              FileBase &pObjFile,
+                              SymbolResolverProxy &pResolver);
+
+  inline const RSInfo &getInfo() const
+  { return *mInfo; }
+
+  // Interfaces to RSInfo
+  inline bool isThreadable() const
+  { return mInfo->isThreadable(); }
+
+  inline void setThreadable(bool pThreadable = true) {
+    if (mInfo->isThreadable() != pThreadable) {
+      mInfo->setThreadable(pThreadable);
+      mIsInfoDirty = true;
+    }
+    return;
+  }
+
+  // Interfaces to ObjectLoader
+  inline void *getSymbolAddress(const char *pName) const
+  { return mLoader->getSymbolAddress(pName); }
+
+  bool syncInfo(bool pForce = false);
+
+  inline const android::Vector<void *> &getExportVarAddrs() const
+  { return mExportVarAddrs; }
+  inline const android::Vector<void *> &getExportFuncAddrs() const
+  { return mExportFuncAddrs; }
+  inline const android::Vector<void *> &getExportForeachFuncAddrs() const
+  { return mExportForeachFuncAddrs; }
+
+  inline const android::Vector<const char *> &getPragmaKeys() const
+  { return mPragmaKeys; }
+  inline const android::Vector<const char *> &getPragmaValues() const
+  { return mPragmaValues; }
+
+  ~RSExecutable();
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_RS_EXECUTABLE_H
diff --git a/lib/RenderScript/RSForEachExpand.cpp b/lib/ExecutionEngine/RSForEachExpand.cpp
similarity index 96%
rename from lib/RenderScript/RSForEachExpand.cpp
rename to lib/ExecutionEngine/RSForEachExpand.cpp
index 2c7315e..b30dd23 100644
--- a/lib/RenderScript/RSForEachExpand.cpp
+++ b/lib/ExecutionEngine/RSForEachExpand.cpp
@@ -15,21 +15,22 @@
  */
 
 //#define RS_FOREACH_EXPAND_PASS_NDEBUG 0
-#include "bcc/RenderScript/RSTransforms.h"
+#include "RSTransforms.h"
 
 #include <cstdlib>
 
-#include <llvm/DerivedTypes.h>
-#include <llvm/Function.h>
-#include <llvm/Instructions.h>
-#include <llvm/Module.h>
-#include <llvm/Pass.h>
-#include <llvm/Support/IRBuilder.h>
-#include <llvm/Type.h>
+#include "Config.h"
 
-#include "bcc/Config/Config.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/RenderScript/RSInfo.h"
+#include "DebugHelper.h"
+#include "RSInfo.h"
+
+#include "llvm/DerivedTypes.h"
+#include "llvm/Function.h"
+#include "llvm/Instructions.h"
+#include "llvm/Module.h"
+#include "llvm/Pass.h"
+#include "llvm/Type.h"
+#include "llvm/Support/IRBuilder.h"
 
 using namespace bcc;
 
diff --git a/lib/RenderScript/RSInfo.cpp b/lib/ExecutionEngine/RSInfo.cpp
similarity index 98%
rename from lib/RenderScript/RSInfo.cpp
rename to lib/ExecutionEngine/RSInfo.cpp
index 0d31e38..d351d36 100644
--- a/lib/RenderScript/RSInfo.cpp
+++ b/lib/ExecutionEngine/RSInfo.cpp
@@ -15,14 +15,14 @@
  */
 
 //#define LOG_NDEBUG 0
-#include "bcc/RenderScript/RSInfo.h"
+#include "RSInfo.h"
 
 #include <cstring>
 #include <new>
 
-#include "bcc/Support/FileBase.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/Sha1Helper.h"
+#include "FileBase.h"
+#include "DebugHelper.h"
+#include "Sha1Helper.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/RSInfo.h b/lib/ExecutionEngine/RSInfo.h
new file mode 100644
index 0000000..d69d15e
--- /dev/null
+++ b/lib/ExecutionEngine/RSInfo.h
@@ -0,0 +1,251 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_RS_INFO_FILE_H
+#define BCC_EXECUTION_ENGINE_RS_INFO_FILE_H
+
+#include <stdint.h>
+
+#include <utility>
+
+#include "RSScript.h"
+#include "DebugHelper.h"
+
+#include <utils/String8.h>
+#include <utils/Vector.h>
+
+namespace bcc {
+
+// Forward declarations
+class FileBase;
+class InputFile;
+class OutputFile;
+class Source;
+
+namespace rsinfo {
+
+/* RS info file magic */
+#define RSINFO_MAGIC      "\0rsinfo\n"
+
+/* RS info file version, encoded in 4 bytes of ASCII */
+#define RSINFO_VERSION    "003\0"
+
+struct __attribute__((packed)) ListHeader {
+  // The offset from the beginning of the file of data
+  uint32_t offset;
+  // Number of item in the list
+  uint32_t count;
+  // Size of each item
+  uint8_t itemSize;
+};
+
+/* RS info file header */
+struct __attribute__((packed)) Header {
+  // Magic versus version
+  uint8_t magic[8];
+  uint8_t version[4];
+
+  uint8_t isThreadable;
+  uint8_t hasDebugInformation;
+
+  uint16_t headerSize;
+
+  uint32_t strPoolSize;
+
+  struct ListHeader dependencyTable;
+  struct ListHeader pragmaList;
+  struct ListHeader objectSlotList;
+  struct ListHeader exportVarNameList;
+  struct ListHeader exportFuncNameList;
+  struct ListHeader exportForeachFuncList;
+};
+
+typedef uint32_t StringIndexTy;
+// Use value -1 as an invalid string index marker. No need to declare with
+// 'static' modifier since 'const' variable has internal linkage by default.
+const StringIndexTy gInvalidStringIndex = static_cast<StringIndexTy>(-1);
+
+struct __attribute__((packed)) DependencyTableItem {
+  StringIndexTy id;
+  // SHA-1 checksum is stored as a string in string pool (and has fixed-length
+  // 20 bytes)
+  StringIndexTy sha1;
+};
+
+struct __attribute__((packed)) PragmaItem {
+  // Pragma is a key-value pair.
+  StringIndexTy key;
+  StringIndexTy value;
+};
+
+struct __attribute__((packed)) ObjectSlotItem {
+  uint32_t slot;
+};
+
+struct __attribute__((packed)) ExportVarNameItem {
+  StringIndexTy name;
+};
+
+struct __attribute__((packed)) ExportFuncNameItem {
+  StringIndexTy name;
+};
+
+struct __attribute__((packed)) ExportForeachFuncItem {
+  StringIndexTy name;
+  uint32_t signature;
+};
+
+// Return the human-readable name of the given rsinfo::*Item in the template
+// parameter. This is for debugging and error message.
+template<typename Item>
+inline const char *GetItemTypeName();
+
+template<>
+inline const char *GetItemTypeName<DependencyTableItem>()
+{ return "rs dependency info"; }
+
+template<>
+inline const char *GetItemTypeName<PragmaItem>()
+{  return "rs pragma"; }
+
+template<>
+inline const char *GetItemTypeName<ObjectSlotItem>()
+{  return "rs object slot"; }
+
+template<>
+inline const char *GetItemTypeName<ExportVarNameItem>()
+{ return "rs export var"; }
+
+template<>
+inline const char *GetItemTypeName<ExportFuncNameItem>()
+{  return "rs export func"; }
+
+template<>
+inline const char *GetItemTypeName<ExportForeachFuncItem>()
+{ return "rs export foreach"; }
+
+} // end namespace rsinfo
+
+class RSInfo {
+public:
+  typedef android::Vector<std::pair<const char *,
+                                    const uint8_t *> > DependencyTableTy;
+  typedef android::Vector<std::pair<const char*, const char*> > PragmaListTy;
+  typedef android::Vector<uint32_t> ObjectSlotListTy;
+  typedef android::Vector<const char *> ExportVarNameListTy;
+  typedef android::Vector<const char *> ExportFuncNameListTy;
+  typedef android::Vector<std::pair<const char *,
+                                    uint32_t> > ExportForeachFuncListTy;
+
+public:
+  // Calculate or load the SHA-1 information of the built-in dependencies.
+  static void LoadBuiltInSHA1Information();
+
+  // Return the path of the RS info file corresponded to the given output
+  // executable file.
+  static android::String8 GetPath(const FileBase &pFile);
+
+  static const char LibBCCPath[];
+  static const char LibRSPath[];
+
+private:
+  // SHA-1 of the built-in dependencies. Will be initialized in
+  // LoadBuiltInSHA1Information().
+  static uint8_t LibBCCSHA1[20];
+  static uint8_t LibRSSHA1[20];
+
+  static bool CheckDependency(const RSInfo &pInfo,
+                              const char *pInputFilename,
+                              const RSScript::SourceDependencyListTy &pDeps);
+  static bool AddBuiltInDependencies(RSInfo &pInfo);
+
+  rsinfo::Header mHeader;
+
+  char *mStringPool;
+
+  // In most of the time, there're 4 source dependencies stored (libbcc.so,
+  // libRS.so, libclcore and the input bitcode itself.)
+  DependencyTableTy mDependencyTable;
+  PragmaListTy mPragmas;
+  ObjectSlotListTy mObjectSlots;
+  ExportVarNameListTy mExportVarNames;
+  ExportFuncNameListTy mExportFuncNames;
+  ExportForeachFuncListTy mExportForeachFuncs;
+
+  // Initialize an empty RSInfo with its size of string pool is pStringPoolSize.
+  RSInfo(size_t pStringPoolSize);
+
+  // layout() assigns value of offset in each ListHeader (i.e., it decides where
+  // data should go in the file.) It also updates fields other than offset to
+  // reflect the current RSInfo object states to mHeader.
+  bool layout(off_t initial_offset);
+
+public:
+  ~RSInfo();
+
+  // Implemented in RSInfoExtractor.cpp.
+  static RSInfo *ExtractFromSource(
+      const Source &pSource, const RSScript::SourceDependencyListTy &pDeps);
+
+  // Implemented in RSInfoReader.cpp.
+  static RSInfo *ReadFromFile(InputFile &pInput,
+                              const RSScript::SourceDependencyListTy &pDeps);
+
+  // Implemneted in RSInfoWriter.cpp
+  bool write(OutputFile &pOutput);
+
+  void dump() const;
+
+  // const getter
+  inline bool isThreadable() const
+  { return mHeader.isThreadable; }
+  inline bool hasDebugInformation() const
+  { return mHeader.hasDebugInformation; }
+  inline const DependencyTableTy &getDependencyTable() const
+  { return mDependencyTable; }
+  inline const PragmaListTy &getPragmas() const
+  { return mPragmas; }
+  inline const ObjectSlotListTy &getObjectSlots() const
+  { return mObjectSlots; }
+  inline const ExportVarNameListTy &getExportVarNames() const
+  { return mExportVarNames; }
+  inline const ExportFuncNameListTy &getExportFuncNames() const
+  { return mExportFuncNames; }
+  inline const ExportForeachFuncListTy &getExportForeachFuncs() const
+  { return mExportForeachFuncs; }
+
+  const char *getStringFromPool(rsinfo::StringIndexTy pStrIdx) const;
+  rsinfo::StringIndexTy getStringIdxInPool(const char *pStr) const;
+
+  // setter
+  inline void setThreadable(bool pThreadable = true)
+  { mHeader.isThreadable = pThreadable; }
+
+public:
+  enum FloatPrecision {
+    Full,
+    Relaxed,
+    Imprecise,
+  };
+
+  // Return the minimal floating point precision required for the associated
+  // script.
+  enum FloatPrecision getFloatPrecisionRequirement() const;
+};
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_RS_INFO_FILE_H
diff --git a/lib/RenderScript/RSInfoExtractor.cpp b/lib/ExecutionEngine/RSInfoExtractor.cpp
similarity index 98%
rename from lib/RenderScript/RSInfoExtractor.cpp
rename to lib/ExecutionEngine/RSInfoExtractor.cpp
index 43eb1ed..a90becc 100644
--- a/lib/RenderScript/RSInfoExtractor.cpp
+++ b/lib/ExecutionEngine/RSInfoExtractor.cpp
@@ -17,14 +17,14 @@
 //===----------------------------------------------------------------------===//
 // This file implements RSInfo::ExtractFromSource()
 //===----------------------------------------------------------------------===//
-#include "bcc/RenderScript/RSInfo.h"
+#include "RSInfo.h"
 
 #include <llvm/Constants.h>
 #include <llvm/Metadata.h>
 #include <llvm/Module.h>
 
-#include "bcc/Source.h"
-#include "bcc/Support/DebugHelper.h"
+#include "DebugHelper.h"
+#include "Source.h"
 
 using namespace bcc;
 
diff --git a/lib/RenderScript/RSInfoReader.cpp b/lib/ExecutionEngine/RSInfoReader.cpp
similarity index 98%
rename from lib/RenderScript/RSInfoReader.cpp
rename to lib/ExecutionEngine/RSInfoReader.cpp
index 4e42ffd..a3eca5a 100644
--- a/lib/RenderScript/RSInfoReader.cpp
+++ b/lib/ExecutionEngine/RSInfoReader.cpp
@@ -18,14 +18,14 @@
 // This file implements RSInfo::ReadFromFile()
 //===----------------------------------------------------------------------===//
 
-#include "bcc/RenderScript/RSInfo.h"
+#include "RSInfo.h"
 
 #include <new>
 
 #include <utils/FileMap.h>
 
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/InputFile.h"
+#include "DebugHelper.h"
+#include "InputFile.h"
 
 using namespace bcc;
 
diff --git a/lib/RenderScript/RSInfoWriter.cpp b/lib/ExecutionEngine/RSInfoWriter.cpp
similarity index 98%
rename from lib/RenderScript/RSInfoWriter.cpp
rename to lib/ExecutionEngine/RSInfoWriter.cpp
index 1f19839..d54fb41 100644
--- a/lib/RenderScript/RSInfoWriter.cpp
+++ b/lib/ExecutionEngine/RSInfoWriter.cpp
@@ -18,10 +18,10 @@
 // This file implements RSInfo::write()
 //===----------------------------------------------------------------------===//
 
-#include "bcc/RenderScript/RSInfo.h"
+#include "RSInfo.h"
 
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/OutputFile.h"
+#include "DebugHelper.h"
+#include "OutputFile.h"
 
 using namespace bcc;
 
diff --git a/lib/RenderScript/RSScript.cpp b/lib/ExecutionEngine/RSScript.cpp
similarity index 95%
rename from lib/RenderScript/RSScript.cpp
rename to lib/ExecutionEngine/RSScript.cpp
index 4cf8475..7ec84d9 100644
--- a/lib/RenderScript/RSScript.cpp
+++ b/lib/ExecutionEngine/RSScript.cpp
@@ -14,13 +14,13 @@
  * limitations under the License.
  */
 
-#include "bcc/RenderScript/RSScript.h"
+#include "RSScript.h"
 
 #include <cstring>
 
 #include <llvm/ADT/STLExtras.h>
 
-#include "bcc/Support/DebugHelper.h"
+#include "DebugHelper.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/RSScript.h b/lib/ExecutionEngine/RSScript.h
new file mode 100644
index 0000000..1ae9c9d
--- /dev/null
+++ b/lib/ExecutionEngine/RSScript.h
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_RS_SCRIPT_H
+#define BCC_EXECUTION_ENGINE_RS_SCRIPT_H
+
+#include <string>
+
+#include <llvm/ADT/SmallVector.h>
+#include <llvm/Support/CodeGen.h>
+
+#include "Script.h"
+
+namespace bcc {
+
+class RSInfo;
+class Source;
+
+class RSScript : public Script {
+public:
+  class SourceDependency {
+  private:
+    std::string mSourceName;
+    uint8_t mSHA1[20];
+
+  public:
+    SourceDependency(const std::string &pSourceName,
+                     const uint8_t *pSHA1);
+
+    inline const std::string &getSourceName() const
+    { return mSourceName; }
+
+    inline const uint8_t *getSHA1Checksum() const
+    { return mSHA1; }
+  };
+  typedef llvm::SmallVectorImpl<SourceDependency *> SourceDependencyListTy;
+
+  // This is one-one mapping with the llvm::CodeGenOpt::Level in
+  // llvm/Support/CodeGen.h. Therefore, value of this type can safely cast
+  // to llvm::CodeGenOpt::Level. This makes RSScript LLVM-free.
+  enum OptimizationLevel {
+    kOptLvl0, // -O0
+    kOptLvl1, // -O1
+    kOptLvl2, // -O2, -Os
+    kOptLvl3  // -O3
+  };
+
+private:
+  llvm::SmallVector<SourceDependency *, 4> mSourceDependencies;
+
+  const RSInfo *mInfo;
+
+  unsigned mCompilerVersion;
+
+  OptimizationLevel mOptimizationLevel;
+
+private:
+  // This will be invoked when the containing source has been reset.
+  virtual bool doReset();
+
+public:
+  RSScript(Source &pSource);
+
+  // Add dependency information for this script given the source named
+  // pSourceName. pSHA1 is the SHA-1 checksum of the given source. Return
+  // false on error.
+  bool addSourceDependency(const std::string &pSourceName,
+                           const uint8_t *pSHA1);
+
+  const SourceDependencyListTy &getSourceDependencies() const
+  { return mSourceDependencies; }
+
+  // Set the associated RSInfo of the script.
+  void setInfo(const RSInfo *pInfo)
+  { mInfo = pInfo; }
+
+  const RSInfo *getInfo() const
+  { return mInfo; }
+
+  void setCompilerVersion(unsigned pCompilerVersion)
+  {  mCompilerVersion = pCompilerVersion; }
+
+  unsigned getCompilerVersion() const
+  {  return mCompilerVersion; }
+
+  void setOptimizationLevel(OptimizationLevel pOptimizationLevel)
+  {  mOptimizationLevel = pOptimizationLevel; }
+
+  OptimizationLevel getOptimizationLevel() const
+  {  return mOptimizationLevel; }
+
+  ~RSScript();
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_RS_SCRIPT_H
diff --git a/lib/ExecutionEngine/RSTransforms.h b/lib/ExecutionEngine/RSTransforms.h
new file mode 100644
index 0000000..ec5f690
--- /dev/null
+++ b/lib/ExecutionEngine/RSTransforms.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_RS_TRANSFORMS_H
+#define BCC_EXECUTION_ENGINE_RS_TRANSFORMS_H
+
+#include "RSInfo.h"
+
+namespace llvm {
+  class ModulePass;
+}
+
+namespace bcc {
+
+llvm::ModulePass *
+createRSForEachExpandPass(const RSInfo::ExportForeachFuncListTy &pForeachFuncs);
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_RS_TRANSFORMS_H
diff --git a/lib/Core/Script.cpp b/lib/ExecutionEngine/Script.cpp
similarity index 94%
rename from lib/Core/Script.cpp
rename to lib/ExecutionEngine/Script.cpp
index 8e8a274..785915c 100644
--- a/lib/Core/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -14,9 +14,9 @@
  * limitations under the License.
  */
 
-#include "bcc/Script.h"
+#include "Script.h"
 
-#include "bcc/Source.h"
+#include "Source.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/Script.h b/lib/ExecutionEngine/Script.h
new file mode 100644
index 0000000..aaa5eba
--- /dev/null
+++ b/lib/ExecutionEngine/Script.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2010-2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_SCRIPT_H
+#define BCC_EXECUTION_ENGINE_SCRIPT_H
+
+namespace bcc {
+
+class Source;
+
+class Script {
+private:
+  // This is the source associated with this object and is going to be
+  // compiled.
+  Source *mSource;
+
+protected:
+  // This hook will be invoked after the script object is succssfully reset
+  // itself.
+  virtual bool doReset()
+  { return true; }
+
+public:
+  Script(Source &pSource) : mSource(&pSource) { }
+
+  virtual ~Script() { }
+
+  // Reset this object with the new source supplied. Return false if this
+  // object remains unchanged after the call (e.g., the supplied source is
+  // the same with the one contain in this object.) If pPreserveCurrent is
+  // false, the current containing source will be destroyed after successfully
+  // reset.
+  bool reset(Source &pSource, bool pPreserveCurrent = false);
+
+  // Merge (or link) another source into the current source associated with
+  // this Script object. Return false on error.
+  //
+  // This is equivalent to the call to Script::merge(...) on mSource.
+  bool mergeSource(Source &pSource, bool pPreserveSource = false);
+
+  inline Source &getSource()
+  { return *mSource; }
+  inline const Source &getSource() const
+  { return *mSource; }
+};
+
+} // end namespace bcc
+
+#endif  // BCC_EXECUTION_ENGINE_SCRIPT_H
diff --git a/lib/Support/Sha1Helper.cpp b/lib/ExecutionEngine/Sha1Helper.cpp
similarity index 90%
rename from lib/Support/Sha1Helper.cpp
rename to lib/ExecutionEngine/Sha1Helper.cpp
index 350e704..07a995f 100644
--- a/lib/Support/Sha1Helper.cpp
+++ b/lib/ExecutionEngine/Sha1Helper.cpp
@@ -1,5 +1,5 @@
 /*
- * copyright 2010-2012, the android open source project
+ * copyright 2010, the android open source project
  *
  * licensed under the apache license, version 2.0 (the "license");
  * you may not use this file except in compliance with the license.
@@ -14,17 +14,18 @@
  * limitations under the license.
  */
 
-#include "bcc/Support/Sha1Helper.h"
+#include "Sha1Helper.h"
 
-#include <cstring>
+#include "Config.h"
+
+#include "DebugHelper.h"
+#include "InputFile.h"
+
+#include <string.h>
 
 #include <utils/StopWatch.h>
 
-#include "bcc/Config/Config.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/InputFile.h"
-
-#include "sha1.h"
+#include <sha1.h>
 
 namespace bcc {
 
diff --git a/lib/ExecutionEngine/Sha1Helper.h b/lib/ExecutionEngine/Sha1Helper.h
new file mode 100644
index 0000000..fe13b7a
--- /dev/null
+++ b/lib/ExecutionEngine/Sha1Helper.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_SHA1HELPER_H
+#define BCC_SHA1HELPER_H
+
+#include "Config.h"
+
+#include <stddef.h>
+
+namespace bcc {
+  extern unsigned char sha1LibBCC_SHA1[20];
+  extern char const *pathLibBCC_SHA1;
+
+  extern unsigned char sha1LibRS[20];
+  extern char const *pathLibRS;
+
+  void calcSHA1(unsigned char *result, char const *data, size_t size);
+
+  void calcFileSHA1(unsigned char *result, char const *filename);
+
+  // Read binary representation of sha1 from filename.
+  void readSHA1(unsigned char *result, int resultsize, char const *filename);
+}
+
+#endif // BCC_SHA1HELPER_H
diff --git a/lib/Core/Source.cpp b/lib/ExecutionEngine/Source.cpp
similarity index 97%
rename from lib/Core/Source.cpp
rename to lib/ExecutionEngine/Source.cpp
index ad5561b..754f3e5 100644
--- a/lib/Core/Source.cpp
+++ b/lib/ExecutionEngine/Source.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/Source.h"
+#include "Source.h"
 
 #include <new>
 
@@ -25,10 +25,9 @@
 #include <llvm/Support/MemoryBuffer.h>
 #include <llvm/Support/system_error.h>
 
-#include "bcc/BCCContext.h"
-#include "bcc/Support/DebugHelper.h"
-
+#include "BCCContext.h"
 #include "BCCContextImpl.h"
+#include "DebugHelper.h"
 
 namespace {
 
diff --git a/lib/ExecutionEngine/Source.h b/lib/ExecutionEngine/Source.h
new file mode 100644
index 0000000..b9a98e8
--- /dev/null
+++ b/lib/ExecutionEngine/Source.h
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2010, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_SOURCE_H
+#define BCC_EXECUTION_ENGINE_SOURCE_H
+
+#include <string>
+
+namespace llvm {
+  class Module;
+}
+
+namespace bcc {
+
+class BCCContext;
+
+class Source {
+private:
+  BCCContext &mContext;
+  llvm::Module *mModule;
+
+  // If true, destructor won't destroy the mModule.
+  bool mNoDelete;
+
+private:
+  Source(BCCContext &pContext, llvm::Module &pModule, bool pNoDelete = false);
+
+public:
+  static Source *CreateFromBuffer(BCCContext &pContext,
+                                  const char *pName,
+                                  const char *pBitcode,
+                                  size_t pBitcodeSize);
+
+  static Source *CreateFromFile(BCCContext &pContext,
+                                const std::string &pPath);
+
+  // Create a Source object from an existing module. If pNoDelete
+  // is true, destructor won't call delete on the given module.
+  static Source *CreateFromModule(BCCContext &pContext,
+                                  llvm::Module &pModule,
+                                  bool pNoDelete = false);
+
+  static Source *CreateEmpty(BCCContext &pContext, const std::string &pName);
+
+  // Merge the current source with pSource. If pPreserveSource is false, pSource
+  // will be destroyed after successfully merged. Return false on error.
+  bool merge(Source &pSource, bool pPreserveSource = false);
+
+  inline BCCContext &getContext()
+  { return mContext; }
+  inline const BCCContext &getContext() const
+  { return mContext; }
+
+  inline llvm::Module &getModule()
+  { return *mModule;  }
+  inline const llvm::Module &getModule() const
+  { return *mModule;  }
+
+  // Get the "identifier" of the bitcode. This will return the value of pName
+  // when it's created using CreateFromBuffer and pPath if CreateFromFile().
+  const std::string &getIdentifier() const;
+
+  ~Source();
+};
+
+} // namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_SOURCE_H
diff --git a/lib/ExecutionEngine/SymbolResolverInterface.h b/lib/ExecutionEngine/SymbolResolverInterface.h
new file mode 100644
index 0000000..c80073d
--- /dev/null
+++ b/lib/ExecutionEngine/SymbolResolverInterface.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_SYMBOL_RESOLVER_INTERFACE_H
+#define BCC_EXECUTION_ENGINE_SYMBOL_RESOLVER_INTERFACE_H
+
+#include <cstddef>
+
+namespace bcc {
+
+class SymbolResolverInterface {
+public:
+  static void *LookupFunction(void *pResolver, const char *pName) {
+    SymbolResolverInterface *resolver =
+        reinterpret_cast<SymbolResolverInterface*>(pResolver);
+    return ((resolver != NULL) ? resolver->getAddress(pName) : NULL);
+  }
+
+  // Should this be a const method?
+  virtual void *getAddress(const char *pName) = 0;
+
+  virtual ~SymbolResolverInterface() { }
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_SYMBOL_RESOLVER_INTERFACE_H
diff --git a/lib/ExecutionEngine/SymbolResolverProxy.cpp b/lib/ExecutionEngine/SymbolResolverProxy.cpp
index 5f3e7dc..29929d9 100644
--- a/lib/ExecutionEngine/SymbolResolverProxy.cpp
+++ b/lib/ExecutionEngine/SymbolResolverProxy.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/ExecutionEngine/SymbolResolverProxy.h"
+#include "SymbolResolverProxy.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/SymbolResolverProxy.h b/lib/ExecutionEngine/SymbolResolverProxy.h
new file mode 100644
index 0000000..7bbdac5
--- /dev/null
+++ b/lib/ExecutionEngine/SymbolResolverProxy.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_SYMBOL_RESOLVER_PROXY_H
+#define BCC_EXECUTION_ENGINE_SYMBOL_RESOLVER_PROXY_H
+
+#include "DebugHelper.h"
+#include "SymbolResolverInterface.h"
+
+#include <utils/Vector.h>
+
+namespace bcc {
+
+class SymbolResolverProxy : public SymbolResolverInterface {
+private:
+  android::Vector<SymbolResolverInterface *> mChain;
+
+public:
+  SymbolResolverProxy() { }
+
+  void chainResolver(SymbolResolverInterface &pResolver);
+
+  virtual void *getAddress(const char *pName);
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_SYMBOL_RESOLVER_PROXY_H
diff --git a/lib/ExecutionEngine/SymbolResolvers.cpp b/lib/ExecutionEngine/SymbolResolvers.cpp
index 62914ac..26941f2 100644
--- a/lib/ExecutionEngine/SymbolResolvers.cpp
+++ b/lib/ExecutionEngine/SymbolResolvers.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/ExecutionEngine/SymbolResolvers.h"
+#include "SymbolResolvers.h"
 
 #include <dlfcn.h>
 
diff --git a/lib/ExecutionEngine/SymbolResolvers.h b/lib/ExecutionEngine/SymbolResolvers.h
new file mode 100644
index 0000000..909211f
--- /dev/null
+++ b/lib/ExecutionEngine/SymbolResolvers.h
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_SYMBOL_RESOLVERS_H
+#define BCC_EXECUTION_ENGINE_SYMBOL_RESOLVERS_H
+
+#include <cstdlib>
+#include <cstring>
+
+#include "SymbolResolverInterface.h"
+
+namespace bcc {
+
+/*
+ * Symbol lookup via dlopen()/dlsym().
+ */
+class DyldSymbolResolver : public SymbolResolverInterface {
+public:
+  typedef void *HandleTy;
+
+private:
+  HandleTy mHandle;
+  char *mError;
+
+public:
+  // If pFileName is NULL, it will search symbol in the current process image.
+  DyldSymbolResolver(const char *pFileName, bool pLazyBinding = true);
+
+  virtual void *getAddress(const char *pName);
+
+  inline bool hasError() const
+  { return (mError != NULL); }
+  inline const char *getError() const
+  { return mError; }
+
+  ~DyldSymbolResolver();
+};
+
+/*
+ * Symbol lookup by searching through an array of SymbolMap.
+ */
+template<typename Subclass>
+class ArraySymbolResolver : public SymbolResolverInterface {
+public:
+  typedef struct {
+    // Symbol name
+    const char *mName;
+    // Symbol address
+    void *mAddr;
+  } SymbolMap;
+
+private:
+  // True if the symbol name is sorted in the array.
+  bool mSorted;
+
+  static int CompareSymbolName(const void *pA, const void *pB) {
+    return ::strcmp(reinterpret_cast<const SymbolMap *>(pA)->mName,
+                    reinterpret_cast<const SymbolMap *>(pB)->mName);
+  }
+
+public:
+  ArraySymbolResolver(bool pSorted = false) : mSorted(pSorted) { }
+
+  virtual void *getAddress(const char *pName) {
+    const SymbolMap *result = NULL;
+
+    if (mSorted) {
+      // Use binary search.
+      const SymbolMap key = { pName, NULL };
+
+      result = reinterpret_cast<SymbolMap *>(
+                   ::bsearch(&key, Subclass::SymbolArray,
+                                   Subclass::NumSymbols,
+                                   sizeof(SymbolMap),
+                                   CompareSymbolName));
+    } else {
+      // Use linear search.
+      for (size_t i = 0; i < Subclass::NumSymbols; i++) {
+        if (::strcmp(Subclass::SymbolArray[i].mName, pName) == 0) {
+          result = &Subclass::SymbolArray[i];
+          break;
+        }
+      }
+    }
+
+    return ((result != NULL) ? result->mAddr : NULL);
+  }
+};
+
+template<typename ContextTy = void *>
+class LookupFunctionSymbolResolver : public SymbolResolverInterface {
+public:
+  typedef void *(*LookupFunctionTy)(ContextTy pContext, const char *pName);
+
+private:
+  LookupFunctionTy mLookupFunc;
+  ContextTy mContext;
+
+public:
+  LookupFunctionSymbolResolver(LookupFunctionTy pLookupFunc = NULL,
+                               ContextTy pContext = NULL)
+    : mLookupFunc(pLookupFunc), mContext(pContext) { }
+
+  virtual void *getAddress(const char *pName) {
+    return ((mLookupFunc != NULL) ? mLookupFunc(mContext, pName) : NULL);
+  }
+
+  inline LookupFunctionTy getLookupFunction() const
+  { return mLookupFunc; }
+  inline ContextTy getContext() const
+  { return mContext; }
+
+  inline void setLookupFunction(LookupFunctionTy pLookupFunc)
+  { mLookupFunc = pLookupFunc; }
+  inline void setContext(ContextTy pContext)
+  { mContext = pContext; }
+};
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_SYMBOL_RESOLVERS_H
diff --git a/lib/Support/TargetCompilerConfigs.cpp b/lib/ExecutionEngine/TargetCompilerConfigs.cpp
similarity index 97%
rename from lib/Support/TargetCompilerConfigs.cpp
rename to lib/ExecutionEngine/TargetCompilerConfigs.cpp
index 6ef7dcf..2e2f5da 100644
--- a/lib/Support/TargetCompilerConfigs.cpp
+++ b/lib/ExecutionEngine/TargetCompilerConfigs.cpp
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-#include "bcc/Support/TargetCompilerConfigs.h"
+#include "TargetCompilerConfigs.h"
 
 using namespace bcc;
 
diff --git a/lib/ExecutionEngine/TargetCompilerConfigs.h b/lib/ExecutionEngine/TargetCompilerConfigs.h
new file mode 100644
index 0000000..bf10a7a
--- /dev/null
+++ b/lib/ExecutionEngine/TargetCompilerConfigs.h
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2012, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef BCC_EXECUTION_ENGINE_TARGET_COMPILER_CONFIGS_H
+#define BCC_EXECUTION_ENGINE_TARGET_COMPILER_CONFIGS_H
+
+#include "CompilerConfig.h"
+#include "Config.h"
+
+namespace bcc {
+
+//===----------------------------------------------------------------------===//
+// ARM
+//===----------------------------------------------------------------------===//
+#if defined(PROVIDE_ARM_CODEGEN)
+class ARMCompilerConfig : public CompilerConfig {
+private:
+  bool mEnableNEON;
+
+  static void GetFeatureVector(std::vector<std::string> &pAttributes,
+                               bool pEnableNEON);
+
+public:
+  ARMCompilerConfig();
+
+  // Return true if config has been changed after returning from this function.
+  bool enableNEON(bool pEnable = true);
+};
+#endif // defined(PROVIDE_ARM_CODEGEN)
+
+//===----------------------------------------------------------------------===//
+// MIPS
+//===----------------------------------------------------------------------===//
+#if defined(PROVIDE_MIPS_CODEGEN)
+class MipsCompilerConfig : public CompilerConfig {
+public:
+  MipsCompilerConfig() : CompilerConfig(DEFAULT_MIPS_TRIPLE_STRING) {}
+};
+#endif // defined(PROVIDE_MIPS_CODEGEN)
+
+//===----------------------------------------------------------------------===//
+// X86 and X86_64
+//===----------------------------------------------------------------------===//
+#if defined(PROVIDE_X86_CODEGEN)
+class X86FamilyCompilerConfigBase : public CompilerConfig {
+protected:
+  X86FamilyCompilerConfigBase(const std::string &pTriple)
+    : CompilerConfig(pTriple) {
+    // Disable frame pointer elimination optimization on x86 family.
+    getTargetOptions().NoFramePointerElim = true;
+    return;
+  }
+};
+
+class X86_32CompilerConfig : public X86FamilyCompilerConfigBase {
+public:
+  X86_32CompilerConfig() :
+      X86FamilyCompilerConfigBase(DEFAULT_X86_TRIPLE_STRING) { }
+};
+
+class X86_64CompilerConfig : public X86FamilyCompilerConfigBase {
+public:
+  X86_64CompilerConfig() :
+      X86FamilyCompilerConfigBase(DEFAULT_X86_64_TRIPLE_STRING) {
+    setCodeModel(llvm::CodeModel::Medium);
+  }
+};
+#endif // defined(PROVIDE_X86_CODEGEN)
+
+//===----------------------------------------------------------------------===//
+// Default target
+//===----------------------------------------------------------------------===//
+class DefaultCompilerConfig : public
+#if defined(DEFAULT_ARM_CODEGEN)
+  ARMCompilerConfig
+#elif defined(DEFAULT_MIPS_CODEGEN)
+  MipsCompilerConfig
+#elif defined(DEFAULT_X86_CODEGEN)
+  X86_32CompilerConfig
+#elif defined(DEFAULT_X86_64_CODEGEN)
+  X86_64CompilerConfig
+#else
+#  error "Unsupported Default Target!"
+#endif
+{ };
+
+} // end namespace bcc
+
+#endif // BCC_EXECUTION_ENGINE_TARGET_COMPILER_CONFIGS_H
diff --git a/lib/Core/bcc.cpp b/lib/ExecutionEngine/bcc.cpp
similarity index 97%
rename from lib/Core/bcc.cpp
rename to lib/ExecutionEngine/bcc.cpp
index 071401b..b830ec2 100644
--- a/lib/Core/bcc.cpp
+++ b/lib/ExecutionEngine/bcc.cpp
@@ -17,22 +17,21 @@
 // Bitcode compiler (bcc) for Android:
 //    This is an eager-compilation JIT running on Android.
 
-#include "bcc/bcc.h"
+#include <bcc/bcc.h>
 
 #include <llvm/Support/CodeGen.h>
 
 #include <utils/StopWatch.h>
 
-#include <bcinfo/BitcodeWrapper.h>
-
-#include "bcc/RenderScript/RSExecutable.h"
-#include "bcc/RenderScript/RSScript.h"
-#include "bcc/Source.h"
-#include "bcc/Support/DebugHelper.h"
-#include "bcc/Support/Initialization.h"
-#include "bcc/Support/Sha1Helper.h"
+#include "DebugHelper.h"
+#include "Initialization.h"
+#include "RSExecutable.h"
+#include "RSScript.h"
+#include "Sha1Helper.h"
+#include "Source.h"
 
 #include "bcc_internal.h"
+#include <bcinfo/BitcodeWrapper.h>
 
 using namespace bcc;
 
diff --git a/lib/Core/bcc_internal.h b/lib/ExecutionEngine/bcc_internal.h
similarity index 94%
rename from lib/Core/bcc_internal.h
rename to lib/ExecutionEngine/bcc_internal.h
index d7cc2cf..c003d6c 100644
--- a/lib/Core/bcc_internal.h
+++ b/lib/ExecutionEngine/bcc_internal.h
@@ -17,10 +17,10 @@
 #ifndef BCC_INTERNAL_H
 #define BCC_INTERNAL_H
 
-#include "bcc/bcc.h"
+#include <bcc/bcc.h>
 
-#include "bcc/BCCContext.h"
-#include "bcc/RenderScript/RSCompilerDriver.h"
+#include "BCCContext.h"
+#include "RSCompilerDriver.h"
 
 #if defined(__cplusplus)
 
diff --git a/lib/RenderScript/Android.mk b/lib/RenderScript/Android.mk
deleted file mode 100644
index 09c5df0..0000000
--- a/lib/RenderScript/Android.mk
+++ /dev/null
@@ -1,72 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-
-LOCAL_PATH := $(call my-dir)
-
-#=====================================================================
-# Common: libbccRenderScript
-#=====================================================================
-
-libbcc_renderscript_SRC_FILES := \
-  RSCompiler.cpp \
-  RSCompilerDriver.cpp \
-  RSExecutable.cpp \
-  RSForEachExpand.cpp \
-  RSInfo.cpp \
-  RSInfoExtractor.cpp \
-  RSInfoReader.cpp \
-  RSInfoWriter.cpp \
-  RSScript.cpp
-
-#=====================================================================
-# Device Static Library: libbccRenderScript
-#=====================================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libbccRenderScript
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-
-LOCAL_SRC_FILES := $(libbcc_renderscript_SRC_FILES)
-
-include $(LIBBCC_DEVICE_BUILD_MK)
-include $(LIBBCC_GEN_CONFIG_MK)
-include $(LLVM_DEVICE_BUILD_MK)
-include $(BUILD_STATIC_LIBRARY)
-
-
-#=====================================================================
-# Host Static Library: libbccRenderScript
-#=====================================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libbccRenderScript
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-LOCAL_IS_HOST_MODULE := true
-
-LOCAL_SRC_FILES := $(libbcc_renderscript_SRC_FILES)
-
-include $(LIBBCC_HOST_BUILD_MK)
-include $(LIBBCC_GEN_CONFIG_MK)
-include $(LLVM_HOST_BUILD_MK)
-include $(BUILD_HOST_STATIC_LIBRARY)
-
-# Build RenderScript runtime (libclcore.bc)
-include $(LOCAL_PATH)/runtime/Android.mk
diff --git a/lib/RenderScript/runtime/clamp.ll b/lib/RenderScript/runtime/clamp.ll
deleted file mode 100644
index f4d58ec..0000000
--- a/lib/RenderScript/runtime/clamp.ll
+++ /dev/null
@@ -1,16 +0,0 @@
-target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:64:128-a0:0:64-n32-S64"
-target triple = "armv7-none-linux-gnueabi"
-
-define i32 @_Z7rsClampjjj(i32 %amount, i32 %low, i32 %high) nounwind readnone alwaysinline {
-  %1 = icmp ult i32 %amount, %low
-  br i1 %1, label %5, label %2
-
-; <label>:2                                       ; preds = %0
-  %3 = icmp ugt i32 %amount, %high
-  %4 = select i1 %3, i32 %high, i32 %amount
-  br label %5
-
-; <label>:5                                       ; preds = %2, %0
-  %6 = phi i32 [ %4, %2 ], [ %low, %0 ]
-  ret i32 %6
-}
diff --git a/lib/RenderScript/runtime/Android.mk b/lib/ScriptCRT/Android.mk
similarity index 100%
rename from lib/RenderScript/runtime/Android.mk
rename to lib/ScriptCRT/Android.mk
diff --git a/lib/RenderScript/runtime/build_clcore.sh b/lib/ScriptCRT/build_clcore.sh
similarity index 100%
rename from lib/RenderScript/runtime/build_clcore.sh
rename to lib/ScriptCRT/build_clcore.sh
diff --git a/lib/RenderScript/runtime/convert.ll b/lib/ScriptCRT/convert.ll
similarity index 100%
rename from lib/RenderScript/runtime/convert.ll
rename to lib/ScriptCRT/convert.ll
diff --git a/lib/RenderScript/runtime/matrix.ll b/lib/ScriptCRT/matrix.ll
similarity index 100%
rename from lib/RenderScript/runtime/matrix.ll
rename to lib/ScriptCRT/matrix.ll
diff --git a/lib/RenderScript/runtime/pixel_packing.ll b/lib/ScriptCRT/pixel_packing.ll
similarity index 100%
rename from lib/RenderScript/runtime/pixel_packing.ll
rename to lib/ScriptCRT/pixel_packing.ll
diff --git a/lib/RenderScript/runtime/rs_allocation.c b/lib/ScriptCRT/rs_allocation.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_allocation.c
rename to lib/ScriptCRT/rs_allocation.c
diff --git a/lib/RenderScript/runtime/rs_cl.c b/lib/ScriptCRT/rs_cl.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_cl.c
rename to lib/ScriptCRT/rs_cl.c
diff --git a/lib/RenderScript/runtime/rs_core.c b/lib/ScriptCRT/rs_core.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_core.c
rename to lib/ScriptCRT/rs_core.c
diff --git a/lib/RenderScript/runtime/rs_element.c b/lib/ScriptCRT/rs_element.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_element.c
rename to lib/ScriptCRT/rs_element.c
diff --git a/lib/RenderScript/runtime/rs_mesh.c b/lib/ScriptCRT/rs_mesh.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_mesh.c
rename to lib/ScriptCRT/rs_mesh.c
diff --git a/lib/RenderScript/runtime/rs_program.c b/lib/ScriptCRT/rs_program.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_program.c
rename to lib/ScriptCRT/rs_program.c
diff --git a/lib/RenderScript/runtime/rs_sample.c b/lib/ScriptCRT/rs_sample.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_sample.c
rename to lib/ScriptCRT/rs_sample.c
diff --git a/lib/RenderScript/runtime/rs_sampler.c b/lib/ScriptCRT/rs_sampler.c
similarity index 100%
rename from lib/RenderScript/runtime/rs_sampler.c
rename to lib/ScriptCRT/rs_sampler.c
diff --git a/lib/RenderScript/runtime/rs_structs.h b/lib/ScriptCRT/rs_structs.h
similarity index 100%
rename from lib/RenderScript/runtime/rs_structs.h
rename to lib/ScriptCRT/rs_structs.h
diff --git a/lib/Support/Android.mk b/lib/Support/Android.mk
deleted file mode 100644
index 4bafba7..0000000
--- a/lib/Support/Android.mk
+++ /dev/null
@@ -1,71 +0,0 @@
-#
-# Copyright (C) 2012 The Android Open Source Project
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#      http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-#
-#
-
-LOCAL_PATH := $(call my-dir)
-
-#=====================================================================
-# Common: libbccSupport
-#=====================================================================
-
-libbcc_support_SRC_FILES := \
-  sha1.c \
-  CompilerConfig.cpp \
-  FileBase.cpp \
-  Initialization.cpp \
-  InputFile.cpp \
-  OutputFile.cpp \
-  Sha1Helper.cpp \
-  TargetCompilerConfigs.cpp
-
-ifeq ($(libbcc_USE_DISASSEMBLER),1)
-libbcc_support_SRC_FILES += Disassembler.cpp
-endif
-
-#=====================================================================
-# Device Static Library: libbccSupport
-#=====================================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libbccSupport
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-
-LOCAL_SRC_FILES := $(libbcc_support_SRC_FILES)
-
-include $(LIBBCC_DEVICE_BUILD_MK)
-include $(LIBBCC_GEN_CONFIG_MK)
-include $(LLVM_DEVICE_BUILD_MK)
-include $(BUILD_STATIC_LIBRARY)
-
-
-#=====================================================================
-# Host Static Library: libbccSupport
-#=====================================================================
-
-include $(CLEAR_VARS)
-
-LOCAL_MODULE := libbccSupport
-LOCAL_MODULE_TAGS := optional
-LOCAL_MODULE_CLASS := STATIC_LIBRARIES
-
-LOCAL_SRC_FILES := $(libbcc_support_SRC_FILES)
-
-include $(LIBBCC_HOST_BUILD_MK)
-include $(LIBBCC_GEN_CONFIG_MK)
-include $(LLVM_HOST_BUILD_MK)
-include $(BUILD_HOST_STATIC_LIBRARY)
diff --git a/lib/Support/sha1.c b/lib/Support/sha1.c
deleted file mode 100644
index e7d9f81..0000000
--- a/lib/Support/sha1.c
+++ /dev/null
@@ -1,534 +0,0 @@
-/* This file is derived from libdex project */
-
-/*
- * Tweaked in various ways for Google/Android:
- *  - Changed from .cpp to .c.
- *  - Made argument to SHA1Update a const pointer, and enabled
- *    SHA1HANDSOFF.  This incurs a speed penalty but prevents us from
- *    trashing the input.
- *  - Include <endian.h> to get endian info.
- *  - Split a small piece into a header file.
- */
-
-/*
-sha1sum: inspired by md5sum.
-
-SHA-1 in C
-By Steve Reid <steve@edmweb.com>
-100% Public Domain
-
------------------
-Modified 7/98
-By James H. Brown <jbrown@burgoyne.com>
-Still 100% Public Domain
-
-bit machines
-Routine SHA1Update changed from
-    void SHA1Update(SHA1_CTX* context, unsigned char* data,
-      unsigned int len)
-to
-    void SHA1Update(SHA1_CTX* context, unsigned char* data,
-      unsigned long len)
-
-The 'len' parameter was declared an int which works fine on 32
-bit machines. However, on 16 bit machines an int is too small
-for the shifts being done against it.  This caused the hash
-function to generate incorrect values if len was greater than
-8191 (8K - 1) due to the 'len << 3' on line 3 of SHA1Update().
-
-Since the file IO in main() reads 16K at a time, any file 8K or
-larger would be guaranteed to generate the wrong hash (e.g.
-Test Vector #3, a million "a"s).
-
-I also changed the declaration of variables i & j in SHA1Update
-to unsigned long from unsigned int for the same reason.
-
-These changes should make no difference to any 32 bit
-implementations since an int and a long are the same size in
-those environments.
-
---
-I also corrected a few compiler warnings generated by Borland
-C.
-1. Added #include <process.h> for exit() prototype
-2. Removed unused variable 'j' in SHA1Final
-3. Changed exit(0) to return(0) at end of main.
-
-ALL changes I made can be located by searching for comments
-containing 'JHB'
-
------------------
-Modified 13 August 2000
-By Michael Paul Johnson <mpj@cryptography.org>
-Still 100% Public Domain
-
-Changed command line syntax, added feature to automatically
-check files against their previous SHA-1 check values, kind of
-like md5sum does. Added functions hexval, verifyfile,
-and sha1file. Rewrote main().
------------------
-
-Test Vectors (from FIPS PUB 180-1)
-"abc"
-  A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
-"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
-  84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
-A million repetitions of "a"
-  34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
-*/
-
-#define SHA1HANDSOFF    /*Copies data before messing with it.*/
-
-/*#define CMDLINE        * include main() and file processing */
-//#ifdef CMDLINE
-//# undef CMDLINE         /* Never include main() for libbcc */
-//#endif
-
-#include "sha1.h"
-
-#include <stdio.h>
-#include <string.h>
-#ifdef __BORLANDC__
-#include <dir.h>
-#include <dos.h>
-#include <process.h>   /*  prototype for exit() - JHB
-               needed for Win32, but chokes Linux - MPJ */
-#define X_LITTLE_ENDIAN /* This should be #define'd if true.*/
-#else
-# define X_LITTLE_ENDIAN
-# include <unistd.h>
-# include <stdlib.h>
-#endif
-#include <ctype.h>
-
-#define LINESIZE 2048
-
-static void SHA1Transform(unsigned long state[5],
-    const unsigned char buffer[64]);
-
-#define rol(value,bits) \
- (((value)<<(bits))|((value)>>(32-(bits))))
-
-/* blk0() and blk() perform the initial expand. */
-/* I got the idea of expanding during the round function from
-   SSLeay */
-#ifdef X_LITTLE_ENDIAN
-#define blk0(i) (block->l[i]=(rol(block->l[i],24)&0xFF00FF00) \
-    |(rol(block->l[i],8)&0x00FF00FF))
-#else
-#define blk0(i) block->l[i]
-#endif
-#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \
-    ^block->l[(i+2)&15]^block->l[i&15],1))
-
-/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */
-#define R0(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk0(i)+0x5A827999+rol(v,5);w=rol(w,30);
-#define R1(v,w,x,y,z,i) z+=((w&(x^y))^y)+blk(i)+0x5A827999+rol(v,5);w=rol(w,30);
-#define R2(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0x6ED9EBA1+rol(v,5);w=rol(w,30);
-#define R3(v,w,x,y,z,i) z+=(((w|x)&y)|(w&x))+blk(i)+0x8F1BBCDC+rol(v,5);w=rol(w,30);
-#define R4(v,w,x,y,z,i) z+=(w^x^y)+blk(i)+0xCA62C1D6+rol(v,5);w=rol(w,30);
-
-
-/* Hash a single 512-bit block. This is the core of the algorithm. */
-
-static void SHA1Transform(unsigned long state[5],
-    const unsigned char buffer[64])
-{
-unsigned long a, b, c, d, e;
-typedef union {
-    unsigned char c[64];
-    unsigned long l[16];
-} CHAR64LONG16;
-CHAR64LONG16* block;
-#ifdef SHA1HANDSOFF
-static unsigned char workspace[64];
-    block = (CHAR64LONG16*)workspace;
-    memcpy(block, buffer, 64);
-#else
-    block = (CHAR64LONG16*)buffer;
-#endif
-    /* Copy context->state[] to working vars */
-    a = state[0];
-    b = state[1];
-    c = state[2];
-    d = state[3];
-    e = state[4];
-    /* 4 rounds of 20 operations each. Loop unrolled. */
-    R0(a,b,c,d,e, 0); R0(e,a,b,c,d, 1); R0(d,e,a,b,c, 2);
-    R0(c,d,e,a,b, 3); R0(b,c,d,e,a, 4); R0(a,b,c,d,e, 5);
-    R0(e,a,b,c,d, 6); R0(d,e,a,b,c, 7); R0(c,d,e,a,b, 8);
-    R0(b,c,d,e,a, 9); R0(a,b,c,d,e,10); R0(e,a,b,c,d,11);
-    R0(d,e,a,b,c,12); R0(c,d,e,a,b,13); R0(b,c,d,e,a,14);
-    R0(a,b,c,d,e,15); R1(e,a,b,c,d,16); R1(d,e,a,b,c,17);
-    R1(c,d,e,a,b,18); R1(b,c,d,e,a,19); R2(a,b,c,d,e,20);
-    R2(e,a,b,c,d,21); R2(d,e,a,b,c,22); R2(c,d,e,a,b,23);
-    R2(b,c,d,e,a,24); R2(a,b,c,d,e,25); R2(e,a,b,c,d,26);
-    R2(d,e,a,b,c,27); R2(c,d,e,a,b,28); R2(b,c,d,e,a,29);
-    R2(a,b,c,d,e,30); R2(e,a,b,c,d,31); R2(d,e,a,b,c,32);
-    R2(c,d,e,a,b,33); R2(b,c,d,e,a,34); R2(a,b,c,d,e,35);
-    R2(e,a,b,c,d,36); R2(d,e,a,b,c,37); R2(c,d,e,a,b,38);
-    R2(b,c,d,e,a,39); R3(a,b,c,d,e,40); R3(e,a,b,c,d,41);
-    R3(d,e,a,b,c,42); R3(c,d,e,a,b,43); R3(b,c,d,e,a,44);
-    R3(a,b,c,d,e,45); R3(e,a,b,c,d,46); R3(d,e,a,b,c,47);
-    R3(c,d,e,a,b,48); R3(b,c,d,e,a,49); R3(a,b,c,d,e,50);
-    R3(e,a,b,c,d,51); R3(d,e,a,b,c,52); R3(c,d,e,a,b,53);
-    R3(b,c,d,e,a,54); R3(a,b,c,d,e,55); R3(e,a,b,c,d,56);
-    R3(d,e,a,b,c,57); R3(c,d,e,a,b,58); R3(b,c,d,e,a,59);
-    R4(a,b,c,d,e,60); R4(e,a,b,c,d,61); R4(d,e,a,b,c,62);
-    R4(c,d,e,a,b,63); R4(b,c,d,e,a,64); R4(a,b,c,d,e,65);
-    R4(e,a,b,c,d,66); R4(d,e,a,b,c,67); R4(c,d,e,a,b,68);
-    R4(b,c,d,e,a,69); R4(a,b,c,d,e,70); R4(e,a,b,c,d,71);
-    R4(d,e,a,b,c,72); R4(c,d,e,a,b,73); R4(b,c,d,e,a,74);
-    R4(a,b,c,d,e,75); R4(e,a,b,c,d,76); R4(d,e,a,b,c,77);
-    R4(c,d,e,a,b,78); R4(b,c,d,e,a,79);
-
-    /* Add the working vars back into context.state[] */
-    state[0] += a;
-    state[1] += b;
-    state[2] += c;
-    state[3] += d;
-    state[4] += e;
-    /* Wipe variables */
-/*    a = b = c = d = e = 0; Nice try, but the compiler
-optimizes this out, anyway, and it produces an annoying
-warning. */
-}
-
-
-/* SHA1Init - Initialize new context */
-
-void SHA1Init(SHA1_CTX* context)
-{
-    /* SHA1 initialization constants */
-    context->state[0] = 0x67452301;
-    context->state[1] = 0xEFCDAB89;
-    context->state[2] = 0x98BADCFE;
-    context->state[3] = 0x10325476;
-    context->state[4] = 0xC3D2E1F0;
-    context->count[0] = context->count[1] = 0;
-}
-
-
-/* Run your data through this. */
-
-void SHA1Update(SHA1_CTX* context, const unsigned char* data,
-    unsigned long len)  /* JHB */
-{
-    unsigned long i, j; /* JHB */
-
-    j = (context->count[0] >> 3) & 63;
-    if ((context->count[0] += len << 3) < (len << 3))
-        context->count[1]++;
-    context->count[1] += (len >> 29);
-    if ((j + len) > 63)
-    {
-        memcpy(&context->buffer[j], data, (i = 64-j));
-        SHA1Transform(context->state, context->buffer);
-        for ( ; i + 63 < len; i += 64) {
-            SHA1Transform(context->state, &data[i]);
-        }
-        j = 0;
-    }
-    else
-        i = 0;
-    memcpy(&context->buffer[j], &data[i], len - i);
-}
-
-
-/* Add padding and return the message digest. */
-
-void SHA1Final(unsigned char digest[HASHSIZE], SHA1_CTX*
-context)
-{
-unsigned long i;    /* JHB */
-unsigned char finalcount[8];
-
-    for (i = 0; i < 8; i++)
-    {
-        finalcount[i] = (unsigned char)((context->count[(i>=4?
-            0:1)]>>((3-(i&3))*8))&255);
-        /* Endian independent */
-    }
-    SHA1Update(context, (unsigned char *)"\200", 1);
-    while ((context->count[0] & 504) != 448) {
-        SHA1Update(context, (unsigned char *)"\0", 1);
-    }
-    SHA1Update(context, finalcount, 8);
-    /* Should cause a SHA1Transform() */
-    for (i = 0; i < HASHSIZE; i++) {
-        digest[i] = (unsigned char)
-         ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
-    }
-    /* Wipe variables */
-    memset(context->buffer, 0, 64);
-    memset(context->state, 0, HASHSIZE);
-    memset(context->count, 0, 8);
-    memset(&finalcount, 0, 8);
-#ifdef SHA1HANDSOFF
-    /* make SHA1Transform overwrite it's own static vars */
-    SHA1Transform(context->state, context->buffer);
-#endif
-}
-
-
-
-#ifdef CMDLINE
-
-/* sha1file computes the SHA-1 hash of the named file and puts
-   it in the 20-byte array digest. If fname is NULL, stdin is
-   assumed.
-*/
-void sha1file(char *fname, unsigned char* digest)
-{
-    int bytesread;
-    SHA1_CTX context;
-    unsigned char buffer[16384];
-    FILE* f;
-
-    if (fname)
-    {
-        f = fopen(fname, "rb");
-        if (!f)
-        {
-            fprintf(stderr, "Can't open %s\n", fname);
-            memset(digest, 0, HASHSIZE);
-            return;
-        }
-    }
-    else
-    {
-        f = stdin;
-    }
-    SHA1Init(&context);
-    while (!feof(f))
-    {
-        bytesread = fread(buffer, 1, 16384, f);
-        SHA1Update(&context, buffer, bytesread);
-    }
-    SHA1Final(digest, &context);
-    if (fname)
-        fclose(f);
-}
-
-/* Convert ASCII hexidecimal digit to 4-bit value. */
-unsigned char hexval(char c)
-{
-    unsigned char h;
-
-    c = toupper(c);
-    if (c >= 'A')
-        h = c - 'A' + 10;
-    else
-        h = c - '0';
-    return h;
-}
-
-/* Verify a file created with sha1sum by redirecting output
-   to a file. */
-int verifyfile(char *fname)
-{
-    int j, k;
-    int found = 0;
-    unsigned char digest[HASHSIZE];
-    unsigned char expected_digest[HASHSIZE];
-    FILE *checkfile;
-    char checkline[LINESIZE];
-    char *s;
-    unsigned char err;
-
-    checkfile = fopen(fname, "rt");
-    if (!checkfile)
-    {
-        fprintf(stderr, "Can't open %s\n", fname);
-        return(0);
-    }
-    do
-    {
-        s = fgets(checkline, LINESIZE, checkfile);
-        if (s)
-        {
-            if ((strlen(checkline)>26)&&
-                1 /*(!strncmp(checkline,"SHA1=", 5))*/)
-            {
-                /* Overwrite newline. */
-                checkline[strlen(checkline)-1]=0;
-                found = 1;
-
-                /* Read expected check value. */
-                for (k=0, j=5; k < HASHSIZE; k++)
-                {
-                    expected_digest[k]=hexval(checkline[j++]);
-                    expected_digest[k]=(expected_digest[k]<<4)
-                        +hexval(checkline[j++]);
-                }
-
-                /* Compute fingerprints */
-                s = checkline+46;
-                sha1file(s, digest);
-
-                /* Compare fingerprints */
-                err = 0;
-                for (k=0; k<HASHSIZE; k++)
-                    err |= digest[k]-
-                        expected_digest[k];
-                if (err)
-                {
-                    fprintf(stderr, "FAILED: %s\n"
-                        " EXPECTED: ", s);
-                    for (k=0; k<HASHSIZE; k++)
-                        fprintf(stderr, "%02X",
-                            expected_digest[k]);
-                    fprintf(stderr,"\n    FOUND: ");
-                    for (k=0; k<HASHSIZE; k++)
-                        fprintf(stderr, "%02X", digest[k]);
-                    fprintf(stderr, "\n");
-                }
-                else
-                {
-                    printf("OK: %s\n", s);
-                }
-            }
-        }
-    } while (s);
-    return found;
-}
-
-
-
-void syntax(char *progname)
-{
-    printf("\nsyntax:\n"
-     "%s [-c|-h][-q] file name[s]\n"
-     "    -c = check files against previous check values\n"
-     "    -g = generate SHA-1 check values (default action)\n"
-     "    -h = display this help\n"
-     "For example,\n"
-     "sha1sum test.txt > check.txt\n"
-     "generates check value for test.txt in check.txt, and\n"
-     "sha1sum -c check.txt\n"
-     "checks test.txt against the check value in check.txt\n",
-     progname);
-    exit(1);
-}
-
-
-/**********************************************************/
-
-int main(int argc, char** argv)
-{
-    int i, j, k;
-    int check = 0;
-    int found = 0;
-    unsigned char digest[HASHSIZE];
-    unsigned char expected_digest[HASHSIZE];
-    FILE *checkfile;
-    char checkline[LINESIZE];
-    char *s;
-#ifdef __BORLANDC__
-    struct ffblk f;
-    int done;
-    char path[MAXPATH];
-    char drive[MAXDRIVE];
-    char dir[MAXDIR];
-    char name[MAXFILE];
-    char ext[MAXEXT];
-#endif
-    unsigned char err;
-    const char *binary_output_file = 0;
-
-    for (i = 1; i < argc; i++)
-    {
-        if (argv[i][0] == '-')
-        {
-            switch (argv[i][1])
-            {
-                case 'B':
-                    ++i;
-                    binary_output_file = argv[i];
-                    break;
-                case 'c':
-                case 'C':
-                    check = 1;
-                    break;
-                case 'g':
-                case 'G':
-                    check = 0;
-                    break;
-                default:
-                    syntax(argv[0]);
-            }
-        }
-    }
-
-    // Read from STDIN
-    sha1file(NULL, digest);
-    if (binary_output_file) {
-      FILE *fout = fopen(binary_output_file, "wb");
-      if (!fout) {
-        fprintf(stderr, "Error: Can not write to %s.\n", binary_output_file);
-        return 1;
-      }
-      fwrite(digest, 1, HASHSIZE, fout);
-      fclose(fout);
-      return 0;
-    }
-    for (j = 0; j < HASHSIZE; j++)
-        printf("%02x", digest[j]);
-    return 0;
-
-    for (i=1; i<argc; i++)
-    {
-        if (argv[i][0] != '-')
-        {
-#ifdef __BORLANDC__
-            fnsplit(argv[i], drive, dir, name, ext);
-            done = findfirst(argv[i], &f, FA_RDONLY |
-                FA_HIDDEN|FA_SYSTEM|FA_ARCH);
-             while (!done)
-            {
-                sprintf(path, "%s%s%s", drive, dir, f.ff_name);
-                s = path;
-#else
-                s = argv[i];
-#endif
-
-                if (check)
-                {   /* Check fingerprint file. */
-                    found |= verifyfile(s);
-                }
-                else
-                {   /* Generate fingerprints & write to
-                       stdout. */
-                    sha1file(s, digest);
-                    //printf("SHA1=");
-                    for (j=0; j<HASHSIZE; j++)
-                        printf("%02x", digest[j]);
-                    printf("  %s\n", s);
-                    found = 1;
-                }
-
-#ifdef __BORLANDC__
-                done = findnext(&f);
-            }
-#endif
-
-        }
-    }
-    if (!found)
-    {
-        if (check)
-        {
-            fprintf(stderr,
-                "No SHA1 lines found in %s\n",
-                argv[i]);
-        }
-        else
-        {
-            fprintf(stderr, "No files checked.\n");
-            syntax(argv[0]);
-        }
-    }
-    return(0);  /* JHB */
-}
-
-#endif  /*CMDLINE*/
diff --git a/lib/Support/sha1.h b/lib/Support/sha1.h
deleted file mode 100644
index 2de1416..0000000
--- a/lib/Support/sha1.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * See "sha1.c" for author info.
- */
-#ifndef _DALVIK_SHA1
-#define _DALVIK_SHA1
-
-typedef struct {
-    unsigned long state[5];
-    unsigned long count[2];
-    unsigned char buffer[64];
-} SHA1_CTX;
-
-#define HASHSIZE 20
-
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
-void SHA1Init(SHA1_CTX* context);
-void SHA1Update(SHA1_CTX* context, const unsigned char* data,
-    unsigned long len);
-void SHA1Final(unsigned char digest[HASHSIZE], SHA1_CTX* context);
-
-#if defined(__cplusplus)
-}
-#endif
-
-#endif /*_DALVIK_SHA1*/