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