Configuring Meta-Programming

Mark S mark@REDACTED
Fri Jan 29 15:25:07 CET 2021


Hello,

I'm looking for advice on how to configure code generated at compile 
time.  My current solution reads the configuration values from a file, 
but the feedback I received indicates that requiring users to create and 
maintain a config file, in order to use this library, will at the very 
least, severely limit its usefulness.

Is there another way to introduce configuration values at compile time?  
Is there a library you can point me to, that has resolved the same issue 
differently?

Specifically, I created code that generates a module, containing a 
custom Cyclic Redundancy Check (CRC) calculation function that utilizes 
a CRC look-up table.  Creating the function and the look-up table 
requires specifying the bit width, polynomial, initial value, final XOR 
value, and whether the input and output values are reflected or not.

To generate the code module, I used Ulf Wiger's parse_trans library. In 
particular, ct_expand:term() to generate the look-up table, and 
codegen:gen_module() to generate the code and finally calling 
merl:compile() to compile the abstract syntax tree, generated by 
gen_module().

Thanks,

Mark Sebald


More information about the erlang-questions mailing list