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 | |
David Gross | 97e5099 | 2017-03-29 20:52:30 +0000 | [diff] [blame^] | 20 | #include "slang_version.h" |
| 21 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 22 | #include <llvm/Support/CodeGen.h> |
David Gross | cf5afcb | 2017-03-20 15:23:26 -0700 | [diff] [blame] | 23 | #include "bcc/Source.h" |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 24 | |
| 25 | namespace llvm { |
| 26 | class Module; |
| 27 | } |
| 28 | |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 29 | namespace bcc { |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 30 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 31 | class Script; |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 32 | class Source; |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 33 | class CompilerConfig; |
| 34 | |
| 35 | typedef llvm::Module *(*RSLinkRuntimeCallback)(bcc::Script *, llvm::Module *, |
| 36 | llvm::Module *); |
Logan | 3f3d31f | 2010-11-27 13:52:03 +0800 | [diff] [blame] | 37 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 38 | class Script { |
| 39 | private: |
| 40 | // This is the source associated with this object and is going to be |
| 41 | // compiled. |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 42 | // TODO(jeanluc) Verify that the lifetime is managed correctly. |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 43 | Source *mSource; |
Zonr Chang | 4ea0886 | 2012-01-17 17:26:49 +0800 | [diff] [blame] | 44 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 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; |
Logan | 3973641 | 2010-12-29 00:24:04 +0800 | [diff] [blame] | 58 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 59 | public: |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 60 | explicit Script(Source *pSource); |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 61 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 62 | ~Script() {} |
Logan | cf3e521 | 2010-12-29 01:44:55 +0800 | [diff] [blame] | 63 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 64 | bool LinkRuntime(const char *rt_path); |
| 65 | |
David Gross | cf5afcb | 2017-03-20 15:23:26 -0700 | [diff] [blame] | 66 | unsigned getCompilerVersion() const { |
| 67 | return getSource().getCompilerVersion(); |
Jean-Luc Brouillet | fc9c55b | 2017-02-21 17:42:09 -0800 | [diff] [blame] | 68 | } |
| 69 | |
David Gross | 97e5099 | 2017-03-29 20:52:30 +0000 | [diff] [blame^] | 70 | bool isStructExplicitlyPaddedBySlang() const { |
| 71 | return getCompilerVersion() >= SlangVersion::N_STRUCT_EXPLICIT_PADDING; |
| 72 | } |
| 73 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 74 | void setOptimizationLevel(llvm::CodeGenOpt::Level pOptimizationLevel) { |
| 75 | mOptimizationLevel = pOptimizationLevel; |
| 76 | } |
| 77 | |
| 78 | llvm::CodeGenOpt::Level getOptimizationLevel() const { |
| 79 | return mOptimizationLevel; |
| 80 | } |
| 81 | |
| 82 | void setLinkRuntimeCallback(RSLinkRuntimeCallback fn) { |
| 83 | mLinkRuntimeCallback = fn; |
| 84 | } |
| 85 | |
| 86 | void setEmbedInfo(bool pEnable) { mEmbedInfo = pEnable; } |
| 87 | |
| 88 | bool getEmbedInfo() const { return mEmbedInfo; } |
| 89 | |
| 90 | // Set to true if we should embed global variable information in the code. |
| 91 | void setEmbedGlobalInfo(bool pEnable) { mEmbedGlobalInfo = pEnable; } |
| 92 | |
| 93 | // Returns true if we should embed global variable information in the code. |
| 94 | bool getEmbedGlobalInfo() const { return mEmbedGlobalInfo; } |
| 95 | |
| 96 | // Set to true if we should skip constant (immutable) global variables when |
| 97 | // potentially embedding information about globals. |
| 98 | void setEmbedGlobalInfoSkipConstant(bool pEnable) { |
| 99 | mEmbedGlobalInfoSkipConstant = pEnable; |
| 100 | } |
| 101 | |
| 102 | // Returns true if we should skip constant (immutable) global variables when |
| 103 | // potentially embedding information about globals. |
| 104 | inline bool getEmbedGlobalInfoSkipConstant() const { |
| 105 | return mEmbedGlobalInfoSkipConstant; |
| 106 | } |
Zonr Chang | 4ea0886 | 2012-01-17 17:26:49 +0800 | [diff] [blame] | 107 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 108 | // Merge (or link) another source into the current source associated with |
| 109 | // this Script object. Return false on error. |
| 110 | // |
| 111 | // This is equivalent to the call to Script::merge(...) on mSource. |
Stephen Hines | 5793613 | 2014-11-25 17:54:59 -0800 | [diff] [blame] | 112 | bool mergeSource(Source &pSource); |
Zonr Chang | 4ea0886 | 2012-01-17 17:26:49 +0800 | [diff] [blame] | 113 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 114 | inline Source &getSource() { return *mSource; } |
| 115 | inline const Source &getSource() const { return *mSource; } |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 116 | }; |
Logan | ecf4cbd | 2011-01-06 05:34:11 +0800 | [diff] [blame] | 117 | |
Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 118 | } // end namespace bcc |
Logan | 4259805 | 2011-01-26 22:41:13 +0800 | [diff] [blame] | 119 | |
Jean-Luc Brouillet | 0a2acce | 2017-02-17 13:29:47 -0800 | [diff] [blame] | 120 | #endif // BCC_SCRIPT_H |