blob: 1ae9c9d1096fc0c7c8612b8eb938a2eb45f27554 [file] [log] [blame]
Zonr Chang19218c02012-04-05 10:44:53 +08001/*
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 Hines2f6a4932012-05-03 12:27:13 -070017#ifndef BCC_EXECUTION_ENGINE_RS_SCRIPT_H
18#define BCC_EXECUTION_ENGINE_RS_SCRIPT_H
Zonr Chang19218c02012-04-05 10:44:53 +080019
Stephen Hines7dfc4d82012-05-03 12:25:21 -070020#include <string>
21
22#include <llvm/ADT/SmallVector.h>
23#include <llvm/Support/CodeGen.h>
24
Stephen Hines2f6a4932012-05-03 12:27:13 -070025#include "Script.h"
Zonr Chang19218c02012-04-05 10:44:53 +080026
Zonr Chang19218c02012-04-05 10:44:53 +080027namespace bcc {
Zonr Chang19218c02012-04-05 10:44:53 +080028
Zonr Changfef9a1b2012-04-13 15:58:24 +080029class RSInfo;
30class Source;
Zonr Chang19218c02012-04-05 10:44:53 +080031
Zonr Changfef9a1b2012-04-13 15:58:24 +080032class RSScript : public Script {
33public:
Stephen Hines7dfc4d82012-05-03 12:25:21 -070034 class SourceDependency {
35 private:
36 std::string mSourceName;
Stephen Hines6975a662012-05-03 12:26:44 -070037 uint8_t mSHA1[20];
Stephen Hines7dfc4d82012-05-03 12:25:21 -070038
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 Changfef9a1b2012-04-13 15:58:24 +080051 // 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 Chang19218c02012-04-05 10:44:53 +080059 };
60
Zonr Changfef9a1b2012-04-13 15:58:24 +080061private:
Stephen Hines7dfc4d82012-05-03 12:25:21 -070062 llvm::SmallVector<SourceDependency *, 4> mSourceDependencies;
63
Zonr Changfef9a1b2012-04-13 15:58:24 +080064 const RSInfo *mInfo;
65
66 unsigned mCompilerVersion;
67
68 OptimizationLevel mOptimizationLevel;
69
70private:
71 // This will be invoked when the containing source has been reset.
72 virtual bool doReset();
73
74public:
75 RSScript(Source &pSource);
76
Stephen Hines7dfc4d82012-05-03 12:25:21 -070077 // 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 Changfef9a1b2012-04-13 15:58:24 +080086 // 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 Hines7dfc4d82012-05-03 12:25:21 -0700104
105 ~RSScript();
Zonr Changfef9a1b2012-04-13 15:58:24 +0800106};
107
108} // end namespace bcc
Zonr Chang19218c02012-04-05 10:44:53 +0800109
Stephen Hines2f6a4932012-05-03 12:27:13 -0700110#endif // BCC_EXECUTION_ENGINE_RS_SCRIPT_H