Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template based C / C++ code generation

Tags:

Any suggestion for template base code generator for C / C++ specifically to generate repetitive code generation? (Not UML / MATLAB model based or other advanced stuff). For a newbie in this field any good generic tutorial (not tool based)?

I came across GNU Autogen looks good but looks like it needs a steep learning curve. I would prefer some plug-in for eclipse like IDE, easy to use and most importantly good tutorials.

like image 352
Kamath Avatar asked Aug 24 '12 14:08

Kamath


People also ask

What is template based code generation?

Template-based code generation (TBCG) is a synthesis technique that produces code from high-level specifications, called templates. TBCG is a popular technique in model-driven engineering (MDE) given that they both emphasize abstraction and automation.

What is C code generation?

20-sim has a C-Code Generator which automatically converts a complete 20-sim model or submodel into C-Code. The application can be used to generate Matlab™/Simulink™ S-Functions, to generate Stand-Alone executables or to generate input/output functions for use in other C and C++ programs.

What is T4 code generation?

In Visual Studio, a T4 text template is a mixture of text blocks and control logic that can generate a text file. The control logic is written as fragments of program code in Visual C# or Visual Basic.


2 Answers

The basic concept of code generation is simple enough - and people's needs are varied enough - that there are quite a few options out there.

  • Boost.Preprocessor is a library of functions built on top of the standard C / C++ preprocessor that makes it much easier to use the preprocessor to do code generation. It's not as flexible as other options, and figuring out preprocessor errors can be tricky, but the fact that it uses only standard language features greatly simplifies using it and integrating it into your builds.
  • If you know Python, there's Cog.
  • Some of Google's projects use Pump.
  • There are many general-purpose templating solutions (Python's Genshi, eRuby, etc.). These are often designed for generating HTML and XML but also work for code.
  • It's also easy enough to hack something together in the scripting language of your choice.

Without knowing more about what your needs are and what tools you're comfortable with, I can't give a more specific recommendation.

I'm not familiar with anything that provides an Eclipse plugin.

like image 66
Josh Kelley Avatar answered Sep 21 '22 04:09

Josh Kelley


If you know Python, then Cog could be considered as light-weight solution: http://www.python.org/about/success/cog/

like image 31
Rost Avatar answered Sep 21 '22 04:09

Rost