From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from de-smtp-delivery-102.mimecast.com (de-smtp-delivery-102.mimecast.com [194.104.109.102]) by sourceware.org (Postfix) with ESMTPS id 13484385736A for ; Fri, 6 May 2022 06:07:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 13484385736A Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01lp2053.outbound.protection.outlook.com [104.47.1.53]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id de-mta-27-qH1rge1hOPKMtmzL7V46hw-1; Fri, 06 May 2022 08:07:39 +0200 X-MC-Unique: qH1rge1hOPKMtmzL7V46hw-1 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ehULWt+9csB0BlG2op2z4WDCgQcfQ9BaM7a0mOsnf1EnujDphF/mCE+mbq9MgoMBWmCw2b8iFB/6Z5SK8hERp4rRXHEeE1lSFQn8jW54RXULQEQpWVgCuJmdMASk+xNSAucEVO6Io/i0J70q7cIQ1s3s1z9ednwYf1Mi8/Po2HIb6qncIcIAImXAQB5WwoPgjkc4zWG6xfXdk2bDaH2VXkEyo3QYPqLgctL292ZIlHxgBNozfPuzqFP5r1rnGJcNe3jQiRc1FndBzv6ofvdKqCqJWtlfY8IYk/EWvLaPWrShqwF7scuaL+Wgxjiqk9bpbOhrF86vYGg9ikZfekjQjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=ygft0KVN0izDyIcbkj/Nsy8DX4jTtoar0TbiyvEgCMg=; b=SNGwcTm5ZhfyM2AUc/z9PiGW6QrbmOQqunpt16MzEmNOw7D7QFlGxVh3ti6Psec0knwOkVUGO3tMXXkvhJ4/xKHpxfbjzeYaDcWQDVLdFXBEnMBVH1q1mhQpvK+nKUrastGPiBtwz1Ztu/C5/Yv5NfgGaXjW7t31NvnGC1tnXzSlWWW/Ap8WGPakUP05mCReGjtjyjxz8xDc6pHwKwE4XSvwrl013sMPl6CpuZvAIcFEwBJKPSU41RJX0q40oYUxxW4MkqJlbsE2OSvy1UEXM0/G07b/Dfgb26nT393IvpP+FLRdHn4QgFiqm7QvDvYshabSrHSa7gOu9InKQKj0zg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none Received: from DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) by DB9PR04MB8378.eurprd04.prod.outlook.com (2603:10a6:10:25f::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5206.27; Fri, 6 May 2022 06:07:39 +0000 Received: from DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::84b:e9d3:8906:8b9c]) by DU2PR04MB8616.eurprd04.prod.outlook.com ([fe80::84b:e9d3:8906:8b9c%6]) with mapi id 15.20.5227.018; Fri, 6 May 2022 06:07:39 +0000 Message-ID: Date: Fri, 6 May 2022 08:07:37 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.8.1 Subject: [PATCH 4/6] gas: fold do_repeat{,_with_expander}() Content-Language: en-US To: Binutils References: Cc: Nick Clifton , Timothy Wall From: Jan Beulich In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-ClientProxiedBy: AM7PR02CA0027.eurprd02.prod.outlook.com (2603:10a6:20b:100::37) To DU2PR04MB8616.eurprd04.prod.outlook.com (2603:10a6:10:2db::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 51e57a83-59a0-4b29-6895-08da2f26b92f X-MS-TrafficTypeDiagnostic: DB9PR04MB8378:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iEFx+d1J7D3JIrIbFde94YD70PwuagGnuw7O+HE2pV7XNJdP3YwU8Lw2QhGAI2J8P+95G6GjowCOO+RPu8bIOKpOR6OAo7YpEE1xeZml0ZkldC7pMtwaDtKEuvLHXECEt6t3Qld09omhOnZIOks5njsGGwFwhSLKz5gSMwVn/EUzJy5Pb4aD94eYjOqH1sfyeQxu3yCzx9J8x/KORfW2GDC1QeFn3aNVX840ENSCpaiIiw1n1z7NrKxve6wqV37gsBZcHtBvRz9rYxCqzpV9oUFS6ycLLz3beaLw1Irp0dhAQty/Oh8M0j0XbqMOyaLL7jkd26BLvJaDxwEDbij2xByumH5NdvZAJsNlOVioHtWNmGntBzoQySvXDUcy0+NU8f2rAhY0fC5PdH+jAsU9tHfv6cCF8swyx4UWTOWMkkdh5ooekOHW7uwATDiL//Ad5eCqek+c0mWp152KasYtNav3Hd1a6i+UpGVqATKUfwZB+sdyCdYnMphPRr34gwT0RfeIk0NX30zfqguINQEhCq+ifs00WafVoApv6Cn5doYEqxVW0BE/Ku7ZZqDY+NeuvADahs7+yymRl686O3lHAoDsDEQc89A2f9N8ofG/5qcycuYP/+wjw15WFicRyphcvwKFuU9qRrSaRdC5omFIo7kY/cCPb+qMvB+hdP2maD1G0uVzPFza7S5qfwP8J1rpFvEtSEVXYH8WkAYqg1a4SXJoLmTlXcoO7wr1MCNhPcE= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DU2PR04MB8616.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230001)(366004)(26005)(2616005)(31696002)(54906003)(6486002)(508600001)(186003)(36756003)(86362001)(31686004)(6512007)(38100700002)(6916009)(66476007)(5660300002)(66946007)(66556008)(8676002)(316002)(2906002)(83380400001)(6506007)(4326008)(8936002)(43740500002)(45980500001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aS9TejlGMmh1RWxQbGo1VkMrM3BnYUxBUGNycUVUdDVkWHdXZ1NmeFRCQW1h?= =?utf-8?B?TktzWGVqTXNpMzJsZEh5a3orRFR4Slc5OUU4VklFSFRtZ3dSckxodURXQjFK?= =?utf-8?B?WkVRN21GNFhYaFpML05vK1JHUlF2b3I5dzlQMCt0K2hYaVU0aDdlRitVUXMy?= =?utf-8?B?Ulc0MkQ0Zlc1OWY2Y2Ztc0JqRkVGaHZaQ0VxbnhmSWZlUDJ5TmNnbFpKbk9K?= =?utf-8?B?M3F1Zmx1aTlvYWNpbkFhWGNVRFB4bDdRQjNoU1VxWkhSRy9TR3MySFNlNTNj?= =?utf-8?B?djJjNXVwUXhVSTYwYXFXckhEWHpDa29zMVVhWnZFbHZISHd0eG1mK3hIYnN2?= =?utf-8?B?eUV0MDVCRVduRUx4OGZrWVh2U0dOaUhHcGgrL2QySWZXNDlvby9IbGNCTGtE?= =?utf-8?B?LzVVb2ozaFZOVEI4ejVmTnlCMnhVVUkyV1BZcGJwbzBwL29aa0FTOFNBbStO?= =?utf-8?B?NVA1M01UNVMvdTlFcSszVWE2MGRyeHlSY0lwZzNncnlqdG1XK3VpYnRzTjFK?= =?utf-8?B?M0tpRFBLQ3YzOEhJL3ZDUmZmcm5HRkZiMVVocmRjQ2x2OGRDTEptcEVQNzhY?= =?utf-8?B?dG1wcnRzbjRJVHVhVnBOL1Fad3R0SkQ0aFQvQkxxNEZua0lyMTFrbkdwZmgz?= =?utf-8?B?ejNiK0taS2dhSVpRaU1hVlRzU1R0N3VGeUFZdFJoOGVyYURyUlZsUEdZMTU0?= =?utf-8?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N0RGSVU1Yjda?= =?utf-8?B?eThsT0NZRVdUUmx6UG05SU1FM01EZjE2RmxLZ25mcUxxYklkSkFCU0xPMk1v?= =?utf-8?B?L21XWDhIOE5xeGxUd1Z1UFUwT2dTOU0wcWRRTXZQNytnaE1jREs1c3ZFcURG?= =?utf-8?B?UWV4N1k1MG91UTBMS0NRWlJIMmE4WmR6M0V2Yno5aEU2bWM3aUtGOHh2SU82?= =?utf-8?B?Nm5LcmpRM09PazU5UWFpSEt4RVFGcVc0Ymg2Z0NWVzFLVFRRUnJsV21DblJU?= =?utf-8?B?bGVSNDRMb1htZytuSEJseWJvam9rRDc4Wll3SkR0UCs5UVZ1UnZLeDhUaTZ3?= =?utf-8?B?N2s5K3FwVUtJMzlib0luV0FITm5PYWZCY3JTeU1NbFV6Y2E5NXRnVUhsKzdw?= =?utf-8?B?Z2tpTzlFbHIwWkdBWTM3Tkl5dnB5aE0vSlNiaGJwb29wRWkwVEJRa201cWI4?= =?utf-8?B?Z2pXYS9tTmdRd2JJb1JJT0lwWlFYTUNYNk5jejdRekdWUUlsdDZndkFSUnpo?= =?utf-8?B?ckFQZEFrUFRkbXpNOTdvcHZtUEZWVjRvbG9IVko2ZGVobTZncG14UnNQVGJI?= =?utf-8?B?cTAvdWgrUzFmMElacmlUS0JINWRNR3NYRUVxc2Y2ckFTQzZ0aVY4OGh6aTNm?= =?utf-8?B?WmcxbG40Tmx0NWsvSEV3WXVFTmR2b2hDbHFxLzZla3gxWnRqMjBhbkU2azA0?= =?utf-8?B?RUQ1eHR3SDB4MEY2cnNudi9peXlSNTNVMTZBNk42QS8rSUdOb002dz09?= X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51e57a83-59a0-4b29-6895-08da2f26b92f X-MS-Exchange-CrossTenant-AuthSource: DU2PR04MB8616.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 May 2022 06:07:38.9594 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xEqJ68H9Zks/gNnuNVvs5Ko0cSnMqJrTU8VoLxmEosNqCREHfvfC1brXnie+n4yjrwQUS0UQPUhcYKGL77OyyQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB8378 X-Spam-Status: No, score=-3031.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Fri, 06 May 2022 06:07:44 -0000 do_repeat_with_expander() already deals with the "no expander" case quite fine, so there's really little point having two functions. What it lacks compared with do_repeat() is a call to sb_build(), which can simply be moved (and the then redundant sb_new() be avoided). Along with this moving also flip if the main if()'s condition such that the "no expander" case is handled first. --- The "with-expander" case has a number of issues, though: - use of literal 8 instead of using the actual size of "expander", - assertion on user controlled value, - subsequent code nevertheless depends on that assertion, - only a single instance of the pattern is being replaced (despite a comment saying otherwise), - no separators are required (checked for) around the found "expander" instance, - "count" is silently truncated from size_t to unsigned long. Furthermore .mrepeat doesn't properly nest with itself or inside e.g. .irp, as the inner .endr will be taken as terminating the other construct. --- a/gas/config/tc-rx.c +++ b/gas/config/tc-rx.c @@ -566,7 +566,7 @@ rx_rept (int ignore ATTRIBUTE_UNUSED) { size_t count = get_absolute_expression (); - do_repeat_with_expander (count, "MREPEAT", "ENDR", "..MACREP"); + do_repeat (count, "MREPEAT", "ENDR", "..MACREP"); } /* Like cons() accept that strings are allowed. */ --- a/gas/config/tc-tic54x.c +++ b/gas/config/tc-tic54x.c @@ -2034,7 +2034,7 @@ tic54x_loop (int count) if (!is_end_of_line[(unsigned char) *input_line_pointer]) count = get_absolute_expression (); - do_repeat ((size_t) count, "LOOP", "ENDLOOP"); + do_repeat ((size_t) count, "LOOP", "ENDLOOP", NULL); } /* Normally, endloop gets eaten by the preceding loop. */ --- a/gas/read.c +++ b/gas/read.c @@ -3094,14 +3094,17 @@ s_rept (int ignore ATTRIBUTE_UNUSED) count = (size_t) get_absolute_expression (); - do_repeat (count, "REPT", "ENDR"); + do_repeat (count, "REPT", "ENDR", NULL); } /* This function provides a generic repeat block implementation. It allows - different directives to be used as the start/end keys. */ + different directives to be used as the start/end keys. Any text matching + the optional EXPANDER in the block is replaced by the remaining iteration + count. */ void -do_repeat (size_t count, const char *start, const char *end) +do_repeat (size_t count, const char *start, const char *end, + const char *expander) { sb one; sb many; @@ -3119,46 +3122,16 @@ do_repeat (size_t count, const char *sta return; } - sb_build (&many, count * one.len); - while (count-- > 0) - sb_add_sb (&many, &one); - - sb_kill (&one); - - input_scrub_include_sb (&many, input_line_pointer, expanding_repeat); - sb_kill (&many); - buffer_limit = input_scrub_next_buffer (&input_line_pointer); -} - -/* Like do_repeat except that any text matching EXPANDER in the - block is replaced by the iteration count. */ - -void -do_repeat_with_expander (size_t count, - const char * start, - const char * end, - const char * expander) -{ - sb one; - sb many; - - if (((ssize_t) count) < 0) + if (expander == NULL || strstr (one.ptr, expander) == NULL) { - as_bad (_("negative count for %s - ignored"), start); - count = 0; + sb_build (&many, count * one.len); + while (count-- > 0) + sb_add_sb (&many, &one); } - - sb_new (&one); - if (!buffer_and_nest (start, end, &one, get_non_macro_line_sb)) + else { - as_bad (_("%s without %s"), start, end); - return; - } - - sb_new (&many); + sb_new (&many); - if (expander != NULL && strstr (one.ptr, expander) != NULL) - { while (count -- > 0) { int len; @@ -3177,9 +3150,6 @@ do_repeat_with_expander (size_t count, sb_kill (& processed); } } - else - while (count-- > 0) - sb_add_sb (&many, &one); sb_kill (&one); --- a/gas/read.h +++ b/gas/read.h @@ -148,8 +148,7 @@ extern void stabs_generate_asm_file (voi extern void stabs_generate_asm_lineno (void); extern void stabs_generate_asm_func (const char *, const char *); extern void stabs_generate_asm_endfunc (const char *, const char *); -extern void do_repeat (size_t, const char *, const char *); -extern void do_repeat_with_expander (size_t, const char *, const char *, const char *); +extern void do_repeat (size_t, const char *, const char *, const char *); extern void end_repeat (int); extern void do_parse_cons_expression (expressionS *, int);