This is the automated part of the conversion of passes from C structs to C++ classes.
It is generated by the refactor_passes.py script in https://github.com/davidmalcolm/gcc-refactoring-scripts The script has its own test suite: test_refactor_passes.py, and you can get an idea of the behavior of the script by reviewing the test suite. This patch converts all existing pass structs for say RTL pass_foo into the following: namespace { const pass_data pass_data_foo = { /* initialization data */ }; class pass_foo : public rtl_opt_pass { public: pass_web(gcc::context *ctxt) : rtl_opt_pass(pass_data_web, ctxt) {} /* opt_pass methods: */ bool gate () { return gate_foo (); } unsigned int execute () { return execute_foo (); } }; // class pass_foo } // anon namespace rtl_opt_pass * make_pass_foo (gcc::context *ctxt) { return new pass_foo (ctxt); } so that the only exposed API to the pass is the factory function (i.e. "make_pass_foo"). It also updates tree-pass.h to replace all of the struct declarations: extern struct rtl_opt_pass pass_foo; with those of the new factory functions: extern rtl_opt_pass *make_pass_foo (gcc::context *ctxt); The full patch is 500k in size; I have posted it to: http://dmalcolm.fedorapeople.org/gcc/large-patches/15e12880a4c291deb984fb628e3142429019b263-0004-Automated-conversion-of-passes-to-C-classes.patch to avoid exceeding mailing list size limits (that version of the patch includes the ChangeLog entries).