BOZ, F2008 and F2015, and future of gfortran
Steve Kargl
sgk@troutmask.apl.washington.edu
Fri Oct 6 17:03:00 GMT 2017
On Fri, Oct 06, 2017 at 01:50:04PM +0200, Richard Biener wrote:
> On Fri, Oct 6, 2017 at 8:20 AM, Steve Kargl
> <sgk@troutmask.apl.washington.edu> wrote:
> > On Fri, Oct 06, 2017 at 07:58:58AM +0200, Richard Biener wrote:
> >> On October 6, 2017 7:02:10 AM GMT+02:00, Steve Kargl <sgk@troutmask.apl.washington.edu> wrote:
> >> >
> >> >program foo
> >> > integer :: i(2) = [z'124', z'bed']
> >> > print *, i
> >> >end program foo
> >> >
> >> >First, this is nonstandard in that a BOZ-literal-constant cannot
> >> >appear in the above context. Unfortunately, the above leads
> >> >to an ICE. I need to figure how to walk the array constructor
> >> >and have gfortran use the type and type kind parameter of the
> >> >lhs to convert the rhs boz.
> >>
> >> I'm just guessing the semantics but you might find
> >> native_encode/interpret_expr useful in this context.
> >>
> >
> > I can handle the needed transformation in the Fortran FE
> > once I figure out how we handle array constructors. In
> > Fortran, [z'124', z'bed'] is an array constructor and
> > Fortran forbids a BOZ from appearing here. This is
> > currently allowed in gfortran, because gfortran upon
> > parsing a BOZ immediately converts it to an INTEGER(N)
> > (with N=8 or 16 depending on target). My patch
> > gives a BOZ a basic type of BT_BOZ, which is new and
> > treated as a typeless sequence of bits. I need to catch
> > an entity with a BT_BOZ basic type and do essentially a
> > JIT conversion to the correct type when translating an
> > array constructor.
>
> Yes, and depending on how you represent BT_BOZ
> native_interpret_expr is exactly such JIT (interpreting
> a memory region in target representation as a tree
> object with given type). native_encode_expr does the
> reverse transform (create such memory region from a
> constant tree object).
I'll take a look at native_interpret_expr. At the moment,
if one has a "gfc_expr *x" that is a BOZ, then my patch
will set
x->expr_type = EXPR_CONSTANT; // Same as before
x->ts.type = BT_BOZ; // New basic type; previously set to BT_INTEGER
x->ts.kind = -1; // New setting; previously gfc_max_integer_kind
x->boz = boz_string; // New char * that hold copy of BOZ string.
For "integer :: x = z'dead'", I have x->boz="zdead". If the BOZ needs
to be converted to an INTEGER, then the first character in x->boz is
used to set the radix and the remaining part of the string is fed into
GMP's mpz_set_str() function. If a BOZ needs to be converted to a
REAL, then I feed the gfc_expr *x through target-memory.c(gfc_convert_boz)
that Tobias wrote awhile ago.
--
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow
More information about the Fortran
mailing list