• 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_VECTOR_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_VECTOR_STUB_BUILDER_H
18 #include "ecmascript/compiler/builtins/builtins_stubs.h"
19 #include "ecmascript/js_api/js_api_vector.h"
20 
21 namespace panda::ecmascript::kungfu {
22 class ContainersVectorStubBuilder : public BuiltinsStubBuilder {
23 public:
ContainersVectorStubBuilder(StubBuilder * parent)24     explicit ContainersVectorStubBuilder(StubBuilder *parent)
25         : BuiltinsStubBuilder(parent) {}
26     ~ContainersVectorStubBuilder() override = default;
27     NO_MOVE_SEMANTIC(ContainersVectorStubBuilder);
28     NO_COPY_SEMANTIC(ContainersVectorStubBuilder);
GenerateCircuit()29     void GenerateCircuit() override {}
30 
31 #define DECLARE_CONTAINERS_VECTOR_STUB_BUILDER(method, ...)           \
32     void method(GateRef glue, GateRef thisValue, GateRef numArgs, Variable *result, Label *exit, Label *slowPath);
BUILTINS_WITH_CONTAINERS_VECTOR_STUB_BUILDER(DECLARE_CONTAINERS_VECTOR_STUB_BUILDER)33 BUILTINS_WITH_CONTAINERS_VECTOR_STUB_BUILDER(DECLARE_CONTAINERS_VECTOR_STUB_BUILDER)
34 #undef DECLARE_CONTAINERS_VECTOR_STUB_BUILDER
35 
36     GateRef GetSize(GateRef obj)
37     {
38         return Load(VariableType::INT32(), obj, IntPtr(JSAPIVector::ELEMENT_COUNT_OFFSET));
39     }
40 
Get(GateRef obj,GateRef index)41     GateRef Get(GateRef obj, GateRef index)
42     {
43         GateRef elementsOffset = IntPtr(JSObject::ELEMENTS_OFFSET);
44         GateRef elements = Load(VariableType::JS_POINTER(), obj, elementsOffset);
45         return GetValueFromTaggedArray(elements, index);
46     }
Set(GateRef glue,GateRef obj,GateRef index,GateRef value)47     void Set(GateRef glue, GateRef obj, GateRef index, GateRef value)
48     {
49         GateRef elementsOffset = IntPtr(JSObject::ELEMENTS_OFFSET);
50         GateRef elements = Load(VariableType::JS_POINTER(), obj, elementsOffset);
51         SetValueToTaggedArray(VariableType::JS_ANY(), glue, elements, index, value);
52     }
53 };
54 }  // namespace panda::ecmascript::kungfu
55 #endif  // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_VECTOR_STUB_BUILDER_H
56