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