Generating C++ code

andrea crotti andrea.crotti.0 at gmail.com
Wed Oct 10 06:41:01 EDT 2012


2012/10/10 Jean-Michel Pichavant <jeanmichel at sequans.com>:
> Well, the C++ code will end up running on a MIPS on a SOC, unfortunately, python is not an option here.
> The xml to C++ makes a lot of sense, because only a small part of the code is generated that way (everything related to log & fatal events). Everything else is written directly in C++.
>
> To answer Andrea's question, the files are regenerated for every compilation (well, unless the xml didn't change, but the xml is highly subject to changes, that's actually its purpose)
>
> Currently we already have a python script that translate this xml file to C++, but it's done in a way that is difficult to maintain. Basically, when parsing the xml file, it writes the generated C++ code. Something like:
> if 'blabla' in xml:
>   h_file.write("#define blabla 55", append="top")
>   c_file.write("someglobal = blabla", append="bottom")
>
> This is working, but the python code is quite difficult to maintain, there's a lot of escaping going on, it's almost impossible to see the structure of the c files unless generating one and hopping it's successful. It's also quite difficult to insert code exactly where you want, because you do not know the order in which the xml trees are defined then parsed.
>
> I was just wondering if a template engine would help. Maybe not.
>
> JM
> --
> http://mail.python.org/mailman/listinfo/python-list


I think it depends on what you're writing from the XML, are you
generating just constants (like the #define) or also new classes for
example?

If it's just constants why don't you do a generation from XML -> ini
or something similar and then parse it in the C++ properly, then it
would be very easy to do?

You could also parse the XML in the first place but probably that's
harder given your requirements, but I don't think that an ini file
would be a problem, or would it?



More information about the Python-list mailing list