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_SCRIPT_H 18 #define BCC_RS_SCRIPT_H 19 20 #include "bcc/Script.h" 21 #include "bcc/Support/Sha1Util.h" 22 23 namespace llvm { 24 class Module; 25 } // end namespace llvm 26 27 namespace bcc { 28 29 class RSInfo; 30 class RSScript; 31 class Source; 32 33 typedef llvm::Module* (*RSLinkRuntimeCallback) (bcc::RSScript *, llvm::Module *, llvm::Module *); 34 35 class RSScript : public Script { 36 public: 37 // This is one-one mapping with the llvm::CodeGenOpt::Level in 38 // llvm/Support/CodeGen.h. Therefore, value of this type can safely cast 39 // to llvm::CodeGenOpt::Level. This makes RSScript LLVM-free. 40 enum OptimizationLevel { 41 kOptLvl0, // -O0 42 kOptLvl1, // -O1 43 kOptLvl2, // -O2, -Os 44 kOptLvl3 // -O3 45 }; 46 47 private: 48 const RSInfo *mInfo; 49 50 unsigned mCompilerVersion; 51 52 OptimizationLevel mOptimizationLevel; 53 54 RSLinkRuntimeCallback mLinkRuntimeCallback; 55 56 bool mEmbedInfo; 57 58 private: 59 // This will be invoked when the containing source has been reset. 60 virtual bool doReset(); 61 62 public: 63 static bool LinkRuntime(RSScript &pScript, const char *rt_path = NULL); 64 65 RSScript(Source &pSource); 66 67 // Set the associated RSInfo of the script. setInfo(const RSInfo * pInfo)68 void setInfo(const RSInfo *pInfo) { 69 mInfo = pInfo; 70 } 71 getInfo()72 const RSInfo *getInfo() const { 73 return mInfo; 74 } 75 setCompilerVersion(unsigned pCompilerVersion)76 void setCompilerVersion(unsigned pCompilerVersion) { 77 mCompilerVersion = pCompilerVersion; 78 } 79 getCompilerVersion()80 unsigned getCompilerVersion() const { 81 return mCompilerVersion; 82 } 83 setOptimizationLevel(OptimizationLevel pOptimizationLevel)84 void setOptimizationLevel(OptimizationLevel pOptimizationLevel) { 85 mOptimizationLevel = pOptimizationLevel; 86 } 87 getOptimizationLevel()88 OptimizationLevel getOptimizationLevel() const { 89 return mOptimizationLevel; 90 } 91 setLinkRuntimeCallback(RSLinkRuntimeCallback fn)92 void setLinkRuntimeCallback(RSLinkRuntimeCallback fn){ 93 mLinkRuntimeCallback = fn; 94 } 95 setEmbedInfo(bool pEnable)96 void setEmbedInfo(bool pEnable) { 97 mEmbedInfo = pEnable; 98 } 99 getEmbedInfo()100 bool getEmbedInfo() const { 101 return mEmbedInfo; 102 } 103 }; 104 105 } // end namespace bcc 106 107 #endif // BCC_RS_SCRIPT_H 108