1# Copyright (c) 2021-2024 Huawei Device Co., Ltd. 2# Licensed under the Apache License, Version 2.0 (the "License"); 3# you may not use this file except in compliance with the License. 4# You may obtain a copy of the License at 5# 6# http://www.apache.org/licenses/LICENSE-2.0 7# 8# Unless required by applicable law or agreed to in writing, software 9# distributed under the License is distributed on an "AS IS" BASIS, 10# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11# See the License for the specific language governing permissions and 12# limitations under the License. 13 14def check_N_v8_format(insn) 15 insn.operands.each do |op| 16 raise "Instruction " + insn.mnemonic + " has unexpected format " + insn.format.pretty if ! op.reg? || op.width != 8 17 end 18end 19 20def get_format_for(insn) 21 fmt = insn.format.pretty 22 if fmt == "imm4_v4_v4_v4_v4_v4" 23 # Merge imm4_v4_v4_v4_v4_v4 and imm4_v4_v4_v4 since they haave the same handling code 24 fmt = "imm4_v4_v4_v4" 25 end 26 27 if insn.prefix 28 if fmt != "pref_imm16_v8" && fmt != "pref_imm16_v8_prof16" 29 check_N_v8_format(insn) 30 end 31 fmt = insn.opcode 32 end 33 return "call_#{fmt}" 34end 35 36def get_call_insns 37 Panda.instructions.select { |insn| insn.properties.include?('call') && insn.properties.include?('dynamic') } 38end 39