Add a dumpBitcode() method to facilitate debugging. Change-Id: I300bc9cf9f06c315c053cb302fdf33a9ca899972
diff --git a/rsScriptC.cpp b/rsScriptC.cpp index 6255b44..71761f1 100644 --- a/rsScriptC.cpp +++ b/rsScriptC.cpp
@@ -242,6 +242,44 @@ rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len); } +static const bool kDebugBitcode = false; + +#ifndef RS_COMPATIBILITY_LIB +#ifndef ANDROID_RS_SERIALIZE + +static bool dumpBitcodeFile(const char *cacheDir, const char *resName, + const char *suffix, const uint8_t *bitcode, + size_t bitcodeLen) { + std::string f(cacheDir); + f.append("/"); + f.append(resName); + f.append("#"); + f.append(suffix); + f.append(".bc"); + + if (!ScriptC::createCacheDir(cacheDir)) { + return false; + } + + FILE *fp = fopen(f.c_str(), "w"); + if (!fp) { + ALOGE("Could not open %s", f.c_str()); + return false; + } + + size_t nWritten = fwrite(bitcode, 1, bitcodeLen, fp); + fclose(fp); + if (nWritten != bitcodeLen) { + ALOGE("Could not write %s", f.c_str()); + return false; + } + return true; +} + +#endif // !ANDROID_RS_SERIALIZE +#endif // !RS_COMPATIBILITY_LIB + + bool ScriptC::runCompiler(Context *rsc, const char *resName, const char *cacheDir, @@ -282,6 +320,12 @@ bitcode = (const uint8_t *) BT->getTranslatedBitcode(); bitcodeLen = BT->getTranslatedBitcodeSize(); + if (kDebugBitcode) { + if (!dumpBitcodeFile(cacheDir, resName, "after", bitcode, bitcodeLen)) { + return false; + } + } + #endif if (!cacheDir) { // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
diff --git a/rsScriptC.h b/rsScriptC.h index 86de5b2..e2a6c7c 100644 --- a/rsScriptC.h +++ b/rsScriptC.h
@@ -61,14 +61,14 @@ //protected: void setupScript(Context *); void setupGLState(Context *); + +#if !defined(RS_COMPATIBILITY_LIB) + static bool createCacheDir(const char *cacheDir); +#endif private: #if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE) bcinfo::BitcodeTranslator *BT; #endif - -#if !defined(RS_COMPATIBILITY_LIB) - bool createCacheDir(const char *cacheDir); -#endif }; }