1#!/usr/bin/env ruby 2# Copyright (c) 2021-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 15Instruction.class_eval do 16 def reg_dst? 17 dst = false 18 ops = operands 19 ops.each do |op| 20 dst = true if op.dst? 21 end 22 dst 23 end 24 25 def dst? 26 dst = false 27 ops = acc_and_operands 28 ops.each do |op| 29 dst = true if op.dst? 30 end 31 dst 32 end 33 34 def reg_src? 35 src = false 36 ops = operands 37 ops.each do |op| 38 next if op.id? 39 40 src = true if op.src? 41 end 42 src 43 end 44 45 def src? 46 src = false 47 ops = acc_and_operands 48 ops.each do |op| 49 next if op.id? 50 51 src = true if op.src? 52 end 53 src 54 end 55 56 def dyn? 57 properties.include?('dynamic') && !properties.include?('maybe_dynamic') 58 end 59 60 def in_ops 61 ops = operands 62 iops = [] 63 ops.each do |op| 64 next if op.id? 65 66 iops << op if op.src? 67 end 68 iops 69 end 70 71 def in_acc_and_ops 72 ops = acc_and_operands 73 iops = [] 74 ops.each do |op| 75 next if op.id? 76 77 iops << op if op.src? 78 end 79 iops 80 end 81 82 def core? 83 namespace == 'core' 84 end 85 86 def field_id? 87 sig.include?('field_id') 88 end 89 90 def literalarray_id? 91 sig.include?('literalarray_id') 92 end 93 94 def string_id? 95 sig.include?('string_id') 96 end 97 98 def static? 99 sig.include?('static') 100 end 101 102 def call? 103 sig.include?('call') 104 end 105 106 def type_id? 107 sig.include?('type_id') 108 end 109 110 def virt? 111 sig.include?('virt') 112 end 113 114 def isinstance? 115 sig.include?('isinstance') 116 end 117 118 def lda_type? 119 sig.include?('lda_type') 120 end 121 122 def newobj? 123 sig.include?('newobj') 124 end 125 126 def initobj? 127 sig.include?('initobj') 128 end 129 130 def ldobj_obj? 131 sig.include?('ldobj.obj') 132 end 133 134 def ldstatic_obj? 135 sig.include?('ldstatic.obj') 136 end 137 138 def ldobj_v_obj? 139 sig.include?('ldobj.v.obj') 140 end 141 142 def static_obj? 143 sig.include?('static.obj') 144 end 145end 146 147Operand.class_eval do 148 attr_accessor :insert 149end 150