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/SourceInfo.cpp b/lib/ExecutionEngine/SourceInfo.cpp
index c069462..5477514 100644
--- a/lib/ExecutionEngine/SourceInfo.cpp
+++ b/lib/ExecutionEngine/SourceInfo.cpp
@@ -27,7 +27,6 @@
#include <llvm/Bitcode/ReaderWriter.h>
#include <llvm/Module.h>
-#include <llvm/LLVMContext.h>
#include <llvm/ADT/OwningPtr.h>
#include <llvm/ADT/StringRef.h>
#include <llvm/Support/MemoryBuffer.h>
@@ -121,7 +120,7 @@
}
-int SourceInfo::prepareModule(llvm::LLVMContext *context) {
+int SourceInfo::prepareModule(llvm::LLVMContext &context) {
if (module)
return 0;
@@ -157,28 +156,16 @@
break;
}
- if (context)
- shared_context = true;
- else
- context = new llvm::LLVMContext();
-
- module = llvm::ParseBitcodeFile(mem.get(), *context, &errmsg);
+ module = llvm::ParseBitcodeFile(mem.get(), context, &errmsg);
if (module == NULL) {
ALOGE("Unable to ParseBitcodeFile: %s\n", errmsg.c_str());
- if (!shared_context)
- delete context;
}
return (module == NULL);
}
SourceInfo::~SourceInfo() {
- if (module != NULL) {
- llvm::LLVMContext *context = &module->getContext();
- delete module;
- if (!shared_context)
- delete context;
- }
+ delete module;
}
template <typename T> void SourceInfo::introDependency(T &checker) {