Introduce Config.h. So that libbcc will rebuild on config change.
diff --git a/lib/bcc/CodeEmitter.cpp b/lib/bcc/CodeEmitter.cpp
index 29e0934..f475abd 100644
--- a/lib/bcc/CodeEmitter.cpp
+++ b/lib/bcc/CodeEmitter.cpp
@@ -16,6 +16,8 @@
#include "CodeEmitter.h"
+#include "Config.h"
+
#include "CodeMemoryManager.h"
#include "Runtime.h"
#include "ScriptCompiled.h"
@@ -48,7 +50,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
#include "llvm/Support/MemoryObject.h"
#endif
@@ -79,7 +81,7 @@
namespace {
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
class BufferMemoryObject : public llvm::MemoryObject {
private:
const uint8_t *mBytes;
@@ -118,7 +120,7 @@
mpConstantPool(NULL),
mpJumpTable(NULL),
mpMMI(NULL),
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
mpAsmInfo(NULL),
mpDisassmbler(NULL),
mpIP(NULL),
@@ -129,7 +131,7 @@
CodeEmitter::~CodeEmitter() {
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
delete mpAsmInfo;
delete mpDisassmbler;
delete mpIP;
@@ -1167,10 +1169,10 @@
void CodeEmitter::Disassemble(const llvm::StringRef &Name,
uint8_t *Start, size_t Length, bool IsStub) {
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
llvm::raw_ostream *OS;
-#if defined(USE_DISASSEMBLER_FILE)
+#if USE_DISASSEMBLER_FILE
std::string ErrorInfo;
OS = new llvm::raw_fd_ostream("/data/local/tmp/out.S",
ErrorInfo,
@@ -1221,13 +1223,13 @@
*OS << "\n";
delete BufferMObj;
-#if defined(USE_DISASSEMBLER_FILE)
+#if USE_DISASSEMBLER_FILE
// If you want the disassemble results write to file, uncomment this.
((llvm::raw_fd_ostream*)OS)->close();
delete OS;
#endif
-#endif // defined(USE_DISASSEMBLER)
+#endif // USE_DISASSEMBLER
}
diff --git a/lib/bcc/CodeEmitter.h b/lib/bcc/CodeEmitter.h
index 289c954..8d34159 100644
--- a/lib/bcc/CodeEmitter.h
+++ b/lib/bcc/CodeEmitter.h
@@ -18,6 +18,8 @@
#include <bcc/bcc_cache.h>
#include "bcc_internal.h"
+#include "Config.h"
+
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
@@ -43,7 +45,7 @@
class MachineFunction;
class MachineJumpTableInfo;
class MachineModuleInfo;
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
class MCAsmInfo;
class MCDisassembler;
class MCInstPrinter;
@@ -138,7 +140,7 @@
std::map<void*, void*> ExternalFnToStubMap;
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
const llvm::MCAsmInfo *mpAsmInfo;
const llvm::MCDisassembler *mpDisassmbler;
llvm::MCInstPrinter *mpIP;
diff --git a/lib/bcc/Compiler.cpp b/lib/bcc/Compiler.cpp
index 188a0ff..ccbfb5d 100644
--- a/lib/bcc/Compiler.cpp
+++ b/lib/bcc/Compiler.cpp
@@ -17,54 +17,10 @@
#define LOG_TAG "bcc"
#include <cutils/log.h>
-#if defined(__arm__)
-# define DEFAULT_ARM_CODEGEN
-# define PROVIDE_ARM_CODEGEN
-#elif defined(__i386__)
-# define DEFAULT_X86_CODEGEN
-# define PROVIDE_X86_CODEGEN
-#elif defined(__x86_64__)
-# define DEFAULT_X64_CODEGEN
-# define PROVIDE_X64_CODEGEN
-#endif
-
-#if defined(FORCE_ARM_CODEGEN)
-# define DEFAULT_ARM_CODEGEN
-# undef DEFAULT_X86_CODEGEN
-# undef DEFAULT_X64_CODEGEN
-# define PROVIDE_ARM_CODEGEN
-# undef PROVIDE_X86_CODEGEN
-# undef PROVIDE_X64_CODEGEN
-#elif defined(FORCE_X86_CODEGEN)
-# undef DEFAULT_ARM_CODEGEN
-# define DEFAULT_X86_CODEGEN
-# undef DEFAULT_X64_CODEGEN
-# undef PROVIDE_ARM_CODEGEN
-# define PROVIDE_X86_CODEGEN
-# undef PROVIDE_X64_CODEGEN
-#elif defined(FORCE_X64_CODEGEN)
-# undef DEFAULT_ARM_CODEGEN
-# undef DEFAULT_X86_CODEGEN
-# define DEFAULT_X64_CODEGEN
-# undef PROVIDE_ARM_CODEGEN
-# undef PROVIDE_X86_CODEGEN
-# define PROVIDE_X64_CODEGEN
-#endif
-
-#if defined(DEFAULT_ARM_CODEGEN)
-# define TARGET_TRIPLE_STRING "armv7-none-linux-gnueabi"
-#elif defined(DEFAULT_X86_CODEGEN)
-# define TARGET_TRIPLE_STRING "i686-unknown-linux"
-#elif defined(DEFAULT_X64_CODEGEN)
-# define TARGET_TRIPLE_STRING "x86_64-unknown-linux"
-#endif
-
-#if (defined(__VFP_FP__) && !defined(__SOFTFP__))
-# define ARM_USE_VFP
-#endif
-
#include "Compiler.h"
+#include "Config.h"
+
#include "ContextManager.h"
#include "ScriptCompiled.h"
#include "Sha1Helper.h"
@@ -167,7 +123,7 @@
#if defined(DEFAULT_ARM_CODEGEN) || defined(PROVIDE_ARM_CODEGEN)
LLVMInitializeARMTargetInfo();
LLVMInitializeARMTarget();
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
LLVMInitializeARMDisassembler();
LLVMInitializeARMAsmPrinter();
#endif
@@ -176,7 +132,7 @@
#if defined(DEFAULT_X86_CODEGEN) || defined(PROVIDE_X86_CODEGEN)
LLVMInitializeX86TargetInfo();
LLVMInitializeX86Target();
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
LLVMInitializeX86Disassembler();
LLVMInitializeX86AsmPrinter();
#endif
@@ -185,7 +141,7 @@
#if defined(DEFAULT_X64_CODEGEN) || defined(PROVIDE_X64_CODEGEN)
LLVMInitializeX86TargetInfo();
LLVMInitializeX86Target();
-#if defined(USE_DISASSEMBLER)
+#if USE_DISASSEMBLER
LLVMInitializeX86Disassembler();
LLVMInitializeX86AsmPrinter();
#endif
@@ -237,11 +193,13 @@
llvm::createFastRegisterAllocator :
llvm::createLinearScanRegisterAllocator);
+#if USE_CACHE
// Calculate the SHA1 checksum of libbcc and libRS.
-#if defined(USE_LIBBCC_SHA1SUM)
+#if USE_LIBBCC_SHA1SUM
calcFileSHA1(sha1LibBCC, pathLibBCC);
#endif
calcFileSHA1(sha1LibRS, pathLibRS);
+#endif
GlobalInitialized = true;
}
diff --git a/lib/bcc/Runtime.c b/lib/bcc/Runtime.c
index 3f690aa..86f8615 100644
--- a/lib/bcc/Runtime.c
+++ b/lib/bcc/Runtime.c
@@ -83,8 +83,6 @@
void *mPtr;
} RuntimeFunction;
-#define USE_VFP_RUNTIME 1
-
#if defined(__arm__)
#define DEF_GENERIC_RUNTIME(func) \
extern void *func;
diff --git a/lib/bcc/Script.cpp b/lib/bcc/Script.cpp
index 23ec7fc..89d6115 100644
--- a/lib/bcc/Script.cpp
+++ b/lib/bcc/Script.cpp
@@ -19,6 +19,8 @@
#include "Script.h"
+#include "Config.h"
+
#include "CacheReader.h"
#include "CacheWriter.h"
#include "FileHandle.h"
@@ -46,10 +48,19 @@
namespace bcc {
Script::~Script() {
- if (mStatus == ScriptStatus::Compiled) {
+ switch (mStatus) {
+ case ScriptStatus::Compiled:
delete mCompiled;
- } else if (mStatus == ScriptStatus::Cached) {
+ break;
+
+#if USE_CACHE
+ case ScriptStatus::Cached:
delete mCached;
+ break;
+#endif
+
+ default:
+ break;
}
}
@@ -108,16 +119,19 @@
return 1;
}
+#if USE_CACHE
// Load Cache File
mCachePath = cachePath;
if (cachePath && internalLoadCache() == 0) {
return 0;
}
+#endif
return internalCompile();
}
+#if USE_CACHE
int Script::internalLoadCache() {
if (getBooleanProp("debug.bcc.nocache")) {
// Android system environment property disable the cache mechanism by
@@ -152,7 +166,7 @@
CacheReader reader;
// Dependencies
-#if defined(USE_LIBBCC_SHA1SUM)
+#if USE_LIBBCC_SHA1SUM
reader.addDependency(BCC_FILE_RESOURCE, pathLibBCC, sha1LibBCC);
#endif
@@ -183,6 +197,7 @@
return 0;
}
+#endif
int Script::internalCompile() {
@@ -233,6 +248,7 @@
return 1;
}
+#if USE_CACHE
// TODO(logan): Write the cache out
if (mCachePath && !getBooleanProp("debug.bcc.nocache")) {
FileHandle file;
@@ -241,7 +257,7 @@
CacheWriter writer;
// Dependencies
-#if defined(USE_LIBBCC_SHA1SUM)
+#if USE_LIBBCC_SHA1SUM
writer.addDependency(BCC_FILE_RESOURCE, pathLibBCC, sha1LibBCC);
#endif
writer.addDependency(BCC_FILE_RESOURCE, pathLibRS, sha1LibRS);
@@ -270,6 +286,7 @@
}
}
}
+#endif // USE_CACHE
return 0;
}
@@ -288,7 +305,9 @@
void *Script::lookup(const char *name) {
switch (mStatus) {
case ScriptStatus::Compiled: return mCompiled->lookup(name);
+#if USE_CACHE
case ScriptStatus::Cached: return mCached->lookup(name);
+#endif
default:
mErrorCode = BCC_INVALID_OPERATION;
@@ -300,7 +319,9 @@
size_t Script::getExportVarCount() const {
switch (mStatus) {
case ScriptStatus::Compiled: return mCompiled->getExportVarCount();
+#if USE_CACHE
case ScriptStatus::Cached: return mCached->getExportVarCount();
+#endif
default: return 0;
}
}
@@ -309,7 +330,9 @@
size_t Script::getExportFuncCount() const {
switch (mStatus) {
case ScriptStatus::Compiled: return mCompiled->getExportFuncCount();
+#if USE_CACHE
case ScriptStatus::Cached: return mCached->getExportFuncCount();
+#endif
default: return 0;
}
}
@@ -318,7 +341,9 @@
size_t Script::getPragmaCount() const {
switch (mStatus) {
case ScriptStatus::Compiled: return mCompiled->getPragmaCount();
+#if USE_CACHE
case ScriptStatus::Cached: return mCached->getPragmaCount();
+#endif
default: return 0;
}
}
@@ -327,7 +352,9 @@
size_t Script::getFuncCount() const {
switch (mStatus) {
case ScriptStatus::Compiled: return mCompiled->getFuncCount();
+#if USE_CACHE
case ScriptStatus::Cached: return mCached->getFuncCount();
+#endif
default: return 0;
}
}
@@ -340,7 +367,10 @@
m##STATUS->getExportVarList(varListSize, varList); \
break;
+#if USE_CACHE
DELEGATE(Cached);
+#endif
+
DELEGATE(Compiled);
#undef DELEGATE
@@ -357,7 +387,10 @@
m##STATUS->getExportFuncList(funcListSize, funcList); \
break;
+#if USE_CACHE
DELEGATE(Cached);
+#endif
+
DELEGATE(Compiled);
#undef DELEGATE
@@ -376,7 +409,10 @@
m##STATUS->getPragmaList(pragmaListSize, keyList, valueList); \
break;
+#if USE_CACHE
DELEGATE(Cached);
+#endif
+
DELEGATE(Compiled);
#undef DELEGATE
@@ -394,7 +430,10 @@
m##STATUS->getFuncInfoList(funcInfoListSize, funcInfoList);
break;
+#if USE_CACHE
DELEGATE(Cached);
+#endif
+
DELEGATE(Compiled);
#undef DELEGATE
@@ -405,7 +444,9 @@
char *Script::getContext() {
switch (mStatus) {
+#if USE_CACHE
case ScriptStatus::Cached: return mCached->getContext();
+#endif
case ScriptStatus::Compiled: return mCompiled->getContext();
default:
diff --git a/lib/bcc/Script.h b/lib/bcc/Script.h
index 1965828..b996a32 100644
--- a/lib/bcc/Script.h
+++ b/lib/bcc/Script.h
@@ -36,7 +36,9 @@
enum StatusType {
Unknown,
Compiled,
+#if USE_CACHE
Cached,
+#endif
};
}
@@ -48,7 +50,9 @@
union {
ScriptCompiled *mCompiled;
+#if USE_CACHE
ScriptCached *mCached;
+#endif
};
char const *mCachePath;
@@ -140,7 +144,9 @@
}
private:
+#if USE_CACHE
int internalLoadCache();
+#endif
int internalCompile();
};
diff --git a/lib/bcc/Sha1Helper.cpp b/lib/bcc/Sha1Helper.cpp
index da1565d..90d5ac6 100644
--- a/lib/bcc/Sha1Helper.cpp
+++ b/lib/bcc/Sha1Helper.cpp
@@ -19,6 +19,8 @@
#include "Sha1Helper.h"
+#include "Config.h"
+
#include "FileHandle.h"
#include <string.h>
@@ -29,7 +31,7 @@
namespace bcc {
-#if defined(USE_LIBBCC_SHA1SUM)
+#if USE_LIBBCC_SHA1SUM
unsigned char sha1LibBCC[20];
char const *pathLibBCC = "/system/lib/libbcc.so";
#endif
diff --git a/lib/bcc/Sha1Helper.h b/lib/bcc/Sha1Helper.h
index b78c3c4..4a1a148 100644
--- a/lib/bcc/Sha1Helper.h
+++ b/lib/bcc/Sha1Helper.h
@@ -17,10 +17,12 @@
#ifndef BCC_SHA1HELPER_H
#define BCC_SHA1HELPER_H
+#include "Config.h"
+
#include <stdint.h>
namespace bcc {
-#if defined(USE_LIBBCC_SHA1SUM)
+#if USE_LIBBCC_SHA1SUM
extern unsigned char sha1LibBCC[20];
extern char const *pathLibBCC;
#endif
diff --git a/lib/bcc/bcc.cpp b/lib/bcc/bcc.cpp
index bc7f16d..696b20b 100644
--- a/lib/bcc/bcc.cpp
+++ b/lib/bcc/bcc.cpp
@@ -23,6 +23,8 @@
#include <bcc/bcc.h>
#include "bcc_internal.h"
+#include "Config.h"
+
#include "Compiler.h"
#include "Script.h"
@@ -126,7 +128,7 @@
void *addr = unwrap(script)->lookup(funcname);
-#if defined(USE_DISASSEMBLER_FILE)
+#if USE_DISASSEMBLER_FILE
LOGD("Function Address: %s --> 0x%p\n", funcname, addr);
#endif
@@ -148,7 +150,7 @@
if (varList) {
unwrap(script)->getExportVarList(varListSize, varList);
-#if defined(USE_DISASSEMBLER_FILE)
+#if USE_DISASSEMBLER_FILE
size_t count = unwrap(script)->getExportVarCount();
LOGD("ExportVarCount = %lu\n", (unsigned long)count);
@@ -178,7 +180,7 @@
if (funcList) {
unwrap(script)->getExportFuncList(funcListSize, funcList);
-#if defined(USE_DISASSEMBLER_FILE)
+#if USE_DISASSEMBLER_FILE
size_t count = unwrap(script)->getExportFuncCount();
LOGD("ExportFuncCount = %lu\n", (unsigned long)count);
@@ -207,10 +209,10 @@
BCC_FUNC_LOGGER();
unwrap(script)->getPragmaList(pragmaListSize, keyList, valueList);
-#if defined(USE_DISASSEMBLER_FILE)
+#if USE_DISASSEMBLER_FILE
if (keyList && valueList) {
- size_t count = script->getPragmaCount();
- LOGD("PragmaCount = %lu\n", count);
+ size_t count = unwrap(script)->getPragmaCount();
+ LOGD("PragmaCount = %lu\n", (unsigned long)count);
if (count > pragmaListSize) {
count = pragmaListSize;