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