On Sun, 2013-02-10 at 11:37 +0200, y a wrote:
Hi all
I am simply awed by the gcc-python-plugin ;)
It looks like a fantastic effort
Thanks!
However, I cant find any sample which actually modifies the original C program
The plugin doesn't yet support modifying the internal representation, only reading it: so far I've only been using the plugin for code analysis.
However, I don't have any philosophical objections to having the plugin support such modifications: for example, it would be very useful to be able to use the plugin for prototyping new optimization passes for GCC proper.
(I have vague ideas of having a "safety switch" so that you have to call gcc.enable_modification() or somesuch before the plugin will allow you to modify the internal representation, and there might be a gcc.was_modified() boolean, so that the plugin "knows" if modifications happened (perhaps akin to the Linux kernel's "tainted" boolean?). Does that sound sane?)
For example, how to add a runtime reference count to each CHAR *
Obviously, this is a large, long term project
For C++, this replaces CHAR* with an object
For C, I might do a simpler effort and just add an additional counter variable for each char*
This sounds do-able, but I'd be wary of this kind of thing: you'd be effectively building a custom compiler that's probably deviating from the language standard. What you propose may be useful to you, but in some senses you'd be building your own programming language, and it's dangerous to only have one toolchain for your programs. I'd worry that you'd be "painting yourself into a corner" language-wise.
But is the python-plugin even suitable for this or should I go for a native gcc plugin ?
Currently it's not suitable, because of the current lack of support for modifications to the internal representation, but I *am* in favor of adding such support. So it would be a major undertaking to do it with the python plugin (as you'd have to add the support yourself, in addition to then using it).
Dave