From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4F1B33853814 for ; Thu, 7 Jul 2022 10:25:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F1B33853814 Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-164-YDLF3oUIM9y19YE4I8Sikg-1; Thu, 07 Jul 2022 06:25:14 -0400 X-MC-Unique: YDLF3oUIM9y19YE4I8Sikg-1 Received: by mail-wr1-f70.google.com with SMTP id h6-20020adfa4c6000000b0021d6a5ac938so2364376wrb.20 for ; Thu, 07 Jul 2022 03:25:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=oRXue4BOPGayo5pm4R8EmRxLrj2gTO5xCkuFRuizODE=; b=D4DEys7gD6zQmOSCPQA9u7zBHSQD3wmSchzXHYpDOG+hUsN+ZRhboBHrUodAzemo/I +4dkmsVqq04QwRZfR+LS8flduM2SwdBOeuNH+GN/sYXf+/oNtyKqu4DogTk73LdY0rPj NNzTg4xtiAhN2JFBhhxbZscIo+eooaV5xFEF8DEsFqwhkLrZfiMxbN6yhpr99o4MljfA 9KjE7J1ClbR5rh1Qc5tFqKWHVoMLUhVjEzBoGxestpCPIqKFWAe8OyQf3X0M+nhf3O8S xt95xJFTLv/LmIT9HWxEqp2MwgDVEDSWVUoVV6H6c7RS23h0J0oEPmi68WIYfTV8t6cy EbXQ== X-Gm-Message-State: AJIora9YegCB0KYdvUseOJgQamFi/yYFzZ4QJ88qJuWvytR58NqZ4QE4 IpGcs6mutjn3KHuc/im/DmFBbMzJ8s6/r+Hu1+xOxn5psTUyOblK+r10apUCnoGiu0iFGo+Z2Gd SkOMye5i/oOdgA02QvGLQlGbUcejWyH5UZiImQ0m3/To5lQEtJ9C8QlUqjGX4ub4r6rUAug== X-Received: by 2002:a05:600c:34c9:b0:3a0:5072:9abe with SMTP id d9-20020a05600c34c900b003a050729abemr3532897wmq.8.1657189512797; Thu, 07 Jul 2022 03:25:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sBWcN/4COo4VbrP0t1SykCpI3LV+XPb55YryxpFNr5DzfQzfCTpH7IRI6Nc3n6QG09F24K/w== X-Received: by 2002:a05:600c:34c9:b0:3a0:5072:9abe with SMTP id d9-20020a05600c34c900b003a050729abemr3532873wmq.8.1657189512515; Thu, 07 Jul 2022 03:25:12 -0700 (PDT) Received: from localhost (15.72.115.87.dyn.plus.net. [87.115.72.15]) by smtp.gmail.com with ESMTPSA id h15-20020a1ccc0f000000b0039749b01ea7sm37969503wmb.32.2022.07.07.03.25.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 03:25:12 -0700 (PDT) From: Andrew Burgess To: binutils@sourceware.org Cc: Andrew Burgess Subject: [PATCH] libopcodes/s390: add support for disassembler styling Date: Thu, 7 Jul 2022 11:25:09 +0100 Message-Id: <20220707102509.1267936-1-aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Jul 2022 10:25:18 -0000 This commit adds disassembler style to the libopcodes s390 disassembler. This conversion was pretty straight forward, I just converted the fprintf_func calls to fprintf_styled_func calls and added an appropriate style. For testing the new styling I just assembled then disassembled the source files in gas/testsuite/gas/s390 and manually checked that the styling looked reasonable. If the user does not request styled output from objdump, then there should be no change in the disassembler output after this commit. --- opcodes/s390-dis.c | 87 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 71 insertions(+), 16 deletions(-) diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c index 03715ed5f0b..df44efb95ab 100644 --- a/opcodes/s390-dis.c +++ b/opcodes/s390-dis.c @@ -186,7 +186,8 @@ s390_print_insn_with_opcode (bfd_vma memaddr, char separator; /* Mnemonic. */ - info->fprintf_func (info->stream, "%s", opcode->name); + info->fprintf_styled_func (info->stream, dis_style_mnemonic, + "%s", opcode->name); /* Operands. */ separator = '\t'; @@ -222,24 +223,60 @@ s390_print_insn_with_opcode (bfd_vma memaddr, } if (flags & S390_OPERAND_GPR) - info->fprintf_func (info->stream, "%c%%r%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%r%u", val.u); + } else if (flags & S390_OPERAND_FPR) - info->fprintf_func (info->stream, "%c%%f%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%f%u", val.u); + } else if (flags & S390_OPERAND_VR) - info->fprintf_func (info->stream, "%c%%v%i", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%v%i", val.u); + } else if (flags & S390_OPERAND_AR) - info->fprintf_func (info->stream, "%c%%a%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%a%u", val.u); + } else if (flags & S390_OPERAND_CR) - info->fprintf_func (info->stream, "%c%%c%u", separator, val.u); + { + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_register, + "%%c%u", val.u); + } else if (flags & S390_OPERAND_PCREL) { - info->fprintf_func (info->stream, "%c", separator); + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); info->print_address_func (memaddr + val.i + val.i, info); } else if (flags & S390_OPERAND_SIGNED) - info->fprintf_func (info->stream, "%c%i", separator, val.i); + { + enum disassembler_style style; + + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + style = ((flags & S390_OPERAND_DISP) + ? dis_style_address_offset : dis_style_immediate); + info->fprintf_styled_func (info->stream, style, "%i", val.i); + } else { + enum disassembler_style style; + if (flags & S390_OPERAND_OR1) val.u &= ~1; if (flags & S390_OPERAND_OR2) @@ -251,14 +288,18 @@ s390_print_insn_with_opcode (bfd_vma memaddr, && val.u == 0 && opindex[1] == 0) break; - info->fprintf_func (info->stream, "%c%u", separator, val.u); + info->fprintf_styled_func (info->stream, dis_style_text, + "%c", separator); + style = ((flags & S390_OPERAND_DISP) + ? dis_style_address_offset : dis_style_immediate); + info->fprintf_styled_func (info->stream, style, "%u", val.u); } if (flags & S390_OPERAND_DISP) separator = '('; else if (flags & S390_OPERAND_BASE) { - info->fprintf_func (info->stream, ")"); + info->fprintf_styled_func (info->stream, dis_style_text, ")"); separator = ','; } else @@ -361,19 +402,33 @@ print_insn_s390 (bfd_vma memaddr, struct disassemble_info *info) value = (value << 8) + (unsigned int) buffer[1]; value = (value << 8) + (unsigned int) buffer[2]; value = (value << 8) + (unsigned int) buffer[3]; - info->fprintf_func (info->stream, ".long\t0x%08x", value); + info->fprintf_styled_func (info->stream, dis_style_assembler_directive, + ".long"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%08x", value); return 4; case 2: value = (unsigned int) buffer[0]; value = (value << 8) + (unsigned int) buffer[1]; - info->fprintf_func (info->stream, ".short\t0x%04x", value); + info->fprintf_styled_func (info->stream, dis_style_assembler_directive, + ".short"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%04x", value); return 2; default: - info->fprintf_func (info->stream, ".byte\t0x%02x", - (unsigned int) buffer[0]); + info->fprintf_styled_func (info->stream, dis_style_assembler_directive, + ".byte"); + info->fprintf_styled_func (info->stream, dis_style_text, + "\t"); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%02x", (unsigned int) buffer[0]); for (i = 1; i < bytes_to_dump; i++) - info->fprintf_func (info->stream, ",0x%02x", - (unsigned int) buffer[i]); + info->fprintf_styled_func (info->stream, dis_style_immediate, + "0x%02x", (unsigned int) buffer[i]); return bytes_to_dump; } return 0; -- 2.25.4