If I have such a structure:
struct test{
float c,
f,
ops;
};
How can I modify the GCC compiler source code to make it as follows:
struct test{
double c,
f,
ops;
};
I now have such a requirement, I need to modify the gcc source code so that when he compiles a structure of a certain mode, he changes its type to a specified type.
Thank you!
your goal is very ambitious!
A possible approach could be to develop your own GCC plugin doing that job.
My recommendations:
budget several months of your time for that work (and perhaps several years) - at least 6 months full time to get a "proof of concept" thing which would fail on most code bases (in C). For C++, add another full year.
read carefully the C11 standard n1570 (if you target C), and the C++11 standard n3337 (if you target C++). That effort alone may take you a full month.
make your plugin open source software, and put its code quickly (e.g. under LGPL license) on some repository such as github or gitlab.
target the latest available version of GCC. In September 2020, that means GCC 10. Plugins and GCC APIs are changing incompatibly from one version to the next. If you need to stick to GCC 8 specifically, be prepared to spend a big amount of money for companies like AdaCore.
read carefully the documentation on GCC internals. You need to understand the GENERIC representation.
study very carefully the
gcc/tree.def
andgcc/treestruct.def
andgcc/gimple.def
files of GCC source code. You need to basically understand every line in them.study very carefully the
gcc/passes.def
file of GCC source code. Again, you need to understand every line in that file.learn to compile GCC from its source code. You certainly want to build it with
g++ -Wall -Wextra -g -O1
read this draft report.
ask help in written English on the
[email protected]
mailing list, but have some working plugin before.consider making a PhD out of this work. It is worth one. Alexandre Lissy in France got a PhD on a very similar topic.
If your code base is in C, consider using Frama-C (or Clang) and design your tool as a C to C transpiler.
Perhaps clever preprocessor tricks like
#define float double
followed by#undef float
might be enough.