blob: 3b10d82031893b0729f2ef5c6b51ee627974b83f [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
David Gross97e50992017-03-29 20:52:30 +000020#include "slang_version.h"
21
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080022#include <llvm/Support/CodeGen.h>
David Grosscf5afcb2017-03-20 15:23:26 -070023#include "bcc/Source.h"
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080024
25namespace llvm {
26class Module;
27}
28
Logan3f3d31f2010-11-27 13:52:03 +080029namespace bcc {
Logancf3e5212010-12-29 01:44:55 +080030
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080031class Script;
Zonr Changccc39a82012-04-05 10:44:53 +080032class Source;
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080033class CompilerConfig;
34
35typedef llvm::Module *(*RSLinkRuntimeCallback)(bcc::Script *, llvm::Module *,
36 llvm::Module *);
Logan3f3d31f2010-11-27 13:52:03 +080037
Zonr Changccc39a82012-04-05 10:44:53 +080038class Script {
39private:
40 // This is the source associated with this object and is going to be
41 // compiled.
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080042 // TODO(jeanluc) Verify that the lifetime is managed correctly.
Zonr Changccc39a82012-04-05 10:44:53 +080043 Source *mSource;
Zonr Chang4ea08862012-01-17 17:26:49 +080044
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080045 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;
Logan39736412010-12-29 00:24:04 +080058
Zonr Changccc39a82012-04-05 10:44:53 +080059public:
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080060 explicit Script(Source *pSource);
Logancf3e5212010-12-29 01:44:55 +080061
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080062 ~Script() {}
Logancf3e5212010-12-29 01:44:55 +080063
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080064 bool LinkRuntime(const char *rt_path);
65
David Grosscf5afcb2017-03-20 15:23:26 -070066 unsigned getCompilerVersion() const {
67 return getSource().getCompilerVersion();
Jean-Luc Brouilletfc9c55b2017-02-21 17:42:09 -080068 }
69
David Gross97e50992017-03-29 20:52:30 +000070 bool isStructExplicitlyPaddedBySlang() const {
71 return getCompilerVersion() >= SlangVersion::N_STRUCT_EXPLICIT_PADDING;
72 }
73
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -080074 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 Chang4ea08862012-01-17 17:26:49 +0800107
Zonr Changccc39a82012-04-05 10:44:53 +0800108 // 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 Hines57936132014-11-25 17:54:59 -0800112 bool mergeSource(Source &pSource);
Zonr Chang4ea08862012-01-17 17:26:49 +0800113
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -0800114 inline Source &getSource() { return *mSource; }
115 inline const Source &getSource() const { return *mSource; }
Zonr Changccc39a82012-04-05 10:44:53 +0800116};
Loganecf4cbd2011-01-06 05:34:11 +0800117
Zonr Changccc39a82012-04-05 10:44:53 +0800118} // end namespace bcc
Logan42598052011-01-26 22:41:13 +0800119
Jean-Luc Brouillet0a2acce2017-02-17 13:29:47 -0800120#endif // BCC_SCRIPT_H