OSDN Git Service

(CPP_SPEC): Remove trailing semi-colon.
[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 "coretypes.h"
26 #include "tm.h"
27 #include "cpplib.h"
28 #include "tree.h"
29 #include "c-pragma.h"
30 #include "c-tree.h"
31 #include "toplev.h"
32 #include "tm_p.h"
33
34 /* Pragmas.  */
35
36 #define BAD(msgid) do { warning (msgid); return; } while (0)
37
38 /* Maintain a small stack of alignments.  This is similar to pragma
39    pack's stack, but simpler.  */
40
41 static void push_field_alignment PARAMS ((int));
42 static void pop_field_alignment PARAMS ((void));
43
44 typedef struct align_stack
45 {
46   int alignment;
47   struct align_stack * prev;
48 } align_stack;
49
50 static struct align_stack * field_align_stack = NULL;
51
52 static void
53 push_field_alignment (bit_alignment)
54      int bit_alignment;
55 {
56   align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
57
58   entry->alignment = maximum_field_alignment;
59   entry->prev = field_align_stack;
60   field_align_stack = entry;
61
62   maximum_field_alignment = bit_alignment;
63 }
64
65 static void
66 pop_field_alignment ()
67 {
68   if (field_align_stack)
69     {
70       align_stack *entry = field_align_stack;
71
72       maximum_field_alignment = entry->alignment;
73       field_align_stack = entry->prev;
74       free (entry);
75     }
76   else
77     error ("too many #pragma options align=reset");
78 }
79
80 /* Handlers for Darwin-specific pragmas.  */
81
82 void
83 darwin_pragma_ignore (pfile)
84      cpp_reader *pfile ATTRIBUTE_UNUSED;
85 {
86   /* Do nothing.  */
87 }
88
89 /* #pragma options align={mac68k|power|reset} */
90
91 void
92 darwin_pragma_options (pfile)
93      cpp_reader *pfile ATTRIBUTE_UNUSED;
94 {
95   const char *arg;
96   tree t, x;
97
98   if (c_lex (&t) != CPP_NAME)
99     BAD ("malformed '#pragma options', ignoring");
100   arg = IDENTIFIER_POINTER (t);
101   if (strcmp (arg, "align"))
102     BAD ("malformed '#pragma options', ignoring");
103   if (c_lex (&t) != CPP_EQ)
104     BAD ("malformed '#pragma options', ignoring");
105   if (c_lex (&t) != CPP_NAME)
106     BAD ("malformed '#pragma options', ignoring");
107
108   if (c_lex (&x) != CPP_EOF)
109     warning ("junk at end of '#pragma options'");
110
111   arg = IDENTIFIER_POINTER (t);
112   if (!strcmp (arg, "mac68k"))
113     push_field_alignment (16);
114   else if (!strcmp (arg, "power"))
115     push_field_alignment (0);
116   else if (!strcmp (arg, "reset"))
117     pop_field_alignment ();
118   else
119     warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
120 }
121
122 /* #pragma unused ([var {, var}*]) */
123
124 void
125 darwin_pragma_unused (pfile)
126      cpp_reader *pfile ATTRIBUTE_UNUSED;
127 {
128   tree decl, x;
129   int tok;
130
131   if (c_lex (&x) != CPP_OPEN_PAREN)
132     BAD ("missing '(' after '#pragma unused', ignoring");
133
134   while (1)
135     {
136       tok = c_lex (&decl);
137       if (tok == CPP_NAME && decl)
138         {
139           tree local = IDENTIFIER_LOCAL_VALUE (decl);
140           if (local && (TREE_CODE (local) == PARM_DECL
141                         || TREE_CODE (local) == VAR_DECL))
142             TREE_USED (local) = 1;
143           tok = c_lex (&x);
144           if (tok != CPP_COMMA)
145             break;
146         }
147     }
148
149   if (tok != CPP_CLOSE_PAREN)
150     BAD ("missing ')' after '#pragma unused', ignoring");
151
152   if (c_lex (&x) != CPP_EOF)
153     warning ("junk at end of '#pragma unused'");
154 }