Wiki

Clone wiki

PyCA / AutoTemplateGeneration

Automated Explicit Template Instantiation Generation

Overview

PyCA attempts to explicitly instantiate templates whenever possible to reduce compile time and code bloat. However, for templates with multiple arguments, this requires explicit instantiation of every combination of parameters in the .cxx files containing the template definitions. To avoid this messy and error-prone list of explicit instantiations, PyCA uses a simple system for automatically generating these explicit template instantiations. It uses files written in a simple template definition language, whose extension is .tpl. For a source file with template definitions, say FieldOpers.cxx, a template definition file named FieldOpers_inst.tpl is created, and the desired templates specified. In the src directory CMakeLists.txt, these files are added to a list to be processed. Each file [foo]_inst.tpl generates a file [foo]_inst.cxx containing the expanded template definitions. The file [foo]_inst.cxx is then set up as a dependency to [foo].cxx, so whenever [foo]_inst.tpl is modified, [foo]_inst.cxx is re-generated and [foo].cxx is recompiled. The file [foo].cxx should have the line #include "[foo]_inst.cxx" in an appropriate location to include the generated instantiations.

TPL file format

The .tpl files consist of two definitions, replacement patterns and template definitions.

Updated