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