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     uint32_t insStartIndex_ {0};
47 };
48 
49 class LocalRegScope : public RegScope {
50 public:
51     explicit LocalRegScope(PandaGen *pg, binder::Scope *scope);
52     explicit LocalRegScope(PandaGen *pg);
53     NO_COPY_SEMANTIC(LocalRegScope);
54     NO_MOVE_SEMANTIC(LocalRegScope);
55     ~LocalRegScope() noexcept;
56 
57     void *operator new(size_t) = delete;
58     void *operator new[](size_t) = delete;
59 
60 private:
61     binder::Scope *prevScope_ {};
62 };
63 
64 class LoopRegScope : public RegScope {
65 public:
66     explicit LoopRegScope(PandaGen *pg, binder::LoopScope *scope);
67     NO_COPY_SEMANTIC(LoopRegScope);
68     NO_MOVE_SEMANTIC(LoopRegScope);
69     ~LoopRegScope();
70 
71     void *operator new(size_t) = delete;
72     void *operator new[](size_t) = delete;
73 
74 private:
75     binder::Scope *prevScope_ {};
76 };
77 
78 class FunctionRegScope : public RegScope {
79 public:
80     explicit FunctionRegScope(PandaGen *pg);
81     NO_COPY_SEMANTIC(FunctionRegScope);
82     NO_MOVE_SEMANTIC(FunctionRegScope);
83     ~FunctionRegScope() noexcept;
84 
85     void *operator new(size_t) = delete;
86     void *operator new[](size_t) = delete;
87 
88 private:
89     EnvScope *envScope_;
90 };
91 
92 }  // namespace panda::es2panda::compiler
93 
94 #endif
95