Changeset 598


Ignore:
Timestamp:
Aug 15, 2003, 11:11:55 PM (22 years ago)
Author:
zap
Message:

Fixed _Optlink and _System finally (I hope).

Location:
trunk/src/gcc/gcc
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/src/gcc/gcc/config/i386/emx.c

    • Property cvs2svn:cvs-rev changed from 1.12 to 1.13
    r597 r598  
    3030#include "toplev.h"
    3131#include "flags.h"
     32
     33#define BIRD_DEBUG
    3234
    3335/* The size of the target's pointer type.  */
     
    6668void dump (tree node)
    6769{
    68     tree        type, type2, context;
     70    tree type, type2, context, name;
    6971    if (!node)
    7072        return;
     
    7375    type2 = type ? TREE_TYPE(type) : NULL;
    7476    context = DECL_P (node) ? DECL_CONTEXT (node) : NULL_TREE;
    75     fprintf(stderr, "dbg: node=%d %s type=%d %s type_type=%d %s context=%d %s\n",
     77    name = DECL_P (node) ? DECL_NAME (node) : NULL_TREE;
     78    fprintf(stderr, "dbg: node=%d %s type=%d %s type_type=%d %s context=%d %s name=%s\n",
    7679            TREE_CODE(node), code(node),
    7780            type ? TREE_CODE(type) : -1, code(type),
    7881            type2 ? TREE_CODE(type2) : -1, code(type2),
    79             context ? TREE_CODE(context) : -1, code(context));
     82            context ? TREE_CODE(context) : -1, code(context),
     83            name ? IDENTIFIER_POINTER (name) : "<none>");
    8084}
    8185
     
    8892
    8993
    90 tree ix86_handle_system_attribute (tree *node, tree name, tree args,
     94tree ix86_handle_vacpp_attribute (tree *node, tree name, tree args,
    9195  int flags, bool *no_add_attrs)
    9296{
    93   tree          type;
    94   (void)args; (void)flags;
    95 
    96 dfprintf ((stderr, "dbg: %s flags=%x\n", __FUNCTION__, flags));
    97 DUMP (*node);
    98 
    99   type = TREE_TYPE (*node);
    100   if (DECL_P (*node))
    101     switch (TREE_CODE (type))
    102       {
    103         case FUNCTION_TYPE:
    104           {
    105             tree          context;
    106             size_t        sl;
    107             const char *  oldsym;
    108             char *        newsym;
    109 
    110             /* typedef and field may end up here. they should not get their name changed! */
    111             if (TREE_CODE (*node) == FIELD_DECL | TREE_CODE (*node) == TYPE_DECL)
    112                 return NULL_TREE;
    113 
    114             /* class method (static) ends up here too, they should be get their
    115                name changed. Try check if context is RECORD_TYPE and pray that
    116                means it's a class...
    117                @todo: verify the class detection here! CLASSTYPE_DECLARED_CLASS?  */
    118             context = DECL_CONTEXT (*node);
    119             DUMP ((context));
    120             if (context && (    TREE_CODE (context) == RECORD_TYPE
    121                             ||  TREE_CODE (context) == UNION_TYPE))
    122               return NULL_TREE;
    123             /** @todo more decl code checks? */
    124 
    125 
    126             /* _System mangling!
    127                Specifying '*' as first symbol character tells gcc (see varasm.c,
     97  tree id, type;
     98  size_t sl;
     99  const char *oldsym;
     100  char *newsym;
     101
     102  DUMP (*node);
     103
     104  switch (TREE_CODE (*node))
     105    {
     106      case FUNCTION_DECL:
     107        /* This is the core of attribute handling. Every other code is
     108           designed so that we end up with a function declaration and
     109           an attached attribute (either optlink or system). */
     110        if (!strcmp (IDENTIFIER_POINTER (name), "system"))
     111          {
     112            /* Here we mangle _System functions as defined by IBM specs.
     113               The function always gets its name as-is (unless it is a method,
     114               which is a undefined case as VACPP always use _Optlink for methods,
     115               at least that's what I have understood from the docs). */
     116            if (TREE_CODE (TREE_TYPE (*node)) == METHOD_TYPE)
     117              break;
     118
     119            oldsym = IDENTIFIER_POINTER (DECL_NAME (*node));
     120            /* Specifying '*' as first symbol character tells gcc (see varasm.c,
    128121               function assemble_name()) to output the label as-is rather than
    129122               invoking the ASM_OUTPUT_LABELREF macro (which prepends a underscore) */
    130             oldsym = IDENTIFIER_POINTER (DECL_NAME (*node));
    131123            sl = strlen (oldsym);
    132124            newsym = xmalloc (sl + 2);
     
    134126            memcpy (newsym + 1, oldsym, sl + 1);
    135127            SET_DECL_ASSEMBLER_NAME (*node, get_identifier (newsym));
    136             dfprintf((stderr, "dbg: name change: %s -> %s\n", oldsym, newsym));
    137             return NULL_TREE;
    138           }
    139         case POINTER_TYPE:
    140           /* Pointer-to-a-function type is allowed */
    141           if (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
    142            && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)
     128          }
     129        else if (!strcmp (IDENTIFIER_POINTER (name), "optlink"))
     130          {
     131            /* All function types have a name which should be mangled
     132               by _Optlink specification. */
     133            id = DECL_ASSEMBLER_NAME (*node);
     134            /* Remove the leading underscore. */
     135            oldsym = IDENTIFIER_POINTER (id);
     136            sl = strlen (oldsym);
     137            newsym = xmalloc (sl + 2);
     138            newsym [0] = '*';
     139            memcpy (newsym + 1, oldsym, sl + 1);
     140            XEXP (DECL_RTL (*node), 0) = gen_rtx (SYMBOL_REF, Pmode,
     141              IDENTIFIER_POINTER (get_identifier (newsym)));
     142          }
     143        else /* Huh?! */
     144          goto warn;
     145
     146        /* The attribute should really be attached to our _TYPE,
     147           not to the _DECL */
     148        type = TREE_TYPE (*node);
     149        goto attach_attr;
     150
     151      case TYPE_DECL:
     152        /* If this is a type declaration with our attribute,
     153           we allow it only if it is a pointer-to-a-function type */
     154        type = TREE_TYPE (*node);
     155        if (TREE_CODE (type) == POINTER_TYPE
     156         && (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
     157          || TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE))
     158          /* Since it is just a type it doesn't have any label to mangle,
     159             but if we attach the attribute to the type all calls through
     160             this pointer will get arguments passed correctly */
     161          {
     162            /* Attach the attribute to the (FUNCTION|METHOD)_TYPE node */
     163            type = TREE_TYPE (type);
     164attach_attr:TYPE_ATTRIBUTES (type) = chainon (TYPE_ATTRIBUTES (type),
     165                                              tree_cons (name, args, NULL_TREE));
     166            *no_add_attrs = true;
    143167            break;
    144         case METHOD_TYPE:
    145         case FIELD_DECL:
    146         case TYPE_DECL:
    147           /* Not a error but no action either */
    148           return NULL_TREE;
    149         default:
    150           break;
    151       }
    152   else if (TREE_CODE (*node) == POINTER_TYPE && type)
    153     { /* Pointer-to-a-function type is allowed */
    154       switch (TREE_CODE (type))
    155         {
    156           case FUNCTION_TYPE:
    157           case METHOD_TYPE:
    158             return NULL_TREE;
    159           default:
    160             break;
    161         }
    162     }
    163   /* potential warnings get here */
    164 
    165   /* IF there is a function in the works, we don't complain and
    166      make sure _System is tried again on the function declaration.
    167      OR if this is a function type we need to pass it up to the
    168      declaration which is likely to be a some kind of type or field.
    169      */
    170   if (   (flags & (int)ATTR_FLAG_FUNCTION_NEXT)
    171       || TREE_CODE (*node) == FUNCTION_TYPE
    172       || TREE_CODE (*node) == METHOD_TYPE)
    173     return tree_cons (name, args, NULL_TREE);
    174 
    175   warning ("`%s' attribute only applies to functions and function types",
    176            IDENTIFIER_POINTER (name));
    177   *no_add_attrs = true;
    178 
    179   return NULL_TREE;
    180 }
    181 
    182 
    183 tree ix86_handle_optlink_attribute (tree *node, tree name, tree args,
    184   int flags, bool *no_add_attrs)
    185 {
    186   tree id, type, typeset;
    187   size_t sl;
    188   const char *oldsym;
    189   char *newsym;
    190 
    191   (void)args; (void)flags;
    192 
    193   typeset = NULL;
    194   type = TREE_TYPE (*node);
    195   if (DECL_P (*node))
    196     switch (TREE_CODE (type))
    197       {
    198         case FUNCTION_TYPE:
    199         case METHOD_TYPE:
    200           typeset = type;
    201         case FIELD_DECL:                /* how come these needs mangling? */
    202         case TYPE_DECL:
    203           id = DECL_ASSEMBLER_NAME (*node);
    204           /* Remove the leading underscore */
    205           oldsym = IDENTIFIER_POINTER (id);
    206           sl = strlen (oldsym);
    207           newsym = xmalloc (sl + 2);
    208           newsym [0] = '*';
    209           memcpy (newsym + 1, oldsym, sl + 1);
    210           XEXP (DECL_RTL (*node), 0) = gen_rtx (SYMBOL_REF, Pmode,
    211             IDENTIFIER_POINTER (get_identifier (newsym)));
    212           break;
    213         case POINTER_TYPE:
    214           /* Pointer-to-a-function type is allowed */
    215           if (TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE
    216            && TREE_CODE (TREE_TYPE (type)) != METHOD_TYPE)
    217             goto warn;
    218 /*@@@@@todo: not finished*/
    219           typeset = type;
    220           break;
    221         default:
    222           goto warn;
    223       }
    224   else if (TREE_CODE (*node) == POINTER_TYPE && type)
    225     { /* Pointer-to-a-function type is allowed */
    226       switch (TREE_CODE (type))
    227         {
    228           case FUNCTION_TYPE:
    229           case METHOD_TYPE:
    230             typeset = type;
    231             break;
    232           default:
    233             goto warn;
    234         }
    235     }
    236   else
    237     {
    238 warn: warning ("`%s' attribute only applies to functions and function types",
    239                IDENTIFIER_POINTER (name));
    240       *no_add_attrs = true;
    241       DUMP (*node);
    242     }
    243 
    244   /* attach attribute to type. */
    245   if (typeset)
    246     {
    247       id = tree_cons (name, args, NULL_TREE);
    248       TYPE_ATTRIBUTES (typeset) = chainon (TYPE_ATTRIBUTES (typeset), id);
    249       return id;
     168          }
     169        goto warn;
     170
     171      case POINTER_TYPE:
     172        if (flags & ATTR_FLAG_FUNCTION_NEXT)
     173          {
     174            /* This is the return type for a function. Ignore attribute
     175               for the return type itself and re-apply it later to the
     176               function itself. */
     177defer_attr: *no_add_attrs = true;
     178            return tree_cons (name, args, NULL_TREE);
     179          }
     180        else if (flags & ATTR_FLAG_DECL_NEXT)
     181          {
     182            /* The node passed is the type of a DECL that will follow.
     183               If the decl is a function or a method, tell decl_attributes()
     184               that the attribute should be applied to the decl rather than
     185               to its return type  */
     186            type = TREE_TYPE (*node);
     187            if (type
     188             && (TREE_CODE (type) == FUNCTION_TYPE
     189              || TREE_CODE (type) == METHOD_TYPE))
     190               goto defer_attr;
     191          }
     192        goto warn;
     193
     194      default:
     195warn:   warning ("`%s' attribute only applies to functions and function types",
     196                 IDENTIFIER_POINTER (name));
     197        *no_add_attrs = true;
     198        DUMP (*node);
     199        break;
    250200    }
    251201
     
    277227    strcpy (lbl, "__POST$");
    278228    if (func_label[0] == '*')
    279         func_label++;
     229      func_label++;
    280230    strcat (lbl, func_label);
    281231    ASM_OUTPUT_LABEL (f, lbl);
  • TabularUnified trunk/src/gcc/gcc/config/i386/emx.h

    • Property cvs2svn:cvs-rev changed from 1.14 to 1.15
    r597 r598  
    9191#define DWARF2_UNWIND_INFO 1
    9292
     93/* This function handles both _System and _Optlink attributes */
     94extern tree ix86_handle_vacpp_attribute PARAMS ((tree *, tree, tree, int, _Bool *));
     95
    9396/* We want the _System attribute */
    9497#define TARGET_SYSTEM_DECL_ATTRIBUTES
    95 /* Handle _System attribute */
    96 extern tree ix86_handle_system_attribute PARAMS ((tree *, tree, tree, int, _Bool *));
     98#define ix86_handle_system_attribute ix86_handle_vacpp_attribute
    9799
    98100/* We want the _Optlink attribute */
    99101#define TARGET_OPTLINK_DECL_ATTRIBUTES
    100 /* Handle _Optlink attribute */
    101 extern tree ix86_handle_optlink_attribute PARAMS ((tree *, tree, tree, int, _Bool *));
     102#define ix86_handle_optlink_attribute ix86_handle_vacpp_attribute
    102103
    103104/* This macros will stick a label to exception table for current file,
  • TabularUnified trunk/src/gcc/gcc/cp/decl.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.2
    r597 r598  
    1363813638  else
    1363913639    {
    13640       decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, NULL);
     13640      decl1 = grokdeclarator (declarator, declspecs, FUNCDEF, 1, &attrs);
    1364113641      /* If the declarator is not suitable for a function definition,
    1364213642         cause a syntax error.  */
Note: See TracChangeset for help on using the changeset viewer.