OSDN Git Service

bytecode
[pf3gnuchains/gcc-fork.git] / gcc / c-pragma.c
1 /* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
2    Copyright (C) 1992 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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.
10
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.
15
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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20 #include <stdio.h>
21 #include "config.h"
22 #include "tree.h"
23 #include "function.h"
24
25 #ifdef HANDLE_SYSV_PRAGMA
26
27 /* Support #pragma weak by default if WEAK_ASM_OP is defined.  */
28 #if !defined (HANDLE_PRAGMA_WEAK) && defined (WEAK_ASM_OP) && defined (SET_ASM_OP)
29 #define HANDLE_PRAGMA_WEAK 1
30 #endif
31
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. */
35
36 extern int maximum_field_alignment;
37
38 /* File used for outputting assembler code.  */
39 extern FILE *asm_out_file;
40
41 /* Handle one token of a pragma directive.  TOKEN is the
42    current token, and STRING is its printable form.  */
43
44 void
45 handle_pragma_token (string, token)
46      char *string;
47      tree token;
48 {
49   static enum pragma_state state = ps_start, type;
50   static char *name;
51   static char *value;
52   static int align;
53
54   if (string == 0)
55     {
56       if (type == ps_pack)
57         {
58           if (state == ps_right)
59             maximum_field_alignment = align * 8;
60           else
61             warning ("malformed `#pragma pack'");
62         }
63       else if (type == ps_weak)
64         {
65 #ifdef HANDLE_PRAGMA_WEAK
66           if (HANDLE_PRAGMA_WEAK)
67             handle_pragma_weak (state, asm_out_file, name, value);
68
69 #endif /* HANDLE_PRAMA_WEAK */
70         }
71
72       type = state = ps_start;
73       return;
74     }
75
76   switch (state)
77     {
78     case ps_start:
79       if (token && TREE_CODE (token) == IDENTIFIER_NODE)
80         {
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
86             type = state = ps_done;
87         }
88       else
89         type = state = ps_done;
90       break;
91
92     case ps_weak:
93       if (token && TREE_CODE (token) == IDENTIFIER_NODE)
94         {
95           name = IDENTIFIER_POINTER (token);
96           state = ps_name;
97         }
98       else
99         state = ps_bad;
100       break;
101
102     case ps_name:
103       state = (strcmp (string, "=") ? ps_bad : ps_equals);
104       break;
105
106     case ps_equals:
107       if (token && TREE_CODE (token) == IDENTIFIER_NODE)
108         {
109           value = IDENTIFIER_POINTER (token);
110           state = ps_value;
111         }
112       else
113         state = ps_bad;
114       break;
115
116     case ps_value:
117       state = ps_bad;
118       break;
119
120     case ps_pack:
121       if (strcmp (string, "(") == 0)
122         state = ps_left;
123       else
124         state = ps_bad;
125       break;
126
127     case ps_left:
128       if (token && TREE_CODE (token) == INTEGER_CST
129           && TREE_INT_CST_HIGH (token) == 0)
130         switch (TREE_INT_CST_LOW (token))
131           {
132           case 1:
133           case 2:
134           case 4:
135             align = TREE_INT_CST_LOW (token);
136             state = ps_align;
137             break;
138
139           default:
140             state = ps_bad;
141           }
142       else if (! token && strcmp (string, ")") == 0)
143         {
144           align = 0;
145           state = ps_right;
146         }
147       else
148         state = ps_bad;
149       break;
150
151     case ps_align:
152       if (strcmp (string, ")") == 0)
153         state = ps_right;
154       else
155         state = ps_bad;
156       break;
157
158     case ps_right:
159       state = ps_bad;
160       break;
161
162     case ps_bad:
163     case ps_done:
164       break;
165
166     default:
167       abort ();
168     }
169 }
170 #endif /* HANDLE_SYSV_PRAGMA */