RSCompilerDriver.h revision 7b980e1717f3cf418f7bc4e40597004bc1139b8b
1/* 2 * Copyright 2012, The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#ifndef BCC_RS_COMPILER_DRIVER_H 18#define BCC_RS_COMPILER_DRIVER_H 19 20#include "bcc/ExecutionEngine/CompilerRTSymbolResolver.h" 21#include "bcc/ExecutionEngine/SymbolResolvers.h" 22#include "bcc/ExecutionEngine/SymbolResolverProxy.h" 23#include "bcc/Renderscript/RSInfo.h" 24#include "bcc/Renderscript/RSCompiler.h" 25#include "bcc/Renderscript/RSScript.h" 26 27namespace bcc { 28 29class BCCContext; 30class CompilerConfig; 31class RSExecutable; 32 33class RSCompilerDriver { 34private: 35 CompilerConfig *mConfig; 36 RSCompiler mCompiler; 37 38 CompilerRTSymbolResolver *mCompilerRuntime; 39 LookupFunctionSymbolResolver<void*> mRSRuntime; 40 SymbolResolverProxy mResolver; 41 42 // Are we compiling under an RS debug context with additional checks? 43 bool mDebugContext; 44 45 // Setup the compiler config for the given script. Return true if mConfig has 46 // been changed and false if it remains unchanged. 47 bool setupConfig(const RSScript &pScript); 48 49 Compiler::ErrorCode compileScript(RSScript &pScript, 50 const char* pScriptName, 51 const char *pOutputPath, 52 const char *pRuntimePath, 53 const RSInfo::DependencyTableTy &pDeps, 54 bool pSkipLoad, bool pDumpIR = false); 55 56public: 57 RSCompilerDriver(bool pUseCompilerRT = true); 58 ~RSCompilerDriver(); 59 60 inline void setRSRuntimeLookupFunction( 61 LookupFunctionSymbolResolver<>::LookupFunctionTy pLookupFunc) 62 { mRSRuntime.setLookupFunction(pLookupFunc); } 63 inline void setRSRuntimeLookupContext(void *pContext) 64 { mRSRuntime.setContext(pContext); } 65 66 RSCompiler *getCompiler() { 67 return &mCompiler; 68 } 69 70 void setConfig(CompilerConfig *config) { 71 mConfig = config; 72 } 73 74 void setDebugContext(bool v) { 75 mDebugContext = v; 76 } 77 78 // FIXME: This method accompany with loadScript and compileScript should 79 // all be const-methods. They're not now because the getAddress() in 80 // SymbolResolverInterface is not a const-method. 81 // Returns true if script is successfully compiled. 82 bool build(BCCContext &pContext, const char *pCacheDir, const char *pResName, 83 const char *pBitcode, size_t pBitcodeSize, 84 const char *pRuntimePath, 85 RSLinkRuntimeCallback pLinkRuntimeCallback = NULL, 86 bool pDumpIR = false); 87 88 // Returns true if script is successfully compiled. 89 bool build(RSScript &pScript, const char *pOut, const char *pRuntimePath); 90 91 RSExecutable *loadScript(const char *pCacheDir, const char *pResName, 92 const char *pBitcode, size_t pBitcodeSize); 93}; 94 95} // end namespace bcc 96 97#endif // BCC_RS_COMPILER_DRIVER_H 98