Refactoring into Script::internalLoadCache()
Move some duplicate code from prepareRelocatable() and prepareExecutable()
into internalLoadCache().
Change-Id: I32b321ef789217f40f47c0a3783e4b232fdd16ee
diff --git a/lib/ExecutionEngine/Script.cpp b/lib/ExecutionEngine/Script.cpp
index 04bed87..024ac7e 100644
--- a/lib/ExecutionEngine/Script.cpp
+++ b/lib/ExecutionEngine/Script.cpp
@@ -184,22 +184,10 @@
char const *cacheName,
llvm::Reloc::Model RelocModel,
unsigned long flags) {
- mObjectType = ScriptObject::Relocatable;
#if USE_CACHE
- if (cacheDir && cacheName) {
- // Set Cache Directory and File Name
- mCacheDir = cacheDir;
- mCacheName = cacheName;
-
- if (!mCacheDir.empty() && *mCacheDir.rbegin() != '/') {
- mCacheDir.push_back('/'); // Ensure mCacheDir is end with '/'
- }
-
- // Check Cache File
- if (internalLoadCache(true) == 0) {
- return 0;
- }
- }
+ if (internalLoadCache(cacheDir, cacheName,
+ ScriptObject::Relocatable, /* checkOnly */true) == 0)
+ return 0;
#endif
CompilerOption option;
@@ -222,22 +210,10 @@
return 1;
}
- mObjectType = ScriptObject::Executable;
#if USE_CACHE
- if (cacheDir && cacheName) {
- // Set Cache Directory and File Name
- mCacheDir = cacheDir;
- mCacheName = cacheName;
-
- if (!mCacheDir.empty() && *mCacheDir.rbegin() != '/') {
- mCacheDir.push_back('/'); // Ensure mCacheDir is end with '/'
- }
-
- // Load Cache File
- if (internalLoadCache(false) == 0) {
- return 0;
- }
- }
+ if (internalLoadCache(cacheDir, cacheName,
+ ScriptObject::Executable, /* checkOnly */false) == 0)
+ return 0;
#endif
CompilerOption option;
@@ -250,7 +226,22 @@
#if USE_CACHE
-int Script::internalLoadCache(bool checkOnly) {
+int Script::internalLoadCache(char const *cacheDir, char const *cacheName,
+ ScriptObject::ObjectType objectType,
+ bool checkOnly) {
+ mObjectType = objectType;
+
+ if ((cacheDir == NULL) || (cacheName == NULL))
+ return 1;
+
+ // Set cache file Name
+ mCacheName = cacheName;
+
+ // Santize the mCacheDir. Ensure that mCacheDir is end with '/'.
+ mCacheDir = cacheDir;
+ if (!mCacheDir.empty() && *mCacheDir.rbegin() != '/')
+ mCacheDir.push_back('/');
+
if (!isCacheable())
return 1;