/* * Copyright 2010, The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef BCC_SCRIPTCOMPILED_H #define BCC_SCRIPTCOMPILED_H #include "Compiler.h" #include "Script.h" #include #include #include #include #include #include namespace llvm { class Module; } namespace bcc { class ScriptCompiled { friend class Compiler; friend class CodeEmitter; private: typedef std::list > PragmaList; typedef std::list ExportVarList; typedef std::list ExportFuncList; typedef std::map FuncInfoMap; typedef std::list ObjectSlotList; private: Script *mpOwner; Compiler mCompiler; ExportVarList mExportVars; std::vector mExportVarsName; std::vector mExportFuncsName; ExportFuncList mExportFuncs; PragmaList mPragmas; ObjectSlotList mObjectSlots; FuncInfoMap mEmittedFunctions; #if USE_OLD_JIT char *mContext; // Context of BCC script (code and data) #endif public: ScriptCompiled(Script *owner) : mpOwner(owner), mCompiler(this) #if USE_OLD_JIT , mContext(NULL) #endif { } ~ScriptCompiled(); llvm::Module *parseBitcodeFile(llvm::MemoryBuffer *MEM) { return mCompiler.parseBitcodeFile(MEM); } int readModule(llvm::Module *module) { return mCompiler.readModule(module); } int linkModule(llvm::Module *module) { return mCompiler.linkModule(module); } int compile(bool compileOnly) { return mCompiler.compile(compileOnly); } char const *getCompilerErrorMessage() { return mCompiler.getErrorMessage(); } void *lookup(const char *name); size_t getExportVarCount() const { return mExportVars.size(); } size_t getExportFuncCount() const { return mExportFuncs.size(); } size_t getPragmaCount() const { return mPragmas.size(); } size_t getFuncCount() const { return mEmittedFunctions.size(); } size_t getObjectSlotCount() const { return mObjectSlots.size(); } void getExportVarList(size_t varListSize, void **varList); void getExportFuncList(size_t funcListSize, void **funcList); void getExportVarNameList(std::vector &varList); void getExportFuncNameList(std::vector &funcList); void getPragmaList(size_t pragmaListSize, char const **keyList, char const **valueList); void getFuncInfoList(size_t funcInfoListSize, FuncInfo *funcInfoList); void getObjectSlotList(size_t objectSlotListSize, uint32_t *objectSlotList); std::vector const & getUserDefinedExternalSymbols() const { return mpOwner->getUserDefinedExternalSymbols(); } #if USE_OLD_JIT char *getContext() { return mContext; } #endif #if USE_MCJIT const char *getELF() const { return &*mCompiler.getELF().begin(); } size_t getELFSize() const { return mCompiler.getELF().size(); } #endif void registerSymbolCallback(BCCSymbolLookupFn pFn, void *pContext) { mCompiler.registerSymbolCallback(pFn, pContext); } }; } // namespace bcc #endif // BCC_SCRIPTCOMPILED_H