Add BCCContext.

Convention:
  * namespace bcc {
    /* no space here */class [ClassName] {
      ...
    };

    } // end namespace bcc
  * Instance variables are prefixed with "m";
  * Class variable/method are captialized;
  * Local variables in the function are in lower case with underscore;
  * Parameters to the function are prefixed with "p";
  * Include guard in the header will look like
    #ifndef BCC_<sub folder>_<class>_H
  * The order of implementation in .cpp is in the order of their
    declaration with the following constraints:
    i.   Class methods go first
    ii.  Recursively apply this rule to the sub-class
    iii. Then the constructor and destructor of the class
    iv.  And then the instance methods
  * The order of includes in Foo.cpp should be:
    i.   Foo.h should always go first
    ii.  C headers
    iii. C++ headers
    iv.  LLVM headers
    iv.  Other headers from the project other than libbcc and Android
         frameworks (i.e., f/b/include/utils/)
    v.   Header files defined in libbcc
    vi.  Header files from Android frameworks (f/b/include/utils/)

    Android frameworks should be included in the last since it
    implicitly includes cutils/log.h which may cause LOG_TAG be
    defined to NULL if no LOG_TAG hasn't been defined ever before
    include it.

  * Avoid including STL and LLVM headers in the BCC headers. Some
    clients (e.g., RenderScript) may prefer not include the C++ STL
    support and don't want to associate with LLVM directly.

BCCContext manages the global data across the libbcc infrastructure.
This includes LLVMContext object required by materialize bitcode into
llvm::Module and LLVM compilation infrastructure.

Furthermore, BCCContext is escalated to be managed in Script instead
of in the SourceInfo.

Change-Id: I60b9da7b5c61f6c684dcf981ba5abaf066e3c883
diff --git a/lib/ExecutionEngine/BCCContext.cpp b/lib/ExecutionEngine/BCCContext.cpp
new file mode 100644
index 0000000..6d0c5b9
--- /dev/null
+++ b/lib/ExecutionEngine/BCCContext.cpp
@@ -0,0 +1,59 @@
+/*
+ * 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.
+ */
+
+#include "BCCContext.h"
+
+#include <new>
+
+#include "BCCContextImpl.h"
+#include "DebugHelper.h"
+
+using namespace bcc;
+
+static BCCContext *GlobalContext = NULL;
+
+BCCContext *BCCContext::GetOrCreateGlobalContext() {
+  if (GlobalContext == NULL) {
+    GlobalContext = new (std::nothrow) BCCContext();
+    if (GlobalContext == NULL) {
+      ALOGE("Out of memory when allocate global BCCContext!");
+    }
+  }
+  return GlobalContext;
+}
+
+void BCCContext::DestroyGlobalContext() {
+  delete GlobalContext;
+  GlobalContext = NULL;
+}
+
+BCCContext::BCCContext() : mImpl(new BCCContextImpl(*this)) { }
+
+BCCContext::~BCCContext() {
+  delete mImpl;
+  if (this == GlobalContext) {
+    // We're deleting the context returned from GetOrCreateGlobalContext().
+    // Reset the GlobalContext.
+    GlobalContext = NULL;
+  }
+  return;
+}
+
+llvm::LLVMContext &BCCContext::getLLVMContext()
+{ return mImpl->mLLVMContext; }
+
+const llvm::LLVMContext &BCCContext::getLLVMContext() const
+{ return mImpl->mLLVMContext; }