Home | History | Annotate | Download | only in ExecutionEngine
      1 /*
      2  * Copyright 2010, 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_SCRIPTCACHED_H
     18 #define BCC_SCRIPTCACHED_H
     19 
     20 #include "Config.h"
     21 
     22 #include <bcc/bcc.h>
     23 #include <bcc/bcc_cache.h>
     24 #include <bcc/bcc_mccache.h>
     25 #include "bcc_internal.h"
     26 
     27 #if USE_MCJIT
     28 #include "librsloader.h"
     29 #endif
     30 
     31 #include <llvm/ADT/SmallVector.h>
     32 
     33 #include <map>
     34 #include <string>
     35 #include <utility>
     36 #include <vector>
     37 
     38 #include <stddef.h>
     39 
     40 namespace llvm {
     41   class Module;
     42 }
     43 
     44 namespace bcc {
     45   class Script;
     46 
     47   class ScriptCached {
     48     friend class CacheReader;
     49     friend class MCCacheReader;
     50 
     51   private:
     52     enum { SMALL_VECTOR_QUICKN = 16 };
     53 
     54     typedef llvm::SmallVector<std::pair<char const *, char const *>,
     55                               SMALL_VECTOR_QUICKN> PragmaList;
     56 
     57     typedef std::map<std::string, std::pair<void *, size_t> > FuncTable;
     58 
     59   private:
     60     Script *mpOwner;
     61 
     62     OBCC_ExportVarList *mpExportVars;
     63     OBCC_ExportFuncList *mpExportFuncs;
     64     PragmaList mPragmas;
     65     OBCC_ObjectSlotList *mpObjectSlotList;
     66 
     67     FuncTable mFunctions;
     68 
     69 #if USE_OLD_JIT
     70     char *mContext;
     71 #endif
     72 
     73 #if USE_MCJIT
     74     RSExecRef mRSExecutable;
     75 #endif
     76 
     77     OBCC_StringPool *mpStringPoolRaw;
     78     std::vector<char const *> mStringPool;
     79 
     80     bool mLibRSThreadable;
     81 
     82   public:
     83     ScriptCached(Script *owner)
     84       : mpOwner(owner),
     85         mpExportVars(NULL),
     86         mpExportFuncs(NULL),
     87         mpObjectSlotList(NULL),
     88 #if USE_OLD_JIT
     89         mContext(NULL),
     90 #endif
     91         mpStringPoolRaw(NULL),
     92         mLibRSThreadable(false) {
     93     }
     94 
     95     ~ScriptCached();
     96 
     97     void *lookup(const char *name);
     98 
     99 
    100     size_t getExportVarCount() const {
    101       return mpExportVars->count;
    102     }
    103 
    104     size_t getExportFuncCount() const {
    105       return mpExportFuncs->count;
    106     }
    107 
    108     size_t getPragmaCount() const {
    109       return mPragmas.size();
    110     }
    111 
    112     size_t getFuncCount() const {
    113       return mFunctions.size();
    114     }
    115 
    116     size_t getObjectSlotCount() const {
    117       return mpObjectSlotList->count;
    118     }
    119 
    120     void getExportVarList(size_t varListSize, void **varList);
    121 
    122     void getExportFuncList(size_t funcListSize, void **funcList);
    123 
    124     void getPragmaList(size_t pragmaListSize,
    125                        char const **keyList,
    126                        char const **valueList);
    127 
    128     void getFuncInfoList(size_t funcInfoListSize, FuncInfo *funcNameList);
    129 
    130     void getObjectSlotList(size_t objectSlotListSize,
    131                            uint32_t *objectSlotList);
    132 
    133 #if USE_OLD_JIT
    134     char *getContext() {
    135       return mContext;
    136     }
    137 #endif
    138 
    139     // Dirty hack for libRS.
    140     // TODO(all): This should be removed in the future.
    141     bool isLibRSThreadable() const {
    142       return mLibRSThreadable;
    143     }
    144 
    145 #if 0
    146     void registerSymbolCallback(BCCSymbolLookupFn pFn, BCCvoid *pContext) {
    147       mCompiler.registerSymbolCallback(pFn, pContext);
    148     }
    149 #endif
    150   };
    151 
    152 } // namespace bcc
    153 
    154 #endif // BCC_SCRIPTCACHED_H
    155