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_REG_SCOPE_H 17 #define ES2PANDA_COMPILER_CORE_REG_SCOPE_H 18 19 #include <macros.h> 20 #include <binder/scope.h> 21 22 namespace panda::es2panda::ir { 23 class AstNode; 24 } // namespace panda::es2panda::ir 25 26 namespace panda::es2panda::compiler { 27 28 class EnvScope; 29 class PandaGen; 30 31 class RegScope { 32 public: 33 explicit RegScope(PandaGen *pg); 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 PandaGen *pg_; 45 uint32_t regBase_; 46 }; 47 48 class LocalRegScope : public RegScope { 49 public: 50 explicit LocalRegScope(PandaGen *pg, binder::Scope *scope); 51 explicit LocalRegScope(PandaGen *pg); 52 NO_COPY_SEMANTIC(LocalRegScope); 53 NO_MOVE_SEMANTIC(LocalRegScope); 54 ~LocalRegScope(); 55 56 void *operator new(size_t) = delete; 57 void *operator new[](size_t) = delete; 58 59 private: 60 binder::Scope *prevScope_ {}; 61 }; 62 63 class LoopRegScope : public RegScope { 64 public: 65 explicit LoopRegScope(PandaGen *pg, binder::LoopScope *scope); 66 NO_COPY_SEMANTIC(LoopRegScope); 67 NO_MOVE_SEMANTIC(LoopRegScope); 68 ~LoopRegScope(); 69 70 void *operator new(size_t) = delete; 71 void *operator new[](size_t) = delete; 72 73 private: 74 binder::Scope *prevScope_ {}; 75 }; 76 77 class FunctionRegScope : public RegScope { 78 public: 79 explicit FunctionRegScope(PandaGen *pg); 80 NO_COPY_SEMANTIC(FunctionRegScope); 81 NO_MOVE_SEMANTIC(FunctionRegScope); 82 ~FunctionRegScope(); 83 84 void *operator new(size_t) = delete; 85 void *operator new[](size_t) = delete; 86 87 private: 88 EnvScope *envScope_; 89 }; 90 91 } // namespace panda::es2panda::compiler 92 93 #endif 94