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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 693 jeremybenn
/* Demonstrates how to add custom attributes */
2
 
3
#include "gcc-plugin.h"
4
#include <stdlib.h>
5
#include "config.h"
6
#include "system.h"
7
#include "coretypes.h"
8
#include "tree.h"
9
#include "tree-pass.h"
10
#include "intl.h"
11
#include "toplev.h"
12
#include "plugin.h"
13
#include "diagnostic.h"
14
 
15
int plugin_is_GPL_compatible;
16
 
17
/* Attribute handler callback */
18
 
19
static tree
20
handle_user_attribute (tree *node, tree name, tree args,
21
                        int flags, bool *no_add_attrs)
22
{
23
  return NULL_TREE;
24
}
25
 
26
/* Attribute definition */
27
 
28
static struct attribute_spec user_attr =
29
  { "user", 1, 1, false,  false, false, handle_user_attribute, false };
30
 
31
/* Plugin callback called during attribute registration */
32
 
33
static void
34
register_attributes (void *event_data, void *data)
35
{
36
  warning (0, G_("Callback to register attributes"));
37
  register_attribute (&user_attr);
38
}
39
 
40
/* Callback function to invoke before the function body is genericized.  */
41
 
42
void
43
handle_pre_generic (void *event_data, void *data)
44
{
45
  tree fndecl = (tree) event_data;
46
  tree arg;
47
  for (arg = DECL_ARGUMENTS(fndecl); arg; arg = DECL_CHAIN (arg)) {
48
      tree attr;
49
      for (attr = DECL_ATTRIBUTES (arg); attr; attr = TREE_CHAIN (attr)) {
50
          tree attrname = TREE_PURPOSE (attr);
51
          tree attrargs = TREE_VALUE (attr);
52
          warning (0, G_("attribute '%s' on param '%s' of function %s"),
53
                   IDENTIFIER_POINTER (attrname),
54
                   IDENTIFIER_POINTER (DECL_NAME (arg)),
55
                   IDENTIFIER_POINTER (DECL_NAME (fndecl))
56
                   );
57
      }
58
  }
59
}
60
 
61
int
62
plugin_init (struct plugin_name_args *plugin_info,
63
             struct plugin_gcc_version *version)
64
{
65
  const char *plugin_name = plugin_info->base_name;
66
  register_callback (plugin_name, PLUGIN_PRE_GENERICIZE,
67
                     handle_pre_generic, NULL);
68
 
69
  register_callback (plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
70
  return 0;
71
}

powered by: WebSVN 2.1.0

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