OSDN Git Service

2002-01-16 H.J. Lu <hjl@gnu.org>
[pf3gnuchains/gcc-fork.git] / gcc / config / darwin-c.c
1 /* Darwin support needed only by C/C++ frontends.
2    Copyright (C) 2001
3    Free Software Foundation, Inc.
4    Contributed by Apple Computer Inc.
5
6 This file is part of GNU CC.
7
8 GNU CC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
11 any later version.
12
13 GNU CC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU CC; see the file COPYING.  If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 #include "config.h"
24 #include "system.h"
25 #include "cpplib.h"
26 #include "tree.h"
27 #include "c-pragma.h"
28 #include "c-lex.h"
29 #include "c-tree.h"
30 #include "toplev.h"
31 #include "tm_p.h"
32
33 /* Pragmas.  */
34
35 #define BAD(msgid) do { warning (msgid); return; } while (0)
36
37 /* Maintain a small stack of alignments.  This is similar to pragma
38    pack's stack, but simpler.  */
39
40 static void push_field_alignment PARAMS ((int));
41 static void pop_field_alignment PARAMS ((void));
42
43 typedef struct align_stack
44 {
45   int alignment;
46   struct align_stack * prev;
47 } align_stack;
48
49 static struct align_stack * field_align_stack = NULL;
50
51 static void
52 push_field_alignment (bit_alignment)
53      int bit_alignment;
54 {
55   align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
56
57   entry->alignment = maximum_field_alignment;
58   entry->prev = field_align_stack;
59   field_align_stack = entry;
60
61   maximum_field_alignment = bit_alignment;
62 }
63
64 static void
65 pop_field_alignment ()
66 {
67   if (field_align_stack)
68     {
69       align_stack *entry = field_align_stack;
70
71       maximum_field_alignment = entry->alignment;
72       field_align_stack = entry->prev;
73       free (entry);
74     }
75   else
76     error ("too many #pragma options align=reset");
77 }
78
79 /* Handlers for Darwin-specific pragmas.  */
80
81 void
82 darwin_pragma_ignore (pfile)
83      cpp_reader *pfile ATTRIBUTE_UNUSED;
84 {
85   /* Do nothing.  */
86 }
87
88 /* #pragma options align={mac68k|power|reset} */
89
90 void
91 darwin_pragma_options (pfile)
92      cpp_reader *pfile ATTRIBUTE_UNUSED;
93 {
94   char *arg;
95   tree t, x;
96
97   if (c_lex (&t) != CPP_NAME)
98     BAD ("malformed '#pragma options', ignoring");
99   arg = IDENTIFIER_POINTER (t);
100   if (strcmp (arg, "align"))
101     BAD ("malformed '#pragma options', ignoring");
102   if (c_lex (&t) != CPP_EQ)
103     BAD ("malformed '#pragma options', ignoring");
104   if (c_lex (&t) != CPP_NAME)
105     BAD ("malformed '#pragma options', ignoring");
106
107   if (c_lex (&x) != CPP_EOF)
108     warning ("junk at end of '#pragma options'");
109
110   arg = IDENTIFIER_POINTER (t);
111   if (!strcmp (arg, "mac68k"))
112     push_field_alignment (16);
113   else if (!strcmp (arg, "power"))
114     push_field_alignment (0);
115   else if (!strcmp (arg, "reset"))
116     pop_field_alignment ();
117   else
118     warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
119 }
120
121 /* #pragma unused ([var {, var}*]) */
122
123 void
124 darwin_pragma_unused (pfile)
125      cpp_reader *pfile ATTRIBUTE_UNUSED;
126 {
127   tree decl, x;
128   int tok;
129
130   if (c_lex (&x) != CPP_OPEN_PAREN)
131     BAD ("missing '(' after '#pragma unused', ignoring");
132
133   while (1)
134     {
135       tok = c_lex (&decl);
136       if (tok == CPP_NAME && decl)
137         {
138           tree local = IDENTIFIER_LOCAL_VALUE (decl);
139           if (local && (TREE_CODE (local) == PARM_DECL
140                         || TREE_CODE (local) == VAR_DECL))
141             TREE_USED (local) = 1;
142           tok = c_lex (&x);
143           if (tok != CPP_COMMA)
144             break;
145         }
146     }
147
148   if (tok != CPP_CLOSE_PAREN)
149     BAD ("missing ')' after '#pragma unused', ignoring");
150
151   if (c_lex (&x) != CPP_EOF)
152     warning ("junk at end of '#pragma unused'");
153 }