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 #include "ScriptCompiled.h"
     18 
     19 #include "bcc_internal.h"
     20 #if USE_OLD_JIT
     21 #include "OldJIT/ContextManager.h"
     22 #endif
     23 #include "DebugHelper.h"
     24 
     25 namespace bcc {
     26 
     27 ScriptCompiled::~ScriptCompiled() {
     28 #if USE_OLD_JIT
     29   // Deallocate the BCC context
     30   if (mContext) {
     31     ContextManager::get().deallocateContext(mContext);
     32   }
     33 
     34   // Delete the emitted function information
     35   for (FuncInfoMap::iterator I = mEmittedFunctions.begin(),
     36        E = mEmittedFunctions.end(); I != E; I++) {
     37     if (I->second != NULL) {
     38       delete I->second;
     39     }
     40   }
     41 #endif
     42 }
     43 
     44 void ScriptCompiled::getExportVarList(size_t varListSize, void **varList) {
     45   if (varList) {
     46     size_t varCount = getExportVarCount();
     47 
     48     if (varCount > varListSize) {
     49       varCount = varListSize;
     50     }
     51 
     52     for (ExportVarList::const_iterator
     53          I = mExportVars.begin(), E = mExportVars.end();
     54          I != E && varCount > 0; ++I, --varCount) {
     55       *varList++ = *I;
     56     }
     57   }
     58 }
     59 
     60 void ScriptCompiled::getExportVarNameList(std::vector<std::string> &varList) {
     61   varList = mExportVarsName;
     62 }
     63 
     64 
     65 void ScriptCompiled::getExportFuncNameList(std::vector<std::string> &funcList) {
     66   funcList = mExportFuncsName;
     67 }
     68 
     69 
     70 void ScriptCompiled::getExportFuncList(size_t funcListSize, void **funcList) {
     71   if (funcList) {
     72     size_t funcCount = getExportFuncCount();
     73 
     74     if (funcCount > funcListSize) {
     75       funcCount = funcListSize;
     76     }
     77 
     78     for (ExportFuncList::const_iterator
     79          I = mExportFuncs.begin(), E = mExportFuncs.end();
     80          I != E && funcCount > 0; ++I, --funcCount) {
     81       *funcList++ = *I;
     82     }
     83   }
     84 }
     85 
     86 
     87 void ScriptCompiled::getPragmaList(size_t pragmaListSize,
     88                                    char const **keyList,
     89                                    char const **valueList) {
     90   size_t pragmaCount = getPragmaCount();
     91 
     92   if (pragmaCount > pragmaListSize) {
     93     pragmaCount = pragmaListSize;
     94   }
     95 
     96   for (PragmaList::const_iterator
     97        I = mPragmas.begin(), E = mPragmas.end();
     98        I != E && pragmaCount > 0; ++I, --pragmaCount) {
     99     if (keyList) { *keyList++ = I->first.c_str(); }
    100     if (valueList) { *valueList++ = I->second.c_str(); }
    101   }
    102 }
    103 
    104 
    105 void *ScriptCompiled::lookup(const char *name) {
    106 #if USE_OLD_JIT
    107   FuncInfoMap::const_iterator I = mEmittedFunctions.find(name);
    108   return (I == mEmittedFunctions.end()) ? NULL : I->second->addr;
    109 #endif
    110 
    111 #if USE_MCJIT
    112   return mCompiler.getSymbolAddress(name);
    113 #endif
    114 
    115   return NULL;
    116 }
    117 
    118 
    119 void ScriptCompiled::getFuncInfoList(size_t funcInfoListSize,
    120                                      FuncInfo *funcInfoList) {
    121   if (funcInfoList) {
    122     size_t funcCount = getFuncCount();
    123 
    124     if (funcCount > funcInfoListSize) {
    125       funcCount = funcInfoListSize;
    126     }
    127 
    128     FuncInfo *info = funcInfoList;
    129     for (FuncInfoMap::const_iterator
    130          I = mEmittedFunctions.begin(), E = mEmittedFunctions.end();
    131          I != E && funcCount > 0; ++I, ++info, --funcCount) {
    132       info->name = I->first.c_str();
    133       info->addr = I->second->addr;
    134       info->size = I->second->size;
    135     }
    136   }
    137 }
    138 
    139 void ScriptCompiled::getObjectSlotList(size_t objectSlotListSize,
    140                                        uint32_t *objectSlotList) {
    141   if (objectSlotList) {
    142     size_t objectSlotCount = getObjectSlotCount();
    143 
    144     if (objectSlotCount > objectSlotListSize) {
    145       objectSlotCount = objectSlotListSize;
    146     }
    147 
    148     for (ObjectSlotList::const_iterator
    149          I = mObjectSlots.begin(), E = mObjectSlots.end();
    150          I != E && objectSlotCount > 0; ++I, --objectSlotCount) {
    151       *objectSlotList++ = *I;
    152     }
    153   }
    154 
    155 }
    156 
    157 } // namespace bcc
    158