RSCompilerDriver.h revision 01f05d4b45cbde1e07d4707152908c1d843f1328
10fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang/*
20fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * Copyright 2012, The Android Open Source Project
30fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang *
40fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * Licensed under the Apache License, Version 2.0 (the "License");
50fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * you may not use this file except in compliance with the License.
60fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * You may obtain a copy of the License at
70fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang *
80fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang *     http://www.apache.org/licenses/LICENSE-2.0
90fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang *
100fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * Unless required by applicable law or agreed to in writing, software
110fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * distributed under the License is distributed on an "AS IS" BASIS,
120fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
130fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * See the License for the specific language governing permissions and
140fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang * limitations under the License.
150fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang */
160fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
17c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#ifndef BCC_RS_COMPILER_DRIVER_H
18c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#define BCC_RS_COMPILER_DRIVER_H
190fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
2009ca95426a7ec66def02e47048bb25289759c6fbShih-wei Liao#include "bcc/ExecutionEngine/CompilerRTSymbolResolver.h"
21c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#include "bcc/ExecutionEngine/SymbolResolvers.h"
22c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#include "bcc/ExecutionEngine/SymbolResolverProxy.h"
23e198abec6c5e3eab380ccf6897b0a0b9c2dd92ddStephen Hines#include "bcc/Renderscript/RSInfo.h"
24e198abec6c5e3eab380ccf6897b0a0b9c2dd92ddStephen Hines#include "bcc/Renderscript/RSCompiler.h"
2501f05d4b45cbde1e07d4707152908c1d843f1328Stephen Hines#include "bcc/Renderscript/RSScript.h"
260fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
270fffa7e4adc90079dc0f252359050fe872b360ddZonr Changnamespace bcc {
280fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
297bcec85228c1eceade6efc9cd7d02ef81c8d55e9Shih-wei Liaoclass BCCContext;
300fffa7e4adc90079dc0f252359050fe872b360ddZonr Changclass CompilerConfig;
310fffa7e4adc90079dc0f252359050fe872b360ddZonr Changclass RSExecutable;
320fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
330fffa7e4adc90079dc0f252359050fe872b360ddZonr Changclass RSCompilerDriver {
340fffa7e4adc90079dc0f252359050fe872b360ddZonr Changprivate:
350fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  CompilerConfig *mConfig;
360fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  RSCompiler mCompiler;
370fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
383ab9da1e1b3d7794994393af086d096397fb84dbStephen Hines  CompilerRTSymbolResolver *mCompilerRuntime;
390fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  LookupFunctionSymbolResolver<void*> mRSRuntime;
400fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  SymbolResolverProxy mResolver;
410fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
421d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines  // Are we compiling under an RS debug context with additional checks?
431d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines  bool mDebugContext;
441d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines
4501f05d4b45cbde1e07d4707152908c1d843f1328Stephen Hines  RSExecutable *loadScriptCache(const char *pObjectPath,
467bcec85228c1eceade6efc9cd7d02ef81c8d55e9Shih-wei Liao                                const RSInfo::DependencyTableTy &pDeps);
470fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
480fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  // Setup the compiler config for the given script. Return true if mConfig has
490fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  // been changed and false if it remains unchanged.
500fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  bool setupConfig(const RSScript &pScript);
510fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
520fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  RSExecutable *compileScript(RSScript &pScript,
53ba4206445e192f4c0fa519eae55c4b84cfb0efeeShih-wei Liao                              const char* pScriptName,
547bcec85228c1eceade6efc9cd7d02ef81c8d55e9Shih-wei Liao                              const char *pOutputPath,
55331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines                              const char *pRuntimePath,
56331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines                              const RSInfo::DependencyTableTy &pDeps,
57331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines                              bool pSkipLoad);
580fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
590fffa7e4adc90079dc0f252359050fe872b360ddZonr Changpublic:
603ab9da1e1b3d7794994393af086d096397fb84dbStephen Hines  RSCompilerDriver(bool pUseCompilerRT = true);
610fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  ~RSCompilerDriver();
620fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
630fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  inline void setRSRuntimeLookupFunction(
640fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang      LookupFunctionSymbolResolver<>::LookupFunctionTy pLookupFunc)
650fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  { mRSRuntime.setLookupFunction(pLookupFunc); }
660fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  inline void setRSRuntimeLookupContext(void *pContext)
670fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  { mRSRuntime.setContext(pContext); }
680fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
69331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines  RSCompiler *getCompiler() {
70331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines    return &mCompiler;
71331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines  }
72331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines
73331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines  void setConfig(CompilerConfig *config) {
74331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines    mConfig = config;
75331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines  }
76331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines
771d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines  void setDebugContext(bool v) {
781d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines    mDebugContext = v;
791d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines  }
801d4a9e4646e8786623daa6ac3917782be56a8fb2Stephen Hines
810fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  // FIXME: This method accompany with loadScriptCache and compileScript should
820fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  //        all be const-methods. They're not now because the getAddress() in
830fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang  //        SymbolResolverInterface is not a const-method.
847bcec85228c1eceade6efc9cd7d02ef81c8d55e9Shih-wei Liao  RSExecutable *build(BCCContext &pContext,
857bcec85228c1eceade6efc9cd7d02ef81c8d55e9Shih-wei Liao                      const char *pCacheDir, const char *pResName,
86331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines                      const char *pBitcode, size_t pBitcodeSize,
8706731a6150ae8014d37258d5f32ef8bc14a3db63Stephen Hines                      const char *pRuntimePath,
8806731a6150ae8014d37258d5f32ef8bc14a3db63Stephen Hines                      RSLinkRuntimeCallback pLinkRuntimeCallback = NULL);
89331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines  RSExecutable *build(RSScript &pScript, const char *pOut,
90331310e1f3f86a795f78e42b3f03558a43829f09Stephen Hines                      const char *pRuntimePath);
910fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang};
920fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
930fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang} // end namespace bcc
940fffa7e4adc90079dc0f252359050fe872b360ddZonr Chang
95c72c4ddfcd79c74f70713da91a69569451b5c19eZonr Chang#endif // BCC_RS_COMPILER_DRIVER_H
96