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