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