Start using bcinfo components within librs.

BUG=4942491

Change-Id: I3a46783511c4954bac9eadbbbefe5abf85498c16
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index e8b1014..dccf71f 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -19,6 +19,10 @@
 #include "utils/Timers.h"
 #include "utils/StopWatch.h"
 
+#ifndef ANDROID_RS_SERIALIZE
+#include <bcinfo/BitcodeTranslator.h>
+#endif
+
 using namespace android;
 using namespace android::renderscript;
 
@@ -28,9 +32,18 @@
     ScriptC * sc = (ScriptC *) tls->mScript
 
 ScriptC::ScriptC(Context *rsc) : Script(rsc) {
+#ifndef ANDROID_RS_SERIALIZE
+    BT = NULL;
+#endif
 }
 
 ScriptC::~ScriptC() {
+#ifndef ANDROID_RS_SERIALIZE
+    if (BT) {
+        delete BT;
+        BT = NULL;
+    }
+#endif
     mRSC->mHal.funcs.script.destroy(mRSC, this);
 }
 
@@ -181,6 +194,22 @@
                           size_t bitcodeLen) {
 
     //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
+#ifndef ANDROID_RS_SERIALIZE
+    uint32_t sdkVersion = rsc->getTargetSdkVersion();
+    if (BT) {
+        delete BT;
+    }
+    BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen,
+                                       sdkVersion);
+    if (!BT->translate()) {
+        LOGE("Failed to translate bitcode from version: %u", sdkVersion);
+        delete BT;
+        BT = NULL;
+        return false;
+    }
+    bitcode = (const uint8_t *) BT->getTranslatedBitcode();
+    bitcodeLen = BT->getTranslatedBitcodeSize();
+#endif
 
     rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0);