]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/cond.c
1 /* cond.c - conditional assembly pseudo-ops, and .include
2 Copyright (C) 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS 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)
11 GAS 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 GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
24 /* This is allocated to grow and shrink as .ifdef/.endif pairs are scanned. */
25 struct obstack cond_obstack
;
33 /* This is what we push and pop. */
34 struct conditional_frame
36 struct file_line if_file_line
; /* the source file & line number of the "if" */
37 struct file_line else_file_line
; /* the source file & line of the "else" */
38 struct conditional_frame
*previous_cframe
;
39 int else_seen
; /* have we seen an else yet? */
40 int ignoring
; /* if we are currently ignoring input. */
41 int dead_tree
; /* if a conditional at a higher level is ignoring input. */
42 }; /* conditional_frame */
44 static void initialize_cframe
PARAMS ((struct conditional_frame
*cframe
));
45 static char *get_mri_string
PARAMS ((int, int *));
47 static struct conditional_frame
*current_cframe
= NULL
;
53 register char *name
; /* points to name of symbol */
54 register struct symbol
*symbolP
; /* Points to symbol */
55 struct conditional_frame cframe
;
57 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
58 name
= input_line_pointer
;
60 if (!is_name_beginner (*name
))
62 as_bad ("invalid identifier for \".ifdef\"");
63 obstack_1grow (&cond_obstack
, 0);
69 symbolP
= symbol_find (name
);
71 initialize_cframe (&cframe
);
72 cframe
.ignoring
= cframe
.dead_tree
|| !((symbolP
!= 0) ^ arg
);
73 current_cframe
= (struct conditional_frame
*) obstack_copy (&cond_obstack
, &cframe
, sizeof (cframe
));
74 } /* if a valid identifyer name */
84 struct conditional_frame cframe
;
87 SKIP_WHITESPACE (); /* Leading whitespace is part of operand. */
88 expression (&operand
);
90 if (operand
.X_op
!= O_constant
)
91 as_bad ("non-constant expression in \".if\" statement");
93 switch ((operatorT
) arg
)
95 case O_eq
: t
= operand
.X_add_number
== 0; break;
96 case O_ne
: t
= operand
.X_add_number
!= 0; break;
97 case O_lt
: t
= operand
.X_add_number
< 0; break;
98 case O_le
: t
= operand
.X_add_number
<= 0; break;
99 case O_ge
: t
= operand
.X_add_number
>= 0; break;
100 case O_gt
: t
= operand
.X_add_number
> 0; break;
105 /* If the above error is signaled, this will dispatch
106 using an undefined result. No big deal. */
107 initialize_cframe (&cframe
);
108 cframe
.ignoring
= cframe
.dead_tree
|| ! t
;
109 current_cframe
= ((struct conditional_frame
*)
110 obstack_copy (&cond_obstack
, &cframe
, sizeof (cframe
)));
114 /* Get a string for the MRI IFC or IFNC pseudo-ops. */
117 get_mri_string (terminator
, len
)
125 s
= ret
= input_line_pointer
;
126 if (*input_line_pointer
== '\'')
129 ++input_line_pointer
;
130 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
132 *s
++ = *input_line_pointer
++;
135 if (*input_line_pointer
!= '\'')
137 ++input_line_pointer
;
144 while (*input_line_pointer
!= terminator
145 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
146 ++input_line_pointer
;
147 s
= input_line_pointer
;
148 while (s
> ret
&& (s
[-1] == ' ' || s
[-1] == '\t'))
156 /* The MRI IFC and IFNC pseudo-ops. */
165 struct conditional_frame cframe
;
167 s1
= get_mri_string (',', &len1
);
169 if (*input_line_pointer
!= ',')
170 as_bad ("bad format for ifc or ifnc");
172 ++input_line_pointer
;
174 s2
= get_mri_string (';', &len2
);
176 res
= len1
== len2
&& strncmp (s1
, s2
, len1
) == 0;
178 initialize_cframe (&cframe
);
179 cframe
.ignoring
= cframe
.dead_tree
|| ! (res
^ arg
);
180 current_cframe
= ((struct conditional_frame
*)
181 obstack_copy (&cond_obstack
, &cframe
, sizeof (cframe
)));
188 struct conditional_frame
*hold
;
190 if (current_cframe
== NULL
)
192 as_bad ("\".endif\" without \".if\"");
196 hold
= current_cframe
;
197 current_cframe
= current_cframe
->previous_cframe
;
198 obstack_free (&cond_obstack
, hold
);
199 } /* if one pop too many */
208 if (current_cframe
== NULL
)
210 as_bad (".else without matching .if - ignored");
213 else if (current_cframe
->else_seen
)
215 as_bad ("duplicate \"else\" - ignored");
216 as_bad_where (current_cframe
->else_file_line
.file
,
217 current_cframe
->else_file_line
.line
,
218 "here is the previous \"else\"");
219 as_bad_where (current_cframe
->if_file_line
.file
,
220 current_cframe
->if_file_line
.line
,
221 "here is the previous \"if\"");
225 as_where (¤t_cframe
->else_file_line
.file
,
226 ¤t_cframe
->else_file_line
.line
);
228 if (!current_cframe
->dead_tree
)
230 current_cframe
->ignoring
= !current_cframe
->ignoring
;
231 } /* if not a dead tree */
233 current_cframe
->else_seen
= 1;
234 } /* if error else do it */
243 as_bad ("ifeqs not implemented.");
253 s
= input_line_pointer
;
267 return (current_cframe
!= NULL
) && (current_cframe
->ignoring
);
270 /* We cannot ignore certain pseudo ops. */
272 && (!strncmp (s
, "if", 2)
273 || !strncmp (s
, "ifdef", 5)
274 || !strncmp (s
, "ifndef", 6)))
276 && (!strncmp (s
, "else", 4)
277 || !strncmp (s
, "endif", 5)
278 || !strncmp (s
, "endc", 4))))
281 return (current_cframe
!= NULL
) && (current_cframe
->ignoring
);
282 } /* ignore_input() */
285 initialize_cframe (cframe
)
286 struct conditional_frame
*cframe
;
288 memset (cframe
, 0, sizeof (*cframe
));
289 as_where (&cframe
->if_file_line
.file
,
290 &cframe
->if_file_line
.line
);
291 cframe
->previous_cframe
= current_cframe
;
292 cframe
->dead_tree
= current_cframe
!= NULL
&& current_cframe
->ignoring
;
295 } /* initialize_cframe() */