From patchwork Thu Jan 13 21:58:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 50001 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 DFEF23857830 for ; Thu, 13 Jan 2022 21:59:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DFEF23857830 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642111157; bh=/F/XqEb/i3R6iayJMyAaNkmpPBJ/O9ixHUTTJGfys8I=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AoQZe0GLwrhSXLpfnd9Rny8Nq4H770rVztXAfvFySlwFGjIEEL5PNxu3/W1D8ksIr nzwOvFw1ANfLGWPpMAfvLgirklJr2gUSdn5YB7Ofe2QvHBwHxrBbKlN0Oc6KwWY0Yp S5VRDAx8CQKRbmt89krA9JmnwuMvFGOXCJaFHdzg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from cc-smtpout1.netcologne.de (cc-smtpout1.netcologne.de [89.1.8.211]) by sourceware.org (Postfix) with ESMTPS id 72E03385840D; Thu, 13 Jan 2022 21:58:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 72E03385840D Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id D30B1128BA; Thu, 13 Jan 2022 22:58:29 +0100 (CET) Received: from [IPv6:2001:4dd7:7a42:0:7285:c2ff:fe6c:992d] (2001-4dd7-7a42-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd7:7a42:0:7285:c2ff:fe6c:992d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA id 6989511DFB; Thu, 13 Jan 2022 22:58:26 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches , Jakub Jelinek Subject: [patch, libgfortran, power-ieee128] Add multiple defaults for GFORTRAN_CONVERT_UNIT Message-ID: <335a168d-b06c-677a-33b2-46887489c130@netcologne.de> Date: Thu, 13 Jan 2022 22:58:25 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 Content-Language: en-US X-NetCologne-Spam: L X-Rspamd-Queue-Id: 6989511DFB X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP 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: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Thomas Koenig via Gcc-patches From: Thomas Koenig Reply-To: Thomas Koenig Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hello world, with this patch, it is now possible to specify both the endianness and the REAL(KIND=16) format using the environment variable GFORTRAN_CONVERT_UNIT. The following now works: koenig@gcc-fortran:~/Tst$ cat write_env.f90 program main real(kind=16) :: x character (len=30) :: conv x = 1/3._16 open (10,file="out.dat",status="replace",access="stream",form="unformatted") inquire(10,convert=conv) print *,conv write (10) 1/3._16 end program main tkoenig@gcc-fortran:~/Tst$ gfortran -g -static-libgfortran write_env.f90 tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="little_endian;r16_ibm" && ./a.out LITTLE_ENDIAN,R16_IBM tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="little_endian;r16_ieee" && ./a.out LITTLE_ENDIAN,R16_IEEE tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="big_endian;r16_ieee" && ./a.out BIG_ENDIAN,R16_IEEE tkoenig@gcc-fortran:~/Tst$ GFORTRAN_CONVERT_UNIT="big_endian;r16_ibm" && ./a.out BIG_ENDIAN,R16_IBM Since the branch has been pushed to trunk, I don't think we need it any more (or do we?), so OK for trunk? Best regards Thomas Allow for multiple defaults in endianness and r16 in GFORTRAN_CONVERT_UNIT. With this patch, it is possible to specify multiple defaults inthe GFORTRAN_CONVERT_UNIT environment variable so that, for example, R16_IEEE and BIG_ENDIAN can be specified together. libgfortran/ChangeLog: * runtime/environ.c: Allow for multiple default values so that separate default specifications for IBM long double format and endianness are possible. diff --git a/libgfortran/runtime/environ.c b/libgfortran/runtime/environ.c index 3d60950234d..a53c64965b6 100644 --- a/libgfortran/runtime/environ.c +++ b/libgfortran/runtime/environ.c @@ -499,78 +499,79 @@ do_parse (void) unit_count = 0; - start = p; - /* Parse the string. First, let's look for a default. */ - tok = next_token (); endian = 0; - - switch (tok) + while (1) { - case NATIVE: - endian = GFC_CONVERT_NATIVE; - break; + start = p; + tok = next_token (); + switch (tok) + { + case NATIVE: + endian = GFC_CONVERT_NATIVE; + break; - case SWAP: - endian = GFC_CONVERT_SWAP; - break; + case SWAP: + endian = GFC_CONVERT_SWAP; + break; - case BIG: - endian = GFC_CONVERT_BIG; - break; + case BIG: + endian = GFC_CONVERT_BIG; + break; - case LITTLE: - endian = GFC_CONVERT_LITTLE; - break; + case LITTLE: + endian = GFC_CONVERT_LITTLE; + break; #ifdef HAVE_GFC_REAL_17 - case R16_IEEE: - endian = GFC_CONVERT_R16_IEEE; - break; + case R16_IEEE: + endian = GFC_CONVERT_R16_IEEE; + break; - case R16_IBM: - endian = GFC_CONVERT_R16_IBM; - break; + case R16_IBM: + endian = GFC_CONVERT_R16_IBM; + break; #endif - case INTEGER: - /* A leading digit means that we are looking at an exception. - Reset the position to the beginning, and continue processing - at the exception list. */ - p = start; - goto exceptions; - break; + case INTEGER: + /* A leading digit means that we are looking at an exception. + Reset the position to the beginning, and continue processing + at the exception list. */ + p = start; + goto exceptions; + break; - case END: - goto end; - break; + case END: + goto end; + break; - default: - goto error; - break; + default: + goto error; + break; } - tok = next_token (); - switch (tok) - { - case ';': - def = endian; - break; + tok = next_token (); + switch (tok) + { + case ';': + def = def == GFC_CONVERT_NONE ? endian : def | endian; + break; - case ':': - /* This isn't a default after all. Reset the position to the - beginning, and continue processing at the exception list. */ - p = start; - goto exceptions; - break; + case ':': + /* This isn't a default after all. Reset the position to the + beginning, and continue processing at the exception list. */ + p = start; + goto exceptions; + break; - case END: - def = endian; - goto end; - break; + case END: + def = def == GFC_CONVERT_NONE ? endian : def | endian; + goto end; + break; - default: - goto error; - break; + default: + goto error; + break; + } } exceptions: