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_LIGHTWEIGHTMAP_STUB_BUILDER_H 17 #define ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_LIGHTWEIGHTMAP_STUB_BUILDER_H 18 #include "ecmascript/compiler/stub_builder-inl.h" 19 #include "ecmascript/js_api/js_api_lightweightmap.h" 20 21 namespace panda::ecmascript::kungfu { 22 class ContainersLightWeightMapStubBuilder : public StubBuilder { 23 public: ContainersLightWeightMapStubBuilder(StubBuilder * parent)24 explicit ContainersLightWeightMapStubBuilder(StubBuilder *parent) 25 : StubBuilder(parent) {} 26 ~ContainersLightWeightMapStubBuilder() override = default; 27 NO_MOVE_SEMANTIC(ContainersLightWeightMapStubBuilder); 28 NO_COPY_SEMANTIC(ContainersLightWeightMapStubBuilder); GenerateCircuit()29 void GenerateCircuit() override {} 30 GetSize(GateRef obj)31 GateRef GetSize(GateRef obj) 32 { 33 return Load(VariableType::INT32(), obj, IntPtr(JSAPILightWeightMap::LWP_LENGTH_OFFSET)); 34 } 35 GetKey(GateRef obj,GateRef index)36 GateRef GetKey(GateRef obj, GateRef index) 37 { 38 GateRef keysOffset = IntPtr(JSAPILightWeightMap::LWP_KEYS_OFFSET); 39 GateRef keys = Load(VariableType::JS_POINTER(), obj, keysOffset); 40 return GetValueFromTaggedArray(keys, index); 41 } 42 GetValue(GateRef obj,GateRef index)43 GateRef GetValue(GateRef obj, GateRef index) 44 { 45 GateRef valuesOffset = IntPtr(JSAPILightWeightMap::LWP_VALUES_OFFSET); 46 GateRef values = Load(VariableType::JS_POINTER(), obj, valuesOffset); 47 return GetValueFromTaggedArray(values, index); 48 } 49 }; 50 } // namespace panda::ecmascript::kungfu 51 #endif // ECMASCRIPT_COMPILER_BUILTINS_CONTAINERS_LIGHTWEIGHTMAP_STUB_BUILDER_H