• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H
17 #define ES2PANDA_COMPILER_CORE_COMPILER_CONTEXT_H
18 
19 #include <macros.h>
20 #include <mem/arena_allocator.h>
21 
22 #include <binder/variable.h>
23 #include <ir/astNode.h>
24 #include <util/patchFix.h>
25 #include <util/ustring.h>
26 
27 #include <cstdint>
28 #include <mutex>
29 
30 namespace panda::es2panda::binder {
31 class Binder;
32 }  // namespace panda::es2panda::binder
33 
34 namespace panda::es2panda::compiler {
35 
36 class DebugInfo;
37 class Emitter;
38 
39 class CompilerContext {
40 public:
41     CompilerContext(binder::Binder *binder, bool isDebug, bool isDebuggerEvaluateExpressionMode,
42                     bool isMergeAbc, bool isJsonInputFile, bool isRecordDebugSource,
43                     const std::string &sourceFile, const std::string &pkgName, util::StringView recordName,
44                     util::PatchFix *patchFixHelper);
45 
46     NO_COPY_SEMANTIC(CompilerContext);
47     NO_MOVE_SEMANTIC(CompilerContext);
48     ~CompilerContext() = default;
49 
Binder()50     binder::Binder *Binder() const
51     {
52         return binder_;
53     }
54 
SourceLang()55     pandasm::extensions::Language SourceLang() const
56     {
57         return binder_ ? binder_->SourceLang() : pandasm::extensions::DEFAULT_LANGUAGE;
58     }
59 
GetEmitter()60     Emitter *GetEmitter() const
61     {
62         return emitter_.get();
63     }
64 
LiteralCount()65     int32_t LiteralCount() const
66     {
67         return literalBufferIdx_;
68     }
69 
NewLiteralIndex()70     int32_t NewLiteralIndex()
71     {
72         std::lock_guard lock(m_);
73         return literalBufferIdx_++;
74     }
75 
Mutex()76     std::mutex &Mutex()
77     {
78         return m_;
79     }
80 
IsDebug()81     bool IsDebug() const
82     {
83         return isDebug_;
84     }
85 
isDebuggerEvaluateExpressionMode()86     bool isDebuggerEvaluateExpressionMode() const
87     {
88         return isDebuggerEvaluateExpressionMode_;
89     }
90 
IsMergeAbc()91     bool IsMergeAbc() const
92     {
93         return isMergeAbc_;
94     }
95 
SourceFile()96     std::string SourceFile() const
97     {
98         return sourceFile_;
99     }
100 
PkgName()101     std::string PkgName() const
102     {
103         return pkgName_;
104     }
105 
PatchFixHelper()106     util::PatchFix *PatchFixHelper() const
107     {
108         return patchFixHelper_;
109     }
110 
RecordName()111     const util::StringView &RecordName() const
112     {
113         return recordName_;
114     }
115 
IsJsonInputFile()116     bool IsJsonInputFile() const
117     {
118         return isJsonInputFile_;
119     }
120 
IsRecordDebugSource()121     bool IsRecordDebugSource() const
122     {
123         return isRecordDebugSource_;
124     }
125 
126 private:
127     binder::Binder *binder_;
128     int32_t literalBufferIdx_ {0};
129     std::mutex m_;
130     bool isDebug_;
131     bool isDebuggerEvaluateExpressionMode_;
132     bool isMergeAbc_;
133     // true when input file is json file
134     bool isJsonInputFile_;
135     bool isRecordDebugSource_;
136     std::string sourceFile_;
137     std::string pkgName_;
138     util::StringView recordName_;
139     util::PatchFix *patchFixHelper_ {nullptr};
140     std::unique_ptr<Emitter> emitter_;
141 };
142 
143 }  // namespace panda::es2panda::compiler
144 
145 #endif
146