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