RSScript.h revision a65fba6fd15b14d930809e64c84fb976a893d038
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
23namespace llvm {
24  class Module;
25}
26
27namespace bcc {
28
29class RSScript;
30class Source;
31
32typedef llvm::Module* (*RSLinkRuntimeCallback) (bcc::RSScript *, llvm::Module *, llvm::Module *);
33
34
35class RSScript : public Script {
36public:
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
47private:
48  unsigned mCompilerVersion;
49
50  OptimizationLevel mOptimizationLevel;
51
52  RSLinkRuntimeCallback mLinkRuntimeCallback;
53
54  bool mEmbedInfo;
55
56private:
57  // This will be invoked when the containing source has been reset.
58  virtual bool doReset();
59
60public:
61  static bool LinkRuntime(RSScript &pScript, const char *rt_path = nullptr);
62
63  RSScript(Source &pSource);
64
65  virtual ~RSScript() { }
66
67  void setCompilerVersion(unsigned pCompilerVersion) {
68    mCompilerVersion = pCompilerVersion;
69  }
70
71  unsigned getCompilerVersion() const {
72    return mCompilerVersion;
73  }
74
75  void setOptimizationLevel(OptimizationLevel pOptimizationLevel) {
76    mOptimizationLevel = pOptimizationLevel;
77  }
78
79  OptimizationLevel getOptimizationLevel() const {
80    return mOptimizationLevel;
81  }
82
83  void setLinkRuntimeCallback(RSLinkRuntimeCallback fn){
84    mLinkRuntimeCallback = fn;
85  }
86
87  void setEmbedInfo(bool pEnable) {
88    mEmbedInfo = pEnable;
89  }
90
91  bool getEmbedInfo() const {
92    return mEmbedInfo;
93  }
94};
95
96} // end namespace bcc
97
98#endif // BCC_RS_SCRIPT_H
99