At the suggestion of Richard Earnshaw I have changed GO_IF_LEGITIMATE_ADDRESS
[official-gcc.git] / gcc / c-pragma.c
blob480daca02987d3ce61e5a4b99cda8808cc384067
1 /* Handle #pragma, system V.4 style. Supports #pragma weak and #pragma pack.
2 Copyright (C) 1992, 1997 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 #include "config.h"
22 #include "system.h"
23 #include "tree.h"
24 #include "except.h"
25 #include "function.h"
26 #include "defaults.h"
27 #include "c-pragma.h"
28 #include "flags.h"
30 #ifdef HANDLE_SYSV_PRAGMA
32 /* When structure field packing is in effect, this variable is the
33 number of bits to use as the maximum alignment. When packing is not
34 in effect, this is zero. */
36 extern int maximum_field_alignment;
38 /* File used for outputting assembler code. */
39 extern FILE *asm_out_file;
41 /* Handle one token of a pragma directive. TOKEN is the
42 current token, and STRING is its printable form. */
44 void
45 handle_pragma_token (string, token)
46 char *string;
47 tree token;
49 static enum pragma_state state = ps_start, type;
50 static char *name;
51 static char *value;
52 static int align;
54 if (string == 0)
56 if (type == ps_pack)
58 if (state == ps_right)
59 maximum_field_alignment = align * 8;
60 else
61 warning ("malformed `#pragma pack'");
63 else if (type == ps_weak)
65 #ifdef HANDLE_PRAGMA_WEAK
66 if (HANDLE_PRAGMA_WEAK)
67 handle_pragma_weak (state, name, value);
69 #endif /* HANDLE_PRAGMA_WEAK */
72 type = state = ps_start;
73 return;
76 switch (state)
78 case ps_start:
79 if (token && TREE_CODE (token) == IDENTIFIER_NODE)
81 if (strcmp (IDENTIFIER_POINTER (token), "pack") == 0)
82 type = state = ps_pack;
83 else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0)
84 type = state = ps_weak;
85 else
87 type = state = ps_done;
89 /* Issue a warning message if we have been asked to do so.
90 Ignoring unknown pragmas in system header file unless
91 an explcit -Wunknown-pragmas has been given. */
92 if (warn_unknown_pragmas > 1
93 || (warn_unknown_pragmas && ! in_system_header))
94 warning ("ignoring pragma: %s", string);
97 else
98 type = state = ps_done;
99 break;
101 case ps_weak:
102 if (token && TREE_CODE (token) == IDENTIFIER_NODE)
104 name = IDENTIFIER_POINTER (token);
105 state = ps_name;
107 else
108 state = ps_bad;
109 break;
111 case ps_name:
112 state = (strcmp (string, "=") ? ps_bad : ps_equals);
113 break;
115 case ps_equals:
116 if (token && TREE_CODE (token) == IDENTIFIER_NODE)
118 value = IDENTIFIER_POINTER (token);
119 state = ps_value;
121 else
122 state = ps_bad;
123 break;
125 case ps_value:
126 state = ps_bad;
127 break;
129 case ps_pack:
130 if (strcmp (string, "(") == 0)
131 state = ps_left;
132 else
133 state = ps_bad;
134 break;
136 case ps_left:
137 if (token && TREE_CODE (token) == INTEGER_CST
138 && TREE_INT_CST_HIGH (token) == 0)
139 switch (TREE_INT_CST_LOW (token))
141 case 1:
142 case 2:
143 case 4:
144 align = TREE_INT_CST_LOW (token);
145 state = ps_align;
146 break;
148 default:
149 state = ps_bad;
151 else if (! token && strcmp (string, ")") == 0)
153 align = 0;
154 state = ps_right;
156 else
157 state = ps_bad;
158 break;
160 case ps_align:
161 if (strcmp (string, ")") == 0)
162 state = ps_right;
163 else
164 state = ps_bad;
165 break;
167 case ps_right:
168 state = ps_bad;
169 break;
171 case ps_bad:
172 case ps_done:
173 break;
175 default:
176 abort ();
179 #endif /* HANDLE_SYSV_PRAGMA */