Script.h revision fc9c55b0c248a04a325c3540b75ecd3ae64fd91f
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_SCRIPT_H
18#define BCC_SCRIPT_H
19
20#include <llvm/Support/CodeGen.h>
21
22namespace llvm {
23class Module;
24}
25
26namespace bcc {
27
28class Script;
29class Source;
30class CompilerConfig;
31
32typedef llvm::Module *(*RSLinkRuntimeCallback)(bcc::Script *, llvm::Module *,
33                                               llvm::Module *);
34
35class Script {
36private:
37  // This is the source associated with this object and is going to be
38  // compiled.
39  // TODO(jeanluc) Verify that the lifetime is managed correctly.
40  Source *mSource;
41
42  // Currently unused.  Will be used in an upcoming CL to fix small_struct bug.
43  unsigned mCompilerVersion;
44
45  llvm::CodeGenOpt::Level mOptimizationLevel;
46
47  RSLinkRuntimeCallback mLinkRuntimeCallback;
48
49  bool mEmbedInfo;
50
51  // Specifies whether we should embed global variable information in the
52  // code via special RS variables that can be examined later by the driver.
53  bool mEmbedGlobalInfo;
54
55  // Specifies whether we should skip constant (immutable) global variables
56  // when potentially embedding information about globals.
57  bool mEmbedGlobalInfoSkipConstant;
58
59public:
60  explicit Script(Source *pSource);
61
62  ~Script() {}
63
64  bool LinkRuntime(const char *rt_path);
65
66  void setCompilerVersion(unsigned pCompilerVersion) {
67    mCompilerVersion = pCompilerVersion;
68  }
69
70  unsigned getCompilerVersion() const { return mCompilerVersion; }
71
72  void setOptimizationLevel(llvm::CodeGenOpt::Level pOptimizationLevel) {
73    mOptimizationLevel = pOptimizationLevel;
74  }
75
76  llvm::CodeGenOpt::Level getOptimizationLevel() const {
77    return mOptimizationLevel;
78  }
79
80  void setLinkRuntimeCallback(RSLinkRuntimeCallback fn) {
81    mLinkRuntimeCallback = fn;
82  }
83
84  void setEmbedInfo(bool pEnable) { mEmbedInfo = pEnable; }
85
86  bool getEmbedInfo() const { return mEmbedInfo; }
87
88  // Set to true if we should embed global variable information in the code.
89  void setEmbedGlobalInfo(bool pEnable) { mEmbedGlobalInfo = pEnable; }
90
91  // Returns true if we should embed global variable information in the code.
92  bool getEmbedGlobalInfo() const { return mEmbedGlobalInfo; }
93
94  // Set to true if we should skip constant (immutable) global variables when
95  // potentially embedding information about globals.
96  void setEmbedGlobalInfoSkipConstant(bool pEnable) {
97    mEmbedGlobalInfoSkipConstant = pEnable;
98  }
99
100  // Returns true if we should skip constant (immutable) global variables when
101  // potentially embedding information about globals.
102  inline bool getEmbedGlobalInfoSkipConstant() const {
103    return mEmbedGlobalInfoSkipConstant;
104  }
105
106  // Merge (or link) another source into the current source associated with
107  // this Script object. Return false on error.
108  //
109  // This is equivalent to the call to Script::merge(...) on mSource.
110  bool mergeSource(Source &pSource);
111
112  inline Source &getSource() { return *mSource; }
113  inline const Source &getSource() const { return *mSource; }
114};
115
116} // end namespace bcc
117
118#endif // BCC_SCRIPT_H
119