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 15module GeneratorTags 16 class Creator 17 def create(instr, command) 18 @create_list = {} 19 iops = instr.in_acc_and_ops 20 iops.each do |op| 21 type = op.type 22 if type.include?('ref') && !type.include?('[]') 23 @create_list['obj'] = true 24 elsif type.include?('[]') 25 @create_list['arr'] = create_arr(type) 26 end 27 end 28 create_id(instr, command) 29 create_spec(instr, command) 30 if instr.static? 31 command['field_id'] = 'R.field0' 32 @create_list['static'] = true 33 end 34 @create_list['func'] = instr.call? && !instr.virt? 35 @create_list['virt'] = instr.virt? 36 [command, @create_list] 37 end 38 39 def create_id(instr, command) 40 command['string_id'] = '"\\n"' if instr.string_id? 41 if instr.field_id? 42 command['field_id'] = 'R.field1' 43 @create_list['obj'] = true 44 end 45 if instr.literalarray_id? 46 command['literalarray_id'] = 'array' 47 @create_list['const_arr'] = {} 48 type = 'i64' 49 @create_list['const_arr']['type'] = type 50 end 51 if instr.type_id? 52 if instr.newobj? || instr.lda_type? 53 command['type_id'] = 'R' 54 @create_list['type'] = true 55 else 56 command['type_id'] = 'i64[]' 57 end 58 end 59 end 60 61 def create_spec(instr, command) 62 if instr.initobj? 63 command['ctor'] = 'R.ctor' 64 @create_list['ctor'] = true 65 end 66 if instr.isinstance? 67 @create_list['isinstance'] = true 68 @create_list['arr'] = create_arr('i64[]') 69 end 70 if instr.ldobj_obj? || instr.ldstatic_obj? || instr.ldobj_v_obj? 71 command['field_id'] = 'R.field3' 72 command['field_id'] = 'R.field4' if instr.static_obj? 73 end 74 if instr.call? 75 command['method_id'] = "foo_#{instr.opcode}" 76 command['method_id'] = "A.#{command['method_id']}" if instr.virt? 77 end 78 end 79 80 def create_arr(type) 81 array_params = {} 82 array_params['size'] = 10 83 type = 'i64[]' if ['top[]', 'ref[]'].include?(type) 84 array_params['type'] = type 85 array_params 86 end 87 end 88end 89