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