Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 1 | /* |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 2 | * Copyright 2012, The Android Open Source Project |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 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 | |
Zonr Chang | c72c4dd | 2012-04-12 15:38:53 +0800 | [diff] [blame] | 17 | #ifndef BCC_SCRIPT_H |
| 18 | #define BCC_SCRIPT_H |
Logan | eaa0cc3 | 2010-12-29 01:04:20 +0800 | [diff] [blame] | 19 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 20 | #include <llvm/Support/CodeGen.h> |
| 21 | |
| 22 | namespace llvm { |
| 23 | class Module; |
| 24 | } |
| 25 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 26 | namespace bcc { |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 27 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 28 | class Script; |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 29 | class Source; |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 30 | class CompilerConfig; |
| 31 | |
| 32 | typedef llvm::Module *(*RSLinkRuntimeCallback)(bcc::Script *, llvm::Module *, |
| 33 | llvm::Module *); |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 34 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 35 | class Script { |
| 36 | private: |
| 37 | // This is the source associated with this object and is going to be |
| 38 | // compiled. |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 39 | // TODO(jeanluc) Verify that the lifetime is managed correctly. |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 40 | Source *mSource; |
Zonr Chang | 4ea0886 | 2012-01-17 17:26:49 +0800 | [diff] [blame] | 41 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 42 | 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; |
Logan | 3973641 | 2010-12-29 00:24:04 +0800 | [diff] [blame] | 55 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 56 | public: |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 57 | explicit Script(Source *pSource); |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 58 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 59 | ~Script() {} |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 60 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 61 | 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 Chang | 4ea0886 | 2012-01-17 17:26:49 +0800 | [diff] [blame] | 96 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 97 | // 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 Hines | 5793613 | 2014-11-25 17:54:59 -0800 | [diff] [blame] | 101 | bool mergeSource(Source &pSource); |
Zonr Chang | 4ea0886 | 2012-01-17 17:26:49 +0800 | [diff] [blame] | 102 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 103 | inline Source &getSource() { return *mSource; } |
| 104 | inline const Source &getSource() const { return *mSource; } |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 105 | }; |
Logan | ecf4cbd | 2011-01-06 05:34:11 +0800 | [diff] [blame] | 106 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 107 | } // end namespace bcc |
Logan | 4259805 | 2011-01-26 22:41:13 +0800 | [diff] [blame] | 108 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame^] | 109 | #endif // BCC_SCRIPT_H |