public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [patch, libgfortran, power-ieee128] Add multiple defaults for GFORTRAN_CONVERT_UNIT
@ 2022-01-13 21:58 Thomas Koenig
  2022-01-17  6:31 ` Thomas Koenig
  0 siblings, 1 reply; 2+ messages in thread
From: Thomas Koenig @ 2022-01-13 21:58 UTC (permalink / raw)
  To: fortran, gcc-patches, Jakub Jelinek

[-- Attachment #1: Type: text/plain, Size: 1553 bytes --]

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.


[-- Attachment #2: p7.diff --]
[-- Type: text/x-patch, Size: 2829 bytes --]

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:

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [patch, libgfortran, power-ieee128] Add multiple defaults for GFORTRAN_CONVERT_UNIT
  2022-01-13 21:58 [patch, libgfortran, power-ieee128] Add multiple defaults for GFORTRAN_CONVERT_UNIT Thomas Koenig
@ 2022-01-17  6:31 ` Thomas Koenig
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Koenig @ 2022-01-17  6:31 UTC (permalink / raw)
  To: fortran, gcc-patches, Jakub Jelinek

On 13.01.22 22:58, Thomas Koenig via Fortran wrote:
> 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.

I have now pushed this to trunk.

Best regards

	Thomas

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-17  6:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-13 21:58 [patch, libgfortran, power-ieee128] Add multiple defaults for GFORTRAN_CONVERT_UNIT Thomas Koenig
2022-01-17  6:31 ` Thomas Koenig

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).