|
|
1.1 root 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
1.1.1.4 ! root 18: the Free Software Foundation, 59 Temple Place - Suite 330,
! 19: Boston, MA 02111-1307, USA. */
1.1 root 20:
21: #include <stdio.h>
22: #include "config.h"
23: #include "tree.h"
1.1.1.2 root 24: #include "function.h"
1.1.1.3 root 25: #include "defaults.h"
1.1.1.4 ! root 26: #include "c-pragma.h"
1.1 root 27:
28: #ifdef HANDLE_SYSV_PRAGMA
29:
30: /* When structure field packing is in effect, this variable is the
31: number of bits to use as the maximum alignment. When packing is not
32: in effect, this is zero. */
33:
34: extern int maximum_field_alignment;
35:
36: /* File used for outputting assembler code. */
37: extern FILE *asm_out_file;
38:
39: /* Handle one token of a pragma directive. TOKEN is the
40: current token, and STRING is its printable form. */
41:
42: void
43: handle_pragma_token (string, token)
44: char *string;
45: tree token;
46: {
1.1.1.2 root 47: static enum pragma_state state = ps_start, type;
1.1 root 48: static char *name;
49: static char *value;
50: static int align;
51:
52: if (string == 0)
53: {
54: if (type == ps_pack)
55: {
56: if (state == ps_right)
57: maximum_field_alignment = align * 8;
58: else
59: warning ("malformed `#pragma pack'");
60: }
61: else if (type == ps_weak)
62: {
63: #ifdef HANDLE_PRAGMA_WEAK
64: if (HANDLE_PRAGMA_WEAK)
1.1.1.4 ! root 65: handle_pragma_weak (state, name, value);
1.1.1.2 root 66:
1.1 root 67: #endif /* HANDLE_PRAMA_WEAK */
68: }
69:
70: type = state = ps_start;
71: return;
72: }
73:
74: switch (state)
75: {
76: case ps_start:
77: if (token && TREE_CODE (token) == IDENTIFIER_NODE)
78: {
79: if (strcmp (IDENTIFIER_POINTER (token), "pack") == 0)
80: type = state = ps_pack;
81: else if (strcmp (IDENTIFIER_POINTER (token), "weak") == 0)
82: type = state = ps_weak;
83: else
84: type = state = ps_done;
85: }
86: else
87: type = state = ps_done;
88: break;
89:
90: case ps_weak:
91: if (token && TREE_CODE (token) == IDENTIFIER_NODE)
92: {
93: name = IDENTIFIER_POINTER (token);
94: state = ps_name;
95: }
96: else
97: state = ps_bad;
98: break;
99:
100: case ps_name:
101: state = (strcmp (string, "=") ? ps_bad : ps_equals);
102: break;
103:
104: case ps_equals:
105: if (token && TREE_CODE (token) == IDENTIFIER_NODE)
106: {
107: value = IDENTIFIER_POINTER (token);
108: state = ps_value;
109: }
110: else
111: state = ps_bad;
112: break;
113:
114: case ps_value:
115: state = ps_bad;
116: break;
117:
118: case ps_pack:
119: if (strcmp (string, "(") == 0)
120: state = ps_left;
121: else
122: state = ps_bad;
123: break;
124:
125: case ps_left:
126: if (token && TREE_CODE (token) == INTEGER_CST
127: && TREE_INT_CST_HIGH (token) == 0)
128: switch (TREE_INT_CST_LOW (token))
129: {
130: case 1:
131: case 2:
132: case 4:
133: align = TREE_INT_CST_LOW (token);
134: state = ps_align;
135: break;
136:
137: default:
138: state = ps_bad;
139: }
140: else if (! token && strcmp (string, ")") == 0)
141: {
142: align = 0;
143: state = ps_right;
144: }
145: else
146: state = ps_bad;
147: break;
148:
149: case ps_align:
150: if (strcmp (string, ")") == 0)
151: state = ps_right;
152: else
153: state = ps_bad;
154: break;
155:
156: case ps_right:
157: state = ps_bad;
158: break;
159:
160: case ps_bad:
161: case ps_done:
162: break;
163:
164: default:
165: abort ();
166: }
167: }
168: #endif /* HANDLE_SYSV_PRAGMA */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.