On Sat, 5 Oct 2019, Bernd Edlinger wrote: > > Like > > > > #define DEFAULT_SOME_MACRO(PARMS) { lots of code } > > > > becomes > > > > #define DEFAULT_SOME_MACRO(PARMS) default_some_macro(PARMS) > > > > static inline int > > default_some_macro (int parm, long another) > > { > > lots of code; > > } > > > > The point is that all this is completely *local* changes. > > > > Hmm, I tried this but it does not work:
The answer to that is an out-of-line function. See the default_register_move_cost function in targhooks.c, the register_move_cost hook and the REGISTER_MOVE_COST target macro, for example. There is a strategy for incremental conversion of a single target macro to a hook that goes as follows: * Define a corresponding target hook. Make the default definition in targhooks.c be one that tests whether the target macro is defined and either uses that macro or the existing default as appropriate. Make tm.texi.in document the hook alongside the macro, saying that the macro is obsolete and new targets should use the hook. * Convert all *uses* of the target macro to use the hook instead. There is no need to change any of the definitions in the various targets with non-default definitions. * Remove the default definition of the target macro, as no longer needed now targhooks.c tests whether the target macro is defined or not. At that point, you have a partial conversion of that target macro to a hook (and consequent gains regarding avoiding shadowing) without having touched any of the target-specific code. Any target can safely convert its own definition of the macro to a definition of the hook, independently of all other targets and all other hooks. Once all targets have changed, the macro can be poisoned and the documentation of the macro and support in targhooks.c for using the macro removed, in the usual fashion for removing a target macro - but that might happen a long time afterwards. It's more work than a pure local conversion to an inline function, or than just renaming variables, but significantly less than a full conversion of the macro to a hook (and in particular should not need testing on more than one target). -- Joseph S. Myers jos...@codesourcery.com