Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* read.c - read a source file - |
ddb393cf ILT |
2 | Copyright (C) 1986, 1987, 1990, 1991, 1993, 1994 |
3 | Free Software Foundation, Inc. | |
3340f7e5 | 4 | |
f8701a3f SC |
5 | This file is part of GAS, the GNU Assembler. |
6 | ||
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) | |
10 | any later version. | |
11 | ||
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. | |
16 | ||
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 | |
a2a5a4fa | 19 | the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
fecd2382 | 20 | |
016e0d42 | 21 | #if 0 |
fecd2382 RP |
22 | #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will |
23 | change this a bit. But then, GNU isn't | |
24 | spozed to run on your machine anyway. | |
25 | (RMS is so shortsighted sometimes.) | |
26 | */ | |
016e0d42 ILT |
27 | #else |
28 | #define MASK_CHAR ((int)(unsigned char)-1) | |
29 | #endif | |
fecd2382 | 30 | |
9a7d824a | 31 | |
9471a360 KR |
32 | /* This is the largest known floating point format (for now). It will |
33 | grow when we do 4361 style flonums. */ | |
fecd2382 | 34 | |
9471a360 | 35 | #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16) |
fecd2382 | 36 | |
016e0d42 ILT |
37 | /* Routines that read assembler source text to build spagetti in memory. |
38 | Another group of these functions is in the expr.c module. */ | |
fecd2382 | 39 | |
9471a360 | 40 | /* for isdigit() */ |
6efd877d KR |
41 | #include <ctype.h> |
42 | ||
fecd2382 | 43 | #include "as.h" |
9471a360 | 44 | #include "subsegs.h" |
1356d77d | 45 | #include "libiberty.h" |
fecd2382 | 46 | #include "obstack.h" |
9a7d824a ILT |
47 | #include "listing.h" |
48 | ||
9a7d824a ILT |
49 | #ifndef TC_START_LABEL |
50 | #define TC_START_LABEL(x,y) (x==':') | |
51 | #endif | |
fecd2382 | 52 | |
016e0d42 ILT |
53 | /* The NOP_OPCODE is for the alignment fill value. |
54 | * fill it a nop instruction so that the disassembler does not choke | |
55 | * on it | |
56 | */ | |
57 | #ifndef NOP_OPCODE | |
58 | #define NOP_OPCODE 0x00 | |
59 | #endif | |
60 | ||
61 | char *input_line_pointer; /*->next char of source file to parse. */ | |
fecd2382 | 62 | |
326d16ca | 63 | int generate_asm_lineno = 0; /* flag to generate line stab for .s file */ |
daad3bbf | 64 | |
fecd2382 | 65 | #if BITS_PER_CHAR != 8 |
6efd877d KR |
66 | /* The following table is indexed by[(char)] and will break if |
67 | a char does not have exactly 256 states (hopefully 0:255!)! */ | |
68 | die horribly; | |
fecd2382 | 69 | #endif |
f8701a3f | 70 | |
c978e704 ILT |
71 | #ifndef LEX_AT |
72 | /* The m88k unfortunately uses @ as a label beginner. */ | |
73 | #define LEX_AT 0 | |
74 | #endif | |
75 | ||
ddb393cf ILT |
76 | #ifndef LEX_BR |
77 | /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */ | |
78 | #define LEX_BR 0 | |
79 | #endif | |
80 | ||
6ef37255 KR |
81 | #ifndef LEX_PCT |
82 | /* The Delta 68k assembler permits % inside label names. */ | |
83 | #define LEX_PCT 0 | |
84 | #endif | |
85 | ||
016e0d42 | 86 | /* used by is_... macros. our ctype[] */ |
1356d77d | 87 | char lex_type[256] = |
016e0d42 ILT |
88 | { |
89 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */ | |
90 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */ | |
6ef37255 | 91 | 0, 0, 0, 0, 3, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */ |
016e0d42 | 92 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 0123456789:;<=>? */ |
c978e704 | 93 | LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */ |
ddb393cf | 94 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */ |
016e0d42 | 95 | 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */ |
ddb393cf | 96 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 0, /* pqrstuvwxyz{|}~. */ |
016e0d42 ILT |
97 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
98 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
99 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
100 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
101 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
102 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
103 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
104 | }; | |
105 | ||
106 | ||
107 | /* | |
fecd2382 RP |
108 | * In: a character. |
109 | * Out: 1 if this character ends a line. | |
110 | */ | |
111 | #define _ (0) | |
016e0d42 ILT |
112 | char is_end_of_line[256] = |
113 | { | |
fecd2382 | 114 | #ifdef CR_EOL |
016e0d42 | 115 | _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */ |
fecd2382 | 116 | #else |
016e0d42 | 117 | _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */ |
fecd2382 | 118 | #endif |
016e0d42 | 119 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
40324362 KR |
120 | #ifdef TC_HPPA |
121 | _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */ | |
122 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */ | |
123 | #else | |
016e0d42 ILT |
124 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
125 | _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */ | |
40324362 | 126 | #endif |
016e0d42 ILT |
127 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
128 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
129 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
130 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
131 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
132 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
133 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
134 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
135 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
136 | }; | |
fecd2382 RP |
137 | #undef _ |
138 | ||
016e0d42 ILT |
139 | /* Functions private to this file. */ |
140 | ||
141 | static char *buffer; /* 1st char of each buffer of lines is here. */ | |
142 | static char *buffer_limit; /*->1 + last char in buffer. */ | |
fecd2382 | 143 | |
2209b19c KR |
144 | #ifdef TARGET_BYTES_BIG_ENDIAN |
145 | /* Hack to deal with tc-*.h defining TARGET_BYTES_BIG_ENDIAN to empty | |
146 | instead of to 0 or 1. */ | |
147 | #if 5 - TARGET_BYTES_BIG_ENDIAN - 5 == 10 | |
148 | #undef TARGET_BYTES_BIG_ENDIAN | |
149 | #define TARGET_BYTES_BIG_ENDIAN 1 | |
150 | #endif | |
151 | int target_big_endian = TARGET_BYTES_BIG_ENDIAN; | |
152 | #else | |
153 | int target_big_endian /* = 0 */; | |
154 | #endif | |
9c6d3f66 | 155 | |
9471a360 | 156 | static char *old_buffer; /* JF a hack */ |
016e0d42 ILT |
157 | static char *old_input; |
158 | static char *old_limit; | |
fecd2382 | 159 | |
016e0d42 | 160 | /* Variables for handling include file directory list. */ |
fecd2382 | 161 | |
016e0d42 ILT |
162 | char **include_dirs; /* List of pointers to directories to |
163 | search for .include's */ | |
164 | int include_dir_count; /* How many are in the list */ | |
165 | int include_dir_maxlen = 1;/* Length of longest in list */ | |
fecd2382 RP |
166 | |
167 | #ifndef WORKING_DOT_WORD | |
016e0d42 | 168 | struct broken_word *broken_words; |
9471a360 | 169 | int new_broken_words; |
fecd2382 RP |
170 | #endif |
171 | ||
e28c40d7 ILT |
172 | /* The current offset into the absolute section. We don't try to |
173 | build frags in the absolute section, since no data can be stored | |
174 | there. We just keep track of the current offset. */ | |
175 | addressT abs_section_offset; | |
176 | ||
1356d77d ILT |
177 | /* If this line had an MRI style label, it is stored in this variable. |
178 | This is used by some of the MRI pseudo-ops. */ | |
179 | static symbolS *mri_line_label; | |
180 | ||
181 | /* This global variable is used to support MRI common sections. We | |
182 | translate such sections into a common symbol. This variable is | |
183 | non-NULL when we are in an MRI common section. */ | |
184 | symbolS *mri_common_symbol; | |
185 | ||
286cb27a ILT |
186 | /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we |
187 | need to align to an even byte boundary unless the next pseudo-op is | |
188 | dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment | |
189 | may be needed. */ | |
190 | static int mri_pending_align; | |
191 | ||
192 | static void do_align PARAMS ((int, char *)); | |
e28c40d7 ILT |
193 | static int hex_float PARAMS ((int, char *)); |
194 | static void do_org PARAMS ((segT, expressionS *, int)); | |
6ef37255 | 195 | char *demand_copy_string PARAMS ((int *lenP)); |
016e0d42 | 196 | int is_it_end_of_statement PARAMS ((void)); |
5ac34ac3 | 197 | static segT get_segmented_expression PARAMS ((expressionS *expP)); |
016e0d42 | 198 | static segT get_known_segmented_expression PARAMS ((expressionS * expP)); |
016e0d42 | 199 | static void pobegin PARAMS ((void)); |
fecd2382 | 200 | \f |
6efd877d | 201 | |
016e0d42 ILT |
202 | void |
203 | read_begin () | |
fecd2382 | 204 | { |
016e0d42 | 205 | const char *p; |
f8701a3f | 206 | |
6efd877d KR |
207 | pobegin (); |
208 | obj_read_begin_hook (); | |
f8701a3f | 209 | |
4380166d KR |
210 | /* Something close -- but not too close -- to a multiple of 1024. |
211 | The debugging malloc I'm using has 24 bytes of overhead. */ | |
212 | obstack_begin (¬es, 5090); | |
213 | obstack_begin (&cond_obstack, 990); | |
f8701a3f | 214 | |
f8701a3f SC |
215 | /* Use machine dependent syntax */ |
216 | for (p = line_separator_chars; *p; p++) | |
58d4951d | 217 | is_end_of_line[(unsigned char) *p] = 1; |
f8701a3f | 218 | /* Use more. FIXME-SOMEDAY. */ |
1356d77d ILT |
219 | |
220 | if (flag_mri) | |
221 | lex_type['?'] = 3; | |
fecd2382 RP |
222 | } |
223 | \f | |
224 | /* set up pseudo-op tables */ | |
225 | ||
1356d77d | 226 | static struct hash_control *po_hash; |
fecd2382 | 227 | |
016e0d42 | 228 | static const pseudo_typeS potable[] = |
fecd2382 | 229 | { |
6efd877d KR |
230 | {"abort", s_abort, 0}, |
231 | {"align", s_align_ptwo, 0}, | |
232 | {"ascii", stringer, 0}, | |
233 | {"asciz", stringer, 1}, | |
931a8fab | 234 | {"balign", s_align_bytes, 0}, |
f8701a3f | 235 | /* block */ |
6efd877d KR |
236 | {"byte", cons, 1}, |
237 | {"comm", s_comm, 0}, | |
1356d77d ILT |
238 | {"common", s_mri_common, 0}, |
239 | {"common.s", s_mri_common, 1}, | |
6efd877d | 240 | {"data", s_data, 0}, |
1356d77d ILT |
241 | {"dc", cons, 2}, |
242 | {"dc.b", cons, 1}, | |
243 | {"dc.d", float_cons, 'd'}, | |
244 | {"dc.l", cons, 4}, | |
245 | {"dc.s", float_cons, 'f'}, | |
246 | {"dc.w", cons, 2}, | |
247 | {"dc.x", float_cons, 'x'}, | |
e28c40d7 ILT |
248 | {"dcb", s_space, 2}, |
249 | {"dcb.b", s_space, 1}, | |
250 | {"dcb.d", s_float_space, 'd'}, | |
251 | {"dcb.l", s_space, 4}, | |
252 | {"dcb.s", s_float_space, 'f'}, | |
253 | {"dcb.w", s_space, 2}, | |
254 | {"dcb.x", s_float_space, 'x'}, | |
1356d77d ILT |
255 | {"ds", s_space, 2}, |
256 | {"ds.b", s_space, 1}, | |
e28c40d7 | 257 | {"ds.d", s_space, 8}, |
1356d77d | 258 | {"ds.l", s_space, 4}, |
e28c40d7 ILT |
259 | {"ds.p", s_space, 12}, |
260 | {"ds.s", s_space, 4}, | |
1356d77d | 261 | {"ds.w", s_space, 2}, |
e28c40d7 | 262 | {"ds.x", s_space, 12}, |
604633ae | 263 | #ifdef S_SET_DESC |
4064305e | 264 | {"desc", s_desc, 0}, |
604633ae | 265 | #endif |
f8701a3f | 266 | /* dim */ |
6efd877d | 267 | {"double", float_cons, 'd'}, |
f8701a3f | 268 | /* dsect */ |
6efd877d KR |
269 | {"eject", listing_eject, 0}, /* Formfeed listing */ |
270 | {"else", s_else, 0}, | |
e28c40d7 | 271 | {"elsec", s_else, 0}, |
6efd877d | 272 | {"end", s_end, 0}, |
e28c40d7 | 273 | {"endc", s_endif, 0}, |
6efd877d | 274 | {"endif", s_endif, 0}, |
f8701a3f | 275 | /* endef */ |
6efd877d | 276 | {"equ", s_set, 0}, |
f8701a3f SC |
277 | /* err */ |
278 | /* extend */ | |
6efd877d | 279 | {"extern", s_ignore, 0}, /* We treat all undef as ext */ |
9a7d824a ILT |
280 | {"appfile", s_app_file, 1}, |
281 | {"appline", s_app_line, 0}, | |
e28c40d7 | 282 | {"fail", s_fail, 0}, |
6efd877d KR |
283 | {"file", s_app_file, 0}, |
284 | {"fill", s_fill, 0}, | |
285 | {"float", float_cons, 'f'}, | |
e28c40d7 | 286 | {"format", s_ignore, 0}, |
6efd877d KR |
287 | {"global", s_globl, 0}, |
288 | {"globl", s_globl, 0}, | |
289 | {"hword", cons, 2}, | |
e28c40d7 | 290 | {"if", s_if, (int) O_ne}, |
6efd877d | 291 | {"ifdef", s_ifdef, 0}, |
e28c40d7 | 292 | {"ifeq", s_if, (int) O_eq}, |
6efd877d | 293 | {"ifeqs", s_ifeqs, 0}, |
e28c40d7 ILT |
294 | {"ifge", s_if, (int) O_ge}, |
295 | {"ifgt", s_if, (int) O_gt}, | |
296 | {"ifle", s_if, (int) O_le}, | |
297 | {"iflt", s_if, (int) O_lt}, | |
6efd877d | 298 | {"ifndef", s_ifdef, 1}, |
e28c40d7 | 299 | {"ifne", s_if, (int) O_ne}, |
6efd877d KR |
300 | {"ifnes", s_ifeqs, 1}, |
301 | {"ifnotdef", s_ifdef, 1}, | |
302 | {"include", s_include, 0}, | |
303 | {"int", cons, 4}, | |
304 | {"lcomm", s_lcomm, 0}, | |
305 | {"lflags", listing_flags, 0}, /* Listing flags */ | |
306 | {"list", listing_list, 1}, /* Turn listing on */ | |
e28c40d7 | 307 | {"llen", listing_psize, 1}, |
6efd877d KR |
308 | {"long", cons, 4}, |
309 | {"lsym", s_lsym, 0}, | |
e28c40d7 | 310 | {"noformat", s_ignore, 0}, |
6efd877d | 311 | {"nolist", listing_list, 0}, /* Turn listing off */ |
80aab579 | 312 | {"octa", cons, 16}, |
e28c40d7 | 313 | {"offset", s_struct, 0}, |
6efd877d | 314 | {"org", s_org, 0}, |
931a8fab | 315 | {"p2align", s_align_ptwo, 0}, |
6efd877d | 316 | {"psize", listing_psize, 0}, /* set paper size */ |
f8701a3f | 317 | /* print */ |
80aab579 | 318 | {"quad", cons, 8}, |
6efd877d | 319 | {"sbttl", listing_title, 1}, /* Subtitle of listing */ |
f8701a3f SC |
320 | /* scl */ |
321 | /* sect */ | |
6efd877d KR |
322 | {"set", s_set, 0}, |
323 | {"short", cons, 2}, | |
324 | {"single", float_cons, 'f'}, | |
f8701a3f | 325 | /* size */ |
6efd877d | 326 | {"space", s_space, 0}, |
4064305e SS |
327 | {"stabd", s_stab, 'd'}, |
328 | {"stabn", s_stab, 'n'}, | |
329 | {"stabs", s_stab, 's'}, | |
ba71c54d | 330 | {"string", stringer, 1}, |
e28c40d7 | 331 | {"struct", s_struct, 0}, |
f8701a3f | 332 | /* tag */ |
6efd877d | 333 | {"text", s_text, 0}, |
6ef37255 KR |
334 | |
335 | /* This is for gcc to use. It's only just been added (2/94), so gcc | |
336 | won't be able to use it for a while -- probably a year or more. | |
337 | But once this has been released, check with gcc maintainers | |
338 | before deleting it or even changing the spelling. */ | |
339 | {"this_GCC_requires_the_GNU_assembler", s_ignore, 0}, | |
340 | /* If we're folding case -- done for some targets, not necessarily | |
341 | all -- the above string in an input file will be converted to | |
342 | this one. Match it either way... */ | |
343 | {"this_gcc_requires_the_gnu_assembler", s_ignore, 0}, | |
344 | ||
6efd877d | 345 | {"title", listing_title, 0}, /* Listing title */ |
f8701a3f SC |
346 | /* type */ |
347 | /* use */ | |
348 | /* val */ | |
1356d77d | 349 | {"xdef", s_globl, 0}, |
4064305e | 350 | {"xstabs", s_xstab, 's'}, |
6efd877d | 351 | {"word", cons, 2}, |
c02fd8dc | 352 | {"zero", s_space, 0}, |
6efd877d | 353 | {NULL} /* end sentinel */ |
fecd2382 RP |
354 | }; |
355 | ||
2209b19c KR |
356 | static int pop_override_ok = 0; |
357 | static const char *pop_table_name; | |
358 | ||
359 | void | |
360 | pop_insert (table) | |
361 | const pseudo_typeS *table; | |
6efd877d | 362 | { |
2209b19c | 363 | const char *errtxt; |
6efd877d | 364 | const pseudo_typeS *pop; |
2209b19c KR |
365 | for (pop = table; pop->poc_name; pop++) |
366 | { | |
367 | errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); | |
368 | if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists"))) | |
369 | as_fatal ("error constructing %s pseudo-op table", pop_table_name); | |
370 | } | |
371 | } | |
6efd877d | 372 | |
2209b19c KR |
373 | #ifndef md_pop_insert |
374 | #define md_pop_insert() pop_insert(md_pseudo_table) | |
375 | #endif | |
376 | ||
377 | #ifndef obj_pop_insert | |
378 | #define obj_pop_insert() pop_insert(obj_pseudo_table) | |
379 | #endif | |
380 | ||
381 | static void | |
382 | pobegin () | |
383 | { | |
6efd877d KR |
384 | po_hash = hash_new (); |
385 | ||
386 | /* Do the target-specific pseudo ops. */ | |
2209b19c KR |
387 | pop_table_name = "md"; |
388 | md_pop_insert (); | |
6efd877d KR |
389 | |
390 | /* Now object specific. Skip any that were in the target table. */ | |
2209b19c KR |
391 | pop_table_name = "obj"; |
392 | pop_override_ok = 1; | |
393 | obj_pop_insert (); | |
6efd877d KR |
394 | |
395 | /* Now portable ones. Skip any that we've seen already. */ | |
2209b19c KR |
396 | pop_table_name = "standard"; |
397 | pop_insert (potable); | |
398 | } | |
fecd2382 | 399 | \f |
58d4951d ILT |
400 | #define HANDLE_CONDITIONAL_ASSEMBLY() \ |
401 | if (ignore_input ()) \ | |
402 | { \ | |
403 | while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \ | |
404 | if (input_line_pointer == buffer_limit) \ | |
405 | break; \ | |
406 | continue; \ | |
f8701a3f | 407 | } |
a39116f1 | 408 | |
fecd2382 RP |
409 | |
410 | /* read_a_source_file() | |
411 | * | |
412 | * We read the file, putting things into a web that | |
413 | * represents what we have been reading. | |
414 | */ | |
6efd877d KR |
415 | void |
416 | read_a_source_file (name) | |
417 | char *name; | |
fecd2382 | 418 | { |
f8701a3f | 419 | register char c; |
6efd877d | 420 | register char *s; /* string of symbol, '\0' appended */ |
f8701a3f | 421 | register int temp; |
6efd877d | 422 | pseudo_typeS *pop; |
f8701a3f | 423 | |
6efd877d | 424 | buffer = input_scrub_new_file (name); |
f8701a3f | 425 | |
6efd877d KR |
426 | listing_file (name); |
427 | listing_newline (""); | |
f8701a3f | 428 | |
6efd877d KR |
429 | while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0) |
430 | { /* We have another line to parse. */ | |
431 | know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */ | |
9471a360 KR |
432 | contin: /* JF this goto is my fault I admit it. |
433 | Someone brave please re-write the whole | |
434 | input section here? Pleeze??? */ | |
6efd877d | 435 | while (input_line_pointer < buffer_limit) |
9471a360 KR |
436 | { |
437 | /* We have more of this buffer to parse. */ | |
f8701a3f SC |
438 | |
439 | /* | |
440 | * We now have input_line_pointer->1st char of next line. | |
441 | * If input_line_pointer [-1] == '\n' then we just | |
442 | * scanned another line: so bump line counters. | |
443 | */ | |
d2550c72 | 444 | if (is_end_of_line[(unsigned char) input_line_pointer[-1]]) |
6efd877d | 445 | { |
a2a5a4fa KR |
446 | #ifdef md_start_line_hook |
447 | md_start_line_hook (); | |
448 | #endif | |
449 | ||
385ce433 JL |
450 | if (input_line_pointer[-1] == '\n') |
451 | bump_line_counters (); | |
f8701a3f | 452 | |
1356d77d ILT |
453 | if (flag_mri |
454 | #ifdef LABELS_WITHOUT_COLONS | |
455 | || 1 | |
456 | #endif | |
457 | ) | |
6efd877d | 458 | { |
1356d77d ILT |
459 | mri_line_label = NULL; |
460 | ||
461 | /* Text at the start of a line must be a label, we | |
462 | run down and stick a colon in. */ | |
463 | if (is_name_beginner (*input_line_pointer)) | |
464 | { | |
465 | char *line_start = input_line_pointer; | |
466 | char c = get_symbol_end (); | |
467 | ||
e28c40d7 | 468 | if (! ignore_input ()) |
1356d77d | 469 | { |
e28c40d7 ILT |
470 | /* In MRI mode, the EQU pseudoop must be |
471 | handled specially. */ | |
472 | if (flag_mri) | |
1356d77d | 473 | { |
e28c40d7 ILT |
474 | if (((strncasecmp (input_line_pointer + 1, |
475 | "EQU", 3) == 0) | |
476 | || (strncasecmp (input_line_pointer + 1, | |
477 | "SET", 3) == 0)) | |
478 | && (input_line_pointer[4] == ' ' | |
479 | || input_line_pointer[4] == '\t')) | |
480 | { | |
481 | input_line_pointer += 4; | |
482 | equals (line_start); | |
483 | continue; | |
484 | } | |
1356d77d | 485 | } |
e28c40d7 ILT |
486 | |
487 | mri_line_label = colon (line_start); | |
1356d77d | 488 | } |
6efd877d | 489 | |
1356d77d ILT |
490 | *input_line_pointer = c; |
491 | if (c == ':') | |
492 | input_line_pointer++; | |
493 | } | |
6efd877d | 494 | } |
9471a360 | 495 | } |
f8701a3f | 496 | |
f8701a3f SC |
497 | /* |
498 | * We are at the begining of a line, or similar place. | |
499 | * We expect a well-formed assembler statement. | |
500 | * A "symbol-name:" is a statement. | |
501 | * | |
502 | * Depending on what compiler is used, the order of these tests | |
503 | * may vary to catch most common case 1st. | |
504 | * Each test is independent of all other tests at the (top) level. | |
505 | * PLEASE make a compiler that doesn't use this assembler. | |
506 | * It is crufty to waste a compiler's time encoding things for this | |
507 | * assembler, which then wastes more time decoding it. | |
508 | * (And communicating via (linear) files is silly! | |
509 | * If you must pass stuff, please pass a tree!) | |
510 | */ | |
9471a360 KR |
511 | if ((c = *input_line_pointer++) == '\t' |
512 | || c == ' ' | |
513 | || c == '\f' | |
514 | || c == 0) | |
6efd877d KR |
515 | { |
516 | c = *input_line_pointer++; | |
517 | } | |
518 | know (c != ' '); /* No further leading whitespace. */ | |
519 | LISTING_NEWLINE (); | |
f8701a3f SC |
520 | /* |
521 | * C is the 1st significant character. | |
522 | * Input_line_pointer points after that character. | |
523 | */ | |
6efd877d | 524 | if (is_name_beginner (c)) |
6ef37255 KR |
525 | { |
526 | /* want user-defined label or pseudo/opcode */ | |
6efd877d KR |
527 | HANDLE_CONDITIONAL_ASSEMBLY (); |
528 | ||
f8701a3f | 529 | s = --input_line_pointer; |
6efd877d | 530 | c = get_symbol_end (); /* name's delimiter */ |
f8701a3f SC |
531 | /* |
532 | * C is character after symbol. | |
533 | * That character's place in the input line is now '\0'. | |
534 | * S points to the beginning of the symbol. | |
535 | * [In case of pseudo-op, s->'.'.] | |
536 | * Input_line_pointer->'\0' where c was. | |
537 | */ | |
9a7d824a | 538 | if (TC_START_LABEL(c, input_line_pointer)) |
6efd877d KR |
539 | { |
540 | colon (s); /* user-defined label */ | |
541 | *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */ | |
f8701a3f | 542 | /* Input_line_pointer->after ':'. */ |
6efd877d KR |
543 | SKIP_WHITESPACE (); |
544 | ||
f8701a3f | 545 | |
6efd877d | 546 | } |
4064305e SS |
547 | else if (c == '=' |
548 | || (input_line_pointer[1] == '=' | |
549 | #ifdef TC_EQUAL_IN_INSN | |
550 | && ! TC_EQUAL_IN_INSN (c, input_line_pointer) | |
551 | #endif | |
552 | )) | |
9c6d3f66 | 553 | { |
6efd877d KR |
554 | equals (s); |
555 | demand_empty_rest_of_line (); | |
556 | } | |
557 | else | |
558 | { /* expect pseudo-op or machine instruction */ | |
8ff6f40e ILT |
559 | pop = NULL; |
560 | ||
d4c8cbd8 JL |
561 | #define IGNORE_OPCODE_CASE |
562 | #ifdef IGNORE_OPCODE_CASE | |
563 | { | |
564 | char *s2 = s; | |
565 | while (*s2) | |
566 | { | |
567 | if (isupper (*s2)) | |
568 | *s2 = tolower (*s2); | |
569 | s2++; | |
570 | } | |
571 | } | |
572 | #endif | |
573 | ||
1356d77d | 574 | if (flag_mri |
8ff6f40e | 575 | #ifdef NO_PSEUDO_DOT |
1356d77d | 576 | || 1 |
8ff6f40e | 577 | #endif |
1356d77d ILT |
578 | ) |
579 | { | |
580 | /* The MRI assembler and the m88k use pseudo-ops | |
581 | without a period. */ | |
582 | pop = (pseudo_typeS *) hash_find (po_hash, s); | |
583 | if (pop != NULL && pop->poc_handler == NULL) | |
584 | pop = NULL; | |
585 | } | |
8ff6f40e ILT |
586 | |
587 | if (pop != NULL || *s == '.') | |
6efd877d KR |
588 | { |
589 | /* | |
9471a360 KR |
590 | * PSEUDO - OP. |
591 | * | |
592 | * WARNING: c has next char, which may be end-of-line. | |
593 | * We lookup the pseudo-op table with s+1 because we | |
594 | * already know that the pseudo-op begins with a '.'. | |
595 | */ | |
6efd877d | 596 | |
8ff6f40e ILT |
597 | if (pop == NULL) |
598 | pop = (pseudo_typeS *) hash_find (po_hash, s + 1); | |
6efd877d | 599 | |
286cb27a ILT |
600 | /* In MRI mode, we may need to insert an |
601 | automatic alignment directive. What a hack | |
602 | this is. */ | |
603 | if (mri_pending_align | |
604 | && (pop == NULL | |
605 | || ! ((pop->poc_handler == cons | |
606 | && pop->poc_val == 1) | |
607 | || (pop->poc_handler == s_space | |
608 | && pop->poc_val == 1)))) | |
609 | { | |
610 | do_align (1, (char *) NULL); | |
611 | mri_pending_align = 0; | |
612 | } | |
613 | ||
6efd877d | 614 | /* Print the error msg now, while we still can */ |
8ff6f40e | 615 | if (pop == NULL) |
6efd877d KR |
616 | { |
617 | as_bad ("Unknown pseudo-op: `%s'", s); | |
f8701a3f | 618 | *input_line_pointer = c; |
6efd877d | 619 | s_ignore (0); |
46b81190 | 620 | continue; |
6efd877d KR |
621 | } |
622 | ||
623 | /* Put it back for error messages etc. */ | |
624 | *input_line_pointer = c; | |
9c6d3f66 KR |
625 | /* The following skip of whitespace is compulsory. |
626 | A well shaped space is sometimes all that separates | |
627 | keyword from operands. */ | |
6efd877d | 628 | if (c == ' ' || c == '\t') |
d4c8cbd8 | 629 | input_line_pointer++; |
6efd877d | 630 | /* |
9471a360 KR |
631 | * Input_line is restored. |
632 | * Input_line_pointer->1st non-blank char | |
633 | * after pseudo-operation. | |
634 | */ | |
46b81190 | 635 | (*pop->poc_handler) (pop->poc_val); |
e28c40d7 ILT |
636 | |
637 | /* If that was .end, just get out now. */ | |
638 | if (pop->poc_handler == s_end) | |
639 | goto quit; | |
6efd877d KR |
640 | } |
641 | else | |
6efd877d | 642 | { /* machine instruction */ |
286cb27a ILT |
643 | if (mri_pending_align) |
644 | { | |
645 | do_align (1, (char *) NULL); | |
646 | mri_pending_align = 0; | |
647 | } | |
648 | ||
6efd877d KR |
649 | /* WARNING: c has char, which may be end-of-line. */ |
650 | /* Also: input_line_pointer->`\0` where c was. */ | |
651 | *input_line_pointer = c; | |
58d4951d | 652 | while (!is_end_of_line[(unsigned char) *input_line_pointer] |
4064305e SS |
653 | #ifdef TC_EOL_IN_INSN |
654 | || TC_EOL_IN_INSN (input_line_pointer) | |
655 | #endif | |
656 | ) | |
6efd877d KR |
657 | { |
658 | input_line_pointer++; | |
659 | } | |
f8701a3f | 660 | |
6efd877d KR |
661 | c = *input_line_pointer; |
662 | *input_line_pointer = '\0'; | |
f8701a3f | 663 | |
326d16ca KH |
664 | #ifdef OBJ_GENERATE_ASM_LINENO |
665 | if (generate_asm_lineno == 0) | |
666 | { | |
f10a96cb | 667 | if (ecoff_no_current_file ()) |
326d16ca KH |
668 | generate_asm_lineno = 1; |
669 | } | |
f10a96cb ILT |
670 | if (generate_asm_lineno == 1) |
671 | { | |
1b434ced ILT |
672 | unsigned int lineno; |
673 | char *s; | |
674 | ||
daad3bbf | 675 | as_where (&s, &lineno); |
326d16ca | 676 | OBJ_GENERATE_ASM_LINENO (s, lineno); |
f10a96cb | 677 | } |
daad3bbf KH |
678 | #endif |
679 | ||
6efd877d | 680 | md_assemble (s); /* Assemble 1 instruction. */ |
f8701a3f | 681 | |
6efd877d | 682 | *input_line_pointer++ = c; |
f8701a3f | 683 | |
d4c8cbd8 JL |
684 | /* We resume loop AFTER the end-of-line from |
685 | this instruction. */ | |
6efd877d | 686 | } /* if (*s=='.') */ |
6efd877d | 687 | } /* if c==':' */ |
f8701a3f | 688 | continue; |
6efd877d | 689 | } /* if (is_name_beginner(c) */ |
f8701a3f | 690 | |
f8701a3f | 691 | |
d4c8cbd8 | 692 | /* Empty statement? */ |
58d4951d | 693 | if (is_end_of_line[(unsigned char) c]) |
d4c8cbd8 | 694 | continue; |
6efd877d | 695 | |
9777b772 KR |
696 | if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) |
697 | && isdigit (c)) | |
d4c8cbd8 JL |
698 | { |
699 | /* local label ("4:") */ | |
6efd877d KR |
700 | char *backup = input_line_pointer; |
701 | ||
702 | HANDLE_CONDITIONAL_ASSEMBLY (); | |
703 | ||
704 | temp = c - '0'; | |
705 | ||
706 | while (isdigit (*input_line_pointer)) | |
707 | { | |
708 | temp = (temp * 10) + *input_line_pointer - '0'; | |
709 | ++input_line_pointer; | |
710 | } /* read the whole number */ | |
711 | ||
9777b772 KR |
712 | if (LOCAL_LABELS_DOLLAR |
713 | && *input_line_pointer == '$' | |
6efd877d KR |
714 | && *(input_line_pointer + 1) == ':') |
715 | { | |
716 | input_line_pointer += 2; | |
717 | ||
718 | if (dollar_label_defined (temp)) | |
719 | { | |
720 | as_fatal ("label \"%d$\" redefined", temp); | |
721 | } | |
722 | ||
723 | define_dollar_label (temp); | |
724 | colon (dollar_label_name (temp, 0)); | |
725 | continue; | |
726 | } | |
6efd877d | 727 | |
9777b772 KR |
728 | if (LOCAL_LABELS_FB |
729 | && *input_line_pointer++ == ':') | |
6efd877d KR |
730 | { |
731 | fb_label_instance_inc (temp); | |
732 | colon (fb_label_name (temp, 0)); | |
733 | continue; | |
734 | } | |
6efd877d KR |
735 | |
736 | input_line_pointer = backup; | |
737 | } /* local label ("4:") */ | |
f8701a3f | 738 | |
6efd877d KR |
739 | if (c && strchr (line_comment_chars, c)) |
740 | { /* Its a comment. Better say APP or NO_APP */ | |
f8701a3f SC |
741 | char *ends; |
742 | char *new_buf; | |
743 | char *new_tmp; | |
604633ae | 744 | unsigned int new_length; |
f8701a3f | 745 | char *tmp_buf = 0; |
6efd877d KR |
746 | extern char *scrub_string, *scrub_last_string; |
747 | ||
748 | bump_line_counters (); | |
749 | s = input_line_pointer; | |
750 | if (strncmp (s, "APP\n", 4)) | |
751 | continue; /* We ignore it */ | |
752 | s += 4; | |
753 | ||
754 | ends = strstr (s, "#NO_APP\n"); | |
755 | ||
756 | if (!ends) | |
757 | { | |
604633ae ILT |
758 | unsigned int tmp_len; |
759 | unsigned int num; | |
6efd877d | 760 | |
f8701a3f SC |
761 | /* The end of the #APP wasn't in this buffer. We |
762 | keep reading in buffers until we find the #NO_APP | |
763 | that goes with this #APP There is one. The specs | |
764 | guarentee it. . . */ | |
6efd877d | 765 | tmp_len = buffer_limit - s; |
85825401 | 766 | tmp_buf = xmalloc (tmp_len + 1); |
4380166d | 767 | memcpy (tmp_buf, s, tmp_len); |
6efd877d KR |
768 | do |
769 | { | |
770 | new_tmp = input_scrub_next_buffer (&buffer); | |
f8701a3f | 771 | if (!new_tmp) |
6efd877d | 772 | break; |
f8701a3f | 773 | else |
6efd877d | 774 | buffer_limit = new_tmp; |
f8701a3f | 775 | input_line_pointer = buffer; |
6efd877d | 776 | ends = strstr (buffer, "#NO_APP\n"); |
f8701a3f | 777 | if (ends) |
6efd877d | 778 | num = ends - buffer; |
f8701a3f | 779 | else |
6efd877d KR |
780 | num = buffer_limit - buffer; |
781 | ||
782 | tmp_buf = xrealloc (tmp_buf, tmp_len + num); | |
9eb5f4b8 | 783 | memcpy (tmp_buf + tmp_len, buffer, num); |
6efd877d KR |
784 | tmp_len += num; |
785 | } | |
786 | while (!ends); | |
787 | ||
788 | input_line_pointer = ends ? ends + 8 : NULL; | |
789 | ||
790 | s = tmp_buf; | |
791 | ends = s + tmp_len; | |
792 | ||
793 | } | |
794 | else | |
795 | { | |
796 | input_line_pointer = ends + 8; | |
797 | } | |
798 | new_buf = xmalloc (100); | |
799 | new_length = 100; | |
800 | new_tmp = new_buf; | |
801 | ||
802 | scrub_string = s; | |
f8701a3f | 803 | scrub_last_string = ends; |
6efd877d KR |
804 | for (;;) |
805 | { | |
f8701a3f SC |
806 | int ch; |
807 | ||
6efd877d KR |
808 | ch = do_scrub_next_char (scrub_from_string, scrub_to_string); |
809 | if (ch == EOF) | |
810 | break; | |
811 | *new_tmp++ = ch; | |
812 | if (new_tmp == new_buf + new_length) | |
813 | { | |
814 | new_buf = xrealloc (new_buf, new_length + 100); | |
815 | new_tmp = new_buf + new_length; | |
816 | new_length += 100; | |
f8701a3f | 817 | } |
fecd2382 | 818 | } |
f8701a3f SC |
819 | |
820 | if (tmp_buf) | |
6efd877d KR |
821 | free (tmp_buf); |
822 | old_buffer = buffer; | |
823 | old_input = input_line_pointer; | |
824 | old_limit = buffer_limit; | |
825 | buffer = new_buf; | |
826 | input_line_pointer = new_buf; | |
827 | buffer_limit = new_tmp; | |
f8701a3f SC |
828 | continue; |
829 | } | |
830 | ||
6efd877d | 831 | HANDLE_CONDITIONAL_ASSEMBLY (); |
f8701a3f SC |
832 | |
833 | /* as_warn("Junk character %d.",c); Now done by ignore_rest */ | |
834 | input_line_pointer--; /* Report unknown char as ignored. */ | |
6efd877d KR |
835 | ignore_rest_of_line (); |
836 | } /* while (input_line_pointer<buffer_limit) */ | |
a2a5a4fa KR |
837 | |
838 | #ifdef md_after_pass_hook | |
839 | md_after_pass_hook (); | |
840 | #endif | |
841 | ||
6efd877d KR |
842 | if (old_buffer) |
843 | { | |
844 | bump_line_counters (); | |
845 | if (old_input != 0) | |
846 | { | |
847 | buffer = old_buffer; | |
848 | input_line_pointer = old_input; | |
849 | buffer_limit = old_limit; | |
f8701a3f SC |
850 | old_buffer = 0; |
851 | goto contin; | |
852 | } | |
853 | } | |
6efd877d | 854 | } /* while (more buffers to scan) */ |
f8701a3f | 855 | |
e28c40d7 ILT |
856 | quit: |
857 | input_scrub_close (); /* Close the input file */ | |
4075afe1 | 858 | } |
fecd2382 | 859 | |
6efd877d | 860 | void |
604633ae ILT |
861 | s_abort (ignore) |
862 | int ignore; | |
6efd877d KR |
863 | { |
864 | as_fatal (".abort detected. Abandoning ship."); | |
4075afe1 KR |
865 | } |
866 | ||
867 | /* Guts of .align directive. */ | |
868 | static void | |
869 | do_align (n, fill) | |
870 | int n; | |
871 | char *fill; | |
872 | { | |
873 | #ifdef md_do_align | |
874 | md_do_align (n, fill, just_record_alignment); | |
875 | #endif | |
876 | if (!fill) | |
877 | { | |
878 | /* @@ Fix this right for BFD! */ | |
879 | static char zero; | |
880 | static char nop_opcode = NOP_OPCODE; | |
881 | ||
882 | if (now_seg != data_section && now_seg != bss_section) | |
883 | { | |
884 | fill = &nop_opcode; | |
885 | } | |
886 | else | |
887 | { | |
888 | fill = &zero; | |
889 | } | |
890 | } | |
891 | /* Only make a frag if we HAVE to. . . */ | |
892 | if (n && !need_pass_2) | |
893 | frag_align (n, *fill); | |
894 | ||
c02fd8dc | 895 | #ifdef md_do_align |
4075afe1 | 896 | just_record_alignment: |
c02fd8dc ILT |
897 | #endif |
898 | ||
4075afe1 KR |
899 | record_alignment (now_seg, n); |
900 | } | |
fecd2382 RP |
901 | |
902 | /* For machines where ".align 4" means align to a 4 byte boundary. */ | |
6efd877d KR |
903 | void |
904 | s_align_bytes (arg) | |
905 | int arg; | |
fecd2382 | 906 | { |
6efd877d | 907 | register unsigned int temp; |
4075afe1 | 908 | char temp_fill; |
6efd877d KR |
909 | unsigned int i = 0; |
910 | unsigned long max_alignment = 1 << 15; | |
f8701a3f | 911 | |
58d4951d | 912 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
913 | temp = arg; /* Default value from pseudo-op table */ |
914 | else | |
915 | temp = get_absolute_expression (); | |
f8701a3f | 916 | |
6efd877d KR |
917 | if (temp > max_alignment) |
918 | { | |
919 | as_bad ("Alignment too large: %d. assumed.", temp = max_alignment); | |
f8701a3f SC |
920 | } |
921 | ||
4075afe1 KR |
922 | /* For the sparc, `.align (1<<n)' actually means `.align n' so we |
923 | have to convert it. */ | |
6efd877d KR |
924 | if (temp != 0) |
925 | { | |
926 | for (i = 0; (temp & 1) == 0; temp >>= 1, ++i) | |
927 | ; | |
f8701a3f | 928 | } |
6efd877d KR |
929 | if (temp != 1) |
930 | as_bad ("Alignment not a power of 2"); | |
f8701a3f | 931 | |
6efd877d KR |
932 | temp = i; |
933 | if (*input_line_pointer == ',') | |
934 | { | |
935 | input_line_pointer++; | |
936 | temp_fill = get_absolute_expression (); | |
4075afe1 | 937 | do_align (temp, &temp_fill); |
f8701a3f | 938 | } |
6efd877d | 939 | else |
4075afe1 | 940 | do_align (temp, (char *) 0); |
49864cfa | 941 | |
6efd877d | 942 | demand_empty_rest_of_line (); |
4075afe1 | 943 | } |
fecd2382 RP |
944 | |
945 | /* For machines where ".align 4" means align to 2**4 boundary. */ | |
6efd877d | 946 | void |
604633ae ILT |
947 | s_align_ptwo (ignore) |
948 | int ignore; | |
6efd877d KR |
949 | { |
950 | register int temp; | |
4075afe1 | 951 | char temp_fill; |
6efd877d KR |
952 | long max_alignment = 15; |
953 | ||
954 | temp = get_absolute_expression (); | |
955 | if (temp > max_alignment) | |
956 | as_bad ("Alignment too large: %d. assumed.", temp = max_alignment); | |
957 | else if (temp < 0) | |
958 | { | |
959 | as_bad ("Alignment negative. 0 assumed."); | |
960 | temp = 0; | |
961 | } | |
962 | if (*input_line_pointer == ',') | |
963 | { | |
964 | input_line_pointer++; | |
965 | temp_fill = get_absolute_expression (); | |
4075afe1 | 966 | do_align (temp, &temp_fill); |
6efd877d KR |
967 | } |
968 | else | |
4075afe1 | 969 | do_align (temp, (char *) 0); |
6efd877d KR |
970 | |
971 | demand_empty_rest_of_line (); | |
4075afe1 | 972 | } |
6efd877d KR |
973 | |
974 | void | |
604633ae ILT |
975 | s_comm (ignore) |
976 | int ignore; | |
6efd877d KR |
977 | { |
978 | register char *name; | |
979 | register char c; | |
980 | register char *p; | |
58d4951d | 981 | offsetT temp; |
6efd877d KR |
982 | register symbolS *symbolP; |
983 | ||
984 | name = input_line_pointer; | |
985 | c = get_symbol_end (); | |
986 | /* just after name is now '\0' */ | |
987 | p = input_line_pointer; | |
988 | *p = c; | |
989 | SKIP_WHITESPACE (); | |
990 | if (*input_line_pointer != ',') | |
991 | { | |
992 | as_bad ("Expected comma after symbol-name: rest of line ignored."); | |
993 | ignore_rest_of_line (); | |
994 | return; | |
995 | } | |
996 | input_line_pointer++; /* skip ',' */ | |
997 | if ((temp = get_absolute_expression ()) < 0) | |
998 | { | |
58d4951d | 999 | as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp); |
6efd877d KR |
1000 | ignore_rest_of_line (); |
1001 | return; | |
1002 | } | |
1003 | *p = 0; | |
1004 | symbolP = symbol_find_or_make (name); | |
1005 | *p = c; | |
1006 | if (S_IS_DEFINED (symbolP)) | |
1007 | { | |
6ef37255 KR |
1008 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1009 | S_GET_NAME (symbolP)); | |
6efd877d KR |
1010 | ignore_rest_of_line (); |
1011 | return; | |
1012 | } | |
1013 | if (S_GET_VALUE (symbolP)) | |
1014 | { | |
58d4951d ILT |
1015 | if (S_GET_VALUE (symbolP) != (valueT) temp) |
1016 | as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.", | |
6efd877d | 1017 | S_GET_NAME (symbolP), |
58d4951d ILT |
1018 | (long) S_GET_VALUE (symbolP), |
1019 | (long) temp); | |
6efd877d KR |
1020 | } |
1021 | else | |
1022 | { | |
58d4951d | 1023 | S_SET_VALUE (symbolP, (valueT) temp); |
6efd877d KR |
1024 | S_SET_EXTERNAL (symbolP); |
1025 | } | |
9471a360 | 1026 | #ifdef OBJ_VMS |
def66e24 DM |
1027 | { |
1028 | extern int flag_one; | |
1029 | if ( (!temp) || !flag_one) | |
1030 | S_GET_OTHER(symbolP) = const_flag; | |
1031 | } | |
9471a360 | 1032 | #endif /* not OBJ_VMS */ |
6efd877d KR |
1033 | know (symbolP->sy_frag == &zero_address_frag); |
1034 | demand_empty_rest_of_line (); | |
1035 | } /* s_comm() */ | |
fecd2382 | 1036 | |
1356d77d ILT |
1037 | /* The MRI COMMON pseudo-op. We handle this by creating a common |
1038 | symbol with the appropriate name. We make s_space do the right | |
1039 | thing by increasing the size. */ | |
1040 | ||
1041 | void | |
1042 | s_mri_common (small) | |
1043 | int small; | |
1044 | { | |
1045 | char *name; | |
1046 | char c; | |
1047 | char *alc = NULL; | |
1048 | symbolS *sym; | |
1049 | offsetT align; | |
1050 | ||
1051 | if (! flag_mri) | |
1052 | { | |
1053 | s_comm (0); | |
1054 | return; | |
1055 | } | |
1056 | ||
1057 | SKIP_WHITESPACE (); | |
1058 | ||
1059 | name = input_line_pointer; | |
1060 | if (! isdigit ((unsigned char) *name)) | |
1061 | c = get_symbol_end (); | |
1062 | else | |
1063 | { | |
1064 | do | |
1065 | { | |
1066 | ++input_line_pointer; | |
1067 | } | |
1068 | while (isdigit ((unsigned char) *input_line_pointer)); | |
1069 | c = *input_line_pointer; | |
1070 | *input_line_pointer = '\0'; | |
1071 | ||
1072 | if (mri_line_label != NULL) | |
1073 | { | |
1074 | alc = (char *) xmalloc (strlen (S_GET_NAME (mri_line_label)) | |
1075 | + (input_line_pointer - name) | |
1076 | + 1); | |
1077 | sprintf (alc, "%s%s", name, S_GET_NAME (mri_line_label)); | |
1078 | name = alc; | |
1079 | } | |
1080 | } | |
1081 | ||
1082 | sym = symbol_find_or_make (name); | |
1083 | *input_line_pointer = c; | |
1084 | if (alc != NULL) | |
1085 | free (alc); | |
1086 | ||
1087 | if (*input_line_pointer != ',') | |
1088 | align = 0; | |
1089 | else | |
1090 | { | |
1091 | ++input_line_pointer; | |
1092 | align = get_absolute_expression (); | |
1093 | } | |
1094 | ||
1095 | if (S_IS_DEFINED (sym)) | |
1096 | { | |
1097 | #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER) | |
1098 | if (! S_IS_COMMON (sym)) | |
1099 | #endif | |
1100 | { | |
1101 | as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym)); | |
1102 | ignore_rest_of_line (); | |
1103 | return; | |
1104 | } | |
1105 | } | |
1106 | ||
1107 | S_SET_EXTERNAL (sym); | |
1108 | mri_common_symbol = sym; | |
1109 | ||
1110 | #ifdef S_SET_ALIGN | |
1111 | if (align != 0) | |
1112 | S_SET_ALIGN (sym, align); | |
1113 | #endif | |
1114 | ||
1115 | if (mri_line_label != NULL) | |
1116 | { | |
1117 | mri_line_label->sy_value.X_op = O_symbol; | |
1118 | mri_line_label->sy_value.X_add_symbol = sym; | |
1119 | mri_line_label->sy_value.X_add_number = S_GET_VALUE (sym); | |
1120 | mri_line_label->sy_frag = &zero_address_frag; | |
1121 | S_SET_SEGMENT (mri_line_label, expr_section); | |
1122 | } | |
1123 | ||
1124 | /* FIXME: We just ignore the small argument, which distinguishes | |
1125 | COMMON and COMMON.S. I don't know what we can do about it. */ | |
1126 | ||
1127 | /* Ignore the type and hptype. */ | |
1128 | if (*input_line_pointer == ',') | |
1129 | input_line_pointer += 2; | |
1130 | if (*input_line_pointer == ',') | |
1131 | input_line_pointer += 2; | |
1132 | demand_empty_rest_of_line (); | |
1133 | } | |
1134 | ||
fecd2382 | 1135 | void |
604633ae ILT |
1136 | s_data (ignore) |
1137 | int ignore; | |
fecd2382 | 1138 | { |
ffffc8fb | 1139 | segT section; |
6efd877d | 1140 | register int temp; |
f8701a3f | 1141 | |
6efd877d | 1142 | temp = get_absolute_expression (); |
def66e24 | 1143 | if (flag_readonly_data_in_text) |
ffffc8fb ILT |
1144 | { |
1145 | section = text_section; | |
1146 | temp += 1000; | |
1147 | } | |
1148 | else | |
1149 | section = data_section; | |
1150 | ||
ffffc8fb | 1151 | subseg_set (section, (subsegT) temp); |
f8701a3f | 1152 | |
9471a360 | 1153 | #ifdef OBJ_VMS |
6efd877d | 1154 | const_flag = 0; |
fecd2382 | 1155 | #endif |
6efd877d | 1156 | demand_empty_rest_of_line (); |
fecd2382 RP |
1157 | } |
1158 | ||
9a7d824a ILT |
1159 | /* Handle the .appfile pseudo-op. This is automatically generated by |
1160 | do_scrub_next_char when a preprocessor # line comment is seen with | |
1161 | a file name. This default definition may be overridden by the | |
1162 | object or CPU specific pseudo-ops. This function is also the | |
1163 | default definition for .file; the APPFILE argument is 1 for | |
1164 | .appfile, 0 for .file. */ | |
1165 | ||
6efd877d | 1166 | void |
9a7d824a ILT |
1167 | s_app_file (appfile) |
1168 | int appfile; | |
6efd877d KR |
1169 | { |
1170 | register char *s; | |
1171 | int length; | |
f8701a3f | 1172 | |
6efd877d KR |
1173 | /* Some assemblers tolerate immediately following '"' */ |
1174 | if ((s = demand_copy_string (&length)) != 0) | |
1175 | { | |
9a7d824a ILT |
1176 | /* If this is a fake .appfile, a fake newline was inserted into |
1177 | the buffer. Passing -2 to new_logical_line tells it to | |
1178 | account for it. */ | |
1179 | new_logical_line (s, appfile ? -2 : -1); | |
6efd877d | 1180 | demand_empty_rest_of_line (); |
9a7d824a ILT |
1181 | #ifdef LISTING |
1182 | if (listing) | |
1183 | listing_source_file (s); | |
1184 | #endif | |
6efd877d | 1185 | } |
2209b19c KR |
1186 | #ifdef obj_app_file |
1187 | obj_app_file (s); | |
40324362 KR |
1188 | #endif |
1189 | } | |
fecd2382 | 1190 | |
9a7d824a ILT |
1191 | /* Handle the .appline pseudo-op. This is automatically generated by |
1192 | do_scrub_next_char when a preprocessor # line comment is seen. | |
1193 | This default definition may be overridden by the object or CPU | |
1194 | specific pseudo-ops. */ | |
1195 | ||
1196 | void | |
604633ae ILT |
1197 | s_app_line (ignore) |
1198 | int ignore; | |
9a7d824a ILT |
1199 | { |
1200 | int l; | |
1201 | ||
1202 | /* The given number is that of the next line. */ | |
1203 | l = get_absolute_expression () - 1; | |
931a8fab KR |
1204 | if (l < 0) |
1205 | /* Some of the back ends can't deal with non-positive line numbers. | |
1206 | Besides, it's silly. */ | |
1207 | as_warn ("Line numbers must be positive; line number %d rejected.", l+1); | |
1208 | else | |
1209 | { | |
1210 | new_logical_line ((char *) NULL, l); | |
9a7d824a | 1211 | #ifdef LISTING |
931a8fab KR |
1212 | if (listing) |
1213 | listing_source_line (l); | |
9a7d824a | 1214 | #endif |
931a8fab | 1215 | } |
9a7d824a ILT |
1216 | demand_empty_rest_of_line (); |
1217 | } | |
1218 | ||
e28c40d7 ILT |
1219 | /* Handle the .end pseudo-op. Actually, the real work is done in |
1220 | read_a_source_file. */ | |
1221 | ||
1222 | void | |
1223 | s_end (ignore) | |
1224 | int ignore; | |
1225 | { | |
1226 | if (flag_mri) | |
1227 | { | |
1228 | /* The MRI assembler permits the start symbol to follow .end, | |
1229 | but we don't support that. */ | |
1230 | SKIP_WHITESPACE (); | |
1231 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1232 | as_warn ("start address not supported"); | |
1233 | } | |
1234 | } | |
1235 | ||
1236 | /* Handle the MRI fail pseudo-op. */ | |
1237 | ||
1238 | void | |
1239 | s_fail (ignore) | |
1240 | int ignore; | |
1241 | { | |
1242 | offsetT temp; | |
1243 | ||
1244 | temp = get_absolute_expression (); | |
1245 | if (temp >= 500) | |
1246 | as_warn (".fail %ld encountered", (long) temp); | |
1247 | else | |
1248 | as_bad (".fail %ld encountered", (long) temp); | |
1249 | demand_empty_rest_of_line (); | |
1250 | } | |
1251 | ||
6efd877d | 1252 | void |
604633ae ILT |
1253 | s_fill (ignore) |
1254 | int ignore; | |
6efd877d KR |
1255 | { |
1256 | long temp_repeat = 0; | |
1257 | long temp_size = 1; | |
1258 | register long temp_fill = 0; | |
1259 | char *p; | |
f8701a3f | 1260 | |
7c2d4011 | 1261 | |
6efd877d KR |
1262 | temp_repeat = get_absolute_expression (); |
1263 | if (*input_line_pointer == ',') | |
1264 | { | |
1265 | input_line_pointer++; | |
1266 | temp_size = get_absolute_expression (); | |
1267 | if (*input_line_pointer == ',') | |
7c2d4011 SC |
1268 | { |
1269 | input_line_pointer++; | |
6efd877d | 1270 | temp_fill = get_absolute_expression (); |
fecd2382 | 1271 | } |
6efd877d | 1272 | } |
c8863a58 | 1273 | /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */ |
fecd2382 | 1274 | #define BSD_FILL_SIZE_CROCK_8 (8) |
6efd877d KR |
1275 | if (temp_size > BSD_FILL_SIZE_CROCK_8) |
1276 | { | |
1277 | as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8); | |
1278 | temp_size = BSD_FILL_SIZE_CROCK_8; | |
1279 | } | |
1280 | if (temp_size < 0) | |
1281 | { | |
1282 | as_warn ("Size negative: .fill ignored."); | |
1283 | temp_size = 0; | |
1284 | } | |
1285 | else if (temp_repeat <= 0) | |
1286 | { | |
1287 | as_warn ("Repeat < 0, .fill ignored"); | |
1288 | temp_size = 0; | |
1289 | } | |
7fd3560a | 1290 | |
6efd877d KR |
1291 | if (temp_size && !need_pass_2) |
1292 | { | |
1293 | p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0); | |
604633ae | 1294 | memset (p, 0, (unsigned int) temp_size); |
c8863a58 KR |
1295 | /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX |
1296 | * flavoured AS. The following bizzare behaviour is to be | |
1297 | * compatible with above. I guess they tried to take up to 8 | |
1298 | * bytes from a 4-byte expression and they forgot to sign | |
1299 | * extend. Un*x Sux. */ | |
fecd2382 | 1300 | #define BSD_FILL_SIZE_CROCK_4 (4) |
604633ae | 1301 | md_number_to_chars (p, (valueT) temp_fill, |
c8863a58 KR |
1302 | (temp_size > BSD_FILL_SIZE_CROCK_4 |
1303 | ? BSD_FILL_SIZE_CROCK_4 | |
1304 | : (int) temp_size)); | |
1305 | /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes) | |
1306 | * but emits no error message because it seems a legal thing to do. | |
1307 | * It is a degenerate case of .fill but could be emitted by a compiler. | |
1308 | */ | |
6efd877d | 1309 | } |
6efd877d | 1310 | demand_empty_rest_of_line (); |
f8701a3f SC |
1311 | } |
1312 | ||
6efd877d | 1313 | void |
604633ae ILT |
1314 | s_globl (ignore) |
1315 | int ignore; | |
6efd877d | 1316 | { |
40324362 KR |
1317 | char *name; |
1318 | int c; | |
1319 | symbolS *symbolP; | |
fecd2382 | 1320 | |
6efd877d KR |
1321 | do |
1322 | { | |
1323 | name = input_line_pointer; | |
1324 | c = get_symbol_end (); | |
1325 | symbolP = symbol_find_or_make (name); | |
1326 | *input_line_pointer = c; | |
1327 | SKIP_WHITESPACE (); | |
1328 | S_SET_EXTERNAL (symbolP); | |
1329 | if (c == ',') | |
1330 | { | |
1331 | input_line_pointer++; | |
1332 | SKIP_WHITESPACE (); | |
1333 | if (*input_line_pointer == '\n') | |
1334 | c = '\n'; | |
1335 | } | |
1336 | } | |
1337 | while (c == ','); | |
1338 | demand_empty_rest_of_line (); | |
40324362 | 1339 | } |
6efd877d KR |
1340 | |
1341 | void | |
1342 | s_lcomm (needs_align) | |
c8863a58 KR |
1343 | /* 1 if this was a ".bss" directive, which may require a 3rd argument |
1344 | (alignment); 0 if it was an ".lcomm" (2 args only) */ | |
1345 | int needs_align; | |
fecd2382 | 1346 | { |
6efd877d KR |
1347 | register char *name; |
1348 | register char c; | |
1349 | register char *p; | |
1350 | register int temp; | |
1351 | register symbolS *symbolP; | |
9a7d824a ILT |
1352 | segT current_seg = now_seg; |
1353 | subsegT current_subseg = now_subseg; | |
6efd877d KR |
1354 | const int max_alignment = 15; |
1355 | int align = 0; | |
9a7d824a | 1356 | segT bss_seg = bss_section; |
6efd877d KR |
1357 | |
1358 | name = input_line_pointer; | |
1359 | c = get_symbol_end (); | |
1360 | p = input_line_pointer; | |
1361 | *p = c; | |
1362 | SKIP_WHITESPACE (); | |
46b81190 ILT |
1363 | |
1364 | /* Accept an optional comma after the name. The comma used to be | |
1365 | required, but Irix 5 cc does not generate it. */ | |
1366 | if (*input_line_pointer == ',') | |
6efd877d | 1367 | { |
46b81190 ILT |
1368 | ++input_line_pointer; |
1369 | SKIP_WHITESPACE (); | |
6efd877d | 1370 | } |
f8701a3f | 1371 | |
6efd877d KR |
1372 | if (*input_line_pointer == '\n') |
1373 | { | |
1374 | as_bad ("Missing size expression"); | |
1375 | return; | |
1376 | } | |
f8701a3f | 1377 | |
6efd877d KR |
1378 | if ((temp = get_absolute_expression ()) < 0) |
1379 | { | |
1380 | as_warn ("BSS length (%d.) <0! Ignored.", temp); | |
1381 | ignore_rest_of_line (); | |
1382 | return; | |
1383 | } | |
f8701a3f | 1384 | |
2ef7731d | 1385 | #if defined (TC_MIPS) || defined (TC_ALPHA) |
a2a5a4fa KR |
1386 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
1387 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
46b81190 | 1388 | { |
a2a5a4fa KR |
1389 | /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */ |
1390 | if (temp <= bfd_get_gp_size (stdoutput)) | |
1391 | { | |
1392 | bss_seg = subseg_new (".sbss", 1); | |
1393 | seg_info (bss_seg)->bss = 1; | |
1394 | } | |
46b81190 | 1395 | } |
9a7d824a | 1396 | #endif |
ede7bc1c SC |
1397 | if (!needs_align) |
1398 | { | |
1399 | /* FIXME. This needs to be machine independent. */ | |
9d90491e ILT |
1400 | if (temp >= 8) |
1401 | align = 3; | |
1402 | else if (temp >= 4) | |
ede7bc1c SC |
1403 | align = 2; |
1404 | else if (temp >= 2) | |
1405 | align = 1; | |
1406 | else | |
c71a604a | 1407 | align = 0; |
ede7bc1c SC |
1408 | |
1409 | record_alignment(bss_seg, align); | |
1410 | } | |
9a7d824a | 1411 | |
6efd877d KR |
1412 | if (needs_align) |
1413 | { | |
1414 | align = 0; | |
1415 | SKIP_WHITESPACE (); | |
1416 | if (*input_line_pointer != ',') | |
1417 | { | |
1418 | as_bad ("Expected comma after size"); | |
1419 | ignore_rest_of_line (); | |
1420 | return; | |
1421 | } | |
1422 | input_line_pointer++; | |
1423 | SKIP_WHITESPACE (); | |
1424 | if (*input_line_pointer == '\n') | |
1425 | { | |
1426 | as_bad ("Missing alignment"); | |
1427 | return; | |
1428 | } | |
1429 | align = get_absolute_expression (); | |
1430 | if (align > max_alignment) | |
1431 | { | |
1432 | align = max_alignment; | |
1433 | as_warn ("Alignment too large: %d. assumed.", align); | |
1434 | } | |
1435 | else if (align < 0) | |
1436 | { | |
1437 | align = 0; | |
1438 | as_warn ("Alignment negative. 0 assumed."); | |
1439 | } | |
9a7d824a | 1440 | record_alignment (bss_seg, align); |
6efd877d | 1441 | } /* if needs align */ |
4075afe1 KR |
1442 | else |
1443 | { | |
1444 | /* Assume some objects may require alignment on some systems. */ | |
1445 | #ifdef TC_ALPHA | |
1446 | if (temp > 1) | |
1447 | { | |
1448 | align = ffs (temp) - 1; | |
1449 | if (temp % (1 << align)) | |
1450 | abort (); | |
1451 | } | |
1452 | #endif | |
1453 | } | |
f8701a3f | 1454 | |
6efd877d KR |
1455 | *p = 0; |
1456 | symbolP = symbol_find_or_make (name); | |
1457 | *p = c; | |
f8701a3f | 1458 | |
6efd877d | 1459 | if ( |
fecd2382 | 1460 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
6efd877d KR |
1461 | S_GET_OTHER (symbolP) == 0 && |
1462 | S_GET_DESC (symbolP) == 0 && | |
fecd2382 | 1463 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
9a7d824a | 1464 | (S_GET_SEGMENT (symbolP) == bss_seg |
6efd877d KR |
1465 | || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0))) |
1466 | { | |
604633ae | 1467 | char *pfrag; |
85825401 | 1468 | |
9a7d824a | 1469 | subseg_set (bss_seg, 1); |
85825401 ILT |
1470 | |
1471 | if (align) | |
1472 | frag_align (align, 0); | |
1473 | /* detach from old frag */ | |
9a7d824a | 1474 | if (S_GET_SEGMENT (symbolP) == bss_seg) |
85825401 ILT |
1475 | symbolP->sy_frag->fr_symbol = NULL; |
1476 | ||
1477 | symbolP->sy_frag = frag_now; | |
604633ae ILT |
1478 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, |
1479 | temp, (char *)0); | |
1480 | *pfrag = 0; | |
f8701a3f | 1481 | |
9a7d824a | 1482 | S_SET_SEGMENT (symbolP, bss_seg); |
85825401 | 1483 | |
fecd2382 | 1484 | #ifdef OBJ_COFF |
6efd877d | 1485 | /* The symbol may already have been created with a preceding |
c8863a58 KR |
1486 | ".globl" directive -- be careful not to step on storage class |
1487 | in that case. Otherwise, set it to static. */ | |
6efd877d KR |
1488 | if (S_GET_STORAGE_CLASS (symbolP) != C_EXT) |
1489 | { | |
1490 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
fecd2382 | 1491 | } |
6efd877d | 1492 | #endif /* OBJ_COFF */ |
6efd877d KR |
1493 | } |
1494 | else | |
6ef37255 KR |
1495 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1496 | S_GET_NAME (symbolP)); | |
f8701a3f | 1497 | |
9a7d824a | 1498 | subseg_set (current_seg, current_subseg); |
9a7d824a ILT |
1499 | |
1500 | demand_empty_rest_of_line (); | |
6efd877d | 1501 | } /* s_lcomm() */ |
fecd2382 | 1502 | |
6efd877d | 1503 | void |
604633ae ILT |
1504 | s_lsym (ignore) |
1505 | int ignore; | |
6efd877d KR |
1506 | { |
1507 | register char *name; | |
1508 | register char c; | |
1509 | register char *p; | |
6efd877d KR |
1510 | expressionS exp; |
1511 | register symbolS *symbolP; | |
1512 | ||
1513 | /* we permit ANY defined expression: BSD4.2 demands constants */ | |
1514 | name = input_line_pointer; | |
1515 | c = get_symbol_end (); | |
1516 | p = input_line_pointer; | |
1517 | *p = c; | |
1518 | SKIP_WHITESPACE (); | |
1519 | if (*input_line_pointer != ',') | |
1520 | { | |
1521 | *p = 0; | |
1522 | as_bad ("Expected comma after name \"%s\"", name); | |
1523 | *p = c; | |
1524 | ignore_rest_of_line (); | |
1525 | return; | |
1526 | } | |
1527 | input_line_pointer++; | |
b31f2abb KR |
1528 | expression (&exp); |
1529 | if (exp.X_op != O_constant | |
1530 | && exp.X_op != O_register) | |
1531 | { | |
1532 | as_bad ("bad expression"); | |
1533 | ignore_rest_of_line (); | |
1534 | return; | |
1535 | } | |
6efd877d KR |
1536 | *p = 0; |
1537 | symbolP = symbol_find_or_make (name); | |
f8701a3f | 1538 | |
c8863a58 KR |
1539 | /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 && |
1540 | symbolP->sy_desc == 0) out of this test because coff doesn't have | |
1541 | those fields, and I can't see when they'd ever be tripped. I | |
1542 | don't think I understand why they were here so I may have | |
1543 | introduced a bug. As recently as 1.37 didn't have this test | |
1544 | anyway. xoxorich. */ | |
f8701a3f | 1545 | |
9471a360 | 1546 | if (S_GET_SEGMENT (symbolP) == undefined_section |
6efd877d KR |
1547 | && S_GET_VALUE (symbolP) == 0) |
1548 | { | |
c8863a58 KR |
1549 | /* The name might be an undefined .global symbol; be sure to |
1550 | keep the "external" bit. */ | |
b31f2abb KR |
1551 | S_SET_SEGMENT (symbolP, |
1552 | (exp.X_op == O_constant | |
1553 | ? absolute_section | |
1554 | : reg_section)); | |
1555 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); | |
6efd877d KR |
1556 | } |
1557 | else | |
1558 | { | |
1559 | as_bad ("Symbol %s already defined", name); | |
1560 | } | |
1561 | *p = c; | |
1562 | demand_empty_rest_of_line (); | |
1563 | } /* s_lsym() */ | |
1564 | ||
e28c40d7 ILT |
1565 | /* Handle changing the location counter. */ |
1566 | ||
1567 | static void | |
1568 | do_org (segment, exp, fill) | |
1569 | segT segment; | |
1570 | expressionS *exp; | |
1571 | int fill; | |
1572 | { | |
1573 | if (segment != now_seg && segment != absolute_section) | |
1574 | as_bad ("invalid segment \"%s\"; segment \"%s\" assumed", | |
1575 | segment_name (segment), segment_name (now_seg)); | |
1576 | ||
1577 | if (now_seg == absolute_section) | |
1578 | { | |
1579 | if (fill != 0) | |
1580 | as_warn ("ignoring fill value in absolute section"); | |
1581 | if (exp->X_op != O_constant) | |
1582 | { | |
1583 | as_bad ("only constant offsets supported in absolute section"); | |
1584 | exp->X_add_number = 0; | |
1585 | } | |
1586 | abs_section_offset = exp->X_add_number; | |
1587 | } | |
1588 | else | |
1589 | { | |
1590 | char *p; | |
1591 | ||
1592 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol, | |
1593 | exp->X_add_number, (char *) NULL); | |
1594 | *p = fill; | |
1595 | } | |
1596 | } | |
1597 | ||
6efd877d | 1598 | void |
604633ae ILT |
1599 | s_org (ignore) |
1600 | int ignore; | |
6efd877d KR |
1601 | { |
1602 | register segT segment; | |
1603 | expressionS exp; | |
1604 | register long temp_fill; | |
e28c40d7 | 1605 | |
9471a360 KR |
1606 | /* Don't believe the documentation of BSD 4.2 AS. There is no such |
1607 | thing as a sub-segment-relative origin. Any absolute origin is | |
1608 | given a warning, then assumed to be segment-relative. Any | |
1609 | segmented origin expression ("foo+42") had better be in the right | |
1610 | segment or the .org is ignored. | |
1611 | ||
1612 | BSD 4.2 AS warns if you try to .org backwards. We cannot because | |
1613 | we never know sub-segment sizes when we are reading code. BSD | |
1614 | will crash trying to emit negative numbers of filler bytes in | |
1615 | certain .orgs. We don't crash, but see as-write for that code. | |
1616 | ||
1617 | Don't make frag if need_pass_2==1. */ | |
6efd877d KR |
1618 | segment = get_known_segmented_expression (&exp); |
1619 | if (*input_line_pointer == ',') | |
1620 | { | |
1621 | input_line_pointer++; | |
1622 | temp_fill = get_absolute_expression (); | |
1623 | } | |
1624 | else | |
1625 | temp_fill = 0; | |
e28c40d7 | 1626 | |
6efd877d | 1627 | if (!need_pass_2) |
e28c40d7 ILT |
1628 | do_org (segment, &exp, temp_fill); |
1629 | ||
6efd877d KR |
1630 | demand_empty_rest_of_line (); |
1631 | } /* s_org() */ | |
1632 | ||
1633 | void | |
604633ae ILT |
1634 | s_set (ignore) |
1635 | int ignore; | |
6efd877d KR |
1636 | { |
1637 | register char *name; | |
1638 | register char delim; | |
1639 | register char *end_name; | |
1640 | register symbolS *symbolP; | |
1641 | ||
1642 | /* | |
c8863a58 KR |
1643 | * Especial apologies for the random logic: |
1644 | * this just grew, and could be parsed much more simply! | |
1645 | * Dean in haste. | |
1646 | */ | |
6efd877d KR |
1647 | name = input_line_pointer; |
1648 | delim = get_symbol_end (); | |
1649 | end_name = input_line_pointer; | |
1650 | *end_name = delim; | |
1651 | SKIP_WHITESPACE (); | |
f8701a3f | 1652 | |
6efd877d KR |
1653 | if (*input_line_pointer != ',') |
1654 | { | |
1655 | *end_name = 0; | |
1656 | as_bad ("Expected comma after name \"%s\"", name); | |
1657 | *end_name = delim; | |
1658 | ignore_rest_of_line (); | |
1659 | return; | |
1660 | } | |
1661 | ||
1662 | input_line_pointer++; | |
1663 | *end_name = 0; | |
1664 | ||
1665 | if (name[0] == '.' && name[1] == '\0') | |
1666 | { | |
1667 | /* Turn '. = mumble' into a .org mumble */ | |
1668 | register segT segment; | |
1669 | expressionS exp; | |
1670 | register char *ptr; | |
1671 | ||
1672 | segment = get_known_segmented_expression (&exp); | |
f8701a3f | 1673 | |
6efd877d | 1674 | if (!need_pass_2) |
e28c40d7 | 1675 | do_org (segment, &exp, 0); |
6efd877d KR |
1676 | |
1677 | *end_name = delim; | |
1678 | return; | |
1679 | } | |
1680 | ||
1681 | if ((symbolP = symbol_find (name)) == NULL | |
1682 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
1683 | { | |
9471a360 | 1684 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); |
fecd2382 | 1685 | #ifdef OBJ_COFF |
6efd877d KR |
1686 | /* "set" symbols are local unless otherwise specified. */ |
1687 | SF_SET_LOCAL (symbolP); | |
fecd2382 | 1688 | #endif /* OBJ_COFF */ |
f8701a3f | 1689 | |
6efd877d | 1690 | } /* make a new symbol */ |
f8701a3f | 1691 | |
6efd877d | 1692 | symbol_table_insert (symbolP); |
f8701a3f | 1693 | |
6efd877d KR |
1694 | *end_name = delim; |
1695 | pseudo_set (symbolP); | |
1696 | demand_empty_rest_of_line (); | |
1697 | } /* s_set() */ | |
fecd2382 | 1698 | |
6efd877d KR |
1699 | void |
1700 | s_space (mult) | |
1701 | int mult; | |
b53ccaac | 1702 | { |
cd3b81bd | 1703 | expressionS exp; |
931a8fab | 1704 | long temp_fill; |
cd3b81bd | 1705 | char *p = 0; |
6efd877d | 1706 | |
a2a5a4fa KR |
1707 | #ifdef md_flush_pending_output |
1708 | md_flush_pending_output (); | |
1709 | #endif | |
1710 | ||
6efd877d | 1711 | /* Just like .fill, but temp_size = 1 */ |
cd3b81bd | 1712 | expression (&exp); |
931a8fab | 1713 | if (exp.X_op == O_constant) |
6efd877d | 1714 | { |
cd3b81bd KR |
1715 | long repeat; |
1716 | ||
1717 | repeat = exp.X_add_number; | |
1718 | if (mult) | |
1719 | repeat *= mult; | |
1720 | if (repeat <= 0) | |
1721 | { | |
1722 | as_warn (".space repeat count is %s, ignored", | |
1723 | repeat ? "negative" : "zero"); | |
1724 | ignore_rest_of_line (); | |
1725 | return; | |
1726 | } | |
1727 | ||
e28c40d7 ILT |
1728 | /* If we are in the absolute section, just bump the offset. */ |
1729 | if (now_seg == absolute_section) | |
1730 | { | |
1731 | abs_section_offset += repeat; | |
1732 | demand_empty_rest_of_line (); | |
1733 | return; | |
1734 | } | |
1735 | ||
1356d77d ILT |
1736 | /* If we are secretly in an MRI common section, then creating |
1737 | space just increases the size of the common symbol. */ | |
1738 | if (mri_common_symbol != NULL) | |
1739 | { | |
1740 | S_SET_VALUE (mri_common_symbol, | |
1741 | S_GET_VALUE (mri_common_symbol) + repeat); | |
1742 | demand_empty_rest_of_line (); | |
1743 | return; | |
1744 | } | |
1745 | ||
cd3b81bd KR |
1746 | if (!need_pass_2) |
1747 | p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, | |
931a8fab | 1748 | repeat, (char *) 0); |
6efd877d KR |
1749 | } |
1750 | else | |
1751 | { | |
e28c40d7 ILT |
1752 | if (now_seg == absolute_section) |
1753 | { | |
1754 | as_bad ("space allocation too complex in absolute section"); | |
1755 | subseg_set (text_section, 0); | |
1756 | } | |
1356d77d ILT |
1757 | if (mri_common_symbol != NULL) |
1758 | { | |
1759 | as_bad ("space allocation too complex in common section"); | |
1760 | mri_common_symbol = NULL; | |
1761 | } | |
cd3b81bd KR |
1762 | if (!need_pass_2) |
1763 | p = frag_var (rs_space, 1, 1, (relax_substateT) 0, | |
1764 | make_expr_symbol (&exp), 0L, (char *) 0); | |
6efd877d | 1765 | } |
931a8fab KR |
1766 | SKIP_WHITESPACE (); |
1767 | if (*input_line_pointer == ',') | |
6efd877d | 1768 | { |
931a8fab | 1769 | input_line_pointer++; |
cd3b81bd | 1770 | temp_fill = get_absolute_expression (); |
6efd877d | 1771 | } |
cd3b81bd | 1772 | else |
6efd877d | 1773 | { |
cd3b81bd | 1774 | temp_fill = 0; |
6efd877d | 1775 | } |
cd3b81bd | 1776 | if (p) |
6efd877d | 1777 | { |
6efd877d KR |
1778 | *p = temp_fill; |
1779 | } | |
1780 | demand_empty_rest_of_line (); | |
cd3b81bd | 1781 | } |
fecd2382 | 1782 | |
e28c40d7 ILT |
1783 | /* This is like s_space, but the value is a floating point number with |
1784 | the given precision. This is for the MRI dcb.s pseudo-op and | |
1785 | friends. */ | |
1786 | ||
1787 | void | |
1788 | s_float_space (float_type) | |
1789 | int float_type; | |
1790 | { | |
1791 | offsetT count; | |
1792 | int flen; | |
1793 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
1794 | ||
1795 | count = get_absolute_expression (); | |
1796 | ||
1797 | SKIP_WHITESPACE (); | |
1798 | if (*input_line_pointer != ',') | |
1799 | { | |
1800 | as_bad ("missing value"); | |
1801 | ignore_rest_of_line (); | |
1802 | return; | |
1803 | } | |
1804 | ||
1805 | ++input_line_pointer; | |
1806 | ||
1807 | SKIP_WHITESPACE (); | |
1808 | ||
1809 | /* Skip any 0{letter} that may be present. Don't even check if the | |
1810 | * letter is legal. */ | |
1811 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) | |
1812 | input_line_pointer += 2; | |
1813 | ||
1814 | /* Accept :xxxx, where the x's are hex digits, for a floating point | |
1815 | with the exact digits specified. */ | |
1816 | if (input_line_pointer[0] == ':') | |
1817 | { | |
1818 | flen = hex_float (float_type, temp); | |
1819 | if (flen < 0) | |
1820 | { | |
1821 | ignore_rest_of_line (); | |
1822 | return; | |
1823 | } | |
1824 | } | |
1825 | else | |
1826 | { | |
1827 | char *err; | |
1828 | ||
1829 | err = md_atof (float_type, temp, &flen); | |
1830 | know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
1831 | know (flen > 0); | |
1832 | if (err) | |
1833 | { | |
1834 | as_bad ("Bad floating literal: %s", err); | |
1835 | ignore_rest_of_line (); | |
1836 | return; | |
1837 | } | |
1838 | } | |
1839 | ||
1840 | while (--count >= 0) | |
1841 | { | |
1842 | char *p; | |
1843 | ||
1844 | p = frag_more (flen); | |
1845 | memcpy (p, temp, (unsigned int) flen); | |
1846 | } | |
1847 | ||
1848 | demand_empty_rest_of_line (); | |
1849 | } | |
1850 | ||
1851 | /* Handle the .struct pseudo-op, as found in MIPS assemblers. */ | |
1852 | ||
1853 | void | |
1854 | s_struct (ignore) | |
1855 | int ignore; | |
1856 | { | |
1857 | abs_section_offset = get_absolute_expression (); | |
1858 | subseg_set (absolute_section, 0); | |
1859 | demand_empty_rest_of_line (); | |
1860 | } | |
1861 | ||
fecd2382 | 1862 | void |
604633ae ILT |
1863 | s_text (ignore) |
1864 | int ignore; | |
fecd2382 | 1865 | { |
6efd877d | 1866 | register int temp; |
f8701a3f | 1867 | |
6efd877d | 1868 | temp = get_absolute_expression (); |
9471a360 | 1869 | subseg_set (text_section, (subsegT) temp); |
6efd877d | 1870 | demand_empty_rest_of_line (); |
80d80c64 KR |
1871 | #ifdef OBJ_VMS |
1872 | const_flag &= ~IN_DEFAULT_SECTION; | |
1873 | #endif | |
6efd877d | 1874 | } /* s_text() */ |
fecd2382 | 1875 | \f |
6efd877d | 1876 | |
6efd877d KR |
1877 | void |
1878 | demand_empty_rest_of_line () | |
1879 | { | |
1880 | SKIP_WHITESPACE (); | |
58d4951d | 1881 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
1882 | { |
1883 | input_line_pointer++; | |
1884 | } | |
1885 | else | |
1886 | { | |
1887 | ignore_rest_of_line (); | |
1888 | } | |
1889 | /* Return having already swallowed end-of-line. */ | |
1890 | } /* Return pointing just after end-of-line. */ | |
fecd2382 RP |
1891 | |
1892 | void | |
6efd877d | 1893 | ignore_rest_of_line () /* For suspect lines: gives warning. */ |
fecd2382 | 1894 | { |
58d4951d | 1895 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 1896 | { |
6efd877d KR |
1897 | if (isprint (*input_line_pointer)) |
1898 | as_bad ("Rest of line ignored. First ignored character is `%c'.", | |
f8701a3f SC |
1899 | *input_line_pointer); |
1900 | else | |
6efd877d | 1901 | as_bad ("Rest of line ignored. First ignored character valued 0x%x.", |
f8701a3f SC |
1902 | *input_line_pointer); |
1903 | while (input_line_pointer < buffer_limit | |
58d4951d | 1904 | && !is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 1905 | { |
6efd877d | 1906 | input_line_pointer++; |
f8701a3f SC |
1907 | } |
1908 | } | |
6efd877d | 1909 | input_line_pointer++; /* Return pointing just after end-of-line. */ |
58d4951d | 1910 | know (is_end_of_line[(unsigned char) input_line_pointer[-1]]); |
fecd2382 RP |
1911 | } |
1912 | ||
1913 | /* | |
1914 | * pseudo_set() | |
1915 | * | |
1916 | * In: Pointer to a symbol. | |
1917 | * Input_line_pointer->expression. | |
1918 | * | |
1919 | * Out: Input_line_pointer->just after any whitespace after expression. | |
1920 | * Tried to set symbol to value of expression. | |
1921 | * Will change symbols type, value, and frag; | |
fecd2382 RP |
1922 | */ |
1923 | void | |
f8701a3f | 1924 | pseudo_set (symbolP) |
6efd877d | 1925 | symbolS *symbolP; |
fecd2382 | 1926 | { |
6efd877d | 1927 | expressionS exp; |
daad3bbf | 1928 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
f8701a3f | 1929 | int ext; |
fecd2382 | 1930 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 1931 | |
6efd877d | 1932 | know (symbolP); /* NULL pointer is logic error. */ |
daad3bbf | 1933 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
6efd877d | 1934 | ext = S_IS_EXTERNAL (symbolP); |
fecd2382 | 1935 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 1936 | |
5ac34ac3 | 1937 | (void) expression (&exp); |
f8701a3f | 1938 | |
5ac34ac3 ILT |
1939 | if (exp.X_op == O_illegal) |
1940 | as_bad ("illegal expression; zero assumed"); | |
1941 | else if (exp.X_op == O_absent) | |
1942 | as_bad ("missing expression; zero assumed"); | |
1943 | else if (exp.X_op == O_big) | |
1944 | as_bad ("%s number invalid; zero assumed", | |
1945 | exp.X_add_number > 0 ? "bignum" : "floating point"); | |
1946 | else if (exp.X_op == O_subtract | |
1947 | && (S_GET_SEGMENT (exp.X_add_symbol) | |
1948 | == S_GET_SEGMENT (exp.X_op_symbol)) | |
1949 | && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol)) | |
1950 | && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag) | |
9471a360 | 1951 | { |
5ac34ac3 ILT |
1952 | exp.X_op = O_constant; |
1953 | exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol) | |
1954 | - S_GET_VALUE (exp.X_op_symbol)); | |
9471a360 | 1955 | } |
5ac34ac3 ILT |
1956 | |
1957 | switch (exp.X_op) | |
9471a360 | 1958 | { |
5ac34ac3 ILT |
1959 | case O_illegal: |
1960 | case O_absent: | |
1961 | case O_big: | |
1962 | exp.X_add_number = 0; | |
1963 | /* Fall through. */ | |
1964 | case O_constant: | |
9471a360 | 1965 | S_SET_SEGMENT (symbolP, absolute_section); |
daad3bbf | 1966 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
1967 | if (ext) |
1968 | S_SET_EXTERNAL (symbolP); | |
6efd877d | 1969 | else |
6efd877d | 1970 | S_CLEAR_EXTERNAL (symbolP); |
fecd2382 | 1971 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
604633ae | 1972 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
6efd877d | 1973 | symbolP->sy_frag = &zero_address_frag; |
5ac34ac3 | 1974 | break; |
f8701a3f | 1975 | |
5ac34ac3 ILT |
1976 | case O_register: |
1977 | S_SET_SEGMENT (symbolP, reg_section); | |
604633ae | 1978 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
5ac34ac3 ILT |
1979 | symbolP->sy_frag = &zero_address_frag; |
1980 | break; | |
1981 | ||
1982 | case O_symbol: | |
ef198870 KR |
1983 | if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section |
1984 | || exp.X_add_number != 0) | |
5ac34ac3 | 1985 | symbolP->sy_value = exp; |
6efd877d KR |
1986 | else |
1987 | { | |
80d80c64 KR |
1988 | symbolS *s = exp.X_add_symbol; |
1989 | ||
1990 | S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s)); | |
daad3bbf | 1991 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
1992 | if (ext) |
1993 | S_SET_EXTERNAL (symbolP); | |
1994 | else | |
1995 | S_CLEAR_EXTERNAL (symbolP); | |
fecd2382 | 1996 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
5ac34ac3 | 1997 | S_SET_VALUE (symbolP, |
80d80c64 KR |
1998 | exp.X_add_number + S_GET_VALUE (s)); |
1999 | symbolP->sy_frag = s->sy_frag; | |
ef198870 | 2000 | copy_symbol_attributes (symbolP, s); |
5ac34ac3 ILT |
2001 | } |
2002 | break; | |
f8701a3f | 2003 | |
5ac34ac3 ILT |
2004 | default: |
2005 | /* The value is some complex expression. | |
2006 | FIXME: Should we set the segment to anything? */ | |
2007 | symbolP->sy_value = exp; | |
2008 | break; | |
f8701a3f | 2009 | } |
fecd2382 RP |
2010 | } |
2011 | \f | |
2012 | /* | |
2013 | * cons() | |
2014 | * | |
2015 | * CONStruct more frag of .bytes, or .words etc. | |
2016 | * Should need_pass_2 be 1 then emit no frag(s). | |
80aab579 | 2017 | * This understands EXPRESSIONS. |
fecd2382 RP |
2018 | * |
2019 | * Bug (?) | |
2020 | * | |
2021 | * This has a split personality. We use expression() to read the | |
2022 | * value. We can detect if the value won't fit in a byte or word. | |
2023 | * But we can't detect if expression() discarded significant digits | |
2024 | * in the case of a long. Not worth the crocks required to fix it. | |
2025 | */ | |
2026 | ||
40324362 KR |
2027 | /* Select a parser for cons expressions. */ |
2028 | ||
2029 | /* Some targets need to parse the expression in various fancy ways. | |
2030 | You can define TC_PARSE_CONS_EXPRESSION to do whatever you like | |
2031 | (for example, the HPPA does this). Otherwise, you can define | |
2032 | BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or | |
2033 | REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these | |
2034 | are defined, which is the normal case, then only simple expressions | |
2035 | are permitted. */ | |
2036 | ||
1356d77d ILT |
2037 | static void |
2038 | parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
2039 | ||
40324362 KR |
2040 | #ifndef TC_PARSE_CONS_EXPRESSION |
2041 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
2042 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES) | |
2043 | static void | |
2044 | parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
2045 | #endif | |
40324362 KR |
2046 | #ifdef REPEAT_CONS_EXPRESSIONS |
2047 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES) | |
2048 | static void | |
2049 | parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
2050 | #endif | |
2051 | ||
2052 | /* If we haven't gotten one yet, just call expression. */ | |
2053 | #ifndef TC_PARSE_CONS_EXPRESSION | |
2054 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP) | |
2055 | #endif | |
2056 | #endif | |
2057 | ||
6efd877d KR |
2058 | /* worker to do .byte etc statements */ |
2059 | /* clobbers input_line_pointer, checks */ | |
2060 | /* end-of-line. */ | |
2061 | void | |
2062 | cons (nbytes) | |
604633ae | 2063 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ |
fecd2382 | 2064 | { |
286cb27a | 2065 | int c; |
6efd877d | 2066 | expressionS exp; |
f8701a3f | 2067 | |
a2a5a4fa KR |
2068 | #ifdef md_flush_pending_output |
2069 | md_flush_pending_output (); | |
2070 | #endif | |
2071 | ||
40324362 | 2072 | if (is_it_end_of_statement ()) |
6efd877d | 2073 | { |
40324362 KR |
2074 | demand_empty_rest_of_line (); |
2075 | return; | |
6efd877d | 2076 | } |
40324362 | 2077 | |
286cb27a | 2078 | c = 0; |
40324362 | 2079 | do |
6efd877d | 2080 | { |
1356d77d ILT |
2081 | if (flag_mri) |
2082 | parse_mri_cons (&exp, (unsigned int) nbytes); | |
2083 | else | |
2084 | TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes); | |
604633ae | 2085 | emit_expr (&exp, (unsigned int) nbytes); |
286cb27a | 2086 | ++c; |
40324362 KR |
2087 | } |
2088 | while (*input_line_pointer++ == ','); | |
2089 | ||
286cb27a ILT |
2090 | /* In MRI mode, after an odd number of bytes, we must align to an |
2091 | even word boundary, unless the next instruction is a dc.b, ds.b | |
2092 | or dcb.b. */ | |
2093 | if (flag_mri && nbytes == 1 && (c & 1) != 0) | |
2094 | mri_pending_align = 1; | |
2095 | ||
40324362 KR |
2096 | input_line_pointer--; /* Put terminator back into stream. */ |
2097 | demand_empty_rest_of_line (); | |
30d3a445 | 2098 | } |
f8701a3f | 2099 | |
40324362 KR |
2100 | /* Put the contents of expression EXP into the object file using |
2101 | NBYTES bytes. If need_pass_2 is 1, this does nothing. */ | |
f8701a3f | 2102 | |
40324362 KR |
2103 | void |
2104 | emit_expr (exp, nbytes) | |
2105 | expressionS *exp; | |
2106 | unsigned int nbytes; | |
2107 | { | |
5ac34ac3 | 2108 | operatorT op; |
40324362 | 2109 | register char *p; |
80aab579 | 2110 | valueT extra_digit = 0; |
f8701a3f | 2111 | |
40324362 KR |
2112 | /* Don't do anything if we are going to make another pass. */ |
2113 | if (need_pass_2) | |
2114 | return; | |
2115 | ||
5ac34ac3 | 2116 | op = exp->X_op; |
40324362 | 2117 | |
e28c40d7 ILT |
2118 | /* Allow `.word 0' in the absolute section. */ |
2119 | if (now_seg == absolute_section) | |
2120 | { | |
2121 | if (op != O_constant || exp->X_add_number != 0) | |
2122 | as_bad ("attempt to store value in absolute section"); | |
2123 | abs_section_offset += nbytes; | |
2124 | return; | |
2125 | } | |
2126 | ||
80aab579 ILT |
2127 | /* Handle a negative bignum. */ |
2128 | if (op == O_uminus | |
2129 | && exp->X_add_number == 0 | |
2130 | && exp->X_add_symbol->sy_value.X_op == O_big | |
2131 | && exp->X_add_symbol->sy_value.X_add_number > 0) | |
2132 | { | |
2133 | int i; | |
2134 | unsigned long carry; | |
2135 | ||
2136 | exp = &exp->X_add_symbol->sy_value; | |
2137 | ||
2138 | /* Negate the bignum: one's complement each digit and add 1. */ | |
2139 | carry = 1; | |
2140 | for (i = 0; i < exp->X_add_number; i++) | |
2141 | { | |
2142 | unsigned long next; | |
2143 | ||
2144 | next = (((~ (generic_bignum[i] & LITTLENUM_MASK)) | |
2145 | & LITTLENUM_MASK) | |
2146 | + carry); | |
2147 | generic_bignum[i] = next & LITTLENUM_MASK; | |
2148 | carry = next >> LITTLENUM_NUMBER_OF_BITS; | |
2149 | } | |
2150 | ||
2151 | /* We can ignore any carry out, because it will be handled by | |
2152 | extra_digit if it is needed. */ | |
2153 | ||
2154 | extra_digit = (valueT) -1; | |
2155 | op = O_big; | |
2156 | } | |
2157 | ||
5ac34ac3 | 2158 | if (op == O_absent || op == O_illegal) |
6efd877d | 2159 | { |
5ac34ac3 ILT |
2160 | as_warn ("zero assumed for missing expression"); |
2161 | exp->X_add_number = 0; | |
2162 | op = O_constant; | |
6efd877d | 2163 | } |
80aab579 | 2164 | else if (op == O_big && exp->X_add_number <= 0) |
6efd877d | 2165 | { |
80aab579 | 2166 | as_bad ("floating point number invalid; zero assumed"); |
40324362 | 2167 | exp->X_add_number = 0; |
5ac34ac3 | 2168 | op = O_constant; |
40324362 | 2169 | } |
5ac34ac3 | 2170 | else if (op == O_register) |
6efd877d | 2171 | { |
5ac34ac3 ILT |
2172 | as_warn ("register value used as expression"); |
2173 | op = O_constant; | |
40324362 | 2174 | } |
6efd877d | 2175 | |
604633ae | 2176 | p = frag_more ((int) nbytes); |
6efd877d | 2177 | |
40324362 KR |
2178 | #ifndef WORKING_DOT_WORD |
2179 | /* If we have the difference of two symbols in a word, save it on | |
2180 | the broken_words list. See the code in write.c. */ | |
5ac34ac3 | 2181 | if (op == O_subtract && nbytes == 2) |
40324362 KR |
2182 | { |
2183 | struct broken_word *x; | |
2184 | ||
2185 | x = (struct broken_word *) xmalloc (sizeof (struct broken_word)); | |
2186 | x->next_broken_word = broken_words; | |
2187 | broken_words = x; | |
2188 | x->frag = frag_now; | |
2189 | x->word_goes_here = p; | |
2190 | x->dispfrag = 0; | |
2191 | x->add = exp->X_add_symbol; | |
5ac34ac3 | 2192 | x->sub = exp->X_op_symbol; |
40324362 KR |
2193 | x->addnum = exp->X_add_number; |
2194 | x->added = 0; | |
2195 | new_broken_words++; | |
2196 | return; | |
2197 | } | |
f8701a3f | 2198 | #endif |
6efd877d | 2199 | |
80aab579 ILT |
2200 | /* If we have an integer, but the number of bytes is too large to |
2201 | pass to md_number_to_chars, handle it as a bignum. */ | |
2202 | if (op == O_constant && nbytes > sizeof (valueT)) | |
2203 | { | |
2204 | valueT val; | |
2205 | int gencnt; | |
2206 | ||
2207 | if (! exp->X_unsigned && exp->X_add_number < 0) | |
2208 | extra_digit = (valueT) -1; | |
2209 | val = (valueT) exp->X_add_number; | |
2210 | gencnt = 0; | |
2211 | do | |
2212 | { | |
2213 | generic_bignum[gencnt] = val & LITTLENUM_MASK; | |
2214 | val >>= LITTLENUM_NUMBER_OF_BITS; | |
2215 | ++gencnt; | |
2216 | } | |
2217 | while (val != 0); | |
2218 | op = exp->X_op = O_big; | |
2219 | exp->X_add_number = gencnt; | |
2220 | } | |
2221 | ||
5ac34ac3 | 2222 | if (op == O_constant) |
40324362 | 2223 | { |
44ce2f32 DE |
2224 | register valueT get; |
2225 | register valueT use; | |
2226 | register valueT mask; | |
2227 | register valueT unmask; | |
40324362 KR |
2228 | |
2229 | /* JF << of >= number of bits in the object is undefined. In | |
2230 | particular SPARC (Sun 4) has problems */ | |
44ce2f32 | 2231 | if (nbytes >= sizeof (valueT)) |
40324362 KR |
2232 | mask = 0; |
2233 | else | |
d2550c72 | 2234 | mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); /* Don't store these bits. */ |
6efd877d | 2235 | |
40324362 | 2236 | unmask = ~mask; /* Do store these bits. */ |
6efd877d | 2237 | |
40324362 KR |
2238 | #ifdef NEVER |
2239 | "Do this mod if you want every overflow check to assume SIGNED 2's complement data."; | |
2240 | mask = ~(unmask >> 1); /* Includes sign bit now. */ | |
2241 | #endif | |
6efd877d | 2242 | |
40324362 KR |
2243 | get = exp->X_add_number; |
2244 | use = get & unmask; | |
2245 | if ((get & mask) != 0 && (get & mask) != mask) | |
2246 | { /* Leading bits contain both 0s & 1s. */ | |
58d4951d | 2247 | as_warn ("Value 0x%lx truncated to 0x%lx.", get, use); |
40324362 | 2248 | } |
604633ae | 2249 | /* put bytes in right order. */ |
44ce2f32 | 2250 | md_number_to_chars (p, use, (int) nbytes); |
40324362 | 2251 | } |
80aab579 ILT |
2252 | else if (op == O_big) |
2253 | { | |
2254 | int size; | |
2255 | LITTLENUM_TYPE *nums; | |
2256 | ||
2257 | know (nbytes % CHARS_PER_LITTLENUM == 0); | |
2258 | ||
2259 | size = exp->X_add_number * CHARS_PER_LITTLENUM; | |
2260 | if (nbytes < size) | |
2261 | { | |
2262 | as_warn ("Bignum truncated to %d bytes", nbytes); | |
2263 | size = nbytes; | |
2264 | } | |
2265 | ||
2266 | if (target_big_endian) | |
2267 | { | |
2268 | while (nbytes > size) | |
2269 | { | |
2270 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
2271 | nbytes -= CHARS_PER_LITTLENUM; | |
2272 | p += CHARS_PER_LITTLENUM; | |
2273 | } | |
2274 | ||
2275 | nums = generic_bignum + size / CHARS_PER_LITTLENUM; | |
2276 | while (size > 0) | |
2277 | { | |
2278 | --nums; | |
2279 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
2280 | size -= CHARS_PER_LITTLENUM; | |
2281 | p += CHARS_PER_LITTLENUM; | |
2282 | } | |
2283 | } | |
2284 | else | |
2285 | { | |
2286 | nums = generic_bignum; | |
2287 | while (size > 0) | |
2288 | { | |
2289 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
2290 | ++nums; | |
2291 | size -= CHARS_PER_LITTLENUM; | |
2292 | p += CHARS_PER_LITTLENUM; | |
2293 | nbytes -= CHARS_PER_LITTLENUM; | |
2294 | } | |
2295 | ||
2296 | while (nbytes > 0) | |
2297 | { | |
2298 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
2299 | nbytes -= CHARS_PER_LITTLENUM; | |
2300 | p += CHARS_PER_LITTLENUM; | |
2301 | } | |
2302 | } | |
2303 | } | |
40324362 KR |
2304 | else |
2305 | { | |
1fbfe108 | 2306 | memset (p, 0, nbytes); |
6efd877d | 2307 | |
40324362 KR |
2308 | /* Now we need to generate a fixS to record the symbol value. |
2309 | This is easy for BFD. For other targets it can be more | |
2310 | complex. For very complex cases (currently, the HPPA and | |
2311 | NS32K), you can define TC_CONS_FIX_NEW to do whatever you | |
2312 | want. For simpler cases, you can define TC_CONS_RELOC to be | |
2313 | the name of the reloc code that should be stored in the fixS. | |
2314 | If neither is defined, the code uses NO_RELOC if it is | |
2315 | defined, and otherwise uses 0. */ | |
6efd877d | 2316 | |
40324362 | 2317 | #ifdef BFD_ASSEMBLER |
4064305e SS |
2318 | #ifdef TC_CONS_FIX_NEW |
2319 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
2320 | #else | |
604633ae | 2321 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 2322 | /* @@ Should look at CPU word size. */ |
ba71c54d KR |
2323 | nbytes == 2 ? BFD_RELOC_16 |
2324 | : nbytes == 8 ? BFD_RELOC_64 | |
2325 | : BFD_RELOC_32); | |
4064305e | 2326 | #endif |
40324362 KR |
2327 | #else |
2328 | #ifdef TC_CONS_FIX_NEW | |
2329 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
2330 | #else | |
2331 | /* Figure out which reloc number to use. Use TC_CONS_RELOC if | |
2332 | it is defined, otherwise use NO_RELOC if it is defined, | |
2333 | otherwise use 0. */ | |
2334 | #ifndef TC_CONS_RELOC | |
2335 | #ifdef NO_RELOC | |
2336 | #define TC_CONS_RELOC NO_RELOC | |
2337 | #else | |
2338 | #define TC_CONS_RELOC 0 | |
2339 | #endif | |
2340 | #endif | |
80aab579 | 2341 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 2342 | TC_CONS_RELOC); |
40324362 KR |
2343 | #endif /* TC_CONS_FIX_NEW */ |
2344 | #endif /* BFD_ASSEMBLER */ | |
2345 | } | |
2346 | } | |
2347 | \f | |
2348 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
6efd877d | 2349 | |
40324362 KR |
2350 | /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as |
2351 | w:x,y:z, where w and y are bitwidths and x and y are values. They | |
2352 | then pack them all together. We do a little better in that we allow | |
2353 | them in words, longs, etc. and we'll pack them in target byte order | |
2354 | for you. | |
6efd877d | 2355 | |
40324362 KR |
2356 | The rules are: pack least significat bit first, if a field doesn't |
2357 | entirely fit, put it in the next unit. Overflowing the bitfield is | |
2358 | explicitly *not* even a warning. The bitwidth should be considered | |
2359 | a "mask". | |
6efd877d | 2360 | |
40324362 KR |
2361 | To use this function the tc-XXX.h file should define |
2362 | BITFIELD_CONS_EXPRESSIONS. */ | |
f8701a3f | 2363 | |
40324362 KR |
2364 | static void |
2365 | parse_bitfield_cons (exp, nbytes) | |
2366 | expressionS *exp; | |
2367 | unsigned int nbytes; | |
2368 | { | |
2369 | unsigned int bits_available = BITS_PER_CHAR * nbytes; | |
2370 | char *hold = input_line_pointer; | |
f8701a3f | 2371 | |
5ac34ac3 | 2372 | (void) expression (exp); |
f8701a3f | 2373 | |
40324362 KR |
2374 | if (*input_line_pointer == ':') |
2375 | { /* bitfields */ | |
2376 | long value = 0; | |
f8701a3f | 2377 | |
40324362 KR |
2378 | for (;;) |
2379 | { | |
2380 | unsigned long width; | |
f8701a3f | 2381 | |
40324362 KR |
2382 | if (*input_line_pointer != ':') |
2383 | { | |
2384 | input_line_pointer = hold; | |
2385 | break; | |
2386 | } /* next piece is not a bitfield */ | |
2387 | ||
2388 | /* In the general case, we can't allow | |
2389 | full expressions with symbol | |
2390 | differences and such. The relocation | |
2391 | entries for symbols not defined in this | |
2392 | assembly would require arbitrary field | |
2393 | widths, positions, and masks which most | |
2394 | of our current object formats don't | |
2395 | support. | |
cd3b81bd | 2396 | |
40324362 KR |
2397 | In the specific case where a symbol |
2398 | *is* defined in this assembly, we | |
2399 | *could* build fixups and track it, but | |
2400 | this could lead to confusion for the | |
2401 | backends. I'm lazy. I'll take any | |
2402 | SEG_ABSOLUTE. I think that means that | |
2403 | you can use a previous .set or | |
2404 | .equ type symbol. xoxorich. */ | |
2405 | ||
5ac34ac3 | 2406 | if (exp->X_op == O_absent) |
6efd877d | 2407 | { |
5ac34ac3 | 2408 | as_warn ("using a bit field width of zero"); |
40324362 | 2409 | exp->X_add_number = 0; |
5ac34ac3 | 2410 | exp->X_op = O_constant; |
40324362 KR |
2411 | } /* implied zero width bitfield */ |
2412 | ||
5ac34ac3 | 2413 | if (exp->X_op != O_constant) |
6efd877d | 2414 | { |
40324362 | 2415 | *input_line_pointer = '\0'; |
5ac34ac3 | 2416 | as_bad ("field width \"%s\" too complex for a bitfield", hold); |
40324362 KR |
2417 | *input_line_pointer = ':'; |
2418 | demand_empty_rest_of_line (); | |
2419 | return; | |
2420 | } /* too complex */ | |
2421 | ||
2422 | if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes)) | |
9471a360 | 2423 | { |
80aab579 | 2424 | as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits", |
40324362 KR |
2425 | width, nbytes, (BITS_PER_CHAR * nbytes)); |
2426 | width = BITS_PER_CHAR * nbytes; | |
2427 | } /* too big */ | |
2428 | ||
2429 | if (width > bits_available) | |
9471a360 | 2430 | { |
40324362 KR |
2431 | /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */ |
2432 | input_line_pointer = hold; | |
2433 | exp->X_add_number = value; | |
2434 | break; | |
2435 | } /* won't fit */ | |
2436 | ||
2437 | hold = ++input_line_pointer; /* skip ':' */ | |
2438 | ||
5ac34ac3 ILT |
2439 | (void) expression (exp); |
2440 | if (exp->X_op != O_constant) | |
9471a360 | 2441 | { |
40324362 KR |
2442 | char cache = *input_line_pointer; |
2443 | ||
2444 | *input_line_pointer = '\0'; | |
5ac34ac3 | 2445 | as_bad ("field value \"%s\" too complex for a bitfield", hold); |
40324362 KR |
2446 | *input_line_pointer = cache; |
2447 | demand_empty_rest_of_line (); | |
2448 | return; | |
2449 | } /* too complex */ | |
2450 | ||
5ac34ac3 ILT |
2451 | value |= ((~(-1 << width) & exp->X_add_number) |
2452 | << ((BITS_PER_CHAR * nbytes) - bits_available)); | |
40324362 KR |
2453 | |
2454 | if ((bits_available -= width) == 0 | |
2455 | || is_it_end_of_statement () | |
2456 | || *input_line_pointer != ',') | |
2457 | { | |
2458 | break; | |
2459 | } /* all the bitfields we're gonna get */ | |
2460 | ||
2461 | hold = ++input_line_pointer; | |
5ac34ac3 | 2462 | (void) expression (exp); |
40324362 KR |
2463 | } /* forever loop */ |
2464 | ||
2465 | exp->X_add_number = value; | |
5ac34ac3 | 2466 | exp->X_op = O_constant; |
80aab579 | 2467 | exp->X_unsigned = 1; |
40324362 KR |
2468 | } /* if looks like a bitfield */ |
2469 | } /* parse_bitfield_cons() */ | |
2470 | ||
2471 | #endif /* BITFIELD_CONS_EXPRESSIONS */ | |
2472 | \f | |
1356d77d | 2473 | /* Handle an MRI style string expression. */ |
40324362 KR |
2474 | |
2475 | static void | |
2476 | parse_mri_cons (exp, nbytes) | |
2477 | expressionS *exp; | |
2478 | unsigned int nbytes; | |
2479 | { | |
1356d77d ILT |
2480 | if (*input_line_pointer != '\'' |
2481 | && (input_line_pointer[1] != '\'' | |
2482 | || (*input_line_pointer != 'A' | |
2483 | && *input_line_pointer != 'E'))) | |
2484 | TC_PARSE_CONS_EXPRESSION (exp, nbytes); | |
2485 | else | |
40324362 | 2486 | { |
40324362 KR |
2487 | int scan = 0; |
2488 | unsigned int result = 0; | |
1356d77d ILT |
2489 | |
2490 | /* An MRI style string. Cut into as many bytes as will fit into | |
2491 | a nbyte chunk, left justify if necessary, and separate with | |
2492 | commas so we can try again later. */ | |
2493 | if (*input_line_pointer == 'A') | |
2494 | ++input_line_pointer; | |
2495 | else if (*input_line_pointer == 'E') | |
2496 | { | |
2497 | as_bad ("EBCDIC constants are not supported"); | |
2498 | ++input_line_pointer; | |
2499 | } | |
2500 | ||
40324362 KR |
2501 | input_line_pointer++; |
2502 | for (scan = 0; scan < nbytes; scan++) | |
2503 | { | |
2504 | if (*input_line_pointer == '\'') | |
2505 | { | |
2506 | if (input_line_pointer[1] == '\'') | |
6efd877d | 2507 | { |
40324362 | 2508 | input_line_pointer++; |
f8701a3f | 2509 | } |
40324362 KR |
2510 | else |
2511 | break; | |
9471a360 | 2512 | } |
40324362 KR |
2513 | result = (result << 8) | (*input_line_pointer++); |
2514 | } | |
f8701a3f | 2515 | |
40324362 KR |
2516 | /* Left justify */ |
2517 | while (scan < nbytes) | |
2518 | { | |
2519 | result <<= 8; | |
2520 | scan++; | |
2521 | } | |
2522 | /* Create correct expression */ | |
5ac34ac3 | 2523 | exp->X_op = O_constant; |
40324362 | 2524 | exp->X_add_number = result; |
40324362 KR |
2525 | /* Fake it so that we can read the next char too */ |
2526 | if (input_line_pointer[0] != '\'' || | |
2527 | (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\'')) | |
2528 | { | |
2529 | input_line_pointer -= 2; | |
2530 | input_line_pointer[0] = ','; | |
2531 | input_line_pointer[1] = '\''; | |
2532 | } | |
2533 | else | |
2534 | input_line_pointer++; | |
2535 | } | |
40324362 | 2536 | } |
40324362 KR |
2537 | \f |
2538 | #ifdef REPEAT_CONS_EXPRESSIONS | |
2539 | ||
2540 | /* Parse a repeat expression for cons. This is used by the MIPS | |
2541 | assembler. The format is NUMBER:COUNT; NUMBER appears in the | |
2542 | object file COUNT times. | |
2543 | ||
2544 | To use this for a target, define REPEAT_CONS_EXPRESSIONS. */ | |
2545 | ||
2546 | static void | |
2547 | parse_repeat_cons (exp, nbytes) | |
2548 | expressionS *exp; | |
2549 | unsigned int nbytes; | |
2550 | { | |
2551 | expressionS count; | |
40324362 KR |
2552 | register int i; |
2553 | ||
2554 | expression (exp); | |
2555 | ||
2556 | if (*input_line_pointer != ':') | |
2557 | { | |
2558 | /* No repeat count. */ | |
2559 | return; | |
2560 | } | |
2561 | ||
2562 | ++input_line_pointer; | |
5ac34ac3 ILT |
2563 | expression (&count); |
2564 | if (count.X_op != O_constant | |
40324362 KR |
2565 | || count.X_add_number <= 0) |
2566 | { | |
2567 | as_warn ("Unresolvable or nonpositive repeat count; using 1"); | |
2568 | return; | |
2569 | } | |
2570 | ||
2571 | /* The cons function is going to output this expression once. So we | |
2572 | output it count - 1 times. */ | |
2573 | for (i = count.X_add_number - 1; i > 0; i--) | |
2574 | emit_expr (exp, nbytes); | |
2575 | } | |
2576 | ||
2577 | #endif /* REPEAT_CONS_EXPRESSIONS */ | |
fecd2382 | 2578 | \f |
e28c40d7 ILT |
2579 | /* Parse a floating point number represented as a hex constant. This |
2580 | permits users to specify the exact bits they want in the floating | |
2581 | point number. */ | |
2582 | ||
2583 | static int | |
2584 | hex_float (float_type, bytes) | |
2585 | int float_type; | |
2586 | char *bytes; | |
2587 | { | |
2588 | int length; | |
2589 | int i; | |
2590 | ||
2591 | switch (float_type) | |
2592 | { | |
2593 | case 'f': | |
2594 | case 'F': | |
2595 | case 's': | |
2596 | case 'S': | |
2597 | length = 4; | |
2598 | break; | |
2599 | ||
2600 | case 'd': | |
2601 | case 'D': | |
2602 | case 'r': | |
2603 | case 'R': | |
2604 | length = 8; | |
2605 | break; | |
2606 | ||
2607 | case 'x': | |
2608 | case 'X': | |
2609 | length = 12; | |
2610 | break; | |
2611 | ||
2612 | case 'p': | |
2613 | case 'P': | |
2614 | length = 12; | |
2615 | break; | |
2616 | ||
2617 | default: | |
2618 | as_bad ("Unknown floating type type '%c'", float_type); | |
2619 | return -1; | |
2620 | } | |
2621 | ||
2622 | /* It would be nice if we could go through expression to parse the | |
2623 | hex constant, but if we get a bignum it's a pain to sort it into | |
2624 | the buffer correctly. */ | |
2625 | i = 0; | |
2626 | while (hex_p (*input_line_pointer) || *input_line_pointer == '_') | |
2627 | { | |
2628 | int d; | |
2629 | ||
2630 | /* The MRI assembler accepts arbitrary underscores strewn about | |
2631 | through the hex constant, so we ignore them as well. */ | |
2632 | if (*input_line_pointer == '_') | |
2633 | { | |
2634 | ++input_line_pointer; | |
2635 | continue; | |
2636 | } | |
2637 | ||
2638 | if (i >= length) | |
2639 | { | |
2640 | as_warn ("Floating point constant too large"); | |
2641 | return -1; | |
2642 | } | |
2643 | d = hex_value (*input_line_pointer) << 4; | |
2644 | ++input_line_pointer; | |
2645 | while (*input_line_pointer == '_') | |
2646 | ++input_line_pointer; | |
2647 | if (hex_p (*input_line_pointer)) | |
2648 | { | |
2649 | d += hex_value (*input_line_pointer); | |
2650 | ++input_line_pointer; | |
2651 | } | |
2652 | bytes[i++] = d; | |
2653 | } | |
2654 | ||
2655 | if (i < length) | |
2656 | memset (bytes + i, 0, length - i); | |
2657 | ||
2658 | return length; | |
2659 | } | |
2660 | ||
fecd2382 RP |
2661 | /* |
2662 | * float_cons() | |
2663 | * | |
2664 | * CONStruct some more frag chars of .floats .ffloats etc. | |
2665 | * Makes 0 or more new frags. | |
2666 | * If need_pass_2 == 1, no frags are emitted. | |
2667 | * This understands only floating literals, not expressions. Sorry. | |
2668 | * | |
2669 | * A floating constant is defined by atof_generic(), except it is preceded | |
2670 | * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its | |
2671 | * reading, I decided to be incompatible. This always tries to give you | |
2672 | * rounded bits to the precision of the pseudo-op. Former AS did premature | |
2673 | * truncatation, restored noisy bits instead of trailing 0s AND gave you | |
2674 | * a choice of 2 flavours of noise according to which of 2 floating-point | |
2675 | * scanners you directed AS to use. | |
2676 | * | |
2677 | * In: input_line_pointer->whitespace before, or '0' of flonum. | |
2678 | * | |
2679 | */ | |
2680 | ||
ba71c54d KR |
2681 | void |
2682 | float_cons (float_type) | |
6efd877d | 2683 | /* Clobbers input_line-pointer, checks end-of-line. */ |
f8701a3f | 2684 | register int float_type; /* 'f':.ffloat ... 'F':.float ... */ |
fecd2382 | 2685 | { |
6efd877d | 2686 | register char *p; |
6efd877d KR |
2687 | int length; /* Number of chars in an object. */ |
2688 | register char *err; /* Error from scanning floating literal. */ | |
2689 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
f8701a3f | 2690 | |
6efd877d | 2691 | if (is_it_end_of_statement ()) |
f8701a3f | 2692 | { |
1e9cf565 ILT |
2693 | demand_empty_rest_of_line (); |
2694 | return; | |
f8701a3f | 2695 | } |
1e9cf565 ILT |
2696 | |
2697 | do | |
f8701a3f SC |
2698 | { |
2699 | /* input_line_pointer->1st char of a flonum (we hope!). */ | |
6efd877d | 2700 | SKIP_WHITESPACE (); |
1e9cf565 | 2701 | |
f8701a3f SC |
2702 | /* Skip any 0{letter} that may be present. Don't even check if the |
2703 | * letter is legal. Someone may invent a "z" format and this routine | |
2704 | * has no use for such information. Lusers beware: you get | |
2705 | * diagnostics if your input is ill-conditioned. | |
2706 | */ | |
6efd877d KR |
2707 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) |
2708 | input_line_pointer += 2; | |
f8701a3f | 2709 | |
1356d77d ILT |
2710 | /* Accept :xxxx, where the x's are hex digits, for a floating |
2711 | point with the exact digits specified. */ | |
2712 | if (input_line_pointer[0] == ':') | |
f8701a3f | 2713 | { |
e28c40d7 ILT |
2714 | ++input_line_pointer; |
2715 | length = hex_float (float_type, temp); | |
2716 | if (length < 0) | |
1356d77d | 2717 | { |
1356d77d ILT |
2718 | ignore_rest_of_line (); |
2719 | return; | |
2720 | } | |
1356d77d ILT |
2721 | } |
2722 | else | |
2723 | { | |
2724 | err = md_atof (float_type, temp, &length); | |
2725 | know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
2726 | know (length > 0); | |
2727 | if (err) | |
2728 | { | |
2729 | as_bad ("Bad floating literal: %s", err); | |
2730 | ignore_rest_of_line (); | |
2731 | return; | |
2732 | } | |
f8701a3f | 2733 | } |
1e9cf565 ILT |
2734 | |
2735 | if (!need_pass_2) | |
f8701a3f | 2736 | { |
1e9cf565 ILT |
2737 | int count; |
2738 | ||
2739 | count = 1; | |
2740 | ||
2741 | #ifdef REPEAT_CONS_EXPRESSIONS | |
2742 | if (*input_line_pointer == ':') | |
2743 | { | |
1e9cf565 ILT |
2744 | expressionS count_exp; |
2745 | ||
2746 | ++input_line_pointer; | |
5ac34ac3 ILT |
2747 | expression (&count_exp); |
2748 | if (count_exp.X_op != O_constant | |
1e9cf565 ILT |
2749 | || count_exp.X_add_number <= 0) |
2750 | { | |
5ac34ac3 | 2751 | as_warn ("unresolvable or nonpositive repeat count; using 1"); |
1e9cf565 ILT |
2752 | } |
2753 | else | |
2754 | count = count_exp.X_add_number; | |
2755 | } | |
2756 | #endif | |
2757 | ||
2758 | while (--count >= 0) | |
a39116f1 | 2759 | { |
f8701a3f | 2760 | p = frag_more (length); |
604633ae | 2761 | memcpy (p, temp, (unsigned int) length); |
a39116f1 | 2762 | } |
542e1629 | 2763 | } |
1e9cf565 | 2764 | SKIP_WHITESPACE (); |
f8701a3f | 2765 | } |
1e9cf565 ILT |
2766 | while (*input_line_pointer++ == ','); |
2767 | ||
2768 | --input_line_pointer; /* Put terminator back into stream. */ | |
6efd877d | 2769 | demand_empty_rest_of_line (); |
f8701a3f | 2770 | } /* float_cons() */ |
fecd2382 RP |
2771 | \f |
2772 | /* | |
2773 | * stringer() | |
2774 | * | |
2775 | * We read 0 or more ',' seperated, double-quoted strings. | |
2776 | * | |
2777 | * Caller should have checked need_pass_2 is FALSE because we don't check it. | |
2778 | */ | |
a39116f1 RP |
2779 | |
2780 | ||
6efd877d KR |
2781 | void |
2782 | stringer (append_zero) /* Worker to do .ascii etc statements. */ | |
2783 | /* Checks end-of-line. */ | |
f8701a3f | 2784 | register int append_zero; /* 0: don't append '\0', else 1 */ |
fecd2382 | 2785 | { |
f8701a3f | 2786 | register unsigned int c; |
6efd877d | 2787 | |
a2a5a4fa KR |
2788 | #ifdef md_flush_pending_output |
2789 | md_flush_pending_output (); | |
2790 | #endif | |
2791 | ||
f8701a3f SC |
2792 | /* |
2793 | * The following awkward logic is to parse ZERO or more strings, | |
2794 | * comma seperated. Recall a string expression includes spaces | |
2795 | * before the opening '\"' and spaces after the closing '\"'. | |
2796 | * We fake a leading ',' if there is (supposed to be) | |
2797 | * a 1st, expression. We keep demanding expressions for each | |
2798 | * ','. | |
2799 | */ | |
6efd877d KR |
2800 | if (is_it_end_of_statement ()) |
2801 | { | |
2802 | c = 0; /* Skip loop. */ | |
2803 | ++input_line_pointer; /* Compensate for end of loop. */ | |
2804 | } | |
f8701a3f | 2805 | else |
6efd877d KR |
2806 | { |
2807 | c = ','; /* Do loop. */ | |
2808 | } | |
2809 | while (c == ',' || c == '<' || c == '"') | |
2810 | { | |
2811 | SKIP_WHITESPACE (); | |
2812 | switch (*input_line_pointer) | |
2813 | { | |
2814 | case '\"': | |
2815 | ++input_line_pointer; /*->1st char of string. */ | |
2816 | while (is_a_char (c = next_char_of_string ())) | |
2817 | { | |
2818 | FRAG_APPEND_1_CHAR (c); | |
2819 | } | |
2820 | if (append_zero) | |
2821 | { | |
2822 | FRAG_APPEND_1_CHAR (0); | |
2823 | } | |
2824 | know (input_line_pointer[-1] == '\"'); | |
2825 | break; | |
2826 | case '<': | |
2827 | input_line_pointer++; | |
2828 | c = get_single_number (); | |
2829 | FRAG_APPEND_1_CHAR (c); | |
2830 | if (*input_line_pointer != '>') | |
2831 | { | |
2832 | as_bad ("Expected <nn>"); | |
2833 | } | |
2834 | input_line_pointer++; | |
2835 | break; | |
2836 | case ',': | |
2837 | input_line_pointer++; | |
2838 | break; | |
2839 | } | |
2840 | SKIP_WHITESPACE (); | |
2841 | c = *input_line_pointer; | |
f8701a3f | 2842 | } |
f8701a3f | 2843 | |
6efd877d KR |
2844 | demand_empty_rest_of_line (); |
2845 | } /* stringer() */ | |
fecd2382 | 2846 | \f |
6efd877d | 2847 | /* FIXME-SOMEDAY: I had trouble here on characters with the |
f8701a3f SC |
2848 | high bits set. We'll probably also have trouble with |
2849 | multibyte chars, wide chars, etc. Also be careful about | |
2850 | returning values bigger than 1 byte. xoxorich. */ | |
fecd2382 | 2851 | |
6efd877d KR |
2852 | unsigned int |
2853 | next_char_of_string () | |
2854 | { | |
2855 | register unsigned int c; | |
2856 | ||
2857 | c = *input_line_pointer++ & CHAR_MASK; | |
2858 | switch (c) | |
2859 | { | |
2860 | case '\"': | |
2861 | c = NOT_A_CHAR; | |
2862 | break; | |
2863 | ||
ddb393cf | 2864 | #ifndef NO_STRING_ESCAPES |
6efd877d KR |
2865 | case '\\': |
2866 | switch (c = *input_line_pointer++) | |
2867 | { | |
2868 | case 'b': | |
2869 | c = '\b'; | |
2870 | break; | |
2871 | ||
2872 | case 'f': | |
2873 | c = '\f'; | |
2874 | break; | |
2875 | ||
2876 | case 'n': | |
2877 | c = '\n'; | |
2878 | break; | |
2879 | ||
2880 | case 'r': | |
2881 | c = '\r'; | |
2882 | break; | |
2883 | ||
2884 | case 't': | |
2885 | c = '\t'; | |
2886 | break; | |
2887 | ||
6efd877d KR |
2888 | case 'v': |
2889 | c = '\013'; | |
2890 | break; | |
6efd877d KR |
2891 | |
2892 | case '\\': | |
2893 | case '"': | |
2894 | break; /* As itself. */ | |
2895 | ||
2896 | case '0': | |
2897 | case '1': | |
2898 | case '2': | |
2899 | case '3': | |
2900 | case '4': | |
2901 | case '5': | |
2902 | case '6': | |
2903 | case '7': | |
2904 | case '8': | |
2905 | case '9': | |
2906 | { | |
2907 | long number; | |
d4c8cbd8 | 2908 | int i; |
6efd877d | 2909 | |
d4c8cbd8 | 2910 | for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++) |
6efd877d KR |
2911 | { |
2912 | number = number * 8 + c - '0'; | |
2913 | } | |
2914 | c = number & 0xff; | |
2915 | } | |
2916 | --input_line_pointer; | |
2917 | break; | |
2918 | ||
d4c8cbd8 JL |
2919 | case 'x': |
2920 | case 'X': | |
2921 | { | |
2922 | long number; | |
2923 | ||
2924 | number = 0; | |
2925 | c = *input_line_pointer++; | |
2926 | while (isxdigit (c)) | |
2927 | { | |
2928 | if (isdigit (c)) | |
2929 | number = number * 16 + c - '0'; | |
2930 | else if (isupper (c)) | |
2931 | number = number * 16 + c - 'A' + 10; | |
2932 | else | |
2933 | number = number * 16 + c - 'a' + 10; | |
2934 | c = *input_line_pointer++; | |
2935 | } | |
2936 | c = number & 0xff; | |
2937 | --input_line_pointer; | |
2938 | } | |
2939 | break; | |
2940 | ||
6efd877d KR |
2941 | case '\n': |
2942 | /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */ | |
2943 | as_warn ("Unterminated string: Newline inserted."); | |
2944 | c = '\n'; | |
2945 | break; | |
2946 | ||
2947 | default: | |
2948 | ||
fecd2382 | 2949 | #ifdef ONLY_STANDARD_ESCAPES |
6efd877d KR |
2950 | as_bad ("Bad escaped character in string, '?' assumed"); |
2951 | c = '?'; | |
fecd2382 | 2952 | #endif /* ONLY_STANDARD_ESCAPES */ |
6efd877d KR |
2953 | |
2954 | break; | |
2955 | } /* switch on escaped char */ | |
2956 | break; | |
ddb393cf | 2957 | #endif /* ! defined (NO_STRING_ESCAPES) */ |
6efd877d KR |
2958 | |
2959 | default: | |
2960 | break; | |
2961 | } /* switch on char */ | |
2962 | return (c); | |
2963 | } /* next_char_of_string() */ | |
fecd2382 RP |
2964 | \f |
2965 | static segT | |
f8701a3f | 2966 | get_segmented_expression (expP) |
6efd877d | 2967 | register expressionS *expP; |
fecd2382 | 2968 | { |
6efd877d | 2969 | register segT retval; |
f8701a3f | 2970 | |
9471a360 | 2971 | retval = expression (expP); |
5ac34ac3 ILT |
2972 | if (expP->X_op == O_illegal |
2973 | || expP->X_op == O_absent | |
2974 | || expP->X_op == O_big) | |
f8701a3f | 2975 | { |
5ac34ac3 ILT |
2976 | as_bad ("expected address expression; zero assumed"); |
2977 | expP->X_op = O_constant; | |
6efd877d | 2978 | expP->X_add_number = 0; |
5ac34ac3 | 2979 | retval = absolute_section; |
f8701a3f | 2980 | } |
5ac34ac3 | 2981 | return retval; |
fecd2382 RP |
2982 | } |
2983 | ||
6efd877d KR |
2984 | static segT |
2985 | get_known_segmented_expression (expP) | |
2986 | register expressionS *expP; | |
fecd2382 | 2987 | { |
6efd877d | 2988 | register segT retval; |
f8701a3f | 2989 | |
9471a360 | 2990 | if ((retval = get_segmented_expression (expP)) == undefined_section) |
f8701a3f | 2991 | { |
5ac34ac3 ILT |
2992 | /* There is no easy way to extract the undefined symbol from the |
2993 | expression. */ | |
2994 | if (expP->X_add_symbol != NULL | |
2995 | && S_GET_SEGMENT (expP->X_add_symbol) != expr_section) | |
2996 | as_warn ("symbol \"%s\" undefined; zero assumed", | |
2997 | S_GET_NAME (expP->X_add_symbol)); | |
f8701a3f | 2998 | else |
5ac34ac3 ILT |
2999 | as_warn ("some symbol undefined; zero assumed"); |
3000 | retval = absolute_section; | |
3001 | expP->X_op = O_constant; | |
6efd877d | 3002 | expP->X_add_number = 0; |
f8701a3f | 3003 | } |
5ac34ac3 | 3004 | know (retval == absolute_section || SEG_NORMAL (retval)); |
f8701a3f | 3005 | return (retval); |
fecd2382 RP |
3006 | } /* get_known_segmented_expression() */ |
3007 | ||
58d4951d | 3008 | offsetT |
f8701a3f | 3009 | get_absolute_expression () |
fecd2382 | 3010 | { |
6efd877d | 3011 | expressionS exp; |
f8701a3f | 3012 | |
5ac34ac3 ILT |
3013 | expression (&exp); |
3014 | if (exp.X_op != O_constant) | |
f8701a3f | 3015 | { |
5ac34ac3 | 3016 | if (exp.X_op != O_absent) |
cd3b81bd | 3017 | as_bad ("bad or irreducible absolute expression; zero assumed"); |
6efd877d | 3018 | exp.X_add_number = 0; |
f8701a3f | 3019 | } |
5ac34ac3 | 3020 | return exp.X_add_number; |
fecd2382 RP |
3021 | } |
3022 | ||
6efd877d KR |
3023 | char /* return terminator */ |
3024 | get_absolute_expression_and_terminator (val_pointer) | |
3025 | long *val_pointer; /* return value of expression */ | |
fecd2382 | 3026 | { |
58d4951d ILT |
3027 | /* FIXME: val_pointer should probably be offsetT *. */ |
3028 | *val_pointer = (long) get_absolute_expression (); | |
6efd877d | 3029 | return (*input_line_pointer++); |
fecd2382 RP |
3030 | } |
3031 | \f | |
3032 | /* | |
3033 | * demand_copy_C_string() | |
3034 | * | |
3035 | * Like demand_copy_string, but return NULL if the string contains any '\0's. | |
3036 | * Give a warning if that happens. | |
3037 | */ | |
3038 | char * | |
f8701a3f | 3039 | demand_copy_C_string (len_pointer) |
6efd877d | 3040 | int *len_pointer; |
fecd2382 | 3041 | { |
6efd877d | 3042 | register char *s; |
f8701a3f | 3043 | |
6efd877d | 3044 | if ((s = demand_copy_string (len_pointer)) != 0) |
f8701a3f SC |
3045 | { |
3046 | register int len; | |
3047 | ||
6efd877d | 3048 | for (len = *len_pointer; |
f8701a3f SC |
3049 | len > 0; |
3050 | len--) | |
3051 | { | |
6efd877d | 3052 | if (*s == 0) |
fecd2382 | 3053 | { |
f8701a3f SC |
3054 | s = 0; |
3055 | len = 1; | |
6efd877d KR |
3056 | *len_pointer = 0; |
3057 | as_bad ("This string may not contain \'\\0\'"); | |
fecd2382 | 3058 | } |
f8701a3f SC |
3059 | } |
3060 | } | |
3061 | return (s); | |
fecd2382 RP |
3062 | } |
3063 | \f | |
3064 | /* | |
3065 | * demand_copy_string() | |
3066 | * | |
3067 | * Demand string, but return a safe (=private) copy of the string. | |
3068 | * Return NULL if we can't read a string here. | |
3069 | */ | |
6ef37255 | 3070 | char * |
6efd877d KR |
3071 | demand_copy_string (lenP) |
3072 | int *lenP; | |
fecd2382 | 3073 | { |
6efd877d KR |
3074 | register unsigned int c; |
3075 | register int len; | |
3076 | char *retval; | |
3077 | ||
3078 | len = 0; | |
3079 | SKIP_WHITESPACE (); | |
3080 | if (*input_line_pointer == '\"') | |
3081 | { | |
3082 | input_line_pointer++; /* Skip opening quote. */ | |
3083 | ||
3084 | while (is_a_char (c = next_char_of_string ())) | |
3085 | { | |
3086 | obstack_1grow (¬es, c); | |
3087 | len++; | |
fecd2382 | 3088 | } |
6efd877d KR |
3089 | /* JF this next line is so demand_copy_C_string will return a null |
3090 | termanated string. */ | |
3091 | obstack_1grow (¬es, '\0'); | |
3092 | retval = obstack_finish (¬es); | |
3093 | } | |
3094 | else | |
3095 | { | |
3096 | as_warn ("Missing string"); | |
3097 | retval = NULL; | |
3098 | ignore_rest_of_line (); | |
3099 | } | |
3100 | *lenP = len; | |
3101 | return (retval); | |
3102 | } /* demand_copy_string() */ | |
fecd2382 RP |
3103 | \f |
3104 | /* | |
3105 | * is_it_end_of_statement() | |
3106 | * | |
3107 | * In: Input_line_pointer->next character. | |
3108 | * | |
3109 | * Do: Skip input_line_pointer over all whitespace. | |
3110 | * | |
3111 | * Out: 1 if input_line_pointer->end-of-line. | |
f8701a3f | 3112 | */ |
6efd877d KR |
3113 | int |
3114 | is_it_end_of_statement () | |
3115 | { | |
3116 | SKIP_WHITESPACE (); | |
58d4951d | 3117 | return (is_end_of_line[(unsigned char) *input_line_pointer]); |
6efd877d | 3118 | } /* is_it_end_of_statement() */ |
fecd2382 | 3119 | |
6efd877d KR |
3120 | void |
3121 | equals (sym_name) | |
3122 | char *sym_name; | |
fecd2382 | 3123 | { |
6efd877d | 3124 | register symbolS *symbolP; /* symbol we are working with */ |
f8701a3f SC |
3125 | |
3126 | input_line_pointer++; | |
6efd877d | 3127 | if (*input_line_pointer == '=') |
f8701a3f SC |
3128 | input_line_pointer++; |
3129 | ||
6efd877d | 3130 | while (*input_line_pointer == ' ' || *input_line_pointer == '\t') |
f8701a3f SC |
3131 | input_line_pointer++; |
3132 | ||
6efd877d KR |
3133 | if (sym_name[0] == '.' && sym_name[1] == '\0') |
3134 | { | |
3135 | /* Turn '. = mumble' into a .org mumble */ | |
3136 | register segT segment; | |
3137 | expressionS exp; | |
3138 | register char *p; | |
f8701a3f | 3139 | |
6efd877d KR |
3140 | segment = get_known_segmented_expression (&exp); |
3141 | if (!need_pass_2) | |
e28c40d7 | 3142 | do_org (segment, &exp, 0); |
6efd877d KR |
3143 | } |
3144 | else | |
3145 | { | |
3146 | symbolP = symbol_find_or_make (sym_name); | |
3147 | pseudo_set (symbolP); | |
3148 | } | |
3149 | } /* equals() */ | |
fecd2382 RP |
3150 | |
3151 | /* .include -- include a file at this point. */ | |
3152 | ||
3153 | /* ARGSUSED */ | |
6efd877d KR |
3154 | void |
3155 | s_include (arg) | |
3156 | int arg; | |
fecd2382 | 3157 | { |
f8701a3f SC |
3158 | char *newbuf; |
3159 | char *filename; | |
3160 | int i; | |
3161 | FILE *try; | |
3162 | char *path; | |
3163 | ||
6efd877d KR |
3164 | filename = demand_copy_string (&i); |
3165 | demand_empty_rest_of_line (); | |
604633ae | 3166 | path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ ); |
6efd877d KR |
3167 | for (i = 0; i < include_dir_count; i++) |
3168 | { | |
3169 | strcpy (path, include_dirs[i]); | |
3170 | strcat (path, "/"); | |
3171 | strcat (path, filename); | |
f2889110 | 3172 | if (0 != (try = fopen (path, "r"))) |
6efd877d KR |
3173 | { |
3174 | fclose (try); | |
3175 | goto gotit; | |
3176 | } | |
3177 | } | |
3178 | free (path); | |
f8701a3f SC |
3179 | path = filename; |
3180 | gotit: | |
3181 | /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */ | |
3182 | newbuf = input_scrub_include_file (path, input_line_pointer); | |
3183 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
6efd877d | 3184 | } /* s_include() */ |
fecd2382 | 3185 | |
6efd877d KR |
3186 | void |
3187 | add_include_dir (path) | |
3188 | char *path; | |
fecd2382 | 3189 | { |
f8701a3f SC |
3190 | int i; |
3191 | ||
3192 | if (include_dir_count == 0) | |
3193 | { | |
6efd877d | 3194 | include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs)); |
f8701a3f SC |
3195 | include_dirs[0] = "."; /* Current dir */ |
3196 | include_dir_count = 2; | |
3197 | } | |
3198 | else | |
3199 | { | |
3200 | include_dir_count++; | |
6efd877d KR |
3201 | include_dirs = (char **) realloc (include_dirs, |
3202 | include_dir_count * sizeof (*include_dirs)); | |
f8701a3f SC |
3203 | } |
3204 | ||
6efd877d | 3205 | include_dirs[include_dir_count - 1] = path; /* New one */ |
f8701a3f | 3206 | |
6efd877d KR |
3207 | i = strlen (path); |
3208 | if (i > include_dir_maxlen) | |
3209 | include_dir_maxlen = i; | |
3210 | } /* add_include_dir() */ | |
fecd2382 | 3211 | |
6efd877d KR |
3212 | void |
3213 | s_ignore (arg) | |
3214 | int arg; | |
fecd2382 | 3215 | { |
58d4951d | 3216 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
3217 | { |
3218 | ++input_line_pointer; | |
3219 | } | |
3220 | ++input_line_pointer; | |
4064305e SS |
3221 | } |
3222 | ||
604633ae | 3223 | |
fecd2382 | 3224 | /* end of read.c */ |