1/** 2 * Copyright (c) 2024 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 16bool HasMethodIdOperandDynamic(AbckitIsaApiDynamicOpcode opcode) 17{ 18 switch(opcode) { 19% Panda::instructions.uniq{|i| i.mnemonic}.each do |inst| 20% res = Opcodes.find{|opc| opc.bc_opcode == inst.mnemonic} 21% method_id_operand = inst.operands.find {|op| op.method_id?} 22% if not res.nil? and not method_id_operand.nil? 23 case <%= res.abckit_opcode %>: 24% end 25% end 26 return true; 27 default: 28 return false; 29 } 30} 31 32int GetMethodIdOperandIndexDynamic(AbckitIsaApiDynamicOpcode opcode) 33{ 34 switch(opcode) { 35% Panda::instructions.uniq{|i| i.mnemonic}.each do |inst| 36% res = Opcodes.find{|opc| opc.bc_opcode == inst.mnemonic} 37% method_id_operand = inst.operands.find {|op| op.method_id?} 38% if not res.nil? and not method_id_operand.nil? 39 case <%= res.abckit_opcode %>: 40 return <%= inst.operands.find_index(method_id_operand)%>; 41% end 42% end 43 default: 44 return -1; 45 } 46} 47 48% additional_deprecated_opcodes = ["JNSTRICTEQUNDEFINED", 49% "JSTRICTEQUNDEFINED", 50% "JNEUNDEFINED", 51% "JEQUNDEFINED", 52% "JNSTRICTEQNULL", 53% "JSTRICTEQNULL", 54% "JNENULL", 55% "JEQNULL", 56% "JNSTRICTEQZ", 57% "JSTRICTEQZ", 58% "STTOGLOBALRECORD", 59% "STCONSTTOGLOBALRECORD", 60% "CREATEREGEXPWITHLITERAL", 61% "CLOSEITERATOR"] 62 63% replaced_opcodes = ["JNSTRICTEQ", 64% "JSTRICTEQ", 65% "JNE", 66% "JEQ"] 67 68% skipped_opcodes = additional_deprecated_opcodes + replaced_opcodes 69 70bool HasStringIdOperandDynamic(AbckitIsaApiDynamicOpcode opcode) 71{ 72 switch(opcode) { 73 case ABCKIT_ISA_API_DYNAMIC_OPCODE_LOADSTRING: 74% Panda::instructions.uniq{|i| i.mnemonic}.each do |inst| 75% if !(skipped_opcodes.include? inst.mnemonic.upcase) 76% res = Opcodes.find{|opc| opc.bc_opcode == inst.mnemonic } 77% string_id_operand = inst.operands.find {|op| op.string_id?} 78% if not res.nil? and not string_id_operand.nil? 79 case <%= res.abckit_opcode %>: 80% end 81% end 82% end 83 return true; 84 default: 85 return false; 86 } 87} 88 89int GetStringIdOperandIndexDynamic(AbckitIsaApiDynamicOpcode opcode) 90{ 91 switch(opcode) { 92 case ABCKIT_ISA_API_DYNAMIC_OPCODE_LOADSTRING: 93 return 0; 94% Panda::instructions.uniq{|i| i.mnemonic}.each do |inst| 95% res = Opcodes.find{|opc| opc.bc_opcode == inst.mnemonic } 96% string_id_operand = inst.operands.find {|op| op.string_id?} 97% if not res.nil? and not string_id_operand.nil? 98 case <%= res.abckit_opcode %>: 99 return <%= inst.operands.find_index(string_id_operand) %>; 100% end 101% end 102 default: 103 return -1; 104 } 105} 106 107bool HasLiteralArrayIdOperandDynamic(AbckitIsaApiDynamicOpcode opcode) 108{ 109 switch(opcode) { 110% Panda::instructions.uniq{|i| i.mnemonic}.each do |inst| 111% res = Opcodes.find{|opc| opc.bc_opcode == inst.mnemonic } 112% litarr_id_operand = inst.operands.find {|op| op.literalarray_id?} 113% if not res.nil? and not litarr_id_operand.nil? 114 case <%= res.abckit_opcode %>: 115% end 116% end 117 return true; 118 default: 119 return false; 120 } 121} 122 123int GetLiteralArrayIdOperandIndexDynamic(AbckitIsaApiDynamicOpcode opcode) 124{ 125 switch(opcode) { 126% Panda::instructions.uniq{|i| i.mnemonic}.each do |inst| 127% res = Opcodes.find{|opc| opc.bc_opcode == inst.mnemonic && !inst.operands.find {|op| op.literalarray_id?}.nil? } 128% litarr_id_operand = inst.operands.find {|op| op.literalarray_id?} 129% if not res.nil? and not litarr_id_operand.nil? 130 case <%= res.abckit_opcode %>: 131 return <%= inst.operands.find_index(litarr_id_operand) %>; 132% end 133% end 134 default: 135 return -1; 136 } 137} 138