diff options
author | eschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2011-03-30 19:56:42 +0000 |
---|---|---|
committer | eschnett <eschnett@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2011-03-30 19:56:42 +0000 |
commit | 5b71eb715b3bc47d41053b4948e7818377905d49 (patch) | |
tree | 53aca875fe06439a692223127efaae17a7c04da1 /lib | |
parent | 23378e71d93792cf0e63682214147670c9c07370 (diff) |
This patch makes the CST stage create prototypes for all scheduled
functions into a new file cctk_ScheduleFunctions.h, which is included
into cctk.h.
This is done only for C (and C++) since Fortran prototypes cannot be
declared at file scope.
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4695 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib')
-rw-r--r-- | lib/make/force-rebuild | 1 | ||||
-rw-r--r-- | lib/make/make.config.defn.in | 2 | ||||
-rw-r--r-- | lib/sbin/CreateScheduleBindings.pl | 162 |
3 files changed, 162 insertions, 3 deletions
diff --git a/lib/make/force-rebuild b/lib/make/force-rebuild index e9aefea8..9c0475b5 100644 --- a/lib/make/force-rebuild +++ b/lib/make/force-rebuild @@ -34,3 +34,4 @@ 21 Nov 2005: Change names of auto-generated capability header files 08 Apr 2008: Add IF clause to scheduler 23 Dec 2010: Rename cctki_Capabilities.h to cctk_Capabilities.h +20 Jan 2011: Generate prototypes for scheduled functions diff --git a/lib/make/make.config.defn.in b/lib/make/make.config.defn.in index 602dc890..ddf76456 100644 --- a/lib/make/make.config.defn.in +++ b/lib/make/make.config.defn.in @@ -176,7 +176,7 @@ export CUCC_POSTPROCESSING = @CUCC_POSTPROCESSING@ export USE_RANLIB = @USE_RANLIB@ # Exclude some files from the dependency lists -export DEP_EXCLUDE_FILES = cctk_Functions\.h|CParameterStructNames\.h|cctk_Arguments\.h|definethisthorn\.h|FParameters.h|CParameters\.h|cctk_Capabilities\.h +export DEP_EXCLUDE_FILES = cctk_Functions\.h|CParameterStructNames\.h|cctk_Arguments\.h|cctk_ScheduleFunctions\.h|definethisthorn\.h|FParameters.h|CParameters\.h|cctk_Capabilities\.h # Command used to get the working directory export GET_WD = @GET_WD@ diff --git a/lib/sbin/CreateScheduleBindings.pl b/lib/sbin/CreateScheduleBindings.pl index 3158fc7d..f5256f94 100644 --- a/lib/sbin/CreateScheduleBindings.pl +++ b/lib/sbin/CreateScheduleBindings.pl @@ -51,8 +51,23 @@ sub CreateScheduleBindings $rsbuffer = &ScheduleCreateFile($thorn, $rhinterface_db, $rhschedule_db); &WriteFile("Schedule$thorn.c",\$rsbuffer); $file_list .= " Schedule$thorn.c"; + + $rsbuffer = &ScheduleCreateInterfaceFile($thorn, $rhinterface_db, $rhschedule_db); + &WriteFile("../include/${thorn}_Schedule.h",\$rsbuffer); } + @data = (); + foreach $thorn (split(' ',$rhinterface_db->{'THORNS'})) + { + push(@data, "#ifdef THORN\_IS\_$thorn"); + push(@data, "#include \"${thorn}_Schedule.h\""); + push(@data, '#endif'); + push(@data, ''); + } + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + $dataout = join ("\n", @data); + &WriteFile('../include/cctk_ScheduleFunctions.h',\$dataout); + $rsbuffer = &ScheduleCreateBindings($rhinterface_db, $rhschedule_db); &WriteFile("BindingsSchedule.c", \$rsbuffer); $file_list .= " BindingsSchedule.c"; @@ -68,6 +83,145 @@ sub CreateScheduleBindings } #/*@@ +# @routine ScheduleCreateInterfaceFile +# @date 2006-05-11 +# @author Erik Schnetter +# @desc +# Create a string containing all the data which should go +# into a schedule interface file. +# @enddesc +#@@*/ +sub ScheduleCreateInterfaceFile +{ + my ($thorn, $rhinterface_db, $rhschedule_db) = @_; + + # Map groups to one of their block numbers (groups may have several + # block numbers) + my %group_block = (); + + for (my $block = 0; + $block < $rhschedule_db->{"\U$thorn\E N_BLOCKS"}; + ++ $block) + { + if ($rhschedule_db->{"\U$thorn\E BLOCK_$block TYPE"} eq "GROUP") + { + my $group = $rhschedule_db->{"\U$thorn\E BLOCK_$block NAME"}; + $group_block{$group} = $block; + } + } + + + + # Process each schedule block + + my @data = (); + push (@data, '#include "cctk_Arguments.h"'); + + for (my $block = 0; + $block < $rhschedule_db->{"\U$thorn\E N_BLOCKS"}; + ++ $block) + { + if ($rhschedule_db->{"\U$thorn\E BLOCK_$block TYPE"} eq "FUNCTION") + { + my ($language, $function); + if ($rhschedule_db->{"\U$thorn\E BLOCK_$block LANG"} =~ m:^\s*C\s*$:i) + { + $language = 'C'; + $function = $rhschedule_db->{"\U$thorn\E BLOCK_$block NAME"}; + } + elsif ($rhschedule_db->{"\U$thorn\E BLOCK_$block LANG"} =~ m:^\s*(F|F77|FORTRAN|F90)\s*$:i) + { + $language = 'Fortran'; + $function = "CCTK_FNAME(".$rhschedule_db->{"\U$thorn\E BLOCK_$block NAME"} .")"; + } + + my $where = $rhschedule_db->{"\U$thorn\E BLOCK_$block WHERE"}; + # Find one outermost enclosing group iteratively (there may + # be serveral outermost enclosing groups) + my %been_there; # avoid cycles + while (! $been_there{$where} && defined $group_block{$where}) + { + $been_there{$where} = defined; + my $block1 = $group_block{$where}; + $where = $rhschedule_db->{"\U$thorn\E BLOCK_$block1 WHERE"}; + } + my $is_special = + $where eq 'CCTK_STARTUP' || + $where eq 'CCTK_RECOVER_PARAMETERS' || + $where eq 'CCTK_SHUTDOWN'; + + push (@data, ''); + if ($language eq 'C') + { + push (@data, '#ifdef CCODE'); + push (@data, '#ifdef __cplusplus'); + push (@data, 'extern "C"'); + push (@data, '#endif'); + if ($is_special) + { + push (@data, "int $function (void);") + } + else + { + push (@data, "void $function (CCTK_ARGUMENTS);") + } + push (@data, '#endif /* CCODE */'); + } + elsif ($language eq 'Fortran') + { +# Can't use CCTK_FNAME in header files (which is implicit in $function) +# push (@data, '#ifdef CCODE'); +# push (@data, '#ifdef __cplusplus'); +# push (@data, 'extern "C"'); +# push (@data, '#endif'); +# if ($is_special) +# { +# push (@data, "CCTK_FCALL int $function (void);") +# } +# else +# { +# push (@data, "CCTK_FCALL void $function (CCTK_FARGUMENTS);") +# } +# push (@data, '#endif /* CCODE */'); +# Can't declare functions in Fortran at file scope +# push (@data, '#ifdef FCODE'); +# push (@data, '#ifdef F90CODE'); +# push (@data, ' interface'); +# if ($is_special) +# { +# push (@data, " integer function $function ()"); +# push (@data, ' implicit none'); +# push (@data, " end function $function"); +# } +# else +# { +# push (@data, " subroutine $function (CCTK_ARGUMENTS)"); +# push (@data, ' implicit none'); +# push (@data, ' DECLARE_CCTK_ARGUMENTS'); +# push (@data, " end subroutine $function"); +# } +# push (@data, ' end interface'); +# push (@data, '#else /* ! F90CODE */'); +# push (@data, " external $function"); +# if ($is_special) +# { +# push (@data, " integer $function"); +# } +# push (@data, '#endif /* F90CODE */'); +# push (@data, '#endif /* FCODE */'); + } + + } + } + + push(@data, "\n"); # workaround for perl 5.004_04 to add a trailing newline + + return join ("\n", @data); +} + + + +#/*@@ # @routine ScheduleCreateFile # @date Fri Sep 17 17:34:26 1999 # @author Tom Goodale @@ -144,9 +298,13 @@ sub ScheduleCreateFile push(@data, '#include "cctk_Parameters.h"'); push(@data, '#include "cctki_ScheduleBindings.h"'); push(@data, ''); - push(@data, '/* prototypes for schedule bindings functions to be registered */'); + #push(@data, '/* prototypes for schedule bindings functions to be registered */'); + #push(@data, '/* Note that this is a cheat, we just need a function pointer. */'); + #push(@data, $prototypes); + #push(@data, ''); + push(@data, '/* Prototypes for Fortran schedule bindings functions to be registered */'); push(@data, '/* Note that this is a cheat, we just need a function pointer. */'); - push(@data, $prototypes); + push(@data, join "\n", (grep /CCTK_FNAME/, (split "\n", $prototypes))); push(@data, ''); push(@data, "void CCTKi_BindingsSchedule_$thorn(void);"); push(@data, "void CCTKi_BindingsSchedule_$thorn(void)"); |