diff options
author | Ian Hinder <ian.hinder@aei.mpg.de> | 2011-05-30 16:13:38 +0200 |
---|---|---|
committer | Ian Hinder <ian.hinder@aei.mpg.de> | 2011-06-09 16:42:50 +0200 |
commit | d53914d640f34ec7bce36263a6bfee2c51597677 (patch) | |
tree | e7f68e17238b28d973ed1922475f094717359c0c /Tools/CodeGen | |
parent | ef17ddd63e26c4625b27e1ae5028681dd29f6066 (diff) |
Differencing.m: Recognise dirN variables and make them work with functions
This assumes that you have shorthands called dir1, dir2 and dir3 which
need to be passed to some differencing operators. This is a
short-term solution to the problem of not being able to use arbitrary
shorthands in differencing operators, which addresses the immediate
requirements of application codes.
Diffstat (limited to 'Tools/CodeGen')
-rw-r--r-- | Tools/CodeGen/Differencing.m | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/Tools/CodeGen/Differencing.m b/Tools/CodeGen/Differencing.m index 70dd24d..70a2c87 100644 --- a/Tools/CodeGen/Differencing.m +++ b/Tools/CodeGen/Differencing.m @@ -362,17 +362,27 @@ ComponentDerivativeOperatorMacroDefinition[componentDerivOp:(name_[inds___] -> e "# define ", macroName, "(u) ", "(", rhs, ")\n", "#else\n", (* new, differencing operators are static functions *) - "# define ", macroName, "(u) ", "(", macroName, "_impl(u,", liName, ",cdj,cdk))\n", - "static CCTK_REAL ", macroName, "_impl(CCTK_REAL const* restrict const u, CCTK_REAL const ", liName, ", ptrdiff_t const cdj, ptrdiff_t const cdk) CCTK_ATTRIBUTE_NOINLINE CCTK_ATTRIBUTE_UNUSED;\n", - "static CCTK_REAL ", macroName, "_impl(CCTK_REAL const* restrict const u, CCTK_REAL const ", liName, ", ptrdiff_t const cdj, ptrdiff_t const cdk)\n", - (* We cannot handle dirN, - so we punt on all expressions that contain dirN *) - If[StringMatchQ[rhs, RegularExpression[".*\\bdir\\d\\b.*"]], - { "{ return ToReal(1e30); /* ERROR */ }\n" }, - { "{\n", - " ptrdiff_t const cdi=sizeof(CCTK_REAL);\n", - " return ", rhs, ";\n", - "}\n" }], + If[! StringMatchQ[rhs, RegularExpression[".*\\bdir\\d\\b.*"]], + { + (* simple case, dirN is not used *) + "# define ", macroName, "(u) ", "(", macroName, "_impl(u,", liName, ",cdj,cdk))\n", + "static CCTK_REAL ", macroName, "_impl(CCTK_REAL const* restrict const u, CCTK_REAL const ", liName, ", ptrdiff_t const cdj, ptrdiff_t const cdk) CCTK_ATTRIBUTE_NOINLINE CCTK_ATTRIBUTE_UNUSED;\n", + "static CCTK_REAL ", macroName, "_impl(CCTK_REAL const* restrict const u, CCTK_REAL const ", liName, ", ptrdiff_t const cdj, ptrdiff_t const cdk)\n", + "{\n", + " ptrdiff_t const cdi=sizeof(CCTK_REAL);\n", + " return ", rhs, ";\n", + "}\n" + }, + { + (* dirN is used *) + "# define ", macroName, "(u) ", "(", macroName, "_impl(u,", liName, ",cdj,cdk,dir1,dir2,dir3))\n", + "static CCTK_REAL ", macroName, "_impl(CCTK_REAL const* restrict const u, CCTK_REAL const ", liName, ", ptrdiff_t const cdj, ptrdiff_t const cdk, ptrdiff_t const dir1, ptrdiff_t const dir2, ptrdiff_t const dir3) CCTK_ATTRIBUTE_NOINLINE CCTK_ATTRIBUTE_UNUSED;\n", + "static CCTK_REAL ", macroName, "_impl(CCTK_REAL const* restrict const u, CCTK_REAL const ", liName, ", ptrdiff_t const cdj, ptrdiff_t const cdk, ptrdiff_t const dir1, ptrdiff_t const dir2, ptrdiff_t const dir3)\n", + "{\n", + " ptrdiff_t const cdi=sizeof(CCTK_REAL);\n", + " return ", rhs, ";\n", + "}\n" + }], "#endif\n" }]}]; |