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_EXECUTABLE_H
     18 #define BCC_RS_EXECUTABLE_H
     19 
     20 #include <cstddef>
     21 
     22 
     23 #include "bcc/ExecutionEngine/ObjectLoader.h"
     24 #include "bcc/Renderscript/RSInfo.h"
     25 #include "bcc/Support/Log.h"
     26 
     27 #include <utils/Vector.h>
     28 
     29 namespace bcc {
     30 
     31 class FileBase;
     32 class OutputFile;
     33 class SymbolResolverProxy;
     34 
     35 /*
     36  * RSExecutable holds the build results of a RSScript.
     37  */
     38 class RSExecutable {
     39 private:
     40   RSInfo *mInfo;
     41   bool mIsInfoDirty;
     42 
     43   FileBase *mObjFile;
     44 
     45   ObjectLoader *mLoader;
     46 
     47   // Memory address of rs export stuffs
     48   android::Vector<void *> mExportVarAddrs;
     49   android::Vector<void *> mExportFuncAddrs;
     50   android::Vector<void *> mExportForeachFuncAddrs;
     51 
     52   // FIXME: These are designed for Renderscript HAL and is initialized in
     53   //        RSExecutable::Create(). Both of them come from RSInfo::getPragmas().
     54   //        If possible, read the pragma key/value pairs directly from RSInfo.
     55   android::Vector<const char *> mPragmaKeys;
     56   android::Vector<const char *> mPragmaValues;
     57 
     58   RSExecutable(RSInfo &pInfo, FileBase &pObjFile, ObjectLoader &pLoader)
     59     : mInfo(&pInfo), mIsInfoDirty(false), mObjFile(&pObjFile), mLoader(&pLoader)
     60   { }
     61 
     62 public:
     63   // This is a NULL-terminated string array which specifies "Special" functions
     64   // in Renderscript (e.g., root().)
     65   static const char *SpecialFunctionNames[];
     66 
     67   // Return NULL on error. If the return object is non-NULL, it claims the
     68   // ownership of pInfo and pObjFile.
     69   static RSExecutable *Create(RSInfo &pInfo,
     70                               FileBase &pObjFile,
     71                               SymbolResolverProxy &pResolver);
     72 
     73   inline const RSInfo &getInfo() const
     74   { return *mInfo; }
     75 
     76   // Interfaces to RSInfo
     77   inline bool isThreadable() const
     78   { return mInfo->isThreadable(); }
     79 
     80   inline void setThreadable(bool pThreadable = true) {
     81     if (mInfo->isThreadable() != pThreadable) {
     82       mInfo->setThreadable(pThreadable);
     83       mIsInfoDirty = true;
     84     }
     85     return;
     86   }
     87 
     88   // Interfaces to ObjectLoader
     89   inline void *getSymbolAddress(const char *pName) const
     90   { return mLoader->getSymbolAddress(pName); }
     91 
     92   bool syncInfo(bool pForce = false);
     93 
     94   // Disassemble and dump the relocated functions to the pOutput.
     95   void dumpDisassembly(OutputFile &pOutput) const;
     96 
     97   inline const android::Vector<void *> &getExportVarAddrs() const
     98   { return mExportVarAddrs; }
     99   inline const android::Vector<void *> &getExportFuncAddrs() const
    100   { return mExportFuncAddrs; }
    101   inline const android::Vector<void *> &getExportForeachFuncAddrs() const
    102   { return mExportForeachFuncAddrs; }
    103 
    104   inline const android::Vector<const char *> &getPragmaKeys() const
    105   { return mPragmaKeys; }
    106   inline const android::Vector<const char *> &getPragmaValues() const
    107   { return mPragmaValues; }
    108 
    109   ~RSExecutable();
    110 };
    111 
    112 } // end namespace bcc
    113 
    114 #endif // BCC_RS_EXECUTABLE_H
    115