1 /* cond.c - conditional assembly pseudo-ops, and .include
2 Copyright 1990, 1991, 1992, 1993, 1995, 1997, 1998, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
27 /* This is allocated to grow and shrink as .ifdef/.endif pairs are
29 struct obstack cond_obstack
;
36 /* We push one of these structures for each .if, and pop it at the
39 struct conditional_frame
{
40 /* The source file & line number of the "if". */
41 struct file_line if_file_line
;
42 /* The source file & line of the "else". */
43 struct file_line else_file_line
;
44 /* The previous conditional. */
45 struct conditional_frame
*previous_cframe
;
46 /* Have we seen an else yet? */
48 /* Whether we are currently ignoring input. */
50 /* Whether a conditional at a higher level is ignoring input.
51 Set also when a branch of an "if .. elseif .." tree has matched
52 to prevent further matches. */
54 /* Macro nesting level at which this conditional was created. */
58 static void initialize_cframe
PARAMS ((struct conditional_frame
*cframe
));
59 static char *get_mri_string
PARAMS ((int, int *));
61 static struct conditional_frame
*current_cframe
= NULL
;
67 /* Points to name of symbol. */
69 /* Points to symbol. */
70 register symbolS
*symbolP
;
71 struct conditional_frame cframe
;
73 /* Leading whitespace is part of operand. */
75 name
= input_line_pointer
;
77 if (!is_name_beginner (*name
))
79 as_bad (_("invalid identifier for \".ifdef\""));
80 obstack_1grow (&cond_obstack
, 0);
81 ignore_rest_of_line ();
87 c
= get_symbol_end ();
88 symbolP
= symbol_find (name
);
89 *input_line_pointer
= c
;
91 initialize_cframe (&cframe
);
92 cframe
.ignoring
= cframe
.dead_tree
|| !((symbolP
!= 0) ^ arg
);
93 current_cframe
= ((struct conditional_frame
*)
94 obstack_copy (&cond_obstack
, &cframe
,
97 if (LISTING_SKIP_COND ()
99 && (cframe
.previous_cframe
== NULL
100 || ! cframe
.previous_cframe
->ignoring
))
103 demand_empty_rest_of_line ();
104 } /* if a valid identifyer name */
112 struct conditional_frame cframe
;
118 stop
= mri_comment_field (&stopc
);
120 /* Leading whitespace is part of operand. */
123 if (current_cframe
!= NULL
&& current_cframe
->ignoring
)
125 operand
.X_add_number
= 0;
126 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
127 ++input_line_pointer
;
131 expression (&operand
);
132 if (operand
.X_op
!= O_constant
)
133 as_bad (_("non-constant expression in \".if\" statement"));
136 switch ((operatorT
) arg
)
138 case O_eq
: t
= operand
.X_add_number
== 0; break;
139 case O_ne
: t
= operand
.X_add_number
!= 0; break;
140 case O_lt
: t
= operand
.X_add_number
< 0; break;
141 case O_le
: t
= operand
.X_add_number
<= 0; break;
142 case O_ge
: t
= operand
.X_add_number
>= 0; break;
143 case O_gt
: t
= operand
.X_add_number
> 0; break;
149 /* If the above error is signaled, this will dispatch
150 using an undefined result. No big deal. */
151 initialize_cframe (&cframe
);
152 cframe
.ignoring
= cframe
.dead_tree
|| ! t
;
153 current_cframe
= ((struct conditional_frame
*)
154 obstack_copy (&cond_obstack
, &cframe
, sizeof (cframe
)));
156 if (LISTING_SKIP_COND ()
158 && (cframe
.previous_cframe
== NULL
159 || ! cframe
.previous_cframe
->ignoring
))
163 mri_comment_end (stop
, stopc
);
165 demand_empty_rest_of_line ();
168 /* Get a string for the MRI IFC or IFNC pseudo-ops. */
171 get_mri_string (terminator
, len
)
179 s
= ret
= input_line_pointer
;
180 if (*input_line_pointer
== '\'')
183 ++input_line_pointer
;
184 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
186 *s
++ = *input_line_pointer
++;
189 if (*input_line_pointer
!= '\'')
191 ++input_line_pointer
;
198 while (*input_line_pointer
!= terminator
199 && ! is_end_of_line
[(unsigned char) *input_line_pointer
])
200 ++input_line_pointer
;
201 s
= input_line_pointer
;
202 while (s
> ret
&& (s
[-1] == ' ' || s
[-1] == '\t'))
210 /* The MRI IFC and IFNC pseudo-ops. */
221 struct conditional_frame cframe
;
224 stop
= mri_comment_field (&stopc
);
226 s1
= get_mri_string (',', &len1
);
228 if (*input_line_pointer
!= ',')
229 as_bad (_("bad format for ifc or ifnc"));
231 ++input_line_pointer
;
233 s2
= get_mri_string (';', &len2
);
235 res
= len1
== len2
&& strncmp (s1
, s2
, len1
) == 0;
237 initialize_cframe (&cframe
);
238 cframe
.ignoring
= cframe
.dead_tree
|| ! (res
^ arg
);
239 current_cframe
= ((struct conditional_frame
*)
240 obstack_copy (&cond_obstack
, &cframe
, sizeof (cframe
)));
242 if (LISTING_SKIP_COND ()
244 && (cframe
.previous_cframe
== NULL
245 || ! cframe
.previous_cframe
->ignoring
))
249 mri_comment_end (stop
, stopc
);
251 demand_empty_rest_of_line ();
261 if (current_cframe
== NULL
)
263 as_bad (_("\".elseif\" without matching \".if\" - ignored"));
265 else if (current_cframe
->else_seen
)
267 as_bad (_("\".elseif\" after \".else\" - ignored"));
268 as_bad_where (current_cframe
->else_file_line
.file
,
269 current_cframe
->else_file_line
.line
,
270 _("here is the previous \"else\""));
271 as_bad_where (current_cframe
->if_file_line
.file
,
272 current_cframe
->if_file_line
.line
,
273 _("here is the previous \"if\""));
277 as_where (¤t_cframe
->else_file_line
.file
,
278 ¤t_cframe
->else_file_line
.line
);
280 if (!current_cframe
->dead_tree
)
282 current_cframe
->dead_tree
= !current_cframe
->ignoring
;
283 current_cframe
->ignoring
= !current_cframe
->ignoring
;
284 if (LISTING_SKIP_COND ())
286 if (! current_cframe
->ignoring
)
291 } /* if not a dead tree */
292 } /* if error else do it */
294 if (current_cframe
== NULL
|| current_cframe
->ignoring
)
296 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
297 ++input_line_pointer
;
301 /* Leading whitespace is part of operand. */
304 expression (&operand
);
305 if (operand
.X_op
!= O_constant
)
306 as_bad (_("non-constant expression in \".elseif\" statement"));
308 switch ((operatorT
) arg
)
310 case O_eq
: t
= operand
.X_add_number
== 0; break;
311 case O_ne
: t
= operand
.X_add_number
!= 0; break;
312 case O_lt
: t
= operand
.X_add_number
< 0; break;
313 case O_le
: t
= operand
.X_add_number
<= 0; break;
314 case O_ge
: t
= operand
.X_add_number
>= 0; break;
315 case O_gt
: t
= operand
.X_add_number
> 0; break;
321 current_cframe
->ignoring
= current_cframe
->dead_tree
|| ! t
;
323 if (LISTING_SKIP_COND ()
324 && current_cframe
->ignoring
325 && (current_cframe
->previous_cframe
== NULL
326 || ! current_cframe
->previous_cframe
->ignoring
))
329 demand_empty_rest_of_line ();
334 int arg ATTRIBUTE_UNUSED
;
336 struct conditional_frame
*hold
;
338 if (current_cframe
== NULL
)
340 as_bad (_("\".endif\" without \".if\""));
344 if (LISTING_SKIP_COND ()
345 && current_cframe
->ignoring
346 && (current_cframe
->previous_cframe
== NULL
347 || ! current_cframe
->previous_cframe
->ignoring
))
350 hold
= current_cframe
;
351 current_cframe
= current_cframe
->previous_cframe
;
352 obstack_free (&cond_obstack
, hold
);
353 } /* if one pop too many */
357 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
358 ++input_line_pointer
;
361 demand_empty_rest_of_line ();
366 int arg ATTRIBUTE_UNUSED
;
368 if (current_cframe
== NULL
)
370 as_bad (_(".else without matching .if - ignored"));
373 else if (current_cframe
->else_seen
)
375 as_bad (_("duplicate \"else\" - ignored"));
376 as_bad_where (current_cframe
->else_file_line
.file
,
377 current_cframe
->else_file_line
.line
,
378 _("here is the previous \"else\""));
379 as_bad_where (current_cframe
->if_file_line
.file
,
380 current_cframe
->if_file_line
.line
,
381 _("here is the previous \"if\""));
385 as_where (¤t_cframe
->else_file_line
.file
,
386 ¤t_cframe
->else_file_line
.line
);
388 if (!current_cframe
->dead_tree
)
390 current_cframe
->ignoring
= !current_cframe
->ignoring
;
391 if (LISTING_SKIP_COND ())
393 if (! current_cframe
->ignoring
)
398 } /* if not a dead tree */
400 current_cframe
->else_seen
= 1;
401 } /* if error else do it */
405 while (! is_end_of_line
[(unsigned char) *input_line_pointer
])
406 ++input_line_pointer
;
409 demand_empty_rest_of_line ();
419 struct conditional_frame cframe
;
421 s1
= demand_copy_C_string (&len1
);
424 if (*input_line_pointer
!= ',')
426 as_bad (_(".ifeqs syntax error"));
427 ignore_rest_of_line ();
431 ++input_line_pointer
;
433 s2
= demand_copy_C_string (&len2
);
435 res
= len1
== len2
&& strncmp (s1
, s2
, len1
) == 0;
437 initialize_cframe (&cframe
);
438 cframe
.ignoring
= cframe
.dead_tree
|| ! (res
^ arg
);
439 current_cframe
= ((struct conditional_frame
*)
440 obstack_copy (&cond_obstack
, &cframe
, sizeof (cframe
)));
442 if (LISTING_SKIP_COND ()
444 && (cframe
.previous_cframe
== NULL
445 || ! cframe
.previous_cframe
->ignoring
))
448 demand_empty_rest_of_line ();
456 s
= input_line_pointer
;
458 if (NO_PSEUDO_DOT
|| flag_m68k_mri
)
466 return (current_cframe
!= NULL
) && (current_cframe
->ignoring
);
469 /* We cannot ignore certain pseudo ops. */
472 && (!strncasecmp (s
, "if", 2)
473 || !strncasecmp (s
, "ifdef", 5)
474 || !strncasecmp (s
, "ifndef", 6)))
477 && (!strncasecmp (s
, "else", 4)
478 || !strncasecmp (s
, "endif", 5)
479 || !strncasecmp (s
, "endc", 4))))
482 return (current_cframe
!= NULL
) && (current_cframe
->ignoring
);
486 initialize_cframe (cframe
)
487 struct conditional_frame
*cframe
;
489 memset (cframe
, 0, sizeof (*cframe
));
490 as_where (&cframe
->if_file_line
.file
,
491 &cframe
->if_file_line
.line
);
492 cframe
->previous_cframe
= current_cframe
;
493 cframe
->dead_tree
= current_cframe
!= NULL
&& current_cframe
->ignoring
;
494 cframe
->macro_nest
= macro_nest
;
497 /* Give an error if a conditional is unterminated inside a macro or
498 the assembly as a whole. If NEST is non negative, we are being
499 called because of the end of a macro expansion. If NEST is
500 negative, we are being called at the of the input files. */
503 cond_finish_check (nest
)
506 if (current_cframe
!= NULL
&& current_cframe
->macro_nest
>= nest
)
509 as_bad (_("end of macro inside conditional"));
511 as_bad (_("end of file inside conditional"));
512 as_bad_where (current_cframe
->if_file_line
.file
,
513 current_cframe
->if_file_line
.line
,
514 _("here is the start of the unterminated conditional"));
515 if (current_cframe
->else_seen
)
516 as_bad_where (current_cframe
->else_file_line
.file
,
517 current_cframe
->else_file_line
.line
,
518 _("here is the \"else\" of the unterminated conditional"));
522 /* This function is called when we exit out of a macro. We assume
523 that any conditionals which began within the macro are correctly
524 nested, and just pop them off the stack. */
527 cond_exit_macro (nest
)
530 while (current_cframe
!= NULL
&& current_cframe
->macro_nest
>= nest
)
532 struct conditional_frame
*hold
;
534 hold
= current_cframe
;
535 current_cframe
= current_cframe
->previous_cframe
;
536 obstack_free (&cond_obstack
, hold
);
This page took 0.109919 seconds and 5 git commands to generate.