1 /* 2 * Copyright (c) 2021 - 2023 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_REG_SCOPE_H 17 #define ES2PANDA_COMPILER_CORE_REG_SCOPE_H 18 19 #include "macros.h" 20 #include "varbinder/scope.h" 21 22 namespace ark::es2panda::ir { 23 class AstNode; 24 } // namespace ark::es2panda::ir 25 26 namespace ark::es2panda::compiler { 27 class EnvScope; 28 class PandaGen; 29 class CodeGen; 30 31 class RegScope { 32 public: 33 explicit RegScope(CodeGen *cg); 34 NO_COPY_SEMANTIC(RegScope); 35 NO_MOVE_SEMANTIC(RegScope); 36 ~RegScope(); 37 38 void *operator new(size_t) = delete; 39 void *operator new[](size_t) = delete; 40 41 protected: 42 void DebuggerCloseScope(); 43 44 // NOLINTBEGIN(misc-non-private-member-variables-in-classes) 45 CodeGen *cg_; 46 uint32_t regBase_; 47 // NOLINTEND(misc-non-private-member-variables-in-classes) 48 }; 49 50 class LocalRegScope : public RegScope { 51 public: 52 explicit LocalRegScope(PandaGen *pg, varbinder::Scope *scope); 53 explicit LocalRegScope(CodeGen *cg, varbinder::Scope *scope); 54 explicit LocalRegScope(PandaGen *pg); 55 NO_COPY_SEMANTIC(LocalRegScope); 56 NO_MOVE_SEMANTIC(LocalRegScope); 57 ~LocalRegScope(); 58 59 void *operator new(size_t) = delete; 60 void *operator new[](size_t) = delete; 61 62 private: 63 varbinder::Scope *prevScope_ {}; 64 }; 65 66 class LoopRegScope : public RegScope { 67 public: 68 explicit LoopRegScope(PandaGen *pg, varbinder::LoopScope *scope); 69 NO_COPY_SEMANTIC(LoopRegScope); 70 NO_MOVE_SEMANTIC(LoopRegScope); 71 ~LoopRegScope(); 72 73 void *operator new(size_t) = delete; 74 void *operator new[](size_t) = delete; 75 76 private: 77 varbinder::Scope *prevScope_ {}; 78 }; 79 80 class FunctionRegScope : public RegScope { 81 public: 82 explicit FunctionRegScope(CodeGen *cg); 83 explicit FunctionRegScope(PandaGen *pg); 84 NO_COPY_SEMANTIC(FunctionRegScope); 85 NO_MOVE_SEMANTIC(FunctionRegScope); 86 ~FunctionRegScope(); 87 88 void *operator new(size_t) = delete; 89 void *operator new[](size_t) = delete; 90 91 private: 92 using StoreParamCb = std::function<void(varbinder::LocalVariable *, VReg)>; 93 void InitializeParams(const StoreParamCb &cb); 94 EnvScope *envScope_ {}; 95 }; 96 } // namespace ark::es2panda::compiler 97 98 #endif 99