Re-factor inclusion of tree.h.
[official-gcc.git] / gcc / testsuite / gcc.dg / plugin / one_time_plugin.c
blob1e601a63c90e1fc4cd7ef20c2626e4e35c65aa23
1 /* Plugin that prints message if it inserted (and invoked) more than once. */
2 #include "config.h"
3 #include "gcc-plugin.h"
4 #include "system.h"
5 #include "coretypes.h"
6 #include "tree.h"
7 #include "tm.h"
8 #include "toplev.h"
9 #include "gimple.h"
10 #include "tree-pass.h"
11 #include "intl.h"
12 #include "context.h"
14 int plugin_is_GPL_compatible;
16 namespace {
18 const pass_data pass_data_one_pass =
20 GIMPLE_PASS, /* type */
21 "cfg", /* name */
22 OPTGROUP_NONE, /* optinfo_flags */
23 true, /* has_gate */
24 true, /* has_execute */
25 TV_NONE, /* tv_id */
26 PROP_gimple_any, /* properties_required */
27 0, /* properties_provided */
28 0, /* properties_destroyed */
29 0, /* todo_flags_start */
30 0, /* todo_flags_finish */
33 class one_pass : public gimple_opt_pass
35 public:
36 one_pass(gcc::context *ctxt)
37 : gimple_opt_pass(pass_data_one_pass, ctxt),
38 counter(0)
41 /* opt_pass methods: */
42 bool gate ();
43 unsigned int execute ();
45 private:
46 int counter;
47 }; // class one_pass
49 } // anon namespace
51 bool one_pass::gate (void)
53 return true;
56 unsigned int one_pass::execute ()
58 if (counter > 0) {
59 printf ("Executed more than once \n");
61 counter++;
62 return 0;
65 gimple_opt_pass *
66 make_one_pass (gcc::context *ctxt)
68 return new one_pass (ctxt);
72 int plugin_init (struct plugin_name_args *plugin_info,
73 struct plugin_gcc_version *version)
75 struct register_pass_info p;
77 p.pass = make_one_pass (g);
78 p.reference_pass_name = "cfg";
79 p.ref_pass_instance_number = 1;
80 p.pos_op = PASS_POS_INSERT_AFTER;
82 register_callback ("one_pass", PLUGIN_PASS_MANAGER_SETUP, NULL, &p);
84 return 0;