Home | History | Annotate | Download | only in Renderscript
      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 
     26 namespace bcc {
     27 
     28 class BCCContext;
     29 class CompilerConfig;
     30 class RSExecutable;
     31 class RSScript;
     32 
     33 class RSCompilerDriver {
     34 private:
     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   RSExecutable *loadScriptCache(const char *pOutputPath,
     46                                 const RSInfo::DependencyTableTy &pDeps);
     47 
     48   // Setup the compiler config for the given script. Return true if mConfig has
     49   // been changed and false if it remains unchanged.
     50   bool setupConfig(const RSScript &pScript);
     51 
     52   RSExecutable *compileScript(RSScript &pScript,
     53                               const char* pScriptName,
     54                               const char *pOutputPath,
     55                               const char *pRuntimePath,
     56                               const RSInfo::DependencyTableTy &pDeps,
     57                               bool pSkipLoad);
     58 
     59 public:
     60   RSCompilerDriver(bool pUseCompilerRT = true);
     61   ~RSCompilerDriver();
     62 
     63   inline void setRSRuntimeLookupFunction(
     64       LookupFunctionSymbolResolver<>::LookupFunctionTy pLookupFunc)
     65   { mRSRuntime.setLookupFunction(pLookupFunc); }
     66   inline void setRSRuntimeLookupContext(void *pContext)
     67   { mRSRuntime.setContext(pContext); }
     68 
     69   RSCompiler *getCompiler() {
     70     return &mCompiler;
     71   }
     72 
     73   void setConfig(CompilerConfig *config) {
     74     mConfig = config;
     75   }
     76 
     77   void setDebugContext(bool v) {
     78     mDebugContext = v;
     79   }
     80 
     81   // FIXME: This method accompany with loadScriptCache and compileScript should
     82   //        all be const-methods. They're not now because the getAddress() in
     83   //        SymbolResolverInterface is not a const-method.
     84   RSExecutable *build(BCCContext &pContext,
     85                       const char *pCacheDir, const char *pResName,
     86                       const char *pBitcode, size_t pBitcodeSize,
     87                       const char *pRuntimePath,
     88                       RSLinkRuntimeCallback pLinkRuntimeCallback = NULL);
     89   RSExecutable *build(RSScript &pScript, const char *pOut,
     90                       const char *pRuntimePath);
     91 };
     92 
     93 } // end namespace bcc
     94 
     95 #endif // BCC_RS_COMPILER_DRIVER_H
     96