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