• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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_TYPEDARRAY_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_BUILTINS_TYPEDARRAY_STUB_BUILDER_H
18 
19 #include "ecmascript/compiler/builtins/builtins_stubs.h"
20 #include "ecmascript/compiler/stub_builder-inl.h"
21 #include "ecmascript/js_arraybuffer.h"
22 #include "ecmascript/js_typed_array.h"
23 
24 namespace panda::ecmascript::kungfu {
25 class BuiltinsTypedArrayStubBuilder : public BuiltinsStubBuilder {
26 public:
BuiltinsTypedArrayStubBuilder(StubBuilder * parent)27     explicit BuiltinsTypedArrayStubBuilder(StubBuilder *parent)
28         : BuiltinsStubBuilder(parent) {}
29     ~BuiltinsTypedArrayStubBuilder() override = default;
30     NO_MOVE_SEMANTIC(BuiltinsTypedArrayStubBuilder);
31     NO_COPY_SEMANTIC(BuiltinsTypedArrayStubBuilder);
GenerateCircuit()32     void GenerateCircuit() override {}
33     GateRef FastGetPropertyByIndex(GateRef glue, GateRef array, GateRef index, GateRef jsType);
34     GateRef FastCopyElementToArray(GateRef glue, GateRef typedArray, GateRef array);
35     GateRef LoadTypedArrayElement(GateRef glue, GateRef array, GateRef key, GateRef jsType);
36     GateRef StoreTypedArrayElement(GateRef glue, GateRef array, GateRef index, GateRef value, GateRef jsType);
37     GateRef CheckTypedArrayIndexInRange(GateRef array, GateRef index);
38     GateRef GetValueFromBuffer(GateRef buffer, GateRef index, GateRef offset, GateRef jsType);
39     GateRef GetDataPointFromBuffer(GateRef arrBuf);
40     GateRef CalculatePositionWithLength(GateRef position, GateRef length);
41     void DoSort(GateRef glue, GateRef receiver, Variable *result, Label *exit, Label *slowPath);
42     void FastSetPropertyByIndex(GateRef glue, GateRef value, GateRef array, GateRef index, GateRef jsType);
43     void SetValueToBuffer(GateRef glue, GateRef value, GateRef buffer, GateRef index,
44                           GateRef offset, GateRef jsType, Label *slowPath);
45 
46 #define DECLARE_BUILTINS_TYPEDARRAY_STUB_BUILDER(method, ...)           \
47     void method(GateRef glue, GateRef numArgs, GateRef end, Variable *result, Label *exit, Label *slowPath);
BUILTINS_WITH_TYPEDARRAY_STUB_BUILDER(DECLARE_BUILTINS_TYPEDARRAY_STUB_BUILDER)48 BUILTINS_WITH_TYPEDARRAY_STUB_BUILDER(DECLARE_BUILTINS_TYPEDARRAY_STUB_BUILDER)
49 #undef DECLARE_BUILTINS_TYPEDARRAY_STUB_BUILDER
50 
51     GateRef GetViewedArrayBuffer(GateRef array)
52     {
53         GateRef offset = IntPtr(JSTypedArray::VIEWED_ARRAY_BUFFER_OFFSET);
54         return Load(VariableType::JS_ANY(), array, offset);
55     }
56 
GetArrayLength(GateRef array)57     GateRef GetArrayLength(GateRef array)
58     {
59         GateRef offset = IntPtr(JSTypedArray::ARRAY_LENGTH_OFFSET);
60         return Load(VariableType::INT32(), array, offset);
61     }
62 
GetByteOffset(GateRef array)63     GateRef GetByteOffset(GateRef array)
64     {
65         GateRef offset = IntPtr(JSTypedArray::BYTE_OFFSET_OFFSET);
66         return Load(VariableType::INT32(), array, offset);
67     }
68 
GetArrayBufferByteLength(GateRef buffer)69     GateRef GetArrayBufferByteLength(GateRef buffer)
70     {
71         GateRef offset = IntPtr(JSArrayBuffer::BYTE_LENGTH_OFFSET);
72         return Load(VariableType::INT32(), buffer, offset);
73     }
74 
GetExternalPointer(GateRef buffer)75     GateRef GetExternalPointer(GateRef buffer)
76     {
77         GateRef offset = IntPtr(JSNativePointer::POINTER_OFFSET);
78         return Load(VariableType::NATIVE_POINTER(), buffer, offset);
79     }
80 private:
ChangeByteArrayTaggedPointerToInt64(GateRef x)81     GateRef ChangeByteArrayTaggedPointerToInt64(GateRef x)
82     {
83         return GetEnvironment()->GetBuilder()->ChangeTaggedPointerToInt64(x);
84     }
85 private:
86     void BuildArrayIterator(GateRef glue, GateRef thisValue, GateRef numArgs,
87         Variable *result, Label *exit, Label *slowPath, IterationKind iteratorKind);
88 };
89 }  // namespace panda::ecmascript::kungfu
90 #endif  // ECMASCRIPT_COMPILER_BUILTINS_TYPEDARRAY_STUB_BUILDER_H