blob: 62c73692dd2b6864c93d2770a842a1c77582225b [file] [log] [blame]
Logan3f3d31f2010-11-27 13:52:03 +08001/*
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -08002 * Copyright 2012, The Android Open Source Project
Logan3f3d31f2010-11-27 13:52:03 +08003 *
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
Zonr Changc72c4dd2012-04-12 15:38:53 +080017#ifndef BCC_SCRIPT_H
18#define BCC_SCRIPT_H
Loganeaa0cc32010-12-29 01:04:20 +080019
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080020#include <llvm/Support/CodeGen.h>
21
22namespace llvm {
23class Module;
24}
25
Logan3f3d31f2010-11-27 13:52:03 +080026namespace bcc {
Logancf3e5212010-12-29 01:44:55 +080027
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080028class Script;
Zonr Changccc39a82012-04-05 10:44:53 +080029class Source;
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080030class CompilerConfig;
31
32typedef llvm::Module *(*RSLinkRuntimeCallback)(bcc::Script *, llvm::Module *,
33 llvm::Module *);
Logan3f3d31f2010-11-27 13:52:03 +080034
Zonr Changccc39a82012-04-05 10:44:53 +080035class Script {
36private:
37 // This is the source associated with this object and is going to be
38 // compiled.
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080039 // TODO(jeanluc) Verify that the lifetime is managed correctly.
Zonr Changccc39a82012-04-05 10:44:53 +080040 Source *mSource;
Zonr Chang4ea08862012-01-17 17:26:49 +080041
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080042 llvm::CodeGenOpt::Level mOptimizationLevel;
43
44 RSLinkRuntimeCallback mLinkRuntimeCallback;
45
46 bool mEmbedInfo;
47
48 // Specifies whether we should embed global variable information in the
49 // code via special RS variables that can be examined later by the driver.
50 bool mEmbedGlobalInfo;
51
52 // Specifies whether we should skip constant (immutable) global variables
53 // when potentially embedding information about globals.
54 bool mEmbedGlobalInfoSkipConstant;
Logan39736412010-12-29 00:24:04 +080055
Zonr Changccc39a82012-04-05 10:44:53 +080056public:
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080057 explicit Script(Source *pSource);
Logancf3e5212010-12-29 01:44:55 +080058
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080059 ~Script() {}
Logancf3e5212010-12-29 01:44:55 +080060
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080061 bool LinkRuntime(const char *rt_path);
62
63 void setOptimizationLevel(llvm::CodeGenOpt::Level pOptimizationLevel) {
64 mOptimizationLevel = pOptimizationLevel;
65 }
66
67 llvm::CodeGenOpt::Level getOptimizationLevel() const {
68 return mOptimizationLevel;
69 }
70
71 void setLinkRuntimeCallback(RSLinkRuntimeCallback fn) {
72 mLinkRuntimeCallback = fn;
73 }
74
75 void setEmbedInfo(bool pEnable) { mEmbedInfo = pEnable; }
76
77 bool getEmbedInfo() const { return mEmbedInfo; }
78
79 // Set to true if we should embed global variable information in the code.
80 void setEmbedGlobalInfo(bool pEnable) { mEmbedGlobalInfo = pEnable; }
81
82 // Returns true if we should embed global variable information in the code.
83 bool getEmbedGlobalInfo() const { return mEmbedGlobalInfo; }
84
85 // Set to true if we should skip constant (immutable) global variables when
86 // potentially embedding information about globals.
87 void setEmbedGlobalInfoSkipConstant(bool pEnable) {
88 mEmbedGlobalInfoSkipConstant = pEnable;
89 }
90
91 // Returns true if we should skip constant (immutable) global variables when
92 // potentially embedding information about globals.
93 inline bool getEmbedGlobalInfoSkipConstant() const {
94 return mEmbedGlobalInfoSkipConstant;
95 }
Zonr Chang4ea08862012-01-17 17:26:49 +080096
Zonr Changccc39a82012-04-05 10:44:53 +080097 // Merge (or link) another source into the current source associated with
98 // this Script object. Return false on error.
99 //
100 // This is equivalent to the call to Script::merge(...) on mSource.
Stephen Hines57936132014-11-25 17:54:59 -0800101 bool mergeSource(Source &pSource);
Zonr Chang4ea08862012-01-17 17:26:49 +0800102
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -0800103 inline Source &getSource() { return *mSource; }
104 inline const Source &getSource() const { return *mSource; }
Zonr Changccc39a82012-04-05 10:44:53 +0800105};
Loganecf4cbd2011-01-06 05:34:11 +0800106
Zonr Changccc39a82012-04-05 10:44:53 +0800107} // end namespace bcc
Logan42598052011-01-26 22:41:13 +0800108
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -0800109#endif // BCC_SCRIPT_H