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);
+}
diff --git a/bcc_script.h b/bcc_script.h
new file mode 100644
index 0000000..5798b82
--- /dev/null
+++ b/bcc_script.h
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2010, 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.
+ */
+
+#ifndef BCC_SCRIPT_H
+#define BCC_SCRIPT_H
+
+#include <bcc/bcc.h>
+#include "bcc_compiler.h"
+
+namespace bcc {
+
+ class BCCscript {
+ public:
+ //////////////////////////////////////////////////////////////////////////
+ // Part I. Compiler
+ //////////////////////////////////////////////////////////////////////////
+ Compiler compiler;
+
+ void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
+ compiler.registerSymbolCallback(pFn, pContext);
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+ // Part II. Logistics & Error handling
+ //////////////////////////////////////////////////////////////////////////
+ BCCscript() {
+ bccError = BCC_NO_ERROR;
+ }
+
+ ~BCCscript() {
+ }
+
+ void setError(BCCenum error) {
+ if (bccError == BCC_NO_ERROR && error != BCC_NO_ERROR) {
+ bccError = error;
+ }
+ }
+
+ BCCenum getError() {
+ BCCenum result = bccError;
+ bccError = BCC_NO_ERROR;
+ return result;
+ }
+
+ BCCenum bccError;
+ };
+
+} // namespace bcc
+
+#endif // BCC_SCRIPT_H
diff --git a/include/bcc/bcc.h b/include/bcc/bcc.h
index 7f4af42..505eca3 100644
--- a/include/bcc/bcc.h
+++ b/include/bcc/bcc.h
@@ -26,9 +26,24 @@
typedef ssize_t BCCsizei;
typedef unsigned int BCCenum;
typedef void BCCvoid;
+
+#if !defined(__cplusplus)
+
typedef struct BCCscript BCCscript;
typedef struct BCCtype BCCtype;
+#else
+
+namespace bcc {
+ class BCCscript;
+ class BCCtype;
+}
+
+typedef bcc::BCCscript BCCscript;
+typedef bcc::BCCtype BCCtype;
+
+#endif
+
#define BCC_NO_ERROR 0x0000
#define BCC_INVALID_ENUM 0x0500
#define BCC_INVALID_OPERATION 0x0502