1 /** 2 * Copyright (c) 2021-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 #ifndef PANDA_RUNTIME_VREGISTER_ITERATOR_H_ 16 #define PANDA_RUNTIME_VREGISTER_ITERATOR_H_ 17 18 namespace panda::interpreter { 19 20 template <BytecodeInstruction::Format format> 21 class VRegisterIterator { 22 public: 23 // NOLINTNEXTLINE(performance-move-const-arg) VRegisterIterator(BytecodeInstruction insn,Frame * frame)24 explicit VRegisterIterator(BytecodeInstruction insn, Frame *frame) : instn_(std::move(insn)), frame_(frame) {} 25 26 template <class T> GetAs(size_t param_idx)27 ALWAYS_INLINE inline T GetAs(size_t param_idx) const 28 { 29 size_t vreg_idx; 30 31 if constexpr (format == BytecodeInstruction::Format::V4_V4_ID16 /* short */) { 32 switch (param_idx) { 33 case 0: { 34 vreg_idx = instn_.GetVReg<format, 0>(); 35 break; 36 } 37 case 1: { 38 vreg_idx = instn_.GetVReg<format, 1>(); 39 break; 40 } 41 default: 42 UNREACHABLE(); 43 } 44 } else if constexpr (format == BytecodeInstruction::Format::V4_V4_V4_V4_ID16) { 45 switch (param_idx) { 46 case 0: { 47 vreg_idx = instn_.GetVReg<format, 0>(); 48 break; 49 } 50 case 1: { 51 vreg_idx = instn_.GetVReg<format, 1>(); 52 break; 53 } 54 case 2: { 55 vreg_idx = instn_.GetVReg<format, 2>(); 56 break; 57 } 58 case 3: { 59 vreg_idx = instn_.GetVReg<format, 3>(); 60 break; 61 } 62 default: 63 UNREACHABLE(); 64 } 65 } else if constexpr (format == BytecodeInstruction::Format::V8_ID16 /* range */) { 66 vreg_idx = instn_.GetVReg<format, 0>() + param_idx; 67 } else { 68 UNREACHABLE(); 69 } 70 71 auto vreg = frame_->GetVReg(vreg_idx); 72 return vreg.template GetAs<T>(); 73 } 74 75 private: 76 BytecodeInstruction instn_; 77 Frame *frame_; 78 }; 79 80 } // namespace panda::interpreter 81 82 #endif // PANDA_RUNTIME_CORETYPES_ARRAY_H_ 83