1 /* cond.c - conditional assembly pseudo-ops, and .include
2 Copyright (C) 1990, 1991 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, 675 Mass Ave, Cambridge, MA 02139, USA. */
24 /* This is allocated to grow and shrink as .ifdef/.endif pairs are scanned. */
25 struct obstack cond_obstack
;
34 /* This is what we push and pop. */
35 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 */
46 static void get_file_line(struct file_line
*into
);
47 static void initialize_cframe(struct conditional_frame
*cframe
);
48 static void set_file_line(struct file_line
*from
);
52 static void get_file_line();
53 static void initialize_cframe();
54 static void set_file_line();
58 static struct conditional_frame
*current_cframe
= NULL
;
63 register char *name
; /* points to name of symbol */
64 register struct symbol
*symbolP
; /* Points to symbol */
65 struct conditional_frame cframe
;
67 SKIP_WHITESPACE(); /* Leading whitespace is part of operand. */
68 name
= input_line_pointer
;
70 if (!is_name_beginner(*name
)) {
71 as_bad("invalid identifier for \".ifdef\"");
72 obstack_1grow(&cond_obstack
, 0);
76 symbolP
= symbol_find(name
);
78 initialize_cframe(&cframe
);
79 cframe
.ignoring
= cframe
.dead_tree
&& !((symbolP
!= 0) ^ arg
);
80 current_cframe
= (struct conditional_frame
*) obstack_copy(&cond_obstack
, &cframe
, sizeof(cframe
));
81 } /* if a valid identifyer name */
90 struct conditional_frame cframe
;
92 SKIP_WHITESPACE(); /* Leading whitespace is part of operand. */
95 if (operand
.X_add_symbol
!= NULL
96 || operand
.X_subtract_symbol
!= NULL
) {
97 as_bad("non-constant expression in \".if\" statement");
100 /* If the above error is signaled, this will dispatch
101 using an undefined result. No big deal. */
102 initialize_cframe(&cframe
);
103 cframe
.ignoring
= cframe
.dead_tree
|| !((operand
.X_add_number
!= 0) ^ arg
);
104 current_cframe
= (struct conditional_frame
*) obstack_copy(&cond_obstack
, &cframe
, sizeof(cframe
));
111 struct conditional_frame
*hold
;
113 if (current_cframe
== NULL
) {
114 as_bad("\".endif\" without \".if\"");
116 hold
= current_cframe
;
117 current_cframe
= current_cframe
->previous_cframe
;
118 obstack_free(&cond_obstack
, hold
);
119 } /* if one pop too many */
127 if (current_cframe
== NULL
) {
128 as_bad(".else without matching .if - ignored");
130 } else if (current_cframe
->else_seen
) {
131 struct file_line hold
;
132 as_bad("duplicate \"else\" - ignored");
134 get_file_line(&hold
);
135 set_file_line(¤t_cframe
->else_file_line
);
136 as_bad("here is the previous \"else\".");
137 set_file_line(¤t_cframe
->if_file_line
);
138 as_bad("here is the matching \".if\".");
139 set_file_line(&hold
);
142 get_file_line(¤t_cframe
->else_file_line
);
144 if (!current_cframe
->dead_tree
) {
145 current_cframe
->ignoring
= !current_cframe
->ignoring
;
146 } /* if not a dead tree */
148 current_cframe
->else_seen
= 1;
149 } /* if error else do it */
157 as_bad("ifeqs not implemented.");
169 char *ptr
= obstack_next_free (&cond_obstack
);
171 /* We cannot ignore certain pseudo ops. */
172 if (input_line_pointer
[-1] == '.'
173 && ((input_line_pointer
[0] == 'i'
174 && (!strncmp (input_line_pointer
, "if", 2)
175 || !strncmp (input_line_pointer
, "ifdef", 5)
176 || !strncmp (input_line_pointer
, "ifndef", 6)))
177 || (input_line_pointer
[0] == 'e'
178 && (!strncmp (input_line_pointer
, "else", 4)
179 || !strncmp (input_line_pointer
, "endif", 5))))) {
183 return((current_cframe
!= NULL
) && (current_cframe
->ignoring
));
184 } /* ignore_input() */
186 static void initialize_cframe(cframe
)
187 struct conditional_frame
*cframe
;
189 memset(cframe
, 0, sizeof(*cframe
));
190 get_file_line(&(cframe
->if_file_line
));
191 cframe
->previous_cframe
= current_cframe
;
192 cframe
->dead_tree
= current_cframe
!= NULL
&& current_cframe
->ignoring
;
195 } /* initialize_cframe() */
197 static void get_file_line(into
)
198 struct file_line
*into
;
200 extern char *logical_input_file
;
201 extern char *physical_input_file
;
202 extern int logical_input_line
;
203 extern int physical_input_line
;
205 into
->logical_file
= logical_input_file
;
206 into
->logical_line
= logical_input_line
;
207 into
->physical_file
= physical_input_file
;
208 into
->physical_line
= physical_input_line
;
211 } /* get_file_line() */
213 static void set_file_line(from
)
214 struct file_line
*from
;
216 extern char *logical_input_file
;
217 extern char *physical_input_file
;
218 extern int logical_input_line
;
219 extern int physical_input_line
;
221 logical_input_file
= from
->logical_file
;
222 logical_input_line
= from
->logical_line
;
223 physical_input_file
= from
->physical_file
;
224 physical_input_line
= from
->physical_line
;
226 } /* set_file_line() */
This page took 0.034216 seconds and 4 git commands to generate.