A previous programmer preferred to generate large lookup tables (arrays of constants) to save runtime CPU cycles rather than calculating values on the fly. He did this by creating custom Visual C++ projects that were unique for each individual lookup table… which generate array files that are then #included into a completely separate ANSI-C micro-controller (Renesas) project.
This approach is fine for his original calculation assumptions, but has become tedious when the input parameters need to be modified, requiring me to recompile all of the Visual C++ projects and re-import those files into the ANSI-C project. What I would like to do is port the Visual C++ source directly into the ANSI-C microcontroller project and let the compiler create the array tables.
So, my question is: Can ANSI-C compilers compute and generate lookup arrays during compile time? And if so, how should I go about it?
Thanks in advance for your help!
Is there some reason you can’t import his code generation architecture to your build system?
I mean, in make I might consider something like:
where each
table_*contains a complete code generation project whose sole purpose is tho buildtable_n/table_n.h. Also in each table directory a makefile fragment namedmakefile.incwhich provides the dependency lines for generated include files, and now I’ve removed the recursivity.Done right (and this implementation isn’t finished, in part because the point is clearer this way but mostly because I am lazy), you could edit
table_3/table_3.input, typemakein the main directory and get table_3/table_3.h rebuilt and the program incrementally recompiled.