Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 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 | |
Stephen Hines | 2f6a493 | 2012-05-03 12:27:13 -0700 | [diff] [blame] | 17 | #ifndef BCC_EXECUTION_ENGINE_RS_SCRIPT_H |
| 18 | #define BCC_EXECUTION_ENGINE_RS_SCRIPT_H |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 19 | |
Stephen Hines | 7dfc4d8 | 2012-05-03 12:25:21 -0700 | [diff] [blame] | 20 | #include <string> |
| 21 | |
| 22 | #include <llvm/ADT/SmallVector.h> |
| 23 | #include <llvm/Support/CodeGen.h> |
| 24 | |
Stephen Hines | 2f6a493 | 2012-05-03 12:27:13 -0700 | [diff] [blame] | 25 | #include "Script.h" |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 26 | |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 27 | namespace bcc { |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 28 | |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 29 | class RSInfo; |
| 30 | class Source; |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 31 | |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 32 | class RSScript : public Script { |
| 33 | public: |
Stephen Hines | 7dfc4d8 | 2012-05-03 12:25:21 -0700 | [diff] [blame] | 34 | class SourceDependency { |
| 35 | private: |
| 36 | std::string mSourceName; |
Stephen Hines | 6975a66 | 2012-05-03 12:26:44 -0700 | [diff] [blame] | 37 | uint8_t mSHA1[20]; |
Stephen Hines | 7dfc4d8 | 2012-05-03 12:25:21 -0700 | [diff] [blame] | 38 | |
| 39 | public: |
| 40 | SourceDependency(const std::string &pSourceName, |
| 41 | const uint8_t *pSHA1); |
| 42 | |
| 43 | inline const std::string &getSourceName() const |
| 44 | { return mSourceName; } |
| 45 | |
| 46 | inline const uint8_t *getSHA1Checksum() const |
| 47 | { return mSHA1; } |
| 48 | }; |
| 49 | typedef llvm::SmallVectorImpl<SourceDependency *> SourceDependencyListTy; |
| 50 | |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 51 | // This is one-one mapping with the llvm::CodeGenOpt::Level in |
| 52 | // llvm/Support/CodeGen.h. Therefore, value of this type can safely cast |
| 53 | // to llvm::CodeGenOpt::Level. This makes RSScript LLVM-free. |
| 54 | enum OptimizationLevel { |
| 55 | kOptLvl0, // -O0 |
| 56 | kOptLvl1, // -O1 |
| 57 | kOptLvl2, // -O2, -Os |
| 58 | kOptLvl3 // -O3 |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 59 | }; |
| 60 | |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 61 | private: |
Stephen Hines | 7dfc4d8 | 2012-05-03 12:25:21 -0700 | [diff] [blame] | 62 | llvm::SmallVector<SourceDependency *, 4> mSourceDependencies; |
| 63 | |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 64 | const RSInfo *mInfo; |
| 65 | |
| 66 | unsigned mCompilerVersion; |
| 67 | |
| 68 | OptimizationLevel mOptimizationLevel; |
| 69 | |
| 70 | private: |
| 71 | // This will be invoked when the containing source has been reset. |
| 72 | virtual bool doReset(); |
| 73 | |
| 74 | public: |
| 75 | RSScript(Source &pSource); |
| 76 | |
Stephen Hines | 7dfc4d8 | 2012-05-03 12:25:21 -0700 | [diff] [blame] | 77 | // Add dependency information for this script given the source named |
| 78 | // pSourceName. pSHA1 is the SHA-1 checksum of the given source. Return |
| 79 | // false on error. |
| 80 | bool addSourceDependency(const std::string &pSourceName, |
| 81 | const uint8_t *pSHA1); |
| 82 | |
| 83 | const SourceDependencyListTy &getSourceDependencies() const |
| 84 | { return mSourceDependencies; } |
| 85 | |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 86 | // Set the associated RSInfo of the script. |
| 87 | void setInfo(const RSInfo *pInfo) |
| 88 | { mInfo = pInfo; } |
| 89 | |
| 90 | const RSInfo *getInfo() const |
| 91 | { return mInfo; } |
| 92 | |
| 93 | void setCompilerVersion(unsigned pCompilerVersion) |
| 94 | { mCompilerVersion = pCompilerVersion; } |
| 95 | |
| 96 | unsigned getCompilerVersion() const |
| 97 | { return mCompilerVersion; } |
| 98 | |
| 99 | void setOptimizationLevel(OptimizationLevel pOptimizationLevel) |
| 100 | { mOptimizationLevel = pOptimizationLevel; } |
| 101 | |
| 102 | OptimizationLevel getOptimizationLevel() const |
| 103 | { return mOptimizationLevel; } |
Stephen Hines | 7dfc4d8 | 2012-05-03 12:25:21 -0700 | [diff] [blame] | 104 | |
| 105 | ~RSScript(); |
Zonr Chang | fef9a1b | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | } // end namespace bcc |
Zonr Chang | 19218c0 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 109 | |
Stephen Hines | 2f6a493 | 2012-05-03 12:27:13 -0700 | [diff] [blame] | 110 | #endif // BCC_EXECUTION_ENGINE_RS_SCRIPT_H |