• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_LINKEDLIST_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_LINKEDLIST_STUB_BUILDER_H
18 #include "ecmascript/compiler/stub_builder-inl.h"
19 #include "ecmascript/js_api/js_api_linked_list.h"
20 
21 namespace panda::ecmascript::kungfu {
22 class ContainersLinkedListStubBuilder : public StubBuilder {
23 public:
ContainersLinkedListStubBuilder(StubBuilder * parent)24     explicit ContainersLinkedListStubBuilder(StubBuilder *parent)
25         : StubBuilder(parent) {}
26     ~ContainersLinkedListStubBuilder() override = default;
27     NO_MOVE_SEMANTIC(ContainersLinkedListStubBuilder);
28     NO_COPY_SEMANTIC(ContainersLinkedListStubBuilder);
GenerateCircuit()29     void GenerateCircuit() override {}
30 
GetTableLength(GateRef obj)31     GateRef GetTableLength(GateRef obj)
32     {
33         GateRef tableOffset = IntPtr(JSAPILinkedList::DOUBLE_LIST_OFFSET);
34         GateRef table = Load(VariableType::JS_POINTER(), obj, tableOffset);
35         GateRef value = GetValueFromTaggedArray(table, Int32(TaggedDoubleList::NUMBER_OF_NODE_INDEX));
36         return TaggedGetInt(value);
37     }
38 
GetNode(GateRef obj,GateRef index)39     GateRef GetNode(GateRef obj, GateRef index)
40     {
41         GateRef tableOffset = IntPtr(JSAPILinkedList::DOUBLE_LIST_OFFSET);
42         GateRef table = Load(VariableType::JS_POINTER(), obj, tableOffset);
43         return GetValueFromTaggedArray(table, index);
44     }
45 };
46 }  // namespace panda::ecmascript::kungfu
47 #endif  // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_LINKEDLIST_STUB_BUILDER_H