Polaris may be used interactively from the Delta system. Each Polaris function which we desire to use from Delta must have an interface routine set up in a special way to communicate with Delta. It is suggested that the routine names be of the form: <function>_pu(). The following example shows how to write a Polaris routine which writes the Fortran form of the program to ``cout'', and is usable from Delta:
extern "C" int
write_pu(char **data, int *len)
{
P_ASSERT_HANDLER(0);
external_interface_init();
ProgramUnit *pgm = external_program_unit( data, len );
p_assert( pgm, "not a program" );
pgm->write( cout );
return setup_to_return_handle( pgm->pu_tag_ref(), data, len);
}
The next example shows how to pass arguments from Delta to Polaris in addition to passing the program. The current Delta-Polaris interface converts all of the extra arguments to strings. It is up to the routine to covert then back into whatever they should be.
extern "C" int
unroll_loop_pu(char **data, int *len)
{
P_ASSERT_HANDLER(0);
external_interface_init();
List<StringElem> args;
ProgramUnit *pgm = external_program_unit( data, len, args );
p_assert( pgm, "not a valid ProgramUnit" );
if (args.entries() == 2) {
Statement *s1 = pgm->stmts().find_ref( args[0] );
p_assert(s1 && s1->stmt_class() == DO_STMT, "statement is not a loop");
int count = string_to_integer( args[1] );
p_assert( count > 0, "number of iterations must be positive" );
unroll_loop( *pgm, *s1, count );
}
return setup_to_return_handle( pgm->pu_tag_ref(), data, len);
}