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 #include "asyncFunctionBuilder.h"
17
18 #include "compiler/core/pandagen.h"
19 #include "compiler/base/catchTable.h"
20 #include "ir/base/scriptFunction.h"
21
22 namespace panda::es2panda::compiler {
DirectReturn(const ir::AstNode * node) const23 void AsyncFunctionBuilder::DirectReturn(const ir::AstNode *node) const
24 {
25 pg_->AsyncFunctionResolve(node, funcObj_);
26 pg_->EmitReturn(node);
27 }
28
ImplicitReturn(const ir::AstNode * node) const29 void AsyncFunctionBuilder::ImplicitReturn(const ir::AstNode *node) const
30 {
31 pg_->LoadConst(node, Constant::JS_UNDEFINED);
32 DirectReturn(node);
33 }
34
Prepare(const ir::ScriptFunction * node) const35 void AsyncFunctionBuilder::Prepare(const ir::ScriptFunction *node) const
36 {
37 pg_->AsyncFunctionEnter(node);
38 pg_->StoreAccumulator(node, funcObj_);
39 pg_->SetLabel(node, catchTable_->LabelSet().TryBegin());
40 }
41
CleanUp(const ir::ScriptFunction * node) const42 void AsyncFunctionBuilder::CleanUp(const ir::ScriptFunction *node) const
43 {
44 const auto &labelSet = catchTable_->LabelSet();
45
46 pg_->SetLabel(node, labelSet.TryEnd());
47 pg_->SetLabel(node, labelSet.CatchBegin());
48 pg_->AsyncFunctionReject(node, funcObj_);
49 pg_->EmitReturn(node);
50 pg_->SetLabel(node, labelSet.CatchEnd());
51 }
52 } // namespace panda::es2panda::compiler
53