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 LoadTypedArrayElement(GateRef glue, GateRef array, GateRef key, GateRef jsType); 35 GateRef StoreTypedArrayElement(GateRef glue, GateRef array, GateRef index, GateRef value, GateRef jsType); 36 GateRef CheckTypedArrayIndexInRange(GateRef array, GateRef index); 37 GateRef GetValueFromBuffer(GateRef buffer, GateRef index, GateRef offset, GateRef jsType); 38 GateRef IsDetachedBuffer(GateRef buffer); 39 GateRef GetDataPointFromBuffer(GateRef arrBuf); 40 void SubArray(GateRef glue, GateRef thisValue, GateRef relativeBegin, GateRef end, 41 Variable *result, Label *exit, Label *slowPath); GetViewedArrayBuffer(GateRef array)42 GateRef GetViewedArrayBuffer(GateRef array) 43 { 44 GateRef offset = IntPtr(JSTypedArray::VIEWED_ARRAY_BUFFER_OFFSET); 45 return Load(VariableType::JS_ANY(), array, offset); 46 } 47 GetArrayLength(GateRef array)48 GateRef GetArrayLength(GateRef array) 49 { 50 GateRef offset = IntPtr(JSTypedArray::ARRAY_LENGTH_OFFSET); 51 return Load(VariableType::INT32(), array, offset); 52 } 53 GetByteOffset(GateRef array)54 GateRef GetByteOffset(GateRef array) 55 { 56 GateRef offset = IntPtr(JSTypedArray::BYTE_OFFSET_OFFSET); 57 return Load(VariableType::INT32(), array, offset); 58 } 59 GetArrayBufferData(GateRef buffer)60 GateRef GetArrayBufferData(GateRef buffer) 61 { 62 GateRef offset = IntPtr(JSArrayBuffer::DATA_OFFSET); 63 return Load(VariableType::JS_ANY(), buffer, offset); 64 } 65 GetArrayBufferByteLength(GateRef buffer)66 GateRef GetArrayBufferByteLength(GateRef buffer) 67 { 68 GateRef offset = IntPtr(JSArrayBuffer::BYTE_LENGTH_OFFSET); 69 return Load(VariableType::INT32(), buffer, offset); 70 } 71 GetExternalPointer(GateRef buffer)72 GateRef GetExternalPointer(GateRef buffer) 73 { 74 GateRef offset = IntPtr(JSNativePointer::POINTER_OFFSET); 75 return Load(VariableType::JS_ANY(), buffer, offset); 76 } 77 }; 78 } // namespace panda::ecmascript::kungfu 79 #endif // ECMASCRIPT_COMPILER_TYPED_ARRAY_STUB_BUILDER_H