1/* 2 * Copyright (c) 2021 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 16#include <iostream> 17#include "assembly-ins.h" 18 19namespace panda::pandasm { 20 21std::string panda::pandasm::Ins::ToString(std::string endline, bool print_args /* = false */, 22 size_t first_arg_idx /* = 0*/) const { 23 std::string full_operation = ""; 24 std::string reg_case = ""; 25 if (this->set_label) { 26 full_operation += this->label +": "; 27 } 28 switch(this->opcode) { 29% Panda::instructions.group_by(&:mnemonic).each do |mnemonic, group| 30% insn = group.first 31% formats = group.map(&:format) 32% operands = insn.operands 33% properties = insn.properties 34 case panda::pandasm::Opcode::<%= insn.asm_token%>: { 35 full_operation += "<%= insn.mnemonic%>"; 36% print_kind = case 37% when insn.call? && !insn.properties.include?('method_id') 38% 'PrintKind::CALLI' 39% when insn.call? || !insn.public? 40% 'PrintKind::CALL' 41% else 42% 'PrintKind::DEFAULT' 43% end 44 full_operation += this->OperandsToString(<%= print_kind %>, print_args, first_arg_idx); 45 } break; 46% end 47% Panda::pseudo_instructions.each do |insn| 48 case panda::pandasm::Opcode::<%= insn.opcode %>: { 49 full_operation += "<%= insn.opcode %>"; 50 full_operation += this->OperandsToString(PrintKind::DEFAULT, print_args, first_arg_idx); 51 } break; 52% end 53 case panda::pandasm::Opcode::INVALID: { 54 full_operation += ""; 55 } break; 56 } 57 return full_operation + endline; 58} 59 60} // namespace panda::pandasm 61