Source code generation using Python

ats asteinarson at
Sat Dec 6 22:47:26 CET 2008


This is my first posting to a Python group (and I'm starting with
Python seriously only now) , so bear with me if I make some mistakes.

I want to generate 3 different versions of a C++ source code,
basically injecting different flavours of inline assembler depending
on target compiler/CPU.

Code generation should be integrated into a 'master source file' which
is the processed and generates the right code for GCC / MSVC or other
cases. Something like:

  int FastAdd( int t1, int t2 ){
    int r;
      #ARG( eax, "t1")
      #ARG( ebx, "t2")
      #ASM( "add", ebx, eax )
      #RES( eax, "r" )
      r = t1+t2;
    return r;

On processing, given constant USE_INLINE_ASM (or not) the right code
is generated to a target file, which goes into the build process.

I was looking for packages that can do this and came up with some

 - "empy" - - It looks like it could
do the job, but appears non-maintained since 2003.
- "Cheetah" - Looks like more of a tool to do fix replacements of code

There is some logic going on in the "ARG", "ASM" and "RES" sections,
so I need to link code generation with true Python functions.

The situation is really quite similar to HTML/PHP except, here we
would have C++/Python.

Any suggestions?

//Arne S.

More information about the Python-list mailing list