OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [g++.dg/] [plugin/] [dumb_plugin.c] - Blame information for rev 696

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 693 jeremybenn
/* A trivial (dumb) plugin example that shows how to use the GCC plugin
2
   mechanism.  */
3
 
4
#include "gcc-plugin.h"
5
#include <stdlib.h>
6
#include "config.h"
7
#include "system.h"
8
#include "coretypes.h"
9
#include "tree.h"
10
#include "tree-pass.h"
11
#include "intl.h"
12
#include "toplev.h"
13
#include "diagnostic.h"
14
 
15
int plugin_is_GPL_compatible;
16
 
17
/* Callback function to invoke after GCC finishes parsing a struct.  */
18
 
19
void
20
handle_struct (void *event_data, void *data)
21
{
22
  tree type = (tree) event_data;
23
  warning (0, G_("Process struct %s"),
24
           IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))));
25
}
26
 
27
/* Callback function to invoke before the function body is genericized.  */
28
 
29
void
30
handle_pre_generic (void *event_data, void *data)
31
{
32
  tree fndecl = (tree) event_data;
33
  warning (0, G_("Before genericizing function %s"),
34
           IDENTIFIER_POINTER (DECL_NAME (fndecl)));
35
}
36
 
37
/* Callback function to invoke after GCC finishes the compilation unit.  */
38
 
39
void
40
handle_end_of_compilation_unit (void *event_data, void *data)
41
{
42
  warning (0, G_("End of compilation unit"));
43
}
44
 
45
 
46
static unsigned int
47
execute_dumb_plugin_example (void)
48
{
49
  warning (0, G_("Analyze function %s"),
50
           IDENTIFIER_POINTER (DECL_NAME (current_function_decl)));
51
  return 0;
52
}
53
 
54
static bool
55
gate_dumb_plugin_example (void)
56
{
57
  return true;
58
}
59
 
60
static struct gimple_opt_pass pass_dumb_plugin_example =
61
{
62
  {
63
    GIMPLE_PASS,
64
    "dumb_plugin_example",                /* name */
65
    gate_dumb_plugin_example,             /* gate */
66
    execute_dumb_plugin_example,          /* execute */
67
    NULL,                                 /* sub */
68
    NULL,                                 /* next */
69
    0,                                    /* static_pass_number */
70
    TV_NONE,                              /* tv_id */
71
    PROP_cfg,                             /* properties_required */
72
    0,                                    /* properties_provided */
73
    0,                                    /* properties_destroyed */
74
    0,                                    /* todo_flags_start */
75
    TODO_dump_func                        /* todo_flags_finish */
76
  }
77
};
78
 
79
/* Initialization function that GCC calls. This plugin takes an argument
80
   that specifies the name of the reference pass and an instance number,
81
   both of which determine where the plugin pass should be inserted.  */
82
 
83
int
84
plugin_init (struct plugin_name_args *plugin_info,
85
             struct plugin_gcc_version *version)
86
{
87
  struct register_pass_info pass_info;
88
  const char *plugin_name = plugin_info->base_name;
89
  int argc = plugin_info->argc;
90
  struct plugin_argument *argv = plugin_info->argv;
91
  char *ref_pass_name = NULL;
92
  int ref_instance_number = 0;
93
  int i;
94
 
95
  /* Process the plugin arguments. This plugin takes the following arguments:
96
     ref-pass-name=<PASS_NAME> and ref-pass-instance-num=<NUM>.  */
97
  for (i = 0; i < argc; ++i)
98
    {
99
      if (!strcmp (argv[i].key, "ref-pass-name"))
100
        {
101
          if (argv[i].value)
102
            ref_pass_name = argv[i].value;
103
          else
104
            warning (0, G_("option '-fplugin-arg-%s-ref-pass-name'"
105
                           " requires a pass name"), plugin_name);
106
        }
107
      else if (!strcmp (argv[i].key, "ref-pass-instance-num"))
108
        {
109
          if (argv[i].value)
110
            ref_instance_number = strtol (argv[i].value, NULL, 0);
111
          else
112
            warning (0, G_("option '-fplugin-arg-%s-ref-pass-instance-num'"
113
                           " requires an integer value"), plugin_name);
114
        }
115
      else
116
        warning (0, G_("plugin %qs: unrecognized argument %qs ignored"),
117
                 plugin_name, argv[i].key);
118
    }
119
 
120
  if (!ref_pass_name)
121
    {
122
      error (G_("plugin %qs requires a reference pass name"), plugin_name);
123
      return 1;
124
    }
125
 
126
  pass_info.pass = &pass_dumb_plugin_example.pass;
127
  pass_info.reference_pass_name = ref_pass_name;
128
  pass_info.ref_pass_instance_number = ref_instance_number;
129
  pass_info.pos_op = PASS_POS_INSERT_AFTER;
130
 
131
  register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &pass_info);
132
 
133
  register_callback (plugin_name, PLUGIN_FINISH_TYPE, handle_struct, NULL);
134
 
135
  register_callback (plugin_name, PLUGIN_PRE_GENERICIZE,
136
                     handle_pre_generic, NULL);
137
 
138
  register_callback (plugin_name, PLUGIN_FINISH_UNIT,
139
                     handle_end_of_compilation_unit, NULL);
140
  return 0;
141
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.