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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [testsuite/] [g++.dg/] [plugin/] [dumb_plugin.c] - Blame information for rev 328

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

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

powered by: WebSVN 2.1.0

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