Revert "Migrate to use new libbcc APIs."

This reverts commit 187673e91a83c961078367a2777e7114cc5c734f.
diff --git a/src/pixelflinger2/pixelflinger2.h b/src/pixelflinger2/pixelflinger2.h
index 3be7fd9..b7f3046 100644
--- a/src/pixelflinger2/pixelflinger2.h
+++ b/src/pixelflinger2/pixelflinger2.h
@@ -62,9 +62,9 @@
 #  define MAX2(a, b) ((a) > (b) ? (a) : (b))
 #endif
 
-namespace bcc
+namespace llvm
 {
-class BCCContext;
+class LLVMContext;
 };
 
 #if !USE_LLVM_SCANLINE
@@ -88,7 +88,7 @@
    GGLSurface depthSurface;
    GGLSurface stencilSurface;
 
-   bcc::BCCContext * bccCtx;
+   llvm::LLVMContext * llvmCtx;
 
    struct {
       int depth; // assuming ieee 754 32 bit float and 32 bit 2's complement int; z_32
diff --git a/src/pixelflinger2/shader.cpp b/src/pixelflinger2/shader.cpp
index 7e01bd5..e5277d8 100644
--- a/src/pixelflinger2/shader.cpp
+++ b/src/pixelflinger2/shader.cpp
@@ -22,18 +22,9 @@
 
 #include <llvm/LLVMContext.h>
 #include <llvm/Module.h>
-#include <llvm/Support/raw_ostream.h>
+#include <bcc/bcc.h>
 #include <dlfcn.h>
 
-#include <bcc/BCCContext.h>
-#include <bcc/Compiler.h>
-#include <bcc/ExecutionEngine/ObjectLoader.h>
-#include <bcc/ExecutionEngine/SymbolResolvers.h>
-#include <bcc/Script.h>
-#include <bcc/Source.h>
-#include <bcc/Support/Initialization.h>
-#include <bcc/Support/TargetCompilerConfigs.h>
-
 
 #include "src/talloc/hieralloc.h"
 #include "src/mesa/main/shaderobj.h"
@@ -116,13 +107,15 @@
 };
 
 struct Instance {
-   bcc::Script * script;
-   llvm::SmallVector<char, 1024> resultObj;
-   bcc::ObjectLoader * exec;
+   llvm::Module * module;
+   struct BCCOpaqueScript * script;
    void (* function)();
    ~Instance() {
-      delete script;
-      delete exec;
+      // TODO: check bccDisposeScript, which seems to dispose llvm::Module
+      if (script)
+         bccDisposeScript(script);
+      else if (module)
+         delete module;
    }
 };
 
@@ -393,45 +386,31 @@
 static void CodeGen(Instance * instance, const char * mainName, gl_shader * shader,
                     gl_shader_program * program, const GGLState * gglCtx)
 {
-   bcc::Compiler compiler;
-   bcc::Compiler::ErrorCode compile_result;
-   llvm::raw_svector_ostream out(instance->resultObj);
+   SymbolLookupContext ctx = {gglCtx, program, shader};
+   int result = 0;
 
 //   instance->module->dump();
 
-   compile_result = compiler.config(bcc::DefaultCompilerConfig());
-   if (compile_result != bcc::Compiler::kSuccess) {
-      ALOGD("failed config compiler (%s)", bcc::Compiler::GetErrorString(compile_result));
+   BCCScriptRef & script = instance->script;
+   script = bccCreateScript();
+   result = bccReadModule(script, "glsl", (LLVMModuleRef)instance->module, 0);
+   assert(0 == result);
+   result = bccRegisterSymbolCallback(script, SymbolLookup, &ctx);
+   assert(0 == result);
+   result = bccPrepareExecutable(script, NULL, NULL, 0);
+
+   result = bccGetError(script);
+   if (result != 0) {
+      ALOGD("failed bcc_compile");
       assert(0);
       return;
    }
 
-   compiler.enableLTO(/* pEnable */false); // Disable LTO passes execution.
-
-   compile_result = compiler.compile(*instance->script, out);
-   if (compile_result != bcc::Compiler::kSuccess) {
-      ALOGD("failed to compile (%s)", bcc::Compiler::GetErrorString(compile_result));
-      assert(0);
-      return;
-   }
-
-   SymbolLookupContext ctx = {gglCtx, program, shader};
-   bcc::LookupFunctionSymbolResolver<void*> resolver(SymbolLookup, &ctx);
-
-   instance->exec = bcc::ObjectLoader::Load(instance->resultObj.begin(), instance->resultObj.size(),
-                                            /* pName */"glsl", resolver, /* pEnableGDBDebug */false);
-
-   if (!instance->exec) {
-      ALOGD("failed to load the result object");
-      assert(0);
-      return;
-   }
-
-   instance->function = reinterpret_cast<void (*)()>(instance->exec->getSymbolAddress(mainName));
+   instance->function = (void (*)())bccGetFuncAddr(script, mainName);
    assert(instance->function);
-   if (!instance->function) {
-      ALOGD("Could not find '%s'\n", mainName);
-   }
+   result = bccGetError(script);
+   if (result != BCC_NO_ERROR)
+      ALOGD("Could not find '%s': %d\n", mainName, result);
 //   else
 //      printf("bcc_compile %s=%p \n", mainName, instance->function);
 
@@ -441,7 +420,7 @@
 void GenerateScanLine(const GGLState * gglCtx, const gl_shader_program * program, llvm::Module * mod,
                       const char * shaderName, const char * scanlineName);
 
-void GGLShaderUse(void * bccCtx, const GGLState * gglState, gl_shader_program * program)
+void GGLShaderUse(void * llvmCtx, const GGLState * gglState, gl_shader_program * program)
 {
 //   ALOGD("%s", program->Shaders[MESA_SHADER_FRAGMENT]->Source);
    for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
@@ -457,12 +436,10 @@
       ShaderKey shaderKey;
       GetShaderKey(gglState, shader, &shaderKey);
       Instance * instance = shader->executable->instances[shaderKey];
-      bcc::BCCContext * compilerCtx = reinterpret_cast<bcc::BCCContext *>(bccCtx);
       if (!instance) {
 //         puts("begin jit new shader");
          instance = hieralloc_zero(shader->executable, Instance);
-
-         llvm::Module * module = new llvm::Module("glsl", compilerCtx->getLLVMContext());
+         instance->module = new llvm::Module("glsl", *(llvm::LLVMContext *)llvmCtx);
 
          char shaderName [SHADER_KEY_STRING_LEN] = {0};
          GetShaderKeyString(shader->Type, &shaderKey, shaderName, sizeof shaderName / sizeof *shaderName);
@@ -491,20 +468,9 @@
 //         }
 //         fclose(file);
 //#endif
-         if (!glsl_ir_to_llvm_module(shader->ir, module, gglState, shaderName)) {
+         llvm::Module * module = glsl_ir_to_llvm_module(shader->ir, instance->module, gglState, shaderName);
+         if (!module)
             assert(0);
-            delete module;
-         }
-         bcc::Source * source = bcc::Source::CreateFromModule(*compilerCtx, *module);
-         if (!source) {
-            delete module;
-            assert(0);
-         }
-         instance->script = new bcc::Script(*source);
-         if (!instance->script) {
-            delete source;
-            assert(0);
-         }
 //#ifdef __arm__
 //         static const char fileName[] = "/data/pf2.txt";
 //         FILE * file = freopen(fileName, "w", stderr);
@@ -581,7 +547,7 @@
       return;
    }
 
-   GGLShaderUse(ctx->bccCtx, &ctx->state, program);
+   GGLShaderUse(ctx->llvmCtx, &ctx->state, program);
    for (unsigned i = 0; i < MESA_SHADER_TYPES; i++) {
       if (!program->_LinkedShaders[i])
          continue;
@@ -967,9 +933,7 @@
 void InitializeShaderFunctions(struct GGLInterface * iface)
 {
    GGL_GET_CONTEXT(ctx, iface);
-   bcc::init::Initialize();
-
-   ctx->bccCtx = new bcc::BCCContext();
+   ctx->llvmCtx = new llvm::LLVMContext();
 
    iface->ShaderCreate = ShaderCreate;
    iface->ShaderSource = GGLShaderSource;
@@ -1001,6 +965,6 @@
    GGL_GET_CONTEXT(ctx, iface);
    _mesa_glsl_release_types();
    _mesa_glsl_release_functions();
-   delete ctx->bccCtx;
-   ctx->bccCtx = NULL;
+   delete ctx->llvmCtx;
+   ctx->llvmCtx = NULL;
 }