• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #ifndef ECMASCRIPT_COMPILER_TYPED_ARRAY_STUB_BUILDER_H
17 #define ECMASCRIPT_COMPILER_TYPED_ARRAY_STUB_BUILDER_H
18 
19 #include "ecmascript/compiler/stub_builder-inl.h"
20 #include "ecmascript/js_arraybuffer.h"
21 #include "ecmascript/js_typed_array.h"
22 
23 namespace panda::ecmascript::kungfu {
24 class TypedArrayStubBuilder : public StubBuilder {
25 public:
TypedArrayStubBuilder(StubBuilder * parent)26     explicit TypedArrayStubBuilder(StubBuilder *parent)
27         : StubBuilder(parent) {}
28     ~TypedArrayStubBuilder() override = default;
29     NO_MOVE_SEMANTIC(TypedArrayStubBuilder);
30     NO_COPY_SEMANTIC(TypedArrayStubBuilder);
GenerateCircuit()31     void GenerateCircuit() override {}
32     GateRef FastGetPropertyByIndex(GateRef glue, GateRef array, GateRef index, GateRef jsType);
33     GateRef FastCopyElementToArray(GateRef glue, GateRef typedArray, GateRef array);
34     GateRef GetValueFromBuffer(GateRef buffer, GateRef index, GateRef offset, GateRef jsType);
35     GateRef IsDetachedBuffer(GateRef buffer);
36     GateRef GetDataPointFromBuffer(GateRef arrBuf);
GetViewedArrayBuffer(GateRef array)37     GateRef GetViewedArrayBuffer(GateRef array)
38     {
39         GateRef offset = IntPtr(JSTypedArray::VIEWED_ARRAY_BUFFER_OFFSET);
40         return Load(VariableType::JS_ANY(), array, offset);
41     }
42 
GetArrayLength(GateRef array)43     GateRef GetArrayLength(GateRef array)
44     {
45         GateRef offset = IntPtr(JSTypedArray::ARRAY_LENGTH_OFFSET);
46         return Load(VariableType::INT32(), array, offset);
47     }
48 
GetByteOffset(GateRef array)49     GateRef GetByteOffset(GateRef array)
50     {
51         GateRef offset = IntPtr(JSTypedArray::BYTE_OFFSET_OFFSET);
52         return Load(VariableType::INT32(), array, offset);
53     }
54 
GetArrayBufferData(GateRef buffer)55     GateRef GetArrayBufferData(GateRef buffer)
56     {
57         GateRef offset = IntPtr(JSArrayBuffer::DATA_OFFSET);
58         return Load(VariableType::JS_ANY(), buffer, offset);
59     }
60 
GetArrayBufferByteLength(GateRef buffer)61     GateRef GetArrayBufferByteLength(GateRef buffer)
62     {
63         GateRef offset = IntPtr(JSArrayBuffer::BYTE_LENGTH_OFFSET);
64         return Load(VariableType::INT32(), buffer, offset);
65     }
66 
GetExternalPointer(GateRef buffer)67     GateRef GetExternalPointer(GateRef buffer)
68     {
69         GateRef offset = IntPtr(JSNativePointer::POINTER_OFFSET);
70         return Load(VariableType::JS_ANY(), buffer, offset);
71     }
72 };
73 }  // namespace panda::ecmascript::kungfu
74 #endif  // ECMASCRIPT_COMPILER_TYPED_ARRAY_STUB_BUILDER_H