This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PATCH: Darwin pragmas


Here are four target-specific pragmas that Darwin systems need to
support.  In the absence of any consensus on adding documentation or
testsuite for pragmas, the patch doesn't include those, but of course
I'd be happy to write them if it's agreed that they are desirable.
I'd also like to hear of obvious mistakes in the code before committing;
it passes a bootstrap on powerpc-apple-darwin1.3, plus my personal
pragma tests, but it seems that one has to be a little tricky to get
target-specific pragmas to play nice with the different frontends.

Stan

2001-06-25  Stan Shebs  <shebs@apple.com>

        * config/darwin.h (REGISTER_TARGET_PRAGMAS): Define.
        * config/darwin.c (darwin_init_pragma): New function.
        (darwin_pragma_ignore): Ditto.
        (darwin_pragma_options): Ditto.
        (darwin_pragma_unused): Ditto.
        (push_field_alignment): Ditto.
        (pop_field_alignment): Ditto.
        * config/darwin-protos.h: Declare new functions.

Index: config/darwin-protos.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin-protos.h,v
retrieving revision 1.2
diff -c -3 -p -r1.2 darwin-protos.h
*** darwin-protos.h	2001/06/08 02:28:04	1.2
--- darwin-protos.h	2001/06/26 02:29:02
*************** extern void darwin_encode_section_info P
*** 56,58 ****
--- 56,65 ----
  #endif /* TREE_CODE */
  
  extern void machopic_finish PARAMS ((FILE *));
+ 
+ #ifdef GCC_C_PRAGMA_H
+ extern void darwin_init_pragma PARAMS ((int (*) (tree *)));
+ extern void darwin_pragma_ignore PARAMS ((cpp_reader *));
+ extern void darwin_pragma_options PARAMS ((cpp_reader *));
+ extern void darwin_pragma_unused PARAMS ((cpp_reader *));
+ #endif
Index: config/darwin.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.c,v
retrieving revision 1.3
diff -c -3 -p -r1.3 darwin.c
*** darwin.c	2001/06/11 18:59:42	1.3
--- darwin.c	2001/06/26 02:29:03
*************** Boston, MA 02111-1307, USA.  */
*** 38,43 ****
--- 38,50 ----
  #include "function.h"
  #include "ggc.h"
  
+ #include "toplev.h"
+ #include "cpplib.h"
+ #include "c-lex.h"
+ #include "c-pragma.h"
+ 
+ #include "c-tree.h"
+ 
  #include "darwin-protos.h"
  
  extern void machopic_output_stub PARAMS ((FILE *, const char *, const char *));
*************** update_non_lazy_ptrs (name)
*** 1080,1083 ****
--- 1087,1223 ----
  	    }
  	}
      }
+ }
+ 
+ /* Pragma support.  */
+ 
+ #define BAD(msgid) do { warning (msgid); return; } while (0)
+ 
+ static int (*c_lex_func) (tree *);
+ 
+ /* Maintain a small stack of alignments.  This is similar to pragma
+    pack's stack, but simpler.  */
+ 
+ static void push_field_alignment PARAMS ((int));
+ static void pop_field_alignment PARAMS ((void));
+ 
+ typedef struct align_stack
+ {
+   int alignment;
+   struct align_stack * prev;
+ } align_stack;
+ 
+ static struct align_stack * field_align_stack = NULL;
+ 
+ static void
+ push_field_alignment (bit_alignment)
+      int bit_alignment;
+ {
+   align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
+ 
+   entry->alignment = maximum_field_alignment;
+   entry->prev = field_align_stack;
+   field_align_stack = entry;
+ 
+   maximum_field_alignment = bit_alignment;
+ }
+ 
+ static void
+ pop_field_alignment ()
+ {
+   if (field_align_stack)
+     {
+       align_stack *entry = field_align_stack;
+ 
+       maximum_field_alignment = entry->alignment;
+       field_align_stack = entry->prev;
+       free (entry);
+     }
+   else
+     error ("too many #pragma options align=reset");
+ }
+ 
+ /* Capture the token getter so we can call it from pragma handlers.  */
+ 
+ void
+ darwin_init_pragma (get_token)
+      int (*get_token) PARAMS ((tree *));
+ {
+   c_lex_func = get_token;
+ }
+ 
+ /* Handlers for Darwin-specific pragmas.  */
+ 
+ void
+ darwin_pragma_ignore (pfile)
+      cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+   /* Do nothing.  */
+ }
+ 
+ /* #pragma options align={mac68k|power|reset} */
+ 
+ void
+ darwin_pragma_options (pfile)
+      cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+   char *arg;
+   tree t, x;
+ 
+   if (c_lex_func (&t) != CPP_NAME)
+     BAD ("malformed '#pragma options', ignoring");
+   arg = IDENTIFIER_POINTER (t);
+   if (strcmp (arg, "align"))
+     BAD ("malformed '#pragma options', ignoring");
+   if (c_lex_func (&t) != CPP_EQ)
+     BAD ("malformed '#pragma options', ignoring");
+   if (c_lex_func (&t) != CPP_NAME)
+     BAD ("malformed '#pragma options', ignoring");
+ 
+   if (c_lex_func (&x) != CPP_EOF)
+     warning ("junk at end of '#pragma options'");
+ 
+   arg = IDENTIFIER_POINTER (t);
+   if (!strcmp (arg, "mac68k"))
+     push_field_alignment (16);
+   else if (!strcmp (arg, "power"))
+     push_field_alignment (0);
+   else if (!strcmp (arg, "reset"))
+     pop_field_alignment ();
+   else
+     warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
+ }
+ 
+ /* #pragma unused ([var {, var}*]) */
+ 
+ void
+ darwin_pragma_unused (pfile)
+      cpp_reader *pfile ATTRIBUTE_UNUSED;
+ {
+   tree decl, x;
+   int tok;
+ 
+   if (c_lex_func (&x) != CPP_OPEN_PAREN)
+     BAD ("missing '(' after '#pragma unused', ignoring");
+ 
+   while (1)
+     {
+       tok = c_lex_func (&decl);
+       if (tok == CPP_NAME && decl)
+ 	{
+ 	  tree local = IDENTIFIER_LOCAL_VALUE (decl);
+ 	  if (local && (TREE_CODE (local) == PARM_DECL
+ 			|| TREE_CODE (local) == VAR_DECL))
+ 	    TREE_USED (local) = 1;
+ 	  tok = c_lex_func (&x);
+ 	  if (tok != CPP_COMMA)
+ 	    break;
+ 	}
+     }
+ 
+   if (tok != CPP_CLOSE_PAREN)
+     BAD ("missing ')' after '#pragma unused', ignoring");
+ 
+   if (c_lex_func (&x) != CPP_EOF)
+     warning ("junk at end of '#pragma unused'");
  }
Index: config/darwin.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/darwin.h,v
retrieving revision 1.6
diff -c -3 -p -r1.6 darwin.h
*** darwin.h	2001/06/12 00:27:31	1.6
--- darwin.h	2001/06/26 02:29:04
*************** enum machopic_addr_class {
*** 780,782 ****
--- 780,790 ----
        }								\
    } while (0)
  
+ #define REGISTER_TARGET_PRAGMAS(PFILE)                          \
+   do {                                                          \
+     cpp_register_pragma (PFILE, 0, "mark", darwin_pragma_ignore);  \
+     cpp_register_pragma (PFILE, 0, "options", darwin_pragma_options);  \
+     cpp_register_pragma (PFILE, 0, "segment", darwin_pragma_ignore);  \
+     cpp_register_pragma (PFILE, 0, "unused", darwin_pragma_unused);  \
+     darwin_init_pragma (&c_lex);                                \
+   } while (0)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]