Extract BCCscript from bcc.cpp.
diff --git a/bcc.cpp b/bcc.cpp
index 86f54f7..276fb24 100644
--- a/bcc.cpp
+++ b/bcc.cpp
@@ -22,6 +22,7 @@
#include <bcc/bcc.h>
+#include "bcc_script.h"
#include "bcc_compiler.h"
#include <utils/StopWatch.h>
@@ -32,157 +33,118 @@
}
-namespace bcc {
+extern "C" BCCscript *bccCreateScript() {
+ return new BCCscript();
+}
- struct BCCscript {
- //////////////////////////////////////////////////////////////////////////
- // Part I. Compiler
- //////////////////////////////////////////////////////////////////////////
- Compiler compiler;
+extern "C" BCCenum bccGetError(BCCscript *script) {
+ return script->getError();
+}
- void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
- compiler.registerSymbolCallback(pFn, pContext);
- }
+extern "C" void bccDeleteScript(BCCscript *script) {
+ delete script;
+}
- //////////////////////////////////////////////////////////////////////////
- // Part II. Logistics & Error handling
- //////////////////////////////////////////////////////////////////////////
- BCCscript() {
- bccError = BCC_NO_ERROR;
- }
+extern "C" void bccRegisterSymbolCallback(BCCscript *script,
+ BCCSymbolLookupFn pFn,
+ BCCvoid *pContext) {
+ script->registerSymbolCallback(pFn, pContext);
+}
- ~BCCscript() {
- }
+extern "C" int bccReadModule(BCCscript *script, BCCvoid *module) {
+ return script->compiler.readModule(reinterpret_cast<llvm::Module*>(module));
+}
- void setError(BCCenum error) {
- if (bccError == BCC_NO_ERROR && error != BCC_NO_ERROR) {
- bccError = error;
- }
- }
+extern "C" int bccReadBC(BCCscript *script,
+ const BCCchar *bitcode,
+ BCCint size,
+ const BCCchar *resName) {
+ return script->compiler.readBC(bitcode, size, resName);
+}
- BCCenum getError() {
- BCCenum result = bccError;
- bccError = BCC_NO_ERROR;
- return result;
- }
+extern "C" void bccLinkBC(BCCscript *script,
+ const BCCchar *bitcode,
+ BCCint size) {
+ script->compiler.linkBC(bitcode, size);
+}
- BCCenum bccError;
- };
+extern "C" int bccLoadBinary(BCCscript *script) {
+ int result = script->compiler.loadCacheFile();
+ if (result)
+ script->setError(BCC_INVALID_OPERATION);
+ return result;
+}
-
- extern "C" BCCscript *bccCreateScript() {
- return new BCCscript();
- }
-
- extern "C" BCCenum bccGetError(BCCscript *script) {
- return script->getError();
- }
-
- extern "C" void bccDeleteScript(BCCscript *script) {
- delete script;
- }
-
- extern "C" void bccRegisterSymbolCallback(BCCscript *script,
- BCCSymbolLookupFn pFn,
- BCCvoid *pContext) {
- script->registerSymbolCallback(pFn, pContext);
- }
-
- extern "C" int bccReadModule(BCCscript *script, BCCvoid *module) {
- return script->compiler.readModule(reinterpret_cast<llvm::Module*>(module));
- }
-
- extern "C" int bccReadBC(BCCscript *script,
- const BCCchar *bitcode,
- BCCint size,
- const BCCchar *resName) {
- return script->compiler.readBC(bitcode, size, resName);
- }
-
- extern "C" void bccLinkBC(BCCscript *script,
- const BCCchar *bitcode,
- BCCint size) {
- script->compiler.linkBC(bitcode, size);
- }
-
- extern "C" void bccLoadBinary(BCCscript *script) {
- int result = script->compiler.loadCacheFile();
+extern "C" void bccCompileBC(BCCscript *script) {
+ {
+#if defined(__arm__)
+ android::StopWatch compileTimer("RenderScript compile time");
+#endif
+ int result = script->compiler.compile();
if (result)
script->setError(BCC_INVALID_OPERATION);
}
+}
- extern "C" void bccCompileBC(BCCscript *script) {
- {
-#if defined(__arm__)
- android::StopWatch compileTimer("RenderScript compile time");
-#endif
- int result = script->compiler.compile();
- if (result)
- script->setError(BCC_INVALID_OPERATION);
- }
+extern "C" void bccGetScriptInfoLog(BCCscript *script,
+ BCCsizei maxLength,
+ BCCsizei *length,
+ BCCchar *infoLog) {
+ char *message = script->compiler.getErrorMessage();
+ int messageLength = strlen(message) + 1;
+ if (length)
+ *length = messageLength;
+
+ if (infoLog && maxLength > 0) {
+ int trimmedLength = maxLength < messageLength ? maxLength : messageLength;
+ memcpy(infoLog, message, trimmedLength);
+ infoLog[trimmedLength] = 0;
}
+}
- extern "C" void bccGetScriptInfoLog(BCCscript *script,
- BCCsizei maxLength,
- BCCsizei *length,
- BCCchar *infoLog) {
- char *message = script->compiler.getErrorMessage();
- int messageLength = strlen(message) + 1;
- if (length)
- *length = messageLength;
+extern "C" void bccGetScriptLabel(BCCscript *script,
+ const BCCchar *name,
+ BCCvoid **address) {
+ void *value = script->compiler.lookup(name);
+ if (value)
+ *address = value;
+ else
+ script->setError(BCC_INVALID_VALUE);
+}
- if (infoLog && maxLength > 0) {
- int trimmedLength = maxLength < messageLength ? maxLength : messageLength;
- memcpy(infoLog, message, trimmedLength);
- infoLog[trimmedLength] = 0;
- }
- }
+extern "C" void bccGetExportVars(BCCscript *script,
+ BCCsizei *actualVarCount,
+ BCCsizei maxVarCount,
+ BCCvoid **vars) {
+ script->compiler.getExportVars(actualVarCount, maxVarCount, vars);
+}
- extern "C" void bccGetScriptLabel(BCCscript *script,
- const BCCchar *name,
- BCCvoid **address) {
- void *value = script->compiler.lookup(name);
- if (value)
- *address = value;
- else
- script->setError(BCC_INVALID_VALUE);
- }
+extern "C" void bccGetExportFuncs(BCCscript *script,
+ BCCsizei *actualFuncCount,
+ BCCsizei maxFuncCount,
+ BCCvoid **funcs) {
+ script->compiler.getExportFuncs(actualFuncCount, maxFuncCount, funcs);
+}
- extern "C" void bccGetExportVars(BCCscript *script,
- BCCsizei *actualVarCount,
- BCCsizei maxVarCount,
- BCCvoid **vars) {
- script->compiler.getExportVars(actualVarCount, maxVarCount, vars);
- }
+extern "C" void bccGetPragmas(BCCscript *script,
+ BCCsizei *actualStringCount,
+ BCCsizei maxStringCount,
+ BCCchar **strings) {
+ script->compiler.getPragmas(actualStringCount, maxStringCount, strings);
+}
- extern "C" void bccGetExportFuncs(BCCscript *script,
- BCCsizei *actualFuncCount,
- BCCsizei maxFuncCount,
- BCCvoid **funcs) {
- script->compiler.getExportFuncs(actualFuncCount, maxFuncCount, funcs);
- }
+extern "C" void bccGetFunctions(BCCscript *script,
+ BCCsizei *actualFunctionCount,
+ BCCsizei maxFunctionCount,
+ BCCchar **functions) {
+ script->compiler.getFunctions(actualFunctionCount,
+ maxFunctionCount,
+ functions);
+}
- extern "C" void bccGetPragmas(BCCscript *script,
- BCCsizei *actualStringCount,
- BCCsizei maxStringCount,
- BCCchar **strings) {
- script->compiler.getPragmas(actualStringCount, maxStringCount, strings);
- }
-
- extern "C" void bccGetFunctions(BCCscript *script,
- BCCsizei *actualFunctionCount,
- BCCsizei maxFunctionCount,
- BCCchar **functions) {
- script->compiler.getFunctions(actualFunctionCount,
- maxFunctionCount,
- functions);
- }
-
- extern "C" void bccGetFunctionBinary(BCCscript *script,
- BCCchar *function,
- BCCvoid **base,
- BCCsizei *length) {
- script->compiler.getFunctionBinary(function, base, length);
- }
-
-} // namespace bcc
+extern "C" void bccGetFunctionBinary(BCCscript *script,
+ BCCchar *function,
+ BCCvoid **base,
+ BCCsizei *length) {
+ script->compiler.getFunctionBinary(function, base, length);
+}