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