Le 13/12/2024 à 21:55, Steve Kargl a écrit :
On Mon, Dec 09, 2024 at 06:39:19PM -0800, Steve Kargl wrote:
I've an almost complete implementation of F_C_STRING,
but need a bit of insight on the inlining that I'm
trying to implement. In pseudo-code, F_C_STRING is
case 1. f_c_string(string) = trim(string) // c_null_char
case 2. f_c_string(string, asis=.false.) = trim(string) // c_null_char
case 3. f_c_string(string, asis=.true.) = string // c_null_char
Here's where I'm stuck.
FX's message gave most of the information.
More explicitly, what's missing is roughly:
if (asis)
{
/* f_c_string(string, .true.) = string // c_null_char */
gfc_init_block (&block);
len = fold_build2_loc (input_location, PLUS_EXPR, cnode,
fold_convert (cnode, lse.string_length),
fold_convert (cnode, rse.string_length));
var = gfc_conv_string_tmp (se, pchar_type_node, len);
tmp = build_call_expr_loc (input_location, gfor_fndecl_concat_string,
6, len, var,
lse.string_length, lse.expr,
rse.string_length, rse.expr);
gfc_add_expr_to_block (&block, tmp);
tree then_branch = gfc_finish_block (&block);
gfc_init_block (&block);
//
// /* f_c_string(string, .false.) = trim(string) // c_null_char */
//
// gfc_init_se (&tse, se);
// conv_trim (&tse, &lse);
// gfc_add_block_to_block (&se->pre, &tse.pre);
s/&se->pre/block/
//
// len = fold_build2_loc (input_location, PLUS_EXPR, cnode,
// fold_convert (cnode, tse.string_length),
// fold_convert (cnode, rse.string_length));
// var = gfc_conv_string_tmp (se, pchar_type_node, len);
// tmp = build_call_expr_loc (input_location, gfor_fndecl_concat_string,
// 6, len, var,
// tse.string_length, tse.expr,
// rse.string_length, rse.expr);
tree else_branch = gfc_finish_block (&block);
gfc_init_se (&asis_se, se);
gfc_conv_expr (&asis_se, asis);
gfc_add_block_to_block (&se->pre, &asis_se->pre);
gfc_add_block_to_block (&se->???, &asis_se->post);
tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node,
asis_se.expr, then_branch, else_branch);
gfc_add_expr_to_block (&se->pre, tmp);
se->expr = var;
se->string_length = len;
}
else
gfortran needs to select either uncommented code or the code,
based on the whether 'asis' is .true. or .false. I've been
unable to suss out how to set up the conditional. (It's been
too long since I hacked in the trans-* files.)
Any suggestions?
I hope the above helps.
Mikael