Extract getExportVars, getExportFuncs, getPragmas out of Compiler.
diff --git a/lib/bcc/Compiler.cpp b/lib/bcc/Compiler.cpp
index ba3f8aa..41dc020 100644
--- a/lib/bcc/Compiler.cpp
+++ b/lib/bcc/Compiler.cpp
@@ -66,6 +66,7 @@
 #include "Compiler.h"
 
 #include "ContextManager.h"
+#include "ScriptCompiled.h"
 
 #include "llvm/ADT/StringRef.h"
 
@@ -307,8 +308,9 @@
 }
 
 
-Compiler::Compiler()
-  : mUseCache(false),
+Compiler::Compiler(ScriptCompiled *result)
+  : mpResult(result),
+    mUseCache(false),
     mCacheNew(false),
     mCacheFd(-1),
     mCacheMapAddr(NULL),
@@ -359,6 +361,7 @@
   // to decide rather to update the cache or not.
   computeSourceSHA1(bitcode, bitcodeSize);
 
+#if 0
   if (resName && !mCacheLoadFailed) {
     // Turn on mUseCache mode iff
     // 1. Has resName
@@ -380,6 +383,7 @@
       return -mCacheFd - 1;
     }
   }
+#endif
 
   llvm::OwningPtr<llvm::MemoryBuffer> MEM;
 
@@ -971,6 +975,8 @@
 
   // Copy the global address mapping from code emitter and remapping
   if (ExportVarMetadata) {
+    ScriptCompiled::ExportVarList &varList = mpResult->mExportVars;
+
     for (int i = 0, e = ExportVarMetadata->getNumOperands(); i != e; i++) {
       llvm::MDNode *ExportVar = ExportVarMetadata->getOperand(i);
       if (ExportVar != NULL && ExportVar->getNumOperands() > 1) {
@@ -986,7 +992,7 @@
             if (I->first->getValueID() != llvm::Value::GlobalVariableVal)
               continue;
             if (ExportVarName == I->first->getName()) {
-              mExportVars.push_back(I->second);
+              varList.push_back(I->second);
               break;
             }
           }
@@ -996,13 +1002,16 @@
       }
       // if reaching here, we know the global variable record in metadata is
       // not found. So we make an empty slot
-      mExportVars.push_back(NULL);
+      varList.push_back(NULL);
     }
-    assert((mExportVars.size() == ExportVarMetadata->getNumOperands()) &&
+
+    assert((varList.size() == ExportVarMetadata->getNumOperands()) &&
            "Number of slots doesn't match the number of export variables!");
   }
 
   if (ExportFuncMetadata) {
+    ScriptCompiled::ExportFuncList &funcList = mpResult->mExportFuncs;
+
     for (int i = 0, e = ExportFuncMetadata->getNumOperands(); i != e; i++) {
       llvm::MDNode *ExportFunc = ExportFuncMetadata->getOperand(i);
       if (ExportFunc != NULL && ExportFunc->getNumOperands() > 0) {
@@ -1010,7 +1019,7 @@
         if (ExportFuncNameMDS->getValueID() == llvm::Value::MDStringVal) {
           llvm::StringRef ExportFuncName =
             static_cast<llvm::MDString*>(ExportFuncNameMDS)->getString();
-          mExportFuncs.push_back(mCodeEmitter->lookup(ExportFuncName));
+          funcList.push_back(mCodeEmitter->lookup(ExportFuncName));
         }
       }
     }
@@ -1022,7 +1031,9 @@
 
   // Finally, read pragma information from the metadata node of the @Module if
   // any.
-  if (PragmaMetadata)
+  if (PragmaMetadata) {
+    ScriptCompiled::PragmaList &pragmaList = mpResult->mPragmas;
+
     for (int i = 0, e = PragmaMetadata->getNumOperands(); i != e; i++) {
       llvm::MDNode *Pragma = PragmaMetadata->getOperand(i);
       if (Pragma != NULL &&
@@ -1037,7 +1048,7 @@
           llvm::StringRef PragmaValue =
             static_cast<llvm::MDString*>(PragmaValueMDS)->getString();
 
-          mPragmas.push_back(
+          pragmaList.push_back(
             std::make_pair(std::string(PragmaName.data(),
                                        PragmaName.size()),
                            std::string(PragmaValue.data(),
@@ -1045,6 +1056,7 @@
         }
       }
     }
+  }
 
 on_bcc_compile_error:
   // LOGE("on_bcc_compiler_error");
@@ -1089,133 +1101,6 @@
   return addr;
 }
 
-
-// Interface for bccGetExportVars()
-void Compiler::getExportVars(BCCsizei *actualVarCount,
-                             BCCsizei maxVarCount,
-                             BCCvoid **vars) {
-  int varCount;
-
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    varCount = static_cast<int>(mCacheHdr->exportVarsCount);
-    if (actualVarCount)
-      *actualVarCount = varCount;
-    if (varCount > maxVarCount)
-      varCount = maxVarCount;
-    if (vars) {
-      uint32_t *cachedVars = (uint32_t *)(mCacheMapAddr +
-                                          mCacheHdr->exportVarsOffset);
-
-      for (int i = 0; i < varCount; i++) {
-        *vars = (BCCvoid *)((char *)(*cachedVars) + mCacheDiff);
-        vars++;
-        cachedVars++;
-      }
-    }
-    return;
-  }
-
-  varCount = mExportVars.size();
-  if (actualVarCount)
-    *actualVarCount = varCount;
-  if (varCount > maxVarCount)
-    varCount = maxVarCount;
-  if (vars) {
-    for (ExportVarList::const_iterator
-         I = mExportVars.begin(), E = mExportVars.end(); I != E; I++) {
-      *vars++ = *I;
-    }
-  }
-}
-
-
-// Interface for bccGetExportFuncs()
-void Compiler::getExportFuncs(BCCsizei *actualFuncCount,
-                              BCCsizei maxFuncCount,
-                              BCCvoid **funcs) {
-  int funcCount;
-
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    funcCount = static_cast<int>(mCacheHdr->exportFuncsCount);
-    if (actualFuncCount)
-      *actualFuncCount = funcCount;
-    if (funcCount > maxFuncCount)
-      funcCount = maxFuncCount;
-    if (funcs) {
-      uint32_t *cachedFuncs = (uint32_t *)(mCacheMapAddr +
-                                           mCacheHdr->exportFuncsOffset);
-
-      for (int i = 0; i < funcCount; i++) {
-        *funcs = (BCCvoid *)((char *)(*cachedFuncs) + mCacheDiff);
-        funcs++;
-        cachedFuncs++;
-      }
-    }
-    return;
-  }
-
-  funcCount = mExportFuncs.size();
-  if (actualFuncCount)
-    *actualFuncCount = funcCount;
-  if (funcCount > maxFuncCount)
-    funcCount = maxFuncCount;
-  if (funcs) {
-    for (ExportFuncList::const_iterator
-         I = mExportFuncs.begin(), E = mExportFuncs.end(); I != E; I++) {
-      *funcs++ = *I;
-    }
-  }
-}
-
-
-// Interface for bccGetPragmas()
-void Compiler::getPragmas(BCCsizei *actualStringCount,
-                          BCCsizei maxStringCount,
-                          BCCchar **strings) {
-  int stringCount;
-
-  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
-    stringCount = static_cast<int>(mCacheHdr->exportPragmasCount) * 2;
-
-    if (actualStringCount)
-      *actualStringCount = stringCount;
-
-    if (stringCount > maxStringCount)
-      stringCount = maxStringCount;
-
-    if (strings) {
-      char *pragmaTab = mCacheMapAddr + mCacheHdr->exportPragmasOffset;
-
-      oBCCPragmaEntry *cachedPragmaEntries = (oBCCPragmaEntry *)pragmaTab;
-
-      for (int i = 0; stringCount >= 2; stringCount -= 2, i++) {
-        *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaNameOffset;
-        *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaValueOffset;
-      }
-    }
-
-    return;
-  }
-
-  stringCount = mPragmas.size() * 2;
-
-  if (actualStringCount)
-    *actualStringCount = stringCount;
-  if (stringCount > maxStringCount)
-    stringCount = maxStringCount;
-  if (strings) {
-    size_t i = 0;
-    for (PragmaList::const_iterator it = mPragmas.begin();
-         stringCount >= 2; stringCount -= 2, it++, ++i) {
-      *strings++ = const_cast<BCCchar*>(it->first.c_str());
-      *strings++ = const_cast<BCCchar*>(it->second.c_str());
-    }
-  }
-
-  return;
-}
-
-
 // Interface for bccGetFunctions()
 void Compiler::getFunctions(BCCsizei *actualFunctionCount,
                             BCCsizei maxFunctionCount,
@@ -1395,25 +1280,26 @@
 
   // Export Variable Table Offset and Entry Count
   hdr->exportVarsOffset = offset;
-  hdr->exportVarsCount = mExportVars.size();
+  hdr->exportVarsCount = mpResult->mExportVars.size();
 
   offset += hdr->exportVarsCount * sizeof(uint32_t);
 
   // Export Function Table Offset and Entry Count
   hdr->exportFuncsOffset = offset;
-  hdr->exportFuncsCount = mExportFuncs.size();
+  hdr->exportFuncsCount = mpResult->mExportFuncs.size();
 
   offset += hdr->exportFuncsCount * sizeof(uint32_t);
 
   // Export Pragmas Table Offset and Entry Count
   hdr->exportPragmasOffset = offset;
-  hdr->exportPragmasCount = mPragmas.size();
+  hdr->exportPragmasCount = mpResult->mPragmas.size();
   hdr->exportPragmasSize = hdr->exportPragmasCount * sizeof(oBCCPragmaEntry);
 
   offset += hdr->exportPragmasCount * sizeof(oBCCPragmaEntry);
 
-  for (PragmaList::const_iterator
-       I = mPragmas.begin(), E = mPragmas.end(); I != E; ++I) {
+  for (ScriptCompiled::PragmaList::const_iterator
+       I = mpResult->mPragmas.begin(),
+       E = mpResult->mPragmas.end(); I != E; ++I) {
     offset += I->first.size() + 1;
     offset += I->second.size() + 1;
     hdr->exportPragmasSize += I->first.size() + I->second.size() + 2;
@@ -1485,8 +1371,9 @@
       goto bail;
     }
 
-    for (ExportVarList::const_iterator I = mExportVars.begin(),
-         E = mExportVars.end(); I != E; I++) {
+    for (ScriptCompiled::ExportVarList::const_iterator
+         I = mpResult->mExportVars.begin(),
+         E = mpResult->mExportVars.end(); I != E; I++) {
       *ptr++ = reinterpret_cast<uint32_t>(*I);
     }
 
@@ -1508,8 +1395,9 @@
       goto bail;
     }
 
-    for (ExportFuncList::const_iterator I = mExportFuncs.begin(),
-         E = mExportFuncs.end(); I != E; I++) {
+    for (ScriptCompiled::ExportFuncList::const_iterator
+         I = mpResult->mExportFuncs.begin(),
+         E = mpResult->mExportFuncs.end(); I != E; I++) {
       *ptr++ = reinterpret_cast<uint32_t>(*I);
     }
 
@@ -1526,8 +1414,9 @@
     uint32_t pragmaEntryOffset =
       hdr->exportPragmasCount * sizeof(oBCCPragmaEntry);
 
-    for (PragmaList::const_iterator
-         I = mPragmas.begin(), E = mPragmas.end(); I != E; ++I) {
+    for (ScriptCompiled::PragmaList::const_iterator
+         I = mpResult->mPragmas.begin(),
+         E = mpResult->mPragmas.end(); I != E; ++I) {
       oBCCPragmaEntry entry;
 
       entry.pragmaNameOffset = pragmaEntryOffset;
@@ -1542,8 +1431,9 @@
                     "Write export pragma entry");
     }
 
-    for (PragmaList::const_iterator
-         I = mPragmas.begin(), E = mPragmas.end(); I != E; ++I) {
+    for (ScriptCompiled::PragmaList::const_iterator
+         I = mpResult->mPragmas.begin(),
+         E = mpResult->mPragmas.end(); I != E; ++I) {
       sysWriteFully(mCacheFd, I->first.c_str(), I->first.size() + 1,
                     "Write export pragma name string");
       sysWriteFully(mCacheFd, I->second.c_str(), I->second.size() + 1,
diff --git a/lib/bcc/Compiler.h b/lib/bcc/Compiler.h
index 2369f07..cf9623e 100644
--- a/lib/bcc/Compiler.h
+++ b/lib/bcc/Compiler.h
@@ -41,15 +41,10 @@
 
 
 namespace bcc {
+  class ScriptCompiled;
 
   class Compiler {
   private:
-    typedef std::list< std::pair<std::string, std::string> > PragmaList;
-    typedef std::list<void*> ExportVarList;
-    typedef std::list<void*> ExportFuncList;
-
-
-  private:
     //////////////////////////////////////////////////////////////////////////
     // The variable section below (e.g., Triple, CodeGenOptLevel)
     // is initialized in GlobalInitialization()
@@ -84,6 +79,8 @@
 
 
   private:
+    ScriptCompiled *mpResult;
+
     std::string mError;
 
     bool mUseCache;         // Set by readBC()
@@ -99,12 +96,6 @@
 
     unsigned char mSourceSHA1[20];  // Set by readBC()
 
-    PragmaList mPragmas;
-
-    ExportVarList mExportVars;
-
-    ExportFuncList mExportFuncs;
-
     // The memory manager for code emitter
     llvm::OwningPtr<CodeMemoryManager> mCodeMemMgr;
 
@@ -120,7 +111,7 @@
     bool mHasLinked;
 
   public:
-    Compiler();
+    Compiler(ScriptCompiled *result);
 
     // interface for BCCscript::registerSymbolCallback()
     void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
diff --git a/lib/bcc/ScriptCompiled.cpp b/lib/bcc/ScriptCompiled.cpp
new file mode 100644
index 0000000..1611901
--- /dev/null
+++ b/lib/bcc/ScriptCompiled.cpp
@@ -0,0 +1,150 @@
+/*
+ * 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.
+ */
+
+#define LOG_TAG "bcc"
+#include <cutils/log.h>
+
+#include "ScriptCompiled.h"
+
+namespace bcc {
+
+void ScriptCompiled::getExportVars(BCCsizei *actualVarCount,
+                                   BCCsizei maxVarCount,
+                                   BCCvoid **vars) {
+  int varCount;
+
+#if 0
+  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
+    varCount = static_cast<int>(mCacheHdr->exportVarsCount);
+    if (actualVarCount)
+      *actualVarCount = varCount;
+    if (varCount > maxVarCount)
+      varCount = maxVarCount;
+    if (vars) {
+      uint32_t *cachedVars = (uint32_t *)(mCacheMapAddr +
+                                          mCacheHdr->exportVarsOffset);
+
+      for (int i = 0; i < varCount; i++) {
+        *vars = (BCCvoid *)((char *)(*cachedVars) + mCacheDiff);
+        vars++;
+        cachedVars++;
+      }
+    }
+    return;
+  }
+#endif
+
+  varCount = mExportVars.size();
+  if (actualVarCount)
+    *actualVarCount = varCount;
+  if (varCount > maxVarCount)
+    varCount = maxVarCount;
+  if (vars) {
+    for (ExportVarList::const_iterator
+         I = mExportVars.begin(), E = mExportVars.end(); I != E; I++) {
+      *vars++ = *I;
+    }
+  }
+}
+
+
+void ScriptCompiled::getExportFuncs(BCCsizei *actualFuncCount,
+                                    BCCsizei maxFuncCount,
+                                    BCCvoid **funcs) {
+  int funcCount;
+
+#if 0
+  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
+    funcCount = static_cast<int>(mCacheHdr->exportFuncsCount);
+    if (actualFuncCount)
+      *actualFuncCount = funcCount;
+    if (funcCount > maxFuncCount)
+      funcCount = maxFuncCount;
+    if (funcs) {
+      uint32_t *cachedFuncs = (uint32_t *)(mCacheMapAddr +
+                                           mCacheHdr->exportFuncsOffset);
+
+      for (int i = 0; i < funcCount; i++) {
+        *funcs = (BCCvoid *)((char *)(*cachedFuncs) + mCacheDiff);
+        funcs++;
+        cachedFuncs++;
+      }
+    }
+    return;
+  }
+#endif
+
+  funcCount = mExportFuncs.size();
+  if (actualFuncCount)
+    *actualFuncCount = funcCount;
+  if (funcCount > maxFuncCount)
+    funcCount = maxFuncCount;
+  if (funcs) {
+    for (ExportFuncList::const_iterator
+         I = mExportFuncs.begin(), E = mExportFuncs.end(); I != E; I++) {
+      *funcs++ = *I;
+    }
+  }
+}
+
+
+void ScriptCompiled::getPragmas(BCCsizei *actualStringCount,
+                                BCCsizei maxStringCount,
+                                BCCchar **strings) {
+  int stringCount;
+
+#if 0
+  if (mUseCache && mCacheFd >= 0 && !mCacheNew) {
+    stringCount = static_cast<int>(mCacheHdr->exportPragmasCount) * 2;
+
+    if (actualStringCount)
+      *actualStringCount = stringCount;
+
+    if (stringCount > maxStringCount)
+      stringCount = maxStringCount;
+
+    if (strings) {
+      char *pragmaTab = mCacheMapAddr + mCacheHdr->exportPragmasOffset;
+
+      oBCCPragmaEntry *cachedPragmaEntries = (oBCCPragmaEntry *)pragmaTab;
+
+      for (int i = 0; stringCount >= 2; stringCount -= 2, i++) {
+        *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaNameOffset;
+        *strings++ = pragmaTab + cachedPragmaEntries[i].pragmaValueOffset;
+      }
+    }
+
+    return;
+  }
+#endif
+
+  stringCount = mPragmas.size() * 2;
+
+  if (actualStringCount)
+    *actualStringCount = stringCount;
+  if (stringCount > maxStringCount)
+    stringCount = maxStringCount;
+  if (strings) {
+    size_t i = 0;
+    for (PragmaList::const_iterator it = mPragmas.begin();
+         stringCount >= 2; stringCount -= 2, it++, ++i) {
+      *strings++ = const_cast<BCCchar*>(it->first.c_str());
+      *strings++ = const_cast<BCCchar*>(it->second.c_str());
+    }
+  }
+}
+
+} // namespace bcc
diff --git a/lib/bcc/ScriptCompiled.h b/lib/bcc/ScriptCompiled.h
index 03b1fcd..e9c1fa2 100644
--- a/lib/bcc/ScriptCompiled.h
+++ b/lib/bcc/ScriptCompiled.h
@@ -29,13 +29,24 @@
   class Script;
 
   class ScriptCompiled {
+    friend class Compiler;
+
+  private:
+    typedef std::list< std::pair<std::string, std::string> > PragmaList;
+    typedef std::list<void*> ExportVarList;
+    typedef std::list<void*> ExportFuncList;
+
   private:
     Script *mpOwner;
 
     Compiler mCompiler;
 
+    PragmaList mPragmas;
+    ExportVarList mExportVars;
+    ExportFuncList mExportFuncs;
+
   public:
-    ScriptCompiled(Script *owner) : mpOwner(owner) {
+    ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) {
     }
 
     int readBC(const char *bitcode,
@@ -71,21 +82,15 @@
 
     void getExportVars(BCCsizei *actualVarCount,
                        BCCsizei maxVarCount,
-                       BCCvoid **vars) {
-      mCompiler.getExportVars(actualVarCount, maxVarCount, vars);
-    }
+                       BCCvoid **vars);
 
     void getExportFuncs(BCCsizei *actualFuncCount,
                         BCCsizei maxFuncCount,
-                        BCCvoid **funcs) {
-      mCompiler.getExportFuncs(actualFuncCount, maxFuncCount, funcs);
-    }
+                        BCCvoid **funcs);
 
     void getPragmas(BCCsizei *actualStringCount,
                     BCCsizei maxStringCount,
-                    BCCchar **strings) {
-      mCompiler.getPragmas(actualStringCount, maxStringCount, strings);
-    }
+                    BCCchar **strings);
 
     void getFunctions(BCCsizei *actualFunctionCount,
                       BCCsizei maxFunctionCount,