From patchwork Tue May 21 05:54:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 90521 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B35463858416 for ; Tue, 21 May 2024 05:55:03 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by sourceware.org (Postfix) with ESMTPS id 3577E3858C50 for ; Tue, 21 May 2024 05:54:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3577E3858C50 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 3577E3858C50 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::52f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716270875; cv=none; b=NvOPoLXWPgewOP1UMzqHYLZwvb2TSLgWn9EQ2mjuGO53NmVSPEF1FoWbpD/3yjqOm3pffQZk6knmRquFsrNeyqZfvwrJotN59dq2W/YuJZ/3Kqf/vnuqXUCpOpXa6tI+/yeSvYjNgqBR6ND8FYsSb0FtyKQW+aj8Fgy9+6MZNQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716270875; c=relaxed/simple; bh=TLAPNiO6jRFlP5vKgsTH4FoZ2e949SGJW3XNpJ0irOM=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:From:To; b=Kk5lSnrvvLXyXiG/muxg7m4voXVpWgKd/arazmClIw2GjK/RDBhQyBHwsYXIZB/UBQXlyPHRSddQLF5xuISgnct3JJPzMCPOpA8jRjfDDeX2O3pqGH5vmjmAU/2DBW4YDqAGToM4uTG1bMKhp+Zk9HPUMN1P7oXMNZW6IeSMRmw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ed1-x52f.google.com with SMTP id 4fb4d7f45d1cf-574f7c0bab4so10558758a12.0 for ; Mon, 20 May 2024 22:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1716270871; x=1716875671; darn=sourceware.org; h=content-transfer-encoding:in-reply-to:autocrypt:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=D/m3N5OmWY8eBPTg26bHmnjd1NjBhMczeUKdLMDjktg=; b=F8P+G2w6/8XmM06JQNTCT1j4oxQqlKBVXUg3Ew9/5vb+pIEOChGW3IIzPewKjrLvht qwS08fUpdrWR6qdz86auG+dclSuXVsYQge73NrwcpcffYgPivnImpyvvAswplQXQGb34 kpiynCDnxEeMyOjEZpiGauCc79ncSK0tfQAuwxswf8m46pYkiajXAt3cPw+7PhlbXGF3 3Wotbis3h6nkZf2i0620Hi0socbC2IaMGFLVlHL2wt+XhF1oVtdgC3mW9w6Vxk9y1IEy KXG0VEK7arKhPYIXEHbWwn+JM91Z4eImC6s3qxF0g/c6e+7vVP8X8Xhlz23yDMtqPwHC GUow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716270871; x=1716875671; h=content-transfer-encoding:in-reply-to:autocrypt:references:to:from :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=D/m3N5OmWY8eBPTg26bHmnjd1NjBhMczeUKdLMDjktg=; b=raDrC9R3VmpTTjh5PHhEMNZozzsK7/c4iTUBTraHpkEQVYQ6KgsRS84rOoi97UvIw4 bxvGrHhQHWHErPEIqROOCFDNyTUtN6/adyIQ/zrKueVw45+i/y17xNec3nn+X5u2vApO Q8AVzY8lnOBDsp6wH9KChd8A8VqwoQl0IL4HrQtF4tW3bphCCcc8nwcYL0E/FIN/XJEI SN8MFaFDci1ZPbRRMsDXJaMH1w08G7JmyFY6Rb3YQ0zB+w9wkkxPTvqtpD0BoZr/W5LD c34TIG8KZvPVlkxyYxjZu93cS57V3NjTmWQF322yYwPwi8hGEp3UdCM5o0hIg1hn2djX OVKQ== X-Gm-Message-State: AOJu0Yyd/a4aBBwV4ZC4KUcRlLxa93k+InG62yNnn6QhyCbzwCNC2oRQ buQSuCN/IvvUaks0h99vXACkHsEt0VkbXjGNQgKLaIpmRHczX/p4z9gI9AlxoGV0Sv6mNgR9jvU = X-Google-Smtp-Source: AGHT+IFZbctzUJi/EywQGZYgYPulum5TBZ6vykdfr0+VumUA+gs1QCjDCSG1oXm11qMVAX6ZXnEyLg== X-Received: by 2002:a17:906:e258:b0:a5a:5b1a:e2e4 with SMTP id a640c23a62f3a-a5d5b11a849mr738356266b.20.1716270871346; Mon, 20 May 2024 22:54:31 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a5a1789240asm1562613366b.48.2024.05.20.22.54.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 20 May 2024 22:54:31 -0700 (PDT) Message-ID: <19f2e0aa-8f68-4d1a-8340-0fc24247984e@suse.com> Date: Tue, 21 May 2024 07:54:34 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 2/2] gas: extend \+ support to .irp / .irpc Content-Language: en-US From: Jan Beulich To: Binutils References: <2d6b6832-f385-41ad-8bf5-e2b7dba581c8@suse.com> Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+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ocI71I8bT8lIAzreg0WvkWg5V2WZsUMlnDL9 mpwIGFhlbM3gfDMs7MPMu8YQRFVdUvtSpaAs8OFfGQ0ia3LGZcjA6Ik2+xcqscEJzNH+qh8V m5jjp28yZgaqTaRbg3M/+MTbMpicpZuqF4rnB0AQD12/3BNWDR6bmh+EkYSMcEIpQmBM51qM EKYTQGybRCjpnKHGOxG0rfFY1085mBDZCH5Kx0cl0HVJuQKC+dV2ZY5AqjcKwAxpE75MLFkr wkkEGBECAAkFAlk3nEQCGwwACgkQoDSui/t3IH7nnwCfcJWUDUFKdCsBH/E5d+0ZnMQi+G0A nAuWpQkjM1ASeQwSHEeAWPgskBQL In-Reply-To: <2d6b6832-f385-41ad-8bf5-e2b7dba581c8@suse.com> X-Spam-Status: No, score=-3024.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP 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.30 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: binutils-bounces+patchwork=sourceware.org@sourceware.org These are effectively macro-like, without any separate macro definition. They already support \@, so they would better also support \+. This allows, where desired, to get away without maintaining an explicit count variable in source code. With this the recently introduced testcase doesn't need any xfails anymore. --- Perhaps .rep/.rept would benefit even more, but how to (tidily) support the expansion there isn't quite clear to me, yet. While there is support for some kind of expansion, that doesn't quite fit here: We can't just strstr() for "\+", but would need to take into account earlier backslashes as well, to properly deal with uses in e.g. nested .rept. It's also not clear to me whether MIPS'es re-use of s_rept() should then also do the expansion, or whether that ought to remain unchanged in behavior. Unlike for macros, the counter is incremented regardless of errors. I think that's better (and macros may want switching to that, too), in particular when conidering the effect on listings: For macros, as it stands, there may be multiple (partial) macro expansions with the same value, which may end up misleading. --- a/gas/NEWS +++ b/gas/NEWS @@ -3,9 +3,10 @@ * In x86 Intel syntax undue mnemonic suffixes are now warned about. This is a first step towards rejecting their use where unjustified. -* Assembler macros can now use the syntax \+ to access the number of times a - given macro has been executed. This is similar to the already existing \@ - syntax, except that the count is maintained on a per-macro basis. +* Assembler macros as well as the bodies of .irp / .irpc can now use the + syntax \+ to access the number of times a given macro has been executed. + This is similar to the already existing \@ syntax, except that the count is + maintained on a per-macro basis. * Support the NF feature in Intel APX. --- a/gas/macro.c +++ b/gas/macro.c @@ -798,7 +798,8 @@ sub_actual (size_t start, sb *in, sb *t, static const char * macro_expand_body (sb *in, sb *out, formal_entry *formals, - struct htab *formal_hash, const macro_entry *macro) + struct htab *formal_hash, const macro_entry *macro, + unsigned int instance) { sb t; size_t src = 0; @@ -854,13 +855,13 @@ macro_expand_body (sb *in, sb *out, form sprintf (buffer, "%u", macro_number); sb_add_string (out, buffer); } - else if (macro && src < in->len && in->ptr[src] == '+') + else if (src < in->len && in->ptr[src] == '+') { /* Sub in the current macro invocation number. */ char buffer[12]; src++; - sprintf (buffer, "%d", macro->count); + sprintf (buffer, "%d", instance); sb_add_string (out, buffer); } else if (src < in->len && in->ptr[src] == '&') @@ -1213,7 +1214,8 @@ macro_expand (size_t idx, sb *in, macro_ } } - err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m); + err = macro_expand_body (&m->sub, out, m->formals, m->formal_hash, m, + m->count); } /* Discard any unnamed formal arguments. */ @@ -1363,11 +1365,12 @@ expand_irp (int irpc, size_t idx, sb *in if (idx >= in->len) { /* Expand once with a null string. */ - err = macro_expand_body (&sub, out, &f, h, 0); + err = macro_expand_body (&sub, out, &f, h, NULL, 0); } else { bool in_quotes = false; + unsigned int instance = 0; while (idx < in->len) { @@ -1392,7 +1395,8 @@ expand_irp (int irpc, size_t idx, sb *in ++idx; } - err = macro_expand_body (&sub, out, &f, h, 0); + err = macro_expand_body (&sub, out, &f, h, NULL, instance); + ++instance; if (err != NULL) break; if (!irpc) --- a/gas/testsuite/gas/macros/irp-count.d +++ /dev/null @@ -1,2 +0,0 @@ -#name: Macro counters inside IRP commands (irp-count.d) -# Tests that \+ does not trip up IRP commands --- a/gas/testsuite/gas/macros/irp-count.l +++ b/gas/testsuite/gas/macros/irp-count.l @@ -1,3 +1,7 @@ #... -\+ -\+ +a0 +a1 +b2 +x0 +x1 +y2 --- a/gas/testsuite/gas/macros/irp-count.s +++ b/gas/testsuite/gas/macros/irp-count.s @@ -1,7 +1,7 @@ - .irp i,1 - .print "\+" + .irp i,a,a,b + .print "\i\+" .endr - .irpc i,1 - .print "\+" + .irpc i,xxy + .print "\i\+" .endr --- a/gas/testsuite/gas/macros/macros.exp +++ b/gas/testsuite/gas/macros/macros.exp @@ -103,11 +103,5 @@ gas_test_error "exit.s" "" ".exitm outsi run_list_test altmacro run_list_test count - -# The AVR, CRIS, MSP430 and Z80 targets define ONLY_STANDARD_ESCAPES, -# so \+ is rejected. -# AIX targets need an extended regexp to match "\+". -setup_xfail "avr-*-*" "cris*-*-*" "msp430-*-*" "z80-*-*" "*-*-aix*" run_list_test irp-count - run_list_test irpc-quote