This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] more g77 runtime library functions for gfortran


On Thursday 19 August 2004 00:17, Steve Kargl wrote:
> On Wed, Aug 18, 2004 at 10:22:09PM +0100, Paul Brook wrote:
> > On Wednesday 18 August 2004 21:53, Steve Kargl wrote:
> > > On Wed, Aug 18, 2004 at 02:07:45AM +0100, Paul Brook wrote:
> > > > 3) The parameters to the library functions should be passed by value,
> > > > not by reference.
> > >
> > > I have no idea what you want here.
> >
> > You declare the library functions as
> > besj0 (GFC_REAL_4 *x)
> > It would be much more efficient to use
> > besj0 (GFC_REAL_4 x)
>
> This much I know.
>
> > All the arguments are intent(in), so there's no reason to pass them by
> > reference. Obviously this will need corresponding code in
> > trans-intrinsic.c.
>
> This is where I have no idea what to do.  It appears you want
>
>     case GFC_ISYM_BESJ0:
>     case GFC_ISYM_BESJ1:
>     case GFC_ISYM_BESY0:
>     case GFC_ISYM_BESY1:
>       gfc_conv_intrinsic_besj0 (se, expr);
>       break;
>     case GFC_ISYM_BESJN:
>     case GFC_ISYM_BESYN:
>       gfc_conv_intrinsic_besjn (se, expr);
>       break;
>
> void gfc_conv_intrinsic_bessel (se, expr)
> {
>    /* Now what do I do? */
> }

Not tested, but shouldn't be far off:

     case GFC_ISYM_BESJ0:
     case GFC_ISYM_BESJ1:
     case GFC_ISYM_BESY0:
     case GFC_ISYM_BESY1:
     case GFC_ISYM_BESJN:
     case GFC_ISYM_BESYN:
       gfc_conv_intrinsic_libcall (se, expr);
       break;

/* ??? I'm running of ideas for sensibe function names.  We have several
   different conv_intrinsic_<functioncall>, all with different semantics.  */
/* Generate a call to a library implementation of an intrinsic, passing
   arguments by value.  Only works for scalar or elemental functions.  */

void gfc_conv_intrinsic_libcall (se, expr)
{
  gfc_symbol * sym;
  tree typelist;
  tree type;
  tree args;
  tree a;
  tree fndecl;

  assert (expr->ts.type != BT_CHARACTER);
  /* Evaluate the function arguments.  */
  args = gfc_conv_intrinsic_function_args (se, expr);

  /* Find the symbol for the fully resolved function.  */
  sym = gfc_get_intrinsic_sub_symbol (expr->value.function.name);

  if (sym->backend_decl)
    fndecl = sym->backend_decl;
  else
    {
      /* This is a bit messy.  Build a function decl for the resolved name,
	 using the types of the arguments.  */
      typelist = NULL_TREE;
      for (a = args; a != NULL_TREE; arg = TREE_CHAIN (arg))
	typelist = tree_cons (NULL_TREE, TREE_TYPE (TREE_VALUE (a)),
			      typelist);
      typelist = tree_cons (NULL_TREE, void_type_node, NULL_TREE);
      typelist = nreverse (typelist);

      type = gfc_typenode_for_spec (&expr->ts);
      type = build_function_type (type, typelist);

      /* Make a file scope external public decl.  */
      fndecl = build_decl (FUNCTION_DECL, gfc_sym_identifier (sym), type);
      DECL_CONTEXT (fndecl) = NULL_TREE;
      DECL_EXTERNAL (fndecl) = 1;
      TREE_PUBLIC (fndecl) = 1;
      pushdecl_top_level (fndecl);

      /* TODO: Maybe set pure/const flags here?  */

      sym->backend_decl = fndecl;
    }

  /* Call the library function.  */
  se->expr = gfc_build_function_call (fndecl, args);
}

> > > > 5) I don't think a warning/error is the correct behaviour for
> > > > --std=f95. Wouldn't it be better to disable the intrinsic altogether?
> > > > A warning may be a good idea, but it's not what I'd expect in strict
> > > > standard compliant mode.
>
> For now, I'll remove the warning/error messages and start to
> think about how to re-implement intrinsics.c.  I'm sure it
> will be evil.

Ok.

Paul


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]