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, bool enableColumn = false); 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 EnableColumn()86 bool EnableColumn() const 87 { 88 return enableColumn_; 89 } 90 isDebuggerEvaluateExpressionMode()91 bool isDebuggerEvaluateExpressionMode() const 92 { 93 return isDebuggerEvaluateExpressionMode_; 94 } 95 IsMergeAbc()96 bool IsMergeAbc() const 97 { 98 return isMergeAbc_; 99 } 100 SourceFile()101 std::string SourceFile() const 102 { 103 return sourceFile_; 104 } 105 PkgName()106 std::string PkgName() const 107 { 108 return pkgName_; 109 } 110 PatchFixHelper()111 util::PatchFix *PatchFixHelper() const 112 { 113 return patchFixHelper_; 114 } 115 RecordName()116 const util::StringView &RecordName() const 117 { 118 return recordName_; 119 } 120 IsJsonInputFile()121 bool IsJsonInputFile() const 122 { 123 return isJsonInputFile_; 124 } 125 IsRecordDebugSource()126 bool IsRecordDebugSource() const 127 { 128 return isRecordDebugSource_; 129 } 130 131 private: 132 binder::Binder *binder_; 133 int32_t literalBufferIdx_ {0}; 134 std::mutex m_; 135 bool isDebug_; 136 bool isDebuggerEvaluateExpressionMode_; 137 bool isMergeAbc_; 138 // true when input file is json file 139 bool isJsonInputFile_; 140 bool isRecordDebugSource_; 141 std::string sourceFile_; 142 std::string pkgName_; 143 util::StringView recordName_; 144 util::PatchFix *patchFixHelper_ {nullptr}; 145 std::unique_ptr<Emitter> emitter_; 146 bool enableColumn_ {false}; 147 }; 148 149 } // namespace panda::es2panda::compiler 150 151 #endif 152