Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* read.c - read a source file - |
a986926b | 2 | Copyright (C) 1986, 87, 90, 91, 92, 93, 94, 95, 96, 1997 |
ddb393cf | 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 | |
8ff75001 ILT |
18 | along with GAS; see the file COPYING. If not, write to the Free |
19 | Software Foundation, 59 Temple Place - Suite 330, Boston, MA | |
20 | 02111-1307, USA. */ | |
fecd2382 | 21 | |
016e0d42 | 22 | #if 0 |
fecd2382 RP |
23 | #define MASK_CHAR (0xFF) /* If your chars aren't 8 bits, you will |
24 | change this a bit. But then, GNU isn't | |
25 | spozed to run on your machine anyway. | |
26 | (RMS is so shortsighted sometimes.) | |
27 | */ | |
016e0d42 ILT |
28 | #else |
29 | #define MASK_CHAR ((int)(unsigned char)-1) | |
30 | #endif | |
fecd2382 | 31 | |
9a7d824a | 32 | |
9471a360 KR |
33 | /* This is the largest known floating point format (for now). It will |
34 | grow when we do 4361 style flonums. */ | |
fecd2382 | 35 | |
9471a360 | 36 | #define MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT (16) |
fecd2382 | 37 | |
016e0d42 ILT |
38 | /* Routines that read assembler source text to build spagetti in memory. |
39 | Another group of these functions is in the expr.c module. */ | |
fecd2382 | 40 | |
9471a360 | 41 | /* for isdigit() */ |
6efd877d KR |
42 | #include <ctype.h> |
43 | ||
fecd2382 | 44 | #include "as.h" |
9471a360 | 45 | #include "subsegs.h" |
7e047ac2 ILT |
46 | #include "sb.h" |
47 | #include "macro.h" | |
fecd2382 | 48 | #include "obstack.h" |
9a7d824a | 49 | #include "listing.h" |
a69e5977 | 50 | #include "ecoff.h" |
9a7d824a | 51 | |
9a7d824a ILT |
52 | #ifndef TC_START_LABEL |
53 | #define TC_START_LABEL(x,y) (x==':') | |
54 | #endif | |
fecd2382 | 55 | |
016e0d42 ILT |
56 | /* The NOP_OPCODE is for the alignment fill value. |
57 | * fill it a nop instruction so that the disassembler does not choke | |
58 | * on it | |
59 | */ | |
60 | #ifndef NOP_OPCODE | |
61 | #define NOP_OPCODE 0x00 | |
62 | #endif | |
63 | ||
64 | char *input_line_pointer; /*->next char of source file to parse. */ | |
fecd2382 | 65 | |
326d16ca | 66 | int generate_asm_lineno = 0; /* flag to generate line stab for .s file */ |
daad3bbf | 67 | |
fecd2382 | 68 | #if BITS_PER_CHAR != 8 |
6efd877d KR |
69 | /* The following table is indexed by[(char)] and will break if |
70 | a char does not have exactly 256 states (hopefully 0:255!)! */ | |
71 | die horribly; | |
fecd2382 | 72 | #endif |
f8701a3f | 73 | |
c978e704 ILT |
74 | #ifndef LEX_AT |
75 | /* The m88k unfortunately uses @ as a label beginner. */ | |
76 | #define LEX_AT 0 | |
77 | #endif | |
78 | ||
ddb393cf ILT |
79 | #ifndef LEX_BR |
80 | /* The RS/6000 assembler uses {,},[,] as parts of symbol names. */ | |
81 | #define LEX_BR 0 | |
82 | #endif | |
83 | ||
6ef37255 KR |
84 | #ifndef LEX_PCT |
85 | /* The Delta 68k assembler permits % inside label names. */ | |
86 | #define LEX_PCT 0 | |
87 | #endif | |
88 | ||
18c9057f ILT |
89 | #ifndef LEX_QM |
90 | /* The PowerPC Windows NT assemblers permits ? inside label names. */ | |
91 | #define LEX_QM 0 | |
92 | #endif | |
93 | ||
6594d6b9 KR |
94 | #ifndef LEX_DOLLAR |
95 | /* The a29k assembler does not permits labels to start with $. */ | |
96 | #define LEX_DOLLAR 3 | |
97 | #endif | |
98 | ||
151c3ec0 ILT |
99 | #ifndef LEX_TILDE |
100 | /* The Delta 68k assembler permits ~ at start of label names. */ | |
101 | #define LEX_TILDE 0 | |
102 | #endif | |
103 | ||
016e0d42 | 104 | /* used by is_... macros. our ctype[] */ |
1356d77d | 105 | char lex_type[256] = |
016e0d42 ILT |
106 | { |
107 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ABCDEFGHIJKLMNO */ | |
108 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* PQRSTUVWXYZ[\]^_ */ | |
6594d6b9 | 109 | 0, 0, 0, 0, LEX_DOLLAR, LEX_PCT, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, /* _!"#$%&'()*+,-./ */ |
18c9057f | 110 | 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, LEX_QM, /* 0123456789:;<=>? */ |
c978e704 | 111 | LEX_AT, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* @ABCDEFGHIJKLMNO */ |
ddb393cf | 112 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, 0, 3, /* PQRSTUVWXYZ[\]^_ */ |
016e0d42 | 113 | 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* `abcdefghijklmno */ |
151c3ec0 | 114 | 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, LEX_BR, 0, LEX_BR, LEX_TILDE, 0, /* pqrstuvwxyz{|}~. */ |
016e0d42 ILT |
115 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, |
116 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
117 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
118 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
119 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
120 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
121 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | |
122 | }; | |
123 | ||
124 | ||
125 | /* | |
fecd2382 RP |
126 | * In: a character. |
127 | * Out: 1 if this character ends a line. | |
128 | */ | |
129 | #define _ (0) | |
016e0d42 ILT |
130 | char is_end_of_line[256] = |
131 | { | |
fecd2382 | 132 | #ifdef CR_EOL |
016e0d42 | 133 | _, _, _, _, _, _, _, _, _, _, 99, _, _, 99, _, _, /* @abcdefghijklmno */ |
fecd2382 | 134 | #else |
016e0d42 | 135 | _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, _, /* @abcdefghijklmno */ |
fecd2382 | 136 | #endif |
016e0d42 | 137 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
40324362 KR |
138 | #ifdef TC_HPPA |
139 | _,99, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* _!"#$%&'()*+,-./ */ | |
140 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* 0123456789:;<=>? */ | |
141 | #else | |
016e0d42 ILT |
142 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
143 | _, _, _, _, _, _, _, _, _, _, _, 99, _, _, _, _, /* 0123456789:;<=>? */ | |
40324362 | 144 | #endif |
016e0d42 ILT |
145 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ |
146 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
147 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
148 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
149 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
150 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
151 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
152 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
153 | _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, /* */ | |
154 | }; | |
fecd2382 RP |
155 | #undef _ |
156 | ||
016e0d42 ILT |
157 | /* Functions private to this file. */ |
158 | ||
159 | static char *buffer; /* 1st char of each buffer of lines is here. */ | |
160 | static char *buffer_limit; /*->1 + last char in buffer. */ | |
fecd2382 | 161 | |
d428c89f ILT |
162 | /* TARGET_BYTES_BIG_ENDIAN is required to be defined to either 0 or 1 in the |
163 | tc-<CPU>.h file. See the "Porting GAS" section of the internals manual. */ | |
2209b19c | 164 | int target_big_endian = TARGET_BYTES_BIG_ENDIAN; |
9c6d3f66 | 165 | |
9471a360 | 166 | static char *old_buffer; /* JF a hack */ |
016e0d42 ILT |
167 | static char *old_input; |
168 | static char *old_limit; | |
fecd2382 | 169 | |
016e0d42 | 170 | /* Variables for handling include file directory list. */ |
fecd2382 | 171 | |
016e0d42 ILT |
172 | char **include_dirs; /* List of pointers to directories to |
173 | search for .include's */ | |
174 | int include_dir_count; /* How many are in the list */ | |
175 | int include_dir_maxlen = 1;/* Length of longest in list */ | |
fecd2382 RP |
176 | |
177 | #ifndef WORKING_DOT_WORD | |
016e0d42 | 178 | struct broken_word *broken_words; |
9471a360 | 179 | int new_broken_words; |
fecd2382 RP |
180 | #endif |
181 | ||
e28c40d7 ILT |
182 | /* The current offset into the absolute section. We don't try to |
183 | build frags in the absolute section, since no data can be stored | |
184 | there. We just keep track of the current offset. */ | |
185 | addressT abs_section_offset; | |
186 | ||
1356d77d ILT |
187 | /* If this line had an MRI style label, it is stored in this variable. |
188 | This is used by some of the MRI pseudo-ops. */ | |
7e047ac2 | 189 | symbolS *line_label; |
1356d77d ILT |
190 | |
191 | /* This global variable is used to support MRI common sections. We | |
192 | translate such sections into a common symbol. This variable is | |
193 | non-NULL when we are in an MRI common section. */ | |
194 | symbolS *mri_common_symbol; | |
195 | ||
286cb27a ILT |
196 | /* In MRI mode, after a dc.b pseudo-op with an odd number of bytes, we |
197 | need to align to an even byte boundary unless the next pseudo-op is | |
198 | dc.b, ds.b, or dcb.b. This variable is set to 1 if an alignment | |
199 | may be needed. */ | |
200 | static int mri_pending_align; | |
201 | ||
86038ada | 202 | static int scrub_from_string PARAMS ((char **)); |
d428c89f ILT |
203 | static void do_align PARAMS ((int, char *, int, int)); |
204 | static void s_align PARAMS ((int, int)); | |
e28c40d7 ILT |
205 | static int hex_float PARAMS ((int, char *)); |
206 | static void do_org PARAMS ((segT, expressionS *, int)); | |
6ef37255 | 207 | char *demand_copy_string PARAMS ((int *lenP)); |
5ac34ac3 | 208 | static segT get_segmented_expression PARAMS ((expressionS *expP)); |
016e0d42 | 209 | static segT get_known_segmented_expression PARAMS ((expressionS * expP)); |
016e0d42 | 210 | static void pobegin PARAMS ((void)); |
7e047ac2 | 211 | static int get_line_sb PARAMS ((sb *)); |
fecd2382 | 212 | \f |
6efd877d | 213 | |
016e0d42 ILT |
214 | void |
215 | read_begin () | |
fecd2382 | 216 | { |
016e0d42 | 217 | const char *p; |
f8701a3f | 218 | |
6efd877d KR |
219 | pobegin (); |
220 | obj_read_begin_hook (); | |
f8701a3f | 221 | |
4380166d KR |
222 | /* Something close -- but not too close -- to a multiple of 1024. |
223 | The debugging malloc I'm using has 24 bytes of overhead. */ | |
6594d6b9 KR |
224 | obstack_begin (¬es, chunksize); |
225 | obstack_begin (&cond_obstack, chunksize); | |
f8701a3f | 226 | |
f8701a3f SC |
227 | /* Use machine dependent syntax */ |
228 | for (p = line_separator_chars; *p; p++) | |
58d4951d | 229 | is_end_of_line[(unsigned char) *p] = 1; |
f8701a3f | 230 | /* Use more. FIXME-SOMEDAY. */ |
1356d77d ILT |
231 | |
232 | if (flag_mri) | |
233 | lex_type['?'] = 3; | |
fecd2382 RP |
234 | } |
235 | \f | |
236 | /* set up pseudo-op tables */ | |
237 | ||
1356d77d | 238 | static struct hash_control *po_hash; |
fecd2382 | 239 | |
016e0d42 | 240 | static const pseudo_typeS potable[] = |
fecd2382 | 241 | { |
6efd877d KR |
242 | {"abort", s_abort, 0}, |
243 | {"align", s_align_ptwo, 0}, | |
244 | {"ascii", stringer, 0}, | |
245 | {"asciz", stringer, 1}, | |
931a8fab | 246 | {"balign", s_align_bytes, 0}, |
4080c270 ILT |
247 | {"balignw", s_align_bytes, -2}, |
248 | {"balignl", s_align_bytes, -4}, | |
f8701a3f | 249 | /* block */ |
6efd877d KR |
250 | {"byte", cons, 1}, |
251 | {"comm", s_comm, 0}, | |
1356d77d ILT |
252 | {"common", s_mri_common, 0}, |
253 | {"common.s", s_mri_common, 1}, | |
6efd877d | 254 | {"data", s_data, 0}, |
1356d77d ILT |
255 | {"dc", cons, 2}, |
256 | {"dc.b", cons, 1}, | |
257 | {"dc.d", float_cons, 'd'}, | |
258 | {"dc.l", cons, 4}, | |
259 | {"dc.s", float_cons, 'f'}, | |
260 | {"dc.w", cons, 2}, | |
261 | {"dc.x", float_cons, 'x'}, | |
e28c40d7 ILT |
262 | {"dcb", s_space, 2}, |
263 | {"dcb.b", s_space, 1}, | |
264 | {"dcb.d", s_float_space, 'd'}, | |
265 | {"dcb.l", s_space, 4}, | |
266 | {"dcb.s", s_float_space, 'f'}, | |
267 | {"dcb.w", s_space, 2}, | |
268 | {"dcb.x", s_float_space, 'x'}, | |
1356d77d ILT |
269 | {"ds", s_space, 2}, |
270 | {"ds.b", s_space, 1}, | |
e28c40d7 | 271 | {"ds.d", s_space, 8}, |
1356d77d | 272 | {"ds.l", s_space, 4}, |
e28c40d7 ILT |
273 | {"ds.p", s_space, 12}, |
274 | {"ds.s", s_space, 4}, | |
1356d77d | 275 | {"ds.w", s_space, 2}, |
e28c40d7 | 276 | {"ds.x", s_space, 12}, |
42ac8fa8 | 277 | {"debug", s_ignore, 0}, |
604633ae | 278 | #ifdef S_SET_DESC |
4064305e | 279 | {"desc", s_desc, 0}, |
604633ae | 280 | #endif |
f8701a3f | 281 | /* dim */ |
6efd877d | 282 | {"double", float_cons, 'd'}, |
f8701a3f | 283 | /* dsect */ |
6efd877d KR |
284 | {"eject", listing_eject, 0}, /* Formfeed listing */ |
285 | {"else", s_else, 0}, | |
e28c40d7 | 286 | {"elsec", s_else, 0}, |
6efd877d | 287 | {"end", s_end, 0}, |
e28c40d7 | 288 | {"endc", s_endif, 0}, |
6efd877d | 289 | {"endif", s_endif, 0}, |
f8701a3f | 290 | /* endef */ |
6efd877d | 291 | {"equ", s_set, 0}, |
42ac8fa8 | 292 | {"err", s_err, 0}, |
7e047ac2 | 293 | {"exitm", s_mexit, 0}, |
f8701a3f | 294 | /* extend */ |
6efd877d | 295 | {"extern", s_ignore, 0}, /* We treat all undef as ext */ |
9a7d824a ILT |
296 | {"appfile", s_app_file, 1}, |
297 | {"appline", s_app_line, 0}, | |
e28c40d7 | 298 | {"fail", s_fail, 0}, |
6efd877d KR |
299 | {"file", s_app_file, 0}, |
300 | {"fill", s_fill, 0}, | |
301 | {"float", float_cons, 'f'}, | |
e28c40d7 | 302 | {"format", s_ignore, 0}, |
6efd877d KR |
303 | {"global", s_globl, 0}, |
304 | {"globl", s_globl, 0}, | |
305 | {"hword", cons, 2}, | |
e28c40d7 | 306 | {"if", s_if, (int) O_ne}, |
7e047ac2 | 307 | {"ifc", s_ifc, 0}, |
6efd877d | 308 | {"ifdef", s_ifdef, 0}, |
e28c40d7 | 309 | {"ifeq", s_if, (int) O_eq}, |
6efd877d | 310 | {"ifeqs", s_ifeqs, 0}, |
e28c40d7 ILT |
311 | {"ifge", s_if, (int) O_ge}, |
312 | {"ifgt", s_if, (int) O_gt}, | |
313 | {"ifle", s_if, (int) O_le}, | |
314 | {"iflt", s_if, (int) O_lt}, | |
7e047ac2 | 315 | {"ifnc", s_ifc, 1}, |
6efd877d | 316 | {"ifndef", s_ifdef, 1}, |
e28c40d7 | 317 | {"ifne", s_if, (int) O_ne}, |
6efd877d KR |
318 | {"ifnes", s_ifeqs, 1}, |
319 | {"ifnotdef", s_ifdef, 1}, | |
320 | {"include", s_include, 0}, | |
321 | {"int", cons, 4}, | |
7e047ac2 | 322 | {"irp", s_irp, 0}, |
42ac8fa8 | 323 | {"irep", s_irp, 0}, |
7e047ac2 | 324 | {"irpc", s_irp, 1}, |
42ac8fa8 | 325 | {"irepc", s_irp, 1}, |
6efd877d KR |
326 | {"lcomm", s_lcomm, 0}, |
327 | {"lflags", listing_flags, 0}, /* Listing flags */ | |
7d3741ed | 328 | {"linkonce", s_linkonce, 0}, |
6efd877d | 329 | {"list", listing_list, 1}, /* Turn listing on */ |
e28c40d7 | 330 | {"llen", listing_psize, 1}, |
6efd877d KR |
331 | {"long", cons, 4}, |
332 | {"lsym", s_lsym, 0}, | |
7e047ac2 ILT |
333 | {"macro", s_macro, 0}, |
334 | {"mexit", s_mexit, 0}, | |
20710f1c ILT |
335 | {"mri", s_mri, 0}, |
336 | {".mri", s_mri, 0}, /* Special case so .mri works in MRI mode. */ | |
cef72a92 | 337 | {"name", s_ignore, 0}, |
e28c40d7 | 338 | {"noformat", s_ignore, 0}, |
6efd877d | 339 | {"nolist", listing_list, 0}, /* Turn listing off */ |
69e077f3 | 340 | {"nopage", listing_nopage, 0}, |
80aab579 | 341 | {"octa", cons, 16}, |
e28c40d7 | 342 | {"offset", s_struct, 0}, |
6efd877d | 343 | {"org", s_org, 0}, |
931a8fab | 344 | {"p2align", s_align_ptwo, 0}, |
4080c270 ILT |
345 | {"p2alignw", s_align_ptwo, -2}, |
346 | {"p2alignl", s_align_ptwo, -4}, | |
69e077f3 ILT |
347 | {"page", listing_eject, 0}, |
348 | {"plen", listing_psize, 0}, | |
42ac8fa8 | 349 | {"print", s_print, 0}, |
6efd877d | 350 | {"psize", listing_psize, 0}, /* set paper size */ |
42ac8fa8 | 351 | {"purgem", s_purgem, 0}, |
80aab579 | 352 | {"quad", cons, 8}, |
42ac8fa8 | 353 | {"rep", s_rept, 0}, |
7e047ac2 | 354 | {"rept", s_rept, 0}, |
86038ada | 355 | {"rva", s_rva, 4}, |
6efd877d | 356 | {"sbttl", listing_title, 1}, /* Subtitle of listing */ |
f8701a3f SC |
357 | /* scl */ |
358 | /* sect */ | |
6efd877d KR |
359 | {"set", s_set, 0}, |
360 | {"short", cons, 2}, | |
361 | {"single", float_cons, 'f'}, | |
f8701a3f | 362 | /* size */ |
6efd877d | 363 | {"space", s_space, 0}, |
adeab39b | 364 | {"skip", s_space, 0}, |
e14994d9 | 365 | {"spc", s_ignore, 0}, |
4064305e SS |
366 | {"stabd", s_stab, 'd'}, |
367 | {"stabn", s_stab, 'n'}, | |
368 | {"stabs", s_stab, 's'}, | |
ba71c54d | 369 | {"string", stringer, 1}, |
e28c40d7 | 370 | {"struct", s_struct, 0}, |
f8701a3f | 371 | /* tag */ |
6efd877d | 372 | {"text", s_text, 0}, |
6ef37255 KR |
373 | |
374 | /* This is for gcc to use. It's only just been added (2/94), so gcc | |
375 | won't be able to use it for a while -- probably a year or more. | |
376 | But once this has been released, check with gcc maintainers | |
377 | before deleting it or even changing the spelling. */ | |
378 | {"this_GCC_requires_the_GNU_assembler", s_ignore, 0}, | |
379 | /* If we're folding case -- done for some targets, not necessarily | |
380 | all -- the above string in an input file will be converted to | |
381 | this one. Match it either way... */ | |
382 | {"this_gcc_requires_the_gnu_assembler", s_ignore, 0}, | |
383 | ||
6efd877d | 384 | {"title", listing_title, 0}, /* Listing title */ |
e14994d9 | 385 | {"ttl", listing_title, 0}, |
f8701a3f SC |
386 | /* type */ |
387 | /* use */ | |
388 | /* val */ | |
e14994d9 | 389 | {"xcom", s_comm, 0}, |
1356d77d | 390 | {"xdef", s_globl, 0}, |
e14994d9 | 391 | {"xref", s_ignore, 0}, |
4064305e | 392 | {"xstabs", s_xstab, 's'}, |
6efd877d | 393 | {"word", cons, 2}, |
c02fd8dc | 394 | {"zero", s_space, 0}, |
6efd877d | 395 | {NULL} /* end sentinel */ |
fecd2382 RP |
396 | }; |
397 | ||
2209b19c KR |
398 | static int pop_override_ok = 0; |
399 | static const char *pop_table_name; | |
400 | ||
401 | void | |
402 | pop_insert (table) | |
403 | const pseudo_typeS *table; | |
6efd877d | 404 | { |
2209b19c | 405 | const char *errtxt; |
6efd877d | 406 | const pseudo_typeS *pop; |
2209b19c KR |
407 | for (pop = table; pop->poc_name; pop++) |
408 | { | |
409 | errtxt = hash_insert (po_hash, pop->poc_name, (char *) pop); | |
410 | if (errtxt && (!pop_override_ok || strcmp (errtxt, "exists"))) | |
6594d6b9 KR |
411 | as_fatal ("error constructing %s pseudo-op table: %s", pop_table_name, |
412 | errtxt); | |
2209b19c KR |
413 | } |
414 | } | |
6efd877d | 415 | |
2209b19c KR |
416 | #ifndef md_pop_insert |
417 | #define md_pop_insert() pop_insert(md_pseudo_table) | |
418 | #endif | |
419 | ||
420 | #ifndef obj_pop_insert | |
421 | #define obj_pop_insert() pop_insert(obj_pseudo_table) | |
422 | #endif | |
423 | ||
424 | static void | |
425 | pobegin () | |
426 | { | |
6efd877d KR |
427 | po_hash = hash_new (); |
428 | ||
429 | /* Do the target-specific pseudo ops. */ | |
2209b19c KR |
430 | pop_table_name = "md"; |
431 | md_pop_insert (); | |
6efd877d KR |
432 | |
433 | /* Now object specific. Skip any that were in the target table. */ | |
2209b19c KR |
434 | pop_table_name = "obj"; |
435 | pop_override_ok = 1; | |
436 | obj_pop_insert (); | |
6efd877d KR |
437 | |
438 | /* Now portable ones. Skip any that we've seen already. */ | |
2209b19c KR |
439 | pop_table_name = "standard"; |
440 | pop_insert (potable); | |
441 | } | |
fecd2382 | 442 | \f |
58d4951d ILT |
443 | #define HANDLE_CONDITIONAL_ASSEMBLY() \ |
444 | if (ignore_input ()) \ | |
445 | { \ | |
446 | while (! is_end_of_line[(unsigned char) *input_line_pointer++]) \ | |
447 | if (input_line_pointer == buffer_limit) \ | |
448 | break; \ | |
449 | continue; \ | |
f8701a3f | 450 | } |
a39116f1 | 451 | |
fecd2382 | 452 | |
86038ada ILT |
453 | /* This function is used when scrubbing the characters between #APP |
454 | and #NO_APP. */ | |
455 | ||
456 | static char *scrub_string; | |
457 | static char *scrub_string_end; | |
458 | ||
459 | static int | |
460 | scrub_from_string (from) | |
461 | char **from; | |
462 | { | |
463 | int size; | |
464 | ||
465 | *from = scrub_string; | |
466 | size = scrub_string_end - scrub_string; | |
467 | scrub_string = scrub_string_end; | |
468 | return size; | |
469 | } | |
470 | ||
fecd2382 RP |
471 | /* read_a_source_file() |
472 | * | |
473 | * We read the file, putting things into a web that | |
474 | * represents what we have been reading. | |
475 | */ | |
6efd877d KR |
476 | void |
477 | read_a_source_file (name) | |
478 | char *name; | |
fecd2382 | 479 | { |
f8701a3f | 480 | register char c; |
6efd877d | 481 | register char *s; /* string of symbol, '\0' appended */ |
f8701a3f | 482 | register int temp; |
6efd877d | 483 | pseudo_typeS *pop; |
f8701a3f | 484 | |
6efd877d | 485 | buffer = input_scrub_new_file (name); |
f8701a3f | 486 | |
6efd877d KR |
487 | listing_file (name); |
488 | listing_newline (""); | |
f8701a3f | 489 | |
6efd877d KR |
490 | while ((buffer_limit = input_scrub_next_buffer (&input_line_pointer)) != 0) |
491 | { /* We have another line to parse. */ | |
492 | know (buffer_limit[-1] == '\n'); /* Must have a sentinel. */ | |
9471a360 KR |
493 | contin: /* JF this goto is my fault I admit it. |
494 | Someone brave please re-write the whole | |
495 | input section here? Pleeze??? */ | |
6efd877d | 496 | while (input_line_pointer < buffer_limit) |
9471a360 KR |
497 | { |
498 | /* We have more of this buffer to parse. */ | |
f8701a3f SC |
499 | |
500 | /* | |
501 | * We now have input_line_pointer->1st char of next line. | |
502 | * If input_line_pointer [-1] == '\n' then we just | |
503 | * scanned another line: so bump line counters. | |
504 | */ | |
d2550c72 | 505 | if (is_end_of_line[(unsigned char) input_line_pointer[-1]]) |
6efd877d | 506 | { |
a2a5a4fa KR |
507 | #ifdef md_start_line_hook |
508 | md_start_line_hook (); | |
509 | #endif | |
510 | ||
385ce433 JL |
511 | if (input_line_pointer[-1] == '\n') |
512 | bump_line_counters (); | |
f8701a3f | 513 | |
7e047ac2 ILT |
514 | line_label = NULL; |
515 | ||
cef72a92 | 516 | if (flag_m68k_mri |
1356d77d ILT |
517 | #ifdef LABELS_WITHOUT_COLONS |
518 | || 1 | |
519 | #endif | |
520 | ) | |
6efd877d | 521 | { |
1356d77d ILT |
522 | /* Text at the start of a line must be a label, we |
523 | run down and stick a colon in. */ | |
524 | if (is_name_beginner (*input_line_pointer)) | |
525 | { | |
526 | char *line_start = input_line_pointer; | |
7e047ac2 | 527 | char c; |
8ff75001 | 528 | int mri_line_macro; |
7e047ac2 | 529 | |
d428c89f | 530 | LISTING_NEWLINE (); |
7e047ac2 | 531 | HANDLE_CONDITIONAL_ASSEMBLY (); |
1356d77d | 532 | |
7e047ac2 ILT |
533 | c = get_symbol_end (); |
534 | ||
8ff75001 ILT |
535 | /* In MRI mode, the EQU and MACRO pseudoops must |
536 | be handled specially. */ | |
537 | mri_line_macro = 0; | |
cef72a92 | 538 | if (flag_m68k_mri) |
1356d77d | 539 | { |
7e047ac2 ILT |
540 | char *rest = input_line_pointer + 1; |
541 | ||
542 | if (*rest == ':') | |
543 | ++rest; | |
544 | if (*rest == ' ' || *rest == '\t') | |
545 | ++rest; | |
546 | if ((strncasecmp (rest, "EQU", 3) == 0 | |
547 | || strncasecmp (rest, "SET", 3) == 0) | |
548 | && (rest[3] == ' ' || rest[3] == '\t')) | |
1356d77d | 549 | { |
7e047ac2 | 550 | input_line_pointer = rest + 3; |
d428c89f ILT |
551 | equals (line_start, |
552 | strncasecmp (rest, "SET", 3) == 0); | |
7e047ac2 | 553 | continue; |
1356d77d | 554 | } |
8ff75001 ILT |
555 | if (strncasecmp (rest, "MACRO", 5) == 0 |
556 | && (rest[5] == ' ' | |
557 | || rest[5] == '\t' | |
558 | || is_end_of_line[(unsigned char) rest[5]])) | |
559 | mri_line_macro = 1; | |
1356d77d | 560 | } |
6efd877d | 561 | |
8ff75001 ILT |
562 | /* In MRI mode, we need to handle the MACRO |
563 | pseudo-op specially: we don't want to put the | |
564 | symbol in the symbol table. */ | |
565 | if (! mri_line_macro) | |
566 | line_label = colon (line_start); | |
567 | else | |
568 | line_label = symbol_create (line_start, | |
569 | absolute_section, | |
570 | (valueT) 0, | |
571 | &zero_address_frag); | |
7e047ac2 | 572 | |
1356d77d ILT |
573 | *input_line_pointer = c; |
574 | if (c == ':') | |
575 | input_line_pointer++; | |
576 | } | |
6efd877d | 577 | } |
9471a360 | 578 | } |
f8701a3f | 579 | |
f8701a3f SC |
580 | /* |
581 | * We are at the begining of a line, or similar place. | |
582 | * We expect a well-formed assembler statement. | |
583 | * A "symbol-name:" is a statement. | |
584 | * | |
585 | * Depending on what compiler is used, the order of these tests | |
586 | * may vary to catch most common case 1st. | |
587 | * Each test is independent of all other tests at the (top) level. | |
588 | * PLEASE make a compiler that doesn't use this assembler. | |
589 | * It is crufty to waste a compiler's time encoding things for this | |
590 | * assembler, which then wastes more time decoding it. | |
591 | * (And communicating via (linear) files is silly! | |
592 | * If you must pass stuff, please pass a tree!) | |
593 | */ | |
9471a360 KR |
594 | if ((c = *input_line_pointer++) == '\t' |
595 | || c == ' ' | |
596 | || c == '\f' | |
597 | || c == 0) | |
6efd877d KR |
598 | { |
599 | c = *input_line_pointer++; | |
600 | } | |
601 | know (c != ' '); /* No further leading whitespace. */ | |
602 | LISTING_NEWLINE (); | |
f8701a3f SC |
603 | /* |
604 | * C is the 1st significant character. | |
605 | * Input_line_pointer points after that character. | |
606 | */ | |
6efd877d | 607 | if (is_name_beginner (c)) |
6ef37255 KR |
608 | { |
609 | /* want user-defined label or pseudo/opcode */ | |
6efd877d KR |
610 | HANDLE_CONDITIONAL_ASSEMBLY (); |
611 | ||
f8701a3f | 612 | s = --input_line_pointer; |
6efd877d | 613 | c = get_symbol_end (); /* name's delimiter */ |
f8701a3f SC |
614 | /* |
615 | * C is character after symbol. | |
616 | * That character's place in the input line is now '\0'. | |
617 | * S points to the beginning of the symbol. | |
618 | * [In case of pseudo-op, s->'.'.] | |
619 | * Input_line_pointer->'\0' where c was. | |
620 | */ | |
9a7d824a | 621 | if (TC_START_LABEL(c, input_line_pointer)) |
6efd877d | 622 | { |
cef72a92 | 623 | if (flag_m68k_mri) |
7e047ac2 ILT |
624 | { |
625 | char *rest = input_line_pointer + 1; | |
626 | ||
627 | /* In MRI mode, \tsym: set 0 is permitted. */ | |
628 | ||
629 | if (*rest == ':') | |
630 | ++rest; | |
631 | if (*rest == ' ' || *rest == '\t') | |
632 | ++rest; | |
633 | if ((strncasecmp (rest, "EQU", 3) == 0 | |
634 | || strncasecmp (rest, "SET", 3) == 0) | |
635 | && (rest[3] == ' ' || rest[3] == '\t')) | |
636 | { | |
637 | input_line_pointer = rest + 3; | |
d428c89f | 638 | equals (s, 1); |
7e047ac2 ILT |
639 | continue; |
640 | } | |
641 | } | |
642 | ||
643 | line_label = colon (s); /* user-defined label */ | |
6efd877d | 644 | *input_line_pointer++ = ':'; /* Put ':' back for error messages' sake. */ |
f8701a3f | 645 | /* Input_line_pointer->after ':'. */ |
6efd877d KR |
646 | SKIP_WHITESPACE (); |
647 | ||
f8701a3f | 648 | |
6efd877d | 649 | } |
4064305e | 650 | else if (c == '=' |
a6b200da ILT |
651 | || ((c == ' ' || c == '\t') |
652 | && input_line_pointer[1] == '=' | |
4064305e SS |
653 | #ifdef TC_EQUAL_IN_INSN |
654 | && ! TC_EQUAL_IN_INSN (c, input_line_pointer) | |
655 | #endif | |
656 | )) | |
9c6d3f66 | 657 | { |
d428c89f | 658 | equals (s, 1); |
6efd877d KR |
659 | demand_empty_rest_of_line (); |
660 | } | |
661 | else | |
662 | { /* expect pseudo-op or machine instruction */ | |
8ff6f40e ILT |
663 | pop = NULL; |
664 | ||
d4c8cbd8 JL |
665 | #define IGNORE_OPCODE_CASE |
666 | #ifdef IGNORE_OPCODE_CASE | |
667 | { | |
668 | char *s2 = s; | |
669 | while (*s2) | |
670 | { | |
671 | if (isupper (*s2)) | |
672 | *s2 = tolower (*s2); | |
673 | s2++; | |
674 | } | |
675 | } | |
676 | #endif | |
677 | ||
cef72a92 | 678 | if (flag_m68k_mri |
8ff6f40e | 679 | #ifdef NO_PSEUDO_DOT |
1356d77d | 680 | || 1 |
8ff6f40e | 681 | #endif |
1356d77d ILT |
682 | ) |
683 | { | |
684 | /* The MRI assembler and the m88k use pseudo-ops | |
685 | without a period. */ | |
686 | pop = (pseudo_typeS *) hash_find (po_hash, s); | |
687 | if (pop != NULL && pop->poc_handler == NULL) | |
688 | pop = NULL; | |
689 | } | |
8ff6f40e | 690 | |
7e047ac2 | 691 | if (pop != NULL |
cef72a92 | 692 | || (! flag_m68k_mri && *s == '.')) |
6efd877d KR |
693 | { |
694 | /* | |
9471a360 KR |
695 | * PSEUDO - OP. |
696 | * | |
697 | * WARNING: c has next char, which may be end-of-line. | |
698 | * We lookup the pseudo-op table with s+1 because we | |
699 | * already know that the pseudo-op begins with a '.'. | |
700 | */ | |
6efd877d | 701 | |
8ff6f40e ILT |
702 | if (pop == NULL) |
703 | pop = (pseudo_typeS *) hash_find (po_hash, s + 1); | |
6efd877d | 704 | |
286cb27a ILT |
705 | /* In MRI mode, we may need to insert an |
706 | automatic alignment directive. What a hack | |
707 | this is. */ | |
708 | if (mri_pending_align | |
709 | && (pop == NULL | |
710 | || ! ((pop->poc_handler == cons | |
711 | && pop->poc_val == 1) | |
712 | || (pop->poc_handler == s_space | |
a986926b ILT |
713 | && pop->poc_val == 1) |
714 | #ifdef tc_conditional_pseudoop | |
715 | || tc_conditional_pseudoop (pop) | |
716 | #endif | |
717 | || pop->poc_handler == s_if | |
718 | || pop->poc_handler == s_ifdef | |
719 | || pop->poc_handler == s_ifc | |
720 | || pop->poc_handler == s_ifeqs | |
721 | || pop->poc_handler == s_else | |
a75abb6f ILT |
722 | || pop->poc_handler == s_endif |
723 | || pop->poc_handler == s_globl | |
724 | || pop->poc_handler == s_ignore))) | |
286cb27a | 725 | { |
d428c89f | 726 | do_align (1, (char *) NULL, 0, 0); |
286cb27a | 727 | mri_pending_align = 0; |
a6b200da ILT |
728 | if (line_label != NULL) |
729 | { | |
730 | line_label->sy_frag = frag_now; | |
731 | S_SET_VALUE (line_label, frag_now_fix ()); | |
732 | } | |
286cb27a ILT |
733 | } |
734 | ||
6efd877d | 735 | /* Print the error msg now, while we still can */ |
8ff6f40e | 736 | if (pop == NULL) |
6efd877d KR |
737 | { |
738 | as_bad ("Unknown pseudo-op: `%s'", s); | |
f8701a3f | 739 | *input_line_pointer = c; |
6efd877d | 740 | s_ignore (0); |
46b81190 | 741 | continue; |
6efd877d KR |
742 | } |
743 | ||
744 | /* Put it back for error messages etc. */ | |
745 | *input_line_pointer = c; | |
9c6d3f66 KR |
746 | /* The following skip of whitespace is compulsory. |
747 | A well shaped space is sometimes all that separates | |
748 | keyword from operands. */ | |
6efd877d | 749 | if (c == ' ' || c == '\t') |
d4c8cbd8 | 750 | input_line_pointer++; |
6efd877d | 751 | /* |
9471a360 KR |
752 | * Input_line is restored. |
753 | * Input_line_pointer->1st non-blank char | |
754 | * after pseudo-operation. | |
755 | */ | |
46b81190 | 756 | (*pop->poc_handler) (pop->poc_val); |
e28c40d7 ILT |
757 | |
758 | /* If that was .end, just get out now. */ | |
759 | if (pop->poc_handler == s_end) | |
760 | goto quit; | |
6efd877d KR |
761 | } |
762 | else | |
20868ec6 | 763 | { |
4026c122 ILT |
764 | int inquote = 0; |
765 | ||
6efd877d KR |
766 | /* WARNING: c has char, which may be end-of-line. */ |
767 | /* Also: input_line_pointer->`\0` where c was. */ | |
768 | *input_line_pointer = c; | |
58d4951d | 769 | while (!is_end_of_line[(unsigned char) *input_line_pointer] |
4026c122 | 770 | || inquote |
4064305e SS |
771 | #ifdef TC_EOL_IN_INSN |
772 | || TC_EOL_IN_INSN (input_line_pointer) | |
773 | #endif | |
774 | ) | |
6efd877d | 775 | { |
cef72a92 | 776 | if (flag_m68k_mri && *input_line_pointer == '\'') |
4026c122 | 777 | inquote = ! inquote; |
6efd877d KR |
778 | input_line_pointer++; |
779 | } | |
f8701a3f | 780 | |
6efd877d KR |
781 | c = *input_line_pointer; |
782 | *input_line_pointer = '\0'; | |
f8701a3f | 783 | |
326d16ca KH |
784 | #ifdef OBJ_GENERATE_ASM_LINENO |
785 | if (generate_asm_lineno == 0) | |
786 | { | |
f10a96cb | 787 | if (ecoff_no_current_file ()) |
326d16ca KH |
788 | generate_asm_lineno = 1; |
789 | } | |
f10a96cb ILT |
790 | if (generate_asm_lineno == 1) |
791 | { | |
1b434ced ILT |
792 | unsigned int lineno; |
793 | char *s; | |
794 | ||
daad3bbf | 795 | as_where (&s, &lineno); |
326d16ca | 796 | OBJ_GENERATE_ASM_LINENO (s, lineno); |
f10a96cb | 797 | } |
daad3bbf KH |
798 | #endif |
799 | ||
7e047ac2 ILT |
800 | if (macro_defined) |
801 | { | |
802 | sb out; | |
803 | const char *err; | |
804 | ||
805 | if (check_macro (s, &out, '\0', &err)) | |
806 | { | |
807 | if (err != NULL) | |
808 | as_bad (err); | |
809 | *input_line_pointer++ = c; | |
810 | input_scrub_include_sb (&out, | |
811 | input_line_pointer); | |
812 | sb_kill (&out); | |
813 | buffer_limit = | |
814 | input_scrub_next_buffer (&input_line_pointer); | |
815 | continue; | |
816 | } | |
817 | } | |
818 | ||
20868ec6 ILT |
819 | if (mri_pending_align) |
820 | { | |
d428c89f | 821 | do_align (1, (char *) NULL, 0, 0); |
20868ec6 | 822 | mri_pending_align = 0; |
a6b200da ILT |
823 | if (line_label != NULL) |
824 | { | |
825 | line_label->sy_frag = frag_now; | |
826 | S_SET_VALUE (line_label, frag_now_fix ()); | |
827 | } | |
20868ec6 ILT |
828 | } |
829 | ||
6efd877d | 830 | md_assemble (s); /* Assemble 1 instruction. */ |
f8701a3f | 831 | |
6efd877d | 832 | *input_line_pointer++ = c; |
f8701a3f | 833 | |
d4c8cbd8 JL |
834 | /* We resume loop AFTER the end-of-line from |
835 | this instruction. */ | |
6efd877d | 836 | } /* if (*s=='.') */ |
6efd877d | 837 | } /* if c==':' */ |
f8701a3f | 838 | continue; |
6efd877d | 839 | } /* if (is_name_beginner(c) */ |
f8701a3f | 840 | |
f8701a3f | 841 | |
d4c8cbd8 | 842 | /* Empty statement? */ |
58d4951d | 843 | if (is_end_of_line[(unsigned char) c]) |
d4c8cbd8 | 844 | continue; |
6efd877d | 845 | |
9777b772 KR |
846 | if ((LOCAL_LABELS_DOLLAR || LOCAL_LABELS_FB) |
847 | && isdigit (c)) | |
d4c8cbd8 JL |
848 | { |
849 | /* local label ("4:") */ | |
6efd877d KR |
850 | char *backup = input_line_pointer; |
851 | ||
852 | HANDLE_CONDITIONAL_ASSEMBLY (); | |
853 | ||
854 | temp = c - '0'; | |
855 | ||
856 | while (isdigit (*input_line_pointer)) | |
857 | { | |
858 | temp = (temp * 10) + *input_line_pointer - '0'; | |
859 | ++input_line_pointer; | |
860 | } /* read the whole number */ | |
861 | ||
9777b772 KR |
862 | if (LOCAL_LABELS_DOLLAR |
863 | && *input_line_pointer == '$' | |
6efd877d KR |
864 | && *(input_line_pointer + 1) == ':') |
865 | { | |
866 | input_line_pointer += 2; | |
867 | ||
868 | if (dollar_label_defined (temp)) | |
869 | { | |
870 | as_fatal ("label \"%d$\" redefined", temp); | |
871 | } | |
872 | ||
873 | define_dollar_label (temp); | |
874 | colon (dollar_label_name (temp, 0)); | |
875 | continue; | |
876 | } | |
6efd877d | 877 | |
9777b772 KR |
878 | if (LOCAL_LABELS_FB |
879 | && *input_line_pointer++ == ':') | |
6efd877d KR |
880 | { |
881 | fb_label_instance_inc (temp); | |
882 | colon (fb_label_name (temp, 0)); | |
883 | continue; | |
884 | } | |
6efd877d KR |
885 | |
886 | input_line_pointer = backup; | |
887 | } /* local label ("4:") */ | |
f8701a3f | 888 | |
6efd877d KR |
889 | if (c && strchr (line_comment_chars, c)) |
890 | { /* Its a comment. Better say APP or NO_APP */ | |
f8701a3f SC |
891 | char *ends; |
892 | char *new_buf; | |
893 | char *new_tmp; | |
604633ae | 894 | unsigned int new_length; |
f8701a3f | 895 | char *tmp_buf = 0; |
6efd877d KR |
896 | |
897 | bump_line_counters (); | |
898 | s = input_line_pointer; | |
899 | if (strncmp (s, "APP\n", 4)) | |
900 | continue; /* We ignore it */ | |
901 | s += 4; | |
902 | ||
903 | ends = strstr (s, "#NO_APP\n"); | |
904 | ||
905 | if (!ends) | |
906 | { | |
604633ae ILT |
907 | unsigned int tmp_len; |
908 | unsigned int num; | |
6efd877d | 909 | |
f8701a3f SC |
910 | /* The end of the #APP wasn't in this buffer. We |
911 | keep reading in buffers until we find the #NO_APP | |
912 | that goes with this #APP There is one. The specs | |
913 | guarentee it. . . */ | |
6efd877d | 914 | tmp_len = buffer_limit - s; |
85825401 | 915 | tmp_buf = xmalloc (tmp_len + 1); |
4380166d | 916 | memcpy (tmp_buf, s, tmp_len); |
6efd877d KR |
917 | do |
918 | { | |
919 | new_tmp = input_scrub_next_buffer (&buffer); | |
f8701a3f | 920 | if (!new_tmp) |
6efd877d | 921 | break; |
f8701a3f | 922 | else |
6efd877d | 923 | buffer_limit = new_tmp; |
f8701a3f | 924 | input_line_pointer = buffer; |
6efd877d | 925 | ends = strstr (buffer, "#NO_APP\n"); |
f8701a3f | 926 | if (ends) |
6efd877d | 927 | num = ends - buffer; |
f8701a3f | 928 | else |
6efd877d KR |
929 | num = buffer_limit - buffer; |
930 | ||
931 | tmp_buf = xrealloc (tmp_buf, tmp_len + num); | |
9eb5f4b8 | 932 | memcpy (tmp_buf + tmp_len, buffer, num); |
6efd877d KR |
933 | tmp_len += num; |
934 | } | |
935 | while (!ends); | |
936 | ||
937 | input_line_pointer = ends ? ends + 8 : NULL; | |
938 | ||
939 | s = tmp_buf; | |
940 | ends = s + tmp_len; | |
941 | ||
942 | } | |
943 | else | |
944 | { | |
945 | input_line_pointer = ends + 8; | |
946 | } | |
6efd877d KR |
947 | |
948 | scrub_string = s; | |
86038ada ILT |
949 | scrub_string_end = ends; |
950 | ||
951 | new_length = ends - s; | |
952 | new_buf = (char *) xmalloc (new_length); | |
953 | new_tmp = new_buf; | |
6efd877d KR |
954 | for (;;) |
955 | { | |
86038ada ILT |
956 | int space; |
957 | int size; | |
f8701a3f | 958 | |
86038ada ILT |
959 | space = (new_buf + new_length) - new_tmp; |
960 | size = do_scrub_chars (scrub_from_string, new_tmp, space); | |
961 | ||
962 | if (size < space) | |
6efd877d | 963 | { |
86038ada ILT |
964 | new_tmp += size; |
965 | break; | |
f8701a3f | 966 | } |
86038ada ILT |
967 | |
968 | new_buf = xrealloc (new_buf, new_length + 100); | |
969 | new_tmp = new_buf + new_length; | |
970 | new_length += 100; | |
fecd2382 | 971 | } |
f8701a3f SC |
972 | |
973 | if (tmp_buf) | |
6efd877d KR |
974 | free (tmp_buf); |
975 | old_buffer = buffer; | |
976 | old_input = input_line_pointer; | |
977 | old_limit = buffer_limit; | |
978 | buffer = new_buf; | |
979 | input_line_pointer = new_buf; | |
980 | buffer_limit = new_tmp; | |
f8701a3f SC |
981 | continue; |
982 | } | |
983 | ||
6efd877d | 984 | HANDLE_CONDITIONAL_ASSEMBLY (); |
f8701a3f | 985 | |
cef72a92 ILT |
986 | #ifdef tc_unrecognized_line |
987 | if (tc_unrecognized_line (c)) | |
988 | continue; | |
989 | #endif | |
990 | ||
f8701a3f SC |
991 | /* as_warn("Junk character %d.",c); Now done by ignore_rest */ |
992 | input_line_pointer--; /* Report unknown char as ignored. */ | |
6efd877d KR |
993 | ignore_rest_of_line (); |
994 | } /* while (input_line_pointer<buffer_limit) */ | |
a2a5a4fa KR |
995 | |
996 | #ifdef md_after_pass_hook | |
997 | md_after_pass_hook (); | |
998 | #endif | |
999 | ||
6efd877d KR |
1000 | if (old_buffer) |
1001 | { | |
86038ada | 1002 | free (buffer); |
6efd877d KR |
1003 | bump_line_counters (); |
1004 | if (old_input != 0) | |
1005 | { | |
1006 | buffer = old_buffer; | |
1007 | input_line_pointer = old_input; | |
1008 | buffer_limit = old_limit; | |
f8701a3f SC |
1009 | old_buffer = 0; |
1010 | goto contin; | |
1011 | } | |
1012 | } | |
6efd877d | 1013 | } /* while (more buffers to scan) */ |
f8701a3f | 1014 | |
e28c40d7 | 1015 | quit: |
20868ec6 ILT |
1016 | |
1017 | #ifdef md_cleanup | |
1018 | md_cleanup(); | |
1019 | #endif | |
e28c40d7 | 1020 | input_scrub_close (); /* Close the input file */ |
4075afe1 | 1021 | } |
fecd2382 | 1022 | |
18c9057f ILT |
1023 | /* For most MRI pseudo-ops, the line actually ends at the first |
1024 | nonquoted space. This function looks for that point, stuffs a null | |
1025 | in, and sets *STOPCP to the character that used to be there, and | |
42ac8fa8 ILT |
1026 | returns the location. |
1027 | ||
1028 | Until I hear otherwise, I am going to assume that this is only true | |
1029 | for the m68k MRI assembler. */ | |
18c9057f ILT |
1030 | |
1031 | char * | |
1032 | mri_comment_field (stopcp) | |
1033 | char *stopcp; | |
1034 | { | |
42ac8fa8 ILT |
1035 | #ifdef TC_M68K |
1036 | ||
18c9057f ILT |
1037 | char *s; |
1038 | int inquote = 0; | |
1039 | ||
cef72a92 | 1040 | know (flag_m68k_mri); |
18c9057f ILT |
1041 | |
1042 | for (s = input_line_pointer; | |
1043 | ((! is_end_of_line[(unsigned char) *s] && *s != ' ' && *s != '\t') | |
1044 | || inquote); | |
1045 | s++) | |
1046 | { | |
1047 | if (*s == '\'') | |
1048 | inquote = ! inquote; | |
1049 | } | |
1050 | *stopcp = *s; | |
1051 | *s = '\0'; | |
1052 | return s; | |
42ac8fa8 ILT |
1053 | |
1054 | #else | |
1055 | ||
1056 | char *s; | |
1057 | ||
1058 | for (s = input_line_pointer; ! is_end_of_line[(unsigned char) *s]; s++) | |
1059 | ; | |
1060 | *stopcp = *s; | |
1061 | *s = '\0'; | |
1062 | return s; | |
1063 | ||
1064 | #endif | |
1065 | ||
18c9057f ILT |
1066 | } |
1067 | ||
1068 | /* Skip to the end of an MRI comment field. */ | |
1069 | ||
1070 | void | |
1071 | mri_comment_end (stop, stopc) | |
1072 | char *stop; | |
1073 | int stopc; | |
1074 | { | |
1075 | know (flag_mri); | |
1076 | ||
1077 | input_line_pointer = stop; | |
1078 | *stop = stopc; | |
1079 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1080 | ++input_line_pointer; | |
1081 | } | |
1082 | ||
6efd877d | 1083 | void |
604633ae ILT |
1084 | s_abort (ignore) |
1085 | int ignore; | |
6efd877d KR |
1086 | { |
1087 | as_fatal (".abort detected. Abandoning ship."); | |
4075afe1 KR |
1088 | } |
1089 | ||
d428c89f ILT |
1090 | /* Guts of .align directive. N is the power of two to which to align. |
1091 | FILL may be NULL, or it may point to the bytes of the fill pattern. | |
1092 | LEN is the length of whatever FILL points to, if anything. MAX is | |
1093 | the maximum number of characters to skip when doing the alignment, | |
1094 | or 0 if there is no maximum. */ | |
1095 | ||
4075afe1 | 1096 | static void |
d428c89f | 1097 | do_align (n, fill, len, max) |
4075afe1 KR |
1098 | int n; |
1099 | char *fill; | |
71dd3c40 | 1100 | int len; |
d428c89f | 1101 | int max; |
4075afe1 | 1102 | { |
d428c89f ILT |
1103 | char default_fill; |
1104 | ||
4075afe1 | 1105 | #ifdef md_do_align |
d428c89f | 1106 | md_do_align (n, fill, len, max, just_record_alignment); |
4075afe1 | 1107 | #endif |
4075afe1 | 1108 | |
d428c89f ILT |
1109 | if (fill == NULL) |
1110 | { | |
1111 | /* FIXME: Fix this right for BFD! */ | |
4075afe1 | 1112 | if (now_seg != data_section && now_seg != bss_section) |
d428c89f | 1113 | default_fill = NOP_OPCODE; |
4075afe1 | 1114 | else |
d428c89f ILT |
1115 | default_fill = 0; |
1116 | fill = &default_fill; | |
71dd3c40 | 1117 | len = 1; |
4075afe1 | 1118 | } |
71dd3c40 | 1119 | |
4075afe1 | 1120 | /* Only make a frag if we HAVE to. . . */ |
d428c89f | 1121 | if (n != 0 && !need_pass_2) |
71dd3c40 ILT |
1122 | { |
1123 | if (len <= 1) | |
d428c89f | 1124 | frag_align (n, *fill, max); |
71dd3c40 | 1125 | else |
d428c89f | 1126 | frag_align_pattern (n, fill, len, max); |
71dd3c40 | 1127 | } |
4075afe1 | 1128 | |
c02fd8dc | 1129 | #ifdef md_do_align |
4075afe1 | 1130 | just_record_alignment: |
c02fd8dc ILT |
1131 | #endif |
1132 | ||
4075afe1 KR |
1133 | record_alignment (now_seg, n); |
1134 | } | |
fecd2382 | 1135 | |
d428c89f ILT |
1136 | /* Handle the .align pseudo-op. A positive ARG is a default alignment |
1137 | (in bytes). A negative ARG is the negative of the length of the | |
1138 | fill pattern. BYTES_P is non-zero if the alignment value should be | |
1139 | interpreted as the byte boundary, rather than the power of 2. */ | |
1140 | ||
1141 | static void | |
1142 | s_align (arg, bytes_p) | |
6efd877d | 1143 | int arg; |
d428c89f | 1144 | int bytes_p; |
fecd2382 | 1145 | { |
d428c89f | 1146 | register unsigned int align; |
18c9057f ILT |
1147 | char *stop = NULL; |
1148 | char stopc; | |
d428c89f ILT |
1149 | offsetT fill = 0; |
1150 | int max; | |
1151 | int fill_p; | |
18c9057f ILT |
1152 | |
1153 | if (flag_mri) | |
1154 | stop = mri_comment_field (&stopc); | |
f8701a3f | 1155 | |
58d4951d | 1156 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
4080c270 ILT |
1157 | { |
1158 | if (arg < 0) | |
d428c89f | 1159 | align = 0; |
4080c270 | 1160 | else |
d428c89f | 1161 | align = arg; /* Default value from pseudo-op table */ |
4080c270 | 1162 | } |
6efd877d | 1163 | else |
6efd877d | 1164 | { |
d428c89f ILT |
1165 | align = get_absolute_expression (); |
1166 | SKIP_WHITESPACE (); | |
f8701a3f SC |
1167 | } |
1168 | ||
d428c89f | 1169 | if (bytes_p) |
6efd877d | 1170 | { |
d428c89f ILT |
1171 | /* Convert to a power of 2. */ |
1172 | if (align != 0) | |
1173 | { | |
1174 | unsigned int i; | |
1175 | ||
1176 | for (i = 0; (align & 1) == 0; align >>= 1, ++i) | |
1177 | ; | |
1178 | if (align != 1) | |
1179 | as_bad ("Alignment not a power of 2"); | |
1180 | align = i; | |
1181 | } | |
f8701a3f | 1182 | } |
f8701a3f | 1183 | |
d428c89f | 1184 | if (align > 15) |
6efd877d | 1185 | { |
d428c89f ILT |
1186 | align = 15; |
1187 | as_bad ("Alignment too large: %u assumed", align); | |
1188 | } | |
71dd3c40 | 1189 | |
d428c89f ILT |
1190 | if (*input_line_pointer != ',') |
1191 | { | |
1192 | fill_p = 0; | |
1193 | max = 0; | |
1194 | } | |
1195 | else | |
1196 | { | |
1197 | ++input_line_pointer; | |
1198 | if (*input_line_pointer == ',') | |
1199 | fill_p = 0; | |
4080c270 | 1200 | else |
71dd3c40 | 1201 | { |
d428c89f ILT |
1202 | fill = get_absolute_expression (); |
1203 | SKIP_WHITESPACE (); | |
1204 | fill_p = 1; | |
71dd3c40 | 1205 | } |
d428c89f ILT |
1206 | |
1207 | if (*input_line_pointer != ',') | |
1208 | max = 0; | |
71dd3c40 ILT |
1209 | else |
1210 | { | |
d428c89f ILT |
1211 | ++input_line_pointer; |
1212 | max = get_absolute_expression (); | |
71dd3c40 | 1213 | } |
f8701a3f | 1214 | } |
d428c89f ILT |
1215 | |
1216 | if (! fill_p) | |
71dd3c40 | 1217 | { |
4080c270 | 1218 | if (arg < 0) |
71dd3c40 | 1219 | as_warn ("expected fill pattern missing"); |
d428c89f | 1220 | do_align (align, (char *) NULL, 0, max); |
6efd877d | 1221 | } |
d428c89f | 1222 | else |
6efd877d | 1223 | { |
d428c89f | 1224 | int fill_len; |
71dd3c40 | 1225 | |
4080c270 | 1226 | if (arg >= 0) |
d428c89f | 1227 | fill_len = 1; |
4080c270 | 1228 | else |
d428c89f ILT |
1229 | fill_len = - arg; |
1230 | if (fill_len <= 1) | |
71dd3c40 | 1231 | { |
d428c89f ILT |
1232 | char fill_char; |
1233 | ||
1234 | fill_char = fill; | |
1235 | do_align (align, &fill_char, fill_len, max); | |
71dd3c40 ILT |
1236 | } |
1237 | else | |
1238 | { | |
1239 | char ab[16]; | |
1240 | ||
d428c89f | 1241 | if (fill_len > sizeof ab) |
71dd3c40 | 1242 | abort (); |
d428c89f ILT |
1243 | md_number_to_chars (ab, fill, fill_len); |
1244 | do_align (align, ab, fill_len, max); | |
71dd3c40 | 1245 | } |
6efd877d | 1246 | } |
6efd877d | 1247 | |
18c9057f ILT |
1248 | if (flag_mri) |
1249 | mri_comment_end (stop, stopc); | |
1250 | ||
6efd877d | 1251 | demand_empty_rest_of_line (); |
4075afe1 | 1252 | } |
6efd877d | 1253 | |
d428c89f ILT |
1254 | /* Handle the .align pseudo-op on machines where ".align 4" means |
1255 | align to a 4 byte boundary. */ | |
1256 | ||
1257 | void | |
1258 | s_align_bytes (arg) | |
1259 | int arg; | |
1260 | { | |
1261 | s_align (arg, 1); | |
1262 | } | |
1263 | ||
1264 | /* Handle the .align pseud-op on machines where ".align 4" means align | |
1265 | to a 2**4 boundary. */ | |
1266 | ||
1267 | void | |
1268 | s_align_ptwo (arg) | |
1269 | int arg; | |
1270 | { | |
1271 | s_align (arg, 0); | |
1272 | } | |
1273 | ||
6efd877d | 1274 | void |
604633ae ILT |
1275 | s_comm (ignore) |
1276 | int ignore; | |
6efd877d KR |
1277 | { |
1278 | register char *name; | |
1279 | register char c; | |
1280 | register char *p; | |
58d4951d | 1281 | offsetT temp; |
6efd877d | 1282 | register symbolS *symbolP; |
18c9057f ILT |
1283 | char *stop = NULL; |
1284 | char stopc; | |
1285 | ||
1286 | if (flag_mri) | |
1287 | stop = mri_comment_field (&stopc); | |
6efd877d KR |
1288 | |
1289 | name = input_line_pointer; | |
1290 | c = get_symbol_end (); | |
1291 | /* just after name is now '\0' */ | |
1292 | p = input_line_pointer; | |
1293 | *p = c; | |
1294 | SKIP_WHITESPACE (); | |
1295 | if (*input_line_pointer != ',') | |
1296 | { | |
1297 | as_bad ("Expected comma after symbol-name: rest of line ignored."); | |
18c9057f ILT |
1298 | if (flag_mri) |
1299 | mri_comment_end (stop, stopc); | |
6efd877d KR |
1300 | ignore_rest_of_line (); |
1301 | return; | |
1302 | } | |
1303 | input_line_pointer++; /* skip ',' */ | |
1304 | if ((temp = get_absolute_expression ()) < 0) | |
1305 | { | |
58d4951d | 1306 | as_warn (".COMMon length (%ld.) <0! Ignored.", (long) temp); |
18c9057f ILT |
1307 | if (flag_mri) |
1308 | mri_comment_end (stop, stopc); | |
6efd877d KR |
1309 | ignore_rest_of_line (); |
1310 | return; | |
1311 | } | |
1312 | *p = 0; | |
1313 | symbolP = symbol_find_or_make (name); | |
1314 | *p = c; | |
1315 | if (S_IS_DEFINED (symbolP)) | |
1316 | { | |
6ef37255 KR |
1317 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1318 | S_GET_NAME (symbolP)); | |
18c9057f ILT |
1319 | if (flag_mri) |
1320 | mri_comment_end (stop, stopc); | |
6efd877d KR |
1321 | ignore_rest_of_line (); |
1322 | return; | |
1323 | } | |
1324 | if (S_GET_VALUE (symbolP)) | |
1325 | { | |
58d4951d ILT |
1326 | if (S_GET_VALUE (symbolP) != (valueT) temp) |
1327 | as_bad ("Length of .comm \"%s\" is already %ld. Not changed to %ld.", | |
6efd877d | 1328 | S_GET_NAME (symbolP), |
58d4951d ILT |
1329 | (long) S_GET_VALUE (symbolP), |
1330 | (long) temp); | |
6efd877d KR |
1331 | } |
1332 | else | |
1333 | { | |
58d4951d | 1334 | S_SET_VALUE (symbolP, (valueT) temp); |
6efd877d KR |
1335 | S_SET_EXTERNAL (symbolP); |
1336 | } | |
9471a360 | 1337 | #ifdef OBJ_VMS |
def66e24 DM |
1338 | { |
1339 | extern int flag_one; | |
1340 | if ( (!temp) || !flag_one) | |
1341 | S_GET_OTHER(symbolP) = const_flag; | |
1342 | } | |
9471a360 | 1343 | #endif /* not OBJ_VMS */ |
6efd877d | 1344 | know (symbolP->sy_frag == &zero_address_frag); |
18c9057f ILT |
1345 | |
1346 | if (flag_mri) | |
1347 | mri_comment_end (stop, stopc); | |
1348 | ||
6efd877d KR |
1349 | demand_empty_rest_of_line (); |
1350 | } /* s_comm() */ | |
fecd2382 | 1351 | |
1356d77d ILT |
1352 | /* The MRI COMMON pseudo-op. We handle this by creating a common |
1353 | symbol with the appropriate name. We make s_space do the right | |
1354 | thing by increasing the size. */ | |
1355 | ||
1356 | void | |
1357 | s_mri_common (small) | |
1358 | int small; | |
1359 | { | |
1360 | char *name; | |
1361 | char c; | |
1362 | char *alc = NULL; | |
1363 | symbolS *sym; | |
1364 | offsetT align; | |
18c9057f ILT |
1365 | char *stop = NULL; |
1366 | char stopc; | |
1356d77d ILT |
1367 | |
1368 | if (! flag_mri) | |
1369 | { | |
1370 | s_comm (0); | |
1371 | return; | |
1372 | } | |
1373 | ||
18c9057f ILT |
1374 | stop = mri_comment_field (&stopc); |
1375 | ||
1356d77d ILT |
1376 | SKIP_WHITESPACE (); |
1377 | ||
1378 | name = input_line_pointer; | |
1379 | if (! isdigit ((unsigned char) *name)) | |
1380 | c = get_symbol_end (); | |
1381 | else | |
1382 | { | |
1383 | do | |
1384 | { | |
1385 | ++input_line_pointer; | |
1386 | } | |
1387 | while (isdigit ((unsigned char) *input_line_pointer)); | |
1388 | c = *input_line_pointer; | |
1389 | *input_line_pointer = '\0'; | |
1390 | ||
7e047ac2 | 1391 | if (line_label != NULL) |
1356d77d | 1392 | { |
7e047ac2 | 1393 | alc = (char *) xmalloc (strlen (S_GET_NAME (line_label)) |
1356d77d ILT |
1394 | + (input_line_pointer - name) |
1395 | + 1); | |
7e047ac2 | 1396 | sprintf (alc, "%s%s", name, S_GET_NAME (line_label)); |
1356d77d ILT |
1397 | name = alc; |
1398 | } | |
1399 | } | |
1400 | ||
1401 | sym = symbol_find_or_make (name); | |
1402 | *input_line_pointer = c; | |
1403 | if (alc != NULL) | |
1404 | free (alc); | |
1405 | ||
1406 | if (*input_line_pointer != ',') | |
1407 | align = 0; | |
1408 | else | |
1409 | { | |
1410 | ++input_line_pointer; | |
1411 | align = get_absolute_expression (); | |
1412 | } | |
1413 | ||
1414 | if (S_IS_DEFINED (sym)) | |
1415 | { | |
1416 | #if defined (S_IS_COMMON) || defined (BFD_ASSEMBLER) | |
1417 | if (! S_IS_COMMON (sym)) | |
1418 | #endif | |
1419 | { | |
1420 | as_bad ("attempt to re-define symbol `%s'", S_GET_NAME (sym)); | |
18c9057f | 1421 | mri_comment_end (stop, stopc); |
1356d77d ILT |
1422 | ignore_rest_of_line (); |
1423 | return; | |
1424 | } | |
1425 | } | |
1426 | ||
1427 | S_SET_EXTERNAL (sym); | |
1428 | mri_common_symbol = sym; | |
1429 | ||
1430 | #ifdef S_SET_ALIGN | |
1431 | if (align != 0) | |
1432 | S_SET_ALIGN (sym, align); | |
1433 | #endif | |
1434 | ||
7e047ac2 | 1435 | if (line_label != NULL) |
1356d77d | 1436 | { |
7e047ac2 ILT |
1437 | line_label->sy_value.X_op = O_symbol; |
1438 | line_label->sy_value.X_add_symbol = sym; | |
1439 | line_label->sy_value.X_add_number = S_GET_VALUE (sym); | |
1440 | line_label->sy_frag = &zero_address_frag; | |
1441 | S_SET_SEGMENT (line_label, expr_section); | |
1356d77d ILT |
1442 | } |
1443 | ||
1444 | /* FIXME: We just ignore the small argument, which distinguishes | |
1445 | COMMON and COMMON.S. I don't know what we can do about it. */ | |
1446 | ||
1447 | /* Ignore the type and hptype. */ | |
1448 | if (*input_line_pointer == ',') | |
1449 | input_line_pointer += 2; | |
1450 | if (*input_line_pointer == ',') | |
1451 | input_line_pointer += 2; | |
18c9057f ILT |
1452 | |
1453 | mri_comment_end (stop, stopc); | |
1454 | ||
1356d77d ILT |
1455 | demand_empty_rest_of_line (); |
1456 | } | |
1457 | ||
fecd2382 | 1458 | void |
604633ae ILT |
1459 | s_data (ignore) |
1460 | int ignore; | |
fecd2382 | 1461 | { |
ffffc8fb | 1462 | segT section; |
6efd877d | 1463 | register int temp; |
f8701a3f | 1464 | |
6efd877d | 1465 | temp = get_absolute_expression (); |
def66e24 | 1466 | if (flag_readonly_data_in_text) |
ffffc8fb ILT |
1467 | { |
1468 | section = text_section; | |
1469 | temp += 1000; | |
1470 | } | |
1471 | else | |
1472 | section = data_section; | |
1473 | ||
ffffc8fb | 1474 | subseg_set (section, (subsegT) temp); |
f8701a3f | 1475 | |
9471a360 | 1476 | #ifdef OBJ_VMS |
6efd877d | 1477 | const_flag = 0; |
fecd2382 | 1478 | #endif |
6efd877d | 1479 | demand_empty_rest_of_line (); |
fecd2382 RP |
1480 | } |
1481 | ||
9a7d824a | 1482 | /* Handle the .appfile pseudo-op. This is automatically generated by |
86038ada ILT |
1483 | do_scrub_chars when a preprocessor # line comment is seen with a |
1484 | file name. This default definition may be overridden by the object | |
1485 | or CPU specific pseudo-ops. This function is also the default | |
1486 | definition for .file; the APPFILE argument is 1 for .appfile, 0 for | |
1487 | .file. */ | |
9a7d824a | 1488 | |
6efd877d | 1489 | void |
9a7d824a ILT |
1490 | s_app_file (appfile) |
1491 | int appfile; | |
6efd877d KR |
1492 | { |
1493 | register char *s; | |
1494 | int length; | |
f8701a3f | 1495 | |
6efd877d KR |
1496 | /* Some assemblers tolerate immediately following '"' */ |
1497 | if ((s = demand_copy_string (&length)) != 0) | |
1498 | { | |
9a7d824a ILT |
1499 | /* If this is a fake .appfile, a fake newline was inserted into |
1500 | the buffer. Passing -2 to new_logical_line tells it to | |
1501 | account for it. */ | |
1502 | new_logical_line (s, appfile ? -2 : -1); | |
cef72a92 ILT |
1503 | |
1504 | /* In MRI mode, the preprocessor may have inserted an extraneous | |
1505 | backquote. */ | |
1506 | if (flag_m68k_mri | |
1507 | && *input_line_pointer == '\'' | |
1508 | && is_end_of_line[(unsigned char) input_line_pointer[1]]) | |
1509 | ++input_line_pointer; | |
1510 | ||
6efd877d | 1511 | demand_empty_rest_of_line (); |
9a7d824a ILT |
1512 | #ifdef LISTING |
1513 | if (listing) | |
1514 | listing_source_file (s); | |
1515 | #endif | |
6efd877d | 1516 | } |
2209b19c KR |
1517 | #ifdef obj_app_file |
1518 | obj_app_file (s); | |
40324362 KR |
1519 | #endif |
1520 | } | |
fecd2382 | 1521 | |
9a7d824a | 1522 | /* Handle the .appline pseudo-op. This is automatically generated by |
86038ada ILT |
1523 | do_scrub_chars when a preprocessor # line comment is seen. This |
1524 | default definition may be overridden by the object or CPU specific | |
1525 | pseudo-ops. */ | |
9a7d824a ILT |
1526 | |
1527 | void | |
604633ae ILT |
1528 | s_app_line (ignore) |
1529 | int ignore; | |
9a7d824a ILT |
1530 | { |
1531 | int l; | |
1532 | ||
1533 | /* The given number is that of the next line. */ | |
1534 | l = get_absolute_expression () - 1; | |
931a8fab KR |
1535 | if (l < 0) |
1536 | /* Some of the back ends can't deal with non-positive line numbers. | |
1537 | Besides, it's silly. */ | |
1538 | as_warn ("Line numbers must be positive; line number %d rejected.", l+1); | |
1539 | else | |
1540 | { | |
1541 | new_logical_line ((char *) NULL, l); | |
9a7d824a | 1542 | #ifdef LISTING |
931a8fab KR |
1543 | if (listing) |
1544 | listing_source_line (l); | |
9a7d824a | 1545 | #endif |
931a8fab | 1546 | } |
9a7d824a ILT |
1547 | demand_empty_rest_of_line (); |
1548 | } | |
1549 | ||
e28c40d7 ILT |
1550 | /* Handle the .end pseudo-op. Actually, the real work is done in |
1551 | read_a_source_file. */ | |
1552 | ||
1553 | void | |
1554 | s_end (ignore) | |
1555 | int ignore; | |
1556 | { | |
1557 | if (flag_mri) | |
1558 | { | |
1559 | /* The MRI assembler permits the start symbol to follow .end, | |
1560 | but we don't support that. */ | |
1561 | SKIP_WHITESPACE (); | |
18c9057f ILT |
1562 | if (! is_end_of_line[(unsigned char) *input_line_pointer] |
1563 | && *input_line_pointer != '*' | |
1564 | && *input_line_pointer != '!') | |
e28c40d7 ILT |
1565 | as_warn ("start address not supported"); |
1566 | } | |
1567 | } | |
1568 | ||
42ac8fa8 ILT |
1569 | /* Handle the .err pseudo-op. */ |
1570 | ||
1571 | void | |
1572 | s_err (ignore) | |
1573 | int ignore; | |
1574 | { | |
1575 | as_bad (".err encountered"); | |
1576 | demand_empty_rest_of_line (); | |
1577 | } | |
1578 | ||
e28c40d7 ILT |
1579 | /* Handle the MRI fail pseudo-op. */ |
1580 | ||
1581 | void | |
1582 | s_fail (ignore) | |
1583 | int ignore; | |
1584 | { | |
1585 | offsetT temp; | |
18c9057f ILT |
1586 | char *stop = NULL; |
1587 | char stopc; | |
1588 | ||
1589 | if (flag_mri) | |
1590 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
1591 | |
1592 | temp = get_absolute_expression (); | |
1593 | if (temp >= 500) | |
1594 | as_warn (".fail %ld encountered", (long) temp); | |
1595 | else | |
1596 | as_bad (".fail %ld encountered", (long) temp); | |
18c9057f ILT |
1597 | |
1598 | if (flag_mri) | |
1599 | mri_comment_end (stop, stopc); | |
1600 | ||
e28c40d7 ILT |
1601 | demand_empty_rest_of_line (); |
1602 | } | |
1603 | ||
6efd877d | 1604 | void |
604633ae ILT |
1605 | s_fill (ignore) |
1606 | int ignore; | |
6efd877d KR |
1607 | { |
1608 | long temp_repeat = 0; | |
1609 | long temp_size = 1; | |
1610 | register long temp_fill = 0; | |
1611 | char *p; | |
f8701a3f | 1612 | |
624c91d1 KR |
1613 | #ifdef md_flush_pending_output |
1614 | md_flush_pending_output (); | |
1615 | #endif | |
7c2d4011 | 1616 | |
6efd877d KR |
1617 | temp_repeat = get_absolute_expression (); |
1618 | if (*input_line_pointer == ',') | |
1619 | { | |
1620 | input_line_pointer++; | |
1621 | temp_size = get_absolute_expression (); | |
1622 | if (*input_line_pointer == ',') | |
7c2d4011 SC |
1623 | { |
1624 | input_line_pointer++; | |
6efd877d | 1625 | temp_fill = get_absolute_expression (); |
fecd2382 | 1626 | } |
6efd877d | 1627 | } |
c8863a58 | 1628 | /* This is to be compatible with BSD 4.2 AS, not for any rational reason. */ |
fecd2382 | 1629 | #define BSD_FILL_SIZE_CROCK_8 (8) |
6efd877d KR |
1630 | if (temp_size > BSD_FILL_SIZE_CROCK_8) |
1631 | { | |
1632 | as_warn (".fill size clamped to %d.", BSD_FILL_SIZE_CROCK_8); | |
1633 | temp_size = BSD_FILL_SIZE_CROCK_8; | |
1634 | } | |
1635 | if (temp_size < 0) | |
1636 | { | |
1637 | as_warn ("Size negative: .fill ignored."); | |
1638 | temp_size = 0; | |
1639 | } | |
1640 | else if (temp_repeat <= 0) | |
1641 | { | |
a69e5977 ILT |
1642 | if (temp_repeat < 0) |
1643 | as_warn ("Repeat < 0, .fill ignored"); | |
6efd877d KR |
1644 | temp_size = 0; |
1645 | } | |
7fd3560a | 1646 | |
6efd877d KR |
1647 | if (temp_size && !need_pass_2) |
1648 | { | |
1649 | p = frag_var (rs_fill, (int) temp_size, (int) temp_size, (relax_substateT) 0, (symbolS *) 0, temp_repeat, (char *) 0); | |
604633ae | 1650 | memset (p, 0, (unsigned int) temp_size); |
c8863a58 KR |
1651 | /* The magic number BSD_FILL_SIZE_CROCK_4 is from BSD 4.2 VAX |
1652 | * flavoured AS. The following bizzare behaviour is to be | |
1653 | * compatible with above. I guess they tried to take up to 8 | |
1654 | * bytes from a 4-byte expression and they forgot to sign | |
1655 | * extend. Un*x Sux. */ | |
fecd2382 | 1656 | #define BSD_FILL_SIZE_CROCK_4 (4) |
604633ae | 1657 | md_number_to_chars (p, (valueT) temp_fill, |
c8863a58 KR |
1658 | (temp_size > BSD_FILL_SIZE_CROCK_4 |
1659 | ? BSD_FILL_SIZE_CROCK_4 | |
1660 | : (int) temp_size)); | |
1661 | /* Note: .fill (),0 emits no frag (since we are asked to .fill 0 bytes) | |
1662 | * but emits no error message because it seems a legal thing to do. | |
1663 | * It is a degenerate case of .fill but could be emitted by a compiler. | |
1664 | */ | |
6efd877d | 1665 | } |
6efd877d | 1666 | demand_empty_rest_of_line (); |
f8701a3f SC |
1667 | } |
1668 | ||
6efd877d | 1669 | void |
604633ae ILT |
1670 | s_globl (ignore) |
1671 | int ignore; | |
6efd877d | 1672 | { |
40324362 KR |
1673 | char *name; |
1674 | int c; | |
1675 | symbolS *symbolP; | |
18c9057f ILT |
1676 | char *stop = NULL; |
1677 | char stopc; | |
1678 | ||
1679 | if (flag_mri) | |
1680 | stop = mri_comment_field (&stopc); | |
fecd2382 | 1681 | |
6efd877d KR |
1682 | do |
1683 | { | |
1684 | name = input_line_pointer; | |
1685 | c = get_symbol_end (); | |
1686 | symbolP = symbol_find_or_make (name); | |
1687 | *input_line_pointer = c; | |
1688 | SKIP_WHITESPACE (); | |
1689 | S_SET_EXTERNAL (symbolP); | |
1690 | if (c == ',') | |
1691 | { | |
1692 | input_line_pointer++; | |
1693 | SKIP_WHITESPACE (); | |
1694 | if (*input_line_pointer == '\n') | |
1695 | c = '\n'; | |
1696 | } | |
1697 | } | |
1698 | while (c == ','); | |
18c9057f ILT |
1699 | |
1700 | if (flag_mri) | |
1701 | mri_comment_end (stop, stopc); | |
1702 | ||
6efd877d | 1703 | demand_empty_rest_of_line (); |
40324362 | 1704 | } |
6efd877d | 1705 | |
7e047ac2 ILT |
1706 | /* Handle the MRI IRP and IRPC pseudo-ops. */ |
1707 | ||
1708 | void | |
1709 | s_irp (irpc) | |
1710 | int irpc; | |
1711 | { | |
1712 | char *file; | |
1713 | unsigned int line; | |
1714 | sb s; | |
1715 | const char *err; | |
1716 | sb out; | |
1717 | ||
1718 | as_where (&file, &line); | |
1719 | ||
1720 | sb_new (&s); | |
1721 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1722 | sb_add_char (&s, *input_line_pointer++); | |
1723 | ||
1724 | sb_new (&out); | |
1725 | ||
1726 | err = expand_irp (irpc, 0, &s, &out, get_line_sb, '\0'); | |
1727 | if (err != NULL) | |
1728 | as_bad_where (file, line, "%s", err); | |
1729 | ||
1730 | sb_kill (&s); | |
1731 | ||
1732 | input_scrub_include_sb (&out, input_line_pointer); | |
1733 | sb_kill (&out); | |
1734 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
1735 | } | |
1736 | ||
7d3741ed ILT |
1737 | /* Handle the .linkonce pseudo-op. This tells the assembler to mark |
1738 | the section to only be linked once. However, this is not supported | |
1739 | by most object file formats. This takes an optional argument, | |
1740 | which is what to do about duplicates. */ | |
1741 | ||
1742 | void | |
1743 | s_linkonce (ignore) | |
1744 | int ignore; | |
1745 | { | |
1746 | enum linkonce_type type; | |
1747 | ||
1748 | SKIP_WHITESPACE (); | |
1749 | ||
1750 | type = LINKONCE_DISCARD; | |
1751 | ||
1752 | if (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
1753 | { | |
1754 | char *s; | |
1755 | char c; | |
1756 | ||
1757 | s = input_line_pointer; | |
1758 | c = get_symbol_end (); | |
1759 | if (strcasecmp (s, "discard") == 0) | |
1760 | type = LINKONCE_DISCARD; | |
1761 | else if (strcasecmp (s, "one_only") == 0) | |
1762 | type = LINKONCE_ONE_ONLY; | |
1763 | else if (strcasecmp (s, "same_size") == 0) | |
1764 | type = LINKONCE_SAME_SIZE; | |
1765 | else if (strcasecmp (s, "same_contents") == 0) | |
1766 | type = LINKONCE_SAME_CONTENTS; | |
1767 | else | |
1768 | as_warn ("unrecognized .linkonce type `%s'", s); | |
1769 | ||
1770 | *input_line_pointer = c; | |
1771 | } | |
1772 | ||
1773 | #ifdef obj_handle_link_once | |
1774 | obj_handle_link_once (type); | |
1775 | #else /* ! defined (obj_handle_link_once) */ | |
1776 | #ifdef BFD_ASSEMBLER | |
1777 | { | |
1778 | flagword flags; | |
1779 | ||
1780 | if ((bfd_applicable_section_flags (stdoutput) & SEC_LINK_ONCE) == 0) | |
1781 | as_warn (".linkonce is not supported for this object file format"); | |
1782 | ||
1783 | flags = bfd_get_section_flags (stdoutput, now_seg); | |
1784 | flags |= SEC_LINK_ONCE; | |
1785 | switch (type) | |
1786 | { | |
1787 | default: | |
1788 | abort (); | |
1789 | case LINKONCE_DISCARD: | |
1790 | flags |= SEC_LINK_DUPLICATES_DISCARD; | |
1791 | break; | |
1792 | case LINKONCE_ONE_ONLY: | |
1793 | flags |= SEC_LINK_DUPLICATES_ONE_ONLY; | |
1794 | break; | |
1795 | case LINKONCE_SAME_SIZE: | |
1796 | flags |= SEC_LINK_DUPLICATES_SAME_SIZE; | |
1797 | break; | |
1798 | case LINKONCE_SAME_CONTENTS: | |
1799 | flags |= SEC_LINK_DUPLICATES_SAME_CONTENTS; | |
1800 | break; | |
1801 | } | |
1802 | if (! bfd_set_section_flags (stdoutput, now_seg, flags)) | |
1803 | as_bad ("bfd_set_section_flags: %s", | |
1804 | bfd_errmsg (bfd_get_error ())); | |
1805 | } | |
1806 | #else /* ! defined (BFD_ASSEMBLER) */ | |
1807 | as_warn (".linkonce is not supported for this object file format"); | |
1808 | #endif /* ! defined (BFD_ASSEMBLER) */ | |
1809 | #endif /* ! defined (obj_handle_link_once) */ | |
1810 | ||
1811 | demand_empty_rest_of_line (); | |
1812 | } | |
1813 | ||
6efd877d KR |
1814 | void |
1815 | s_lcomm (needs_align) | |
c8863a58 KR |
1816 | /* 1 if this was a ".bss" directive, which may require a 3rd argument |
1817 | (alignment); 0 if it was an ".lcomm" (2 args only) */ | |
1818 | int needs_align; | |
fecd2382 | 1819 | { |
6efd877d KR |
1820 | register char *name; |
1821 | register char c; | |
1822 | register char *p; | |
1823 | register int temp; | |
1824 | register symbolS *symbolP; | |
9a7d824a ILT |
1825 | segT current_seg = now_seg; |
1826 | subsegT current_subseg = now_subseg; | |
6efd877d KR |
1827 | const int max_alignment = 15; |
1828 | int align = 0; | |
9a7d824a | 1829 | segT bss_seg = bss_section; |
6efd877d KR |
1830 | |
1831 | name = input_line_pointer; | |
1832 | c = get_symbol_end (); | |
1833 | p = input_line_pointer; | |
1834 | *p = c; | |
1835 | SKIP_WHITESPACE (); | |
46b81190 ILT |
1836 | |
1837 | /* Accept an optional comma after the name. The comma used to be | |
1838 | required, but Irix 5 cc does not generate it. */ | |
1839 | if (*input_line_pointer == ',') | |
6efd877d | 1840 | { |
46b81190 ILT |
1841 | ++input_line_pointer; |
1842 | SKIP_WHITESPACE (); | |
6efd877d | 1843 | } |
f8701a3f | 1844 | |
6efd877d KR |
1845 | if (*input_line_pointer == '\n') |
1846 | { | |
1847 | as_bad ("Missing size expression"); | |
1848 | return; | |
1849 | } | |
f8701a3f | 1850 | |
6efd877d KR |
1851 | if ((temp = get_absolute_expression ()) < 0) |
1852 | { | |
1853 | as_warn ("BSS length (%d.) <0! Ignored.", temp); | |
1854 | ignore_rest_of_line (); | |
1855 | return; | |
1856 | } | |
f8701a3f | 1857 | |
2ef7731d | 1858 | #if defined (TC_MIPS) || defined (TC_ALPHA) |
a2a5a4fa KR |
1859 | if (OUTPUT_FLAVOR == bfd_target_ecoff_flavour |
1860 | || OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
46b81190 | 1861 | { |
a2a5a4fa KR |
1862 | /* For MIPS and Alpha ECOFF or ELF, small objects are put in .sbss. */ |
1863 | if (temp <= bfd_get_gp_size (stdoutput)) | |
1864 | { | |
1865 | bss_seg = subseg_new (".sbss", 1); | |
1866 | seg_info (bss_seg)->bss = 1; | |
b95bee13 ILT |
1867 | #ifdef BFD_ASSEMBLER |
1868 | if (! bfd_set_section_flags (stdoutput, bss_seg, SEC_ALLOC)) | |
1869 | as_warn ("error setting flags for \".sbss\": %s", | |
1870 | bfd_errmsg (bfd_get_error ())); | |
1871 | #endif | |
a2a5a4fa | 1872 | } |
46b81190 | 1873 | } |
9a7d824a | 1874 | #endif |
ede7bc1c SC |
1875 | if (!needs_align) |
1876 | { | |
1877 | /* FIXME. This needs to be machine independent. */ | |
9d90491e ILT |
1878 | if (temp >= 8) |
1879 | align = 3; | |
1880 | else if (temp >= 4) | |
ede7bc1c SC |
1881 | align = 2; |
1882 | else if (temp >= 2) | |
1883 | align = 1; | |
1884 | else | |
c71a604a | 1885 | align = 0; |
ede7bc1c | 1886 | |
a69e5977 ILT |
1887 | #ifdef OBJ_EVAX |
1888 | /* FIXME: This needs to be done in a more general fashion. */ | |
1889 | align = 3; | |
1890 | #endif | |
1891 | ||
ede7bc1c SC |
1892 | record_alignment(bss_seg, align); |
1893 | } | |
9a7d824a | 1894 | |
6efd877d KR |
1895 | if (needs_align) |
1896 | { | |
1897 | align = 0; | |
1898 | SKIP_WHITESPACE (); | |
1899 | if (*input_line_pointer != ',') | |
1900 | { | |
1901 | as_bad ("Expected comma after size"); | |
1902 | ignore_rest_of_line (); | |
1903 | return; | |
1904 | } | |
1905 | input_line_pointer++; | |
1906 | SKIP_WHITESPACE (); | |
1907 | if (*input_line_pointer == '\n') | |
1908 | { | |
1909 | as_bad ("Missing alignment"); | |
1910 | return; | |
1911 | } | |
1912 | align = get_absolute_expression (); | |
1913 | if (align > max_alignment) | |
1914 | { | |
1915 | align = max_alignment; | |
1916 | as_warn ("Alignment too large: %d. assumed.", align); | |
1917 | } | |
1918 | else if (align < 0) | |
1919 | { | |
1920 | align = 0; | |
1921 | as_warn ("Alignment negative. 0 assumed."); | |
1922 | } | |
9a7d824a | 1923 | record_alignment (bss_seg, align); |
6efd877d | 1924 | } /* if needs align */ |
4075afe1 KR |
1925 | else |
1926 | { | |
1927 | /* Assume some objects may require alignment on some systems. */ | |
a69e5977 | 1928 | #if defined (TC_ALPHA) && ! defined (VMS) |
4075afe1 KR |
1929 | if (temp > 1) |
1930 | { | |
1931 | align = ffs (temp) - 1; | |
1932 | if (temp % (1 << align)) | |
1933 | abort (); | |
1934 | } | |
1935 | #endif | |
1936 | } | |
f8701a3f | 1937 | |
6efd877d KR |
1938 | *p = 0; |
1939 | symbolP = symbol_find_or_make (name); | |
1940 | *p = c; | |
f8701a3f | 1941 | |
6efd877d | 1942 | if ( |
fecd2382 | 1943 | #if defined(OBJ_AOUT) | defined(OBJ_BOUT) |
6efd877d KR |
1944 | S_GET_OTHER (symbolP) == 0 && |
1945 | S_GET_DESC (symbolP) == 0 && | |
fecd2382 | 1946 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
9a7d824a | 1947 | (S_GET_SEGMENT (symbolP) == bss_seg |
6efd877d KR |
1948 | || (!S_IS_DEFINED (symbolP) && S_GET_VALUE (symbolP) == 0))) |
1949 | { | |
604633ae | 1950 | char *pfrag; |
85825401 | 1951 | |
9a7d824a | 1952 | subseg_set (bss_seg, 1); |
85825401 ILT |
1953 | |
1954 | if (align) | |
d428c89f | 1955 | frag_align (align, 0, 0); |
85825401 | 1956 | /* detach from old frag */ |
9a7d824a | 1957 | if (S_GET_SEGMENT (symbolP) == bss_seg) |
85825401 ILT |
1958 | symbolP->sy_frag->fr_symbol = NULL; |
1959 | ||
1960 | symbolP->sy_frag = frag_now; | |
604633ae ILT |
1961 | pfrag = frag_var (rs_org, 1, 1, (relax_substateT)0, symbolP, |
1962 | temp, (char *)0); | |
1963 | *pfrag = 0; | |
f8701a3f | 1964 | |
9a7d824a | 1965 | S_SET_SEGMENT (symbolP, bss_seg); |
85825401 | 1966 | |
fecd2382 | 1967 | #ifdef OBJ_COFF |
6efd877d | 1968 | /* The symbol may already have been created with a preceding |
c8863a58 KR |
1969 | ".globl" directive -- be careful not to step on storage class |
1970 | in that case. Otherwise, set it to static. */ | |
6efd877d KR |
1971 | if (S_GET_STORAGE_CLASS (symbolP) != C_EXT) |
1972 | { | |
1973 | S_SET_STORAGE_CLASS (symbolP, C_STAT); | |
fecd2382 | 1974 | } |
6efd877d | 1975 | #endif /* OBJ_COFF */ |
cef72a92 ILT |
1976 | |
1977 | #ifdef S_SET_SIZE | |
1978 | S_SET_SIZE (symbolP, temp); | |
1979 | #endif | |
6efd877d KR |
1980 | } |
1981 | else | |
6ef37255 KR |
1982 | as_bad ("Ignoring attempt to re-define symbol `%s'.", |
1983 | S_GET_NAME (symbolP)); | |
f8701a3f | 1984 | |
9a7d824a | 1985 | subseg_set (current_seg, current_subseg); |
9a7d824a ILT |
1986 | |
1987 | demand_empty_rest_of_line (); | |
6efd877d | 1988 | } /* s_lcomm() */ |
fecd2382 | 1989 | |
6efd877d | 1990 | void |
604633ae ILT |
1991 | s_lsym (ignore) |
1992 | int ignore; | |
6efd877d KR |
1993 | { |
1994 | register char *name; | |
1995 | register char c; | |
1996 | register char *p; | |
6efd877d KR |
1997 | expressionS exp; |
1998 | register symbolS *symbolP; | |
1999 | ||
2000 | /* we permit ANY defined expression: BSD4.2 demands constants */ | |
2001 | name = input_line_pointer; | |
2002 | c = get_symbol_end (); | |
2003 | p = input_line_pointer; | |
2004 | *p = c; | |
2005 | SKIP_WHITESPACE (); | |
2006 | if (*input_line_pointer != ',') | |
2007 | { | |
2008 | *p = 0; | |
2009 | as_bad ("Expected comma after name \"%s\"", name); | |
2010 | *p = c; | |
2011 | ignore_rest_of_line (); | |
2012 | return; | |
2013 | } | |
2014 | input_line_pointer++; | |
b31f2abb KR |
2015 | expression (&exp); |
2016 | if (exp.X_op != O_constant | |
2017 | && exp.X_op != O_register) | |
2018 | { | |
2019 | as_bad ("bad expression"); | |
2020 | ignore_rest_of_line (); | |
2021 | return; | |
2022 | } | |
6efd877d KR |
2023 | *p = 0; |
2024 | symbolP = symbol_find_or_make (name); | |
f8701a3f | 2025 | |
c8863a58 KR |
2026 | /* FIXME-SOON I pulled a (&& symbolP->sy_other == 0 && |
2027 | symbolP->sy_desc == 0) out of this test because coff doesn't have | |
2028 | those fields, and I can't see when they'd ever be tripped. I | |
2029 | don't think I understand why they were here so I may have | |
2030 | introduced a bug. As recently as 1.37 didn't have this test | |
2031 | anyway. xoxorich. */ | |
f8701a3f | 2032 | |
9471a360 | 2033 | if (S_GET_SEGMENT (symbolP) == undefined_section |
6efd877d KR |
2034 | && S_GET_VALUE (symbolP) == 0) |
2035 | { | |
c8863a58 KR |
2036 | /* The name might be an undefined .global symbol; be sure to |
2037 | keep the "external" bit. */ | |
b31f2abb KR |
2038 | S_SET_SEGMENT (symbolP, |
2039 | (exp.X_op == O_constant | |
2040 | ? absolute_section | |
2041 | : reg_section)); | |
2042 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); | |
6efd877d KR |
2043 | } |
2044 | else | |
2045 | { | |
2046 | as_bad ("Symbol %s already defined", name); | |
2047 | } | |
2048 | *p = c; | |
2049 | demand_empty_rest_of_line (); | |
2050 | } /* s_lsym() */ | |
2051 | ||
7e047ac2 ILT |
2052 | /* Read a line into an sb. */ |
2053 | ||
2054 | static int | |
2055 | get_line_sb (line) | |
2056 | sb *line; | |
2057 | { | |
d428c89f ILT |
2058 | char quote1, quote2, inquote; |
2059 | ||
adeab39b MM |
2060 | if (input_line_pointer[-1] == '\n') |
2061 | bump_line_counters (); | |
2062 | ||
7e047ac2 ILT |
2063 | if (input_line_pointer >= buffer_limit) |
2064 | { | |
2065 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
2066 | if (buffer_limit == 0) | |
2067 | return 0; | |
2068 | } | |
2069 | ||
d428c89f ILT |
2070 | /* If app.c sets any other characters to LEX_IS_STRINGQUOTE, this |
2071 | code needs to be changed. */ | |
2072 | if (! flag_m68k_mri) | |
2073 | quote1 = '"'; | |
2074 | else | |
2075 | quote1 = '\0'; | |
2076 | ||
2077 | quote2 = '\0'; | |
2078 | if (flag_m68k_mri) | |
2079 | quote2 = '\''; | |
2080 | #ifdef LEX_IS_STRINGQUOTE | |
2081 | quote2 = '\''; | |
2082 | #endif | |
2083 | ||
2084 | inquote = '\0'; | |
2085 | while (! is_end_of_line[(unsigned char) *input_line_pointer] | |
2086 | || (inquote != '\0' && *input_line_pointer != '\n')) | |
2087 | { | |
2088 | if (inquote == *input_line_pointer) | |
2089 | inquote = '\0'; | |
2090 | else if (inquote == '\0') | |
2091 | { | |
2092 | if (*input_line_pointer == quote1) | |
2093 | inquote = quote1; | |
2094 | else if (*input_line_pointer == quote2) | |
2095 | inquote = quote2; | |
2096 | } | |
2097 | sb_add_char (line, *input_line_pointer++); | |
2098 | } | |
2099 | while (input_line_pointer < buffer_limit && *input_line_pointer == '\n') | |
7e047ac2 | 2100 | { |
adeab39b MM |
2101 | if (input_line_pointer[-1] == '\n') |
2102 | bump_line_counters (); | |
7e047ac2 ILT |
2103 | ++input_line_pointer; |
2104 | } | |
2105 | return 1; | |
2106 | } | |
2107 | ||
2108 | /* Define a macro. This is an interface to macro.c, which is shared | |
2109 | between gas and gasp. */ | |
2110 | ||
2111 | void | |
2112 | s_macro (ignore) | |
2113 | int ignore; | |
2114 | { | |
2115 | char *file; | |
2116 | unsigned int line; | |
2117 | sb s; | |
2118 | sb label; | |
2119 | const char *err; | |
a69e5977 | 2120 | const char *name; |
7e047ac2 ILT |
2121 | |
2122 | as_where (&file, &line); | |
2123 | ||
2124 | sb_new (&s); | |
2125 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) | |
2126 | sb_add_char (&s, *input_line_pointer++); | |
2127 | ||
2128 | sb_new (&label); | |
2129 | if (line_label != NULL) | |
2130 | sb_add_string (&label, S_GET_NAME (line_label)); | |
2131 | ||
a69e5977 | 2132 | err = define_macro (0, &s, &label, get_line_sb, &name); |
7e047ac2 ILT |
2133 | if (err != NULL) |
2134 | as_bad_where (file, line, "%s", err); | |
2135 | else | |
2136 | { | |
2137 | if (line_label != NULL) | |
2138 | { | |
2139 | S_SET_SEGMENT (line_label, undefined_section); | |
2140 | S_SET_VALUE (line_label, 0); | |
2141 | line_label->sy_frag = &zero_address_frag; | |
2142 | } | |
a69e5977 ILT |
2143 | |
2144 | if (((flag_m68k_mri | |
2145 | #ifdef NO_PSEUDO_DOT | |
2146 | || 1 | |
2147 | #endif | |
2148 | ) | |
2149 | && hash_find (po_hash, name) != NULL) | |
2150 | || (! flag_m68k_mri | |
2151 | && *name == '.' | |
2152 | && hash_find (po_hash, name + 1) != NULL)) | |
2153 | as_warn ("attempt to redefine pseudo-op `%s' ignored", | |
2154 | name); | |
7e047ac2 ILT |
2155 | } |
2156 | ||
2157 | sb_kill (&s); | |
2158 | } | |
2159 | ||
2160 | /* Handle the .mexit pseudo-op, which immediately exits a macro | |
2161 | expansion. */ | |
2162 | ||
2163 | void | |
2164 | s_mexit (ignore) | |
2165 | int ignore; | |
2166 | { | |
2167 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
2168 | } | |
2169 | ||
20710f1c ILT |
2170 | /* Switch in and out of MRI mode. */ |
2171 | ||
2172 | void | |
2173 | s_mri (ignore) | |
2174 | int ignore; | |
2175 | { | |
2176 | int on, old_flag; | |
2177 | ||
2178 | on = get_absolute_expression (); | |
2179 | old_flag = flag_mri; | |
2180 | if (on != 0) | |
2181 | { | |
2182 | flag_mri = 1; | |
2183 | #ifdef TC_M68K | |
2184 | flag_m68k_mri = 1; | |
2185 | #endif | |
2186 | } | |
2187 | else | |
2188 | { | |
2189 | flag_mri = 0; | |
2190 | flag_m68k_mri = 0; | |
2191 | } | |
2192 | ||
2193 | #ifdef MRI_MODE_CHANGE | |
2194 | if (on != old_flag) | |
2195 | MRI_MODE_CHANGE (on); | |
2196 | #endif | |
2197 | ||
2198 | demand_empty_rest_of_line (); | |
2199 | } | |
2200 | ||
e28c40d7 ILT |
2201 | /* Handle changing the location counter. */ |
2202 | ||
2203 | static void | |
2204 | do_org (segment, exp, fill) | |
2205 | segT segment; | |
2206 | expressionS *exp; | |
2207 | int fill; | |
2208 | { | |
2209 | if (segment != now_seg && segment != absolute_section) | |
2210 | as_bad ("invalid segment \"%s\"; segment \"%s\" assumed", | |
2211 | segment_name (segment), segment_name (now_seg)); | |
2212 | ||
2213 | if (now_seg == absolute_section) | |
2214 | { | |
2215 | if (fill != 0) | |
2216 | as_warn ("ignoring fill value in absolute section"); | |
2217 | if (exp->X_op != O_constant) | |
2218 | { | |
2219 | as_bad ("only constant offsets supported in absolute section"); | |
2220 | exp->X_add_number = 0; | |
2221 | } | |
2222 | abs_section_offset = exp->X_add_number; | |
2223 | } | |
2224 | else | |
2225 | { | |
2226 | char *p; | |
2227 | ||
2228 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, exp->X_add_symbol, | |
2229 | exp->X_add_number, (char *) NULL); | |
2230 | *p = fill; | |
2231 | } | |
2232 | } | |
2233 | ||
6efd877d | 2234 | void |
604633ae ILT |
2235 | s_org (ignore) |
2236 | int ignore; | |
6efd877d KR |
2237 | { |
2238 | register segT segment; | |
2239 | expressionS exp; | |
2240 | register long temp_fill; | |
e28c40d7 | 2241 | |
42ac8fa8 ILT |
2242 | /* The m68k MRI assembler has a different meaning for .org. It |
2243 | means to create an absolute section at a given address. We can't | |
2244 | support that--use a linker script instead. */ | |
cef72a92 | 2245 | if (flag_m68k_mri) |
69e077f3 ILT |
2246 | { |
2247 | as_bad ("MRI style ORG pseudo-op not supported"); | |
2248 | ignore_rest_of_line (); | |
2249 | return; | |
2250 | } | |
2251 | ||
9471a360 KR |
2252 | /* Don't believe the documentation of BSD 4.2 AS. There is no such |
2253 | thing as a sub-segment-relative origin. Any absolute origin is | |
2254 | given a warning, then assumed to be segment-relative. Any | |
2255 | segmented origin expression ("foo+42") had better be in the right | |
2256 | segment or the .org is ignored. | |
2257 | ||
2258 | BSD 4.2 AS warns if you try to .org backwards. We cannot because | |
2259 | we never know sub-segment sizes when we are reading code. BSD | |
2260 | will crash trying to emit negative numbers of filler bytes in | |
2261 | certain .orgs. We don't crash, but see as-write for that code. | |
2262 | ||
2263 | Don't make frag if need_pass_2==1. */ | |
6efd877d KR |
2264 | segment = get_known_segmented_expression (&exp); |
2265 | if (*input_line_pointer == ',') | |
2266 | { | |
2267 | input_line_pointer++; | |
2268 | temp_fill = get_absolute_expression (); | |
2269 | } | |
2270 | else | |
2271 | temp_fill = 0; | |
e28c40d7 | 2272 | |
6efd877d | 2273 | if (!need_pass_2) |
e28c40d7 ILT |
2274 | do_org (segment, &exp, temp_fill); |
2275 | ||
6efd877d KR |
2276 | demand_empty_rest_of_line (); |
2277 | } /* s_org() */ | |
2278 | ||
e14994d9 ILT |
2279 | /* Handle parsing for the MRI SECT/SECTION pseudo-op. This should be |
2280 | called by the obj-format routine which handles section changing | |
2281 | when in MRI mode. It will create a new section, and return it. It | |
c7a89bde ILT |
2282 | will set *TYPE to the section type: one of 'C' (code), 'D' (data), |
2283 | 'M' (mixed), or 'R' (romable). If BFD_ASSEMBLER is defined, the | |
2284 | flags will be set in the section. */ | |
e14994d9 ILT |
2285 | |
2286 | void | |
2287 | s_mri_sect (type) | |
2288 | char *type; | |
2289 | { | |
42ac8fa8 ILT |
2290 | #ifdef TC_M68K |
2291 | ||
e14994d9 ILT |
2292 | char *name; |
2293 | char c; | |
2294 | segT seg; | |
2295 | ||
2296 | SKIP_WHITESPACE (); | |
2297 | ||
2298 | name = input_line_pointer; | |
2299 | if (! isdigit ((unsigned char) *name)) | |
2300 | c = get_symbol_end (); | |
2301 | else | |
2302 | { | |
2303 | do | |
2304 | { | |
2305 | ++input_line_pointer; | |
2306 | } | |
2307 | while (isdigit ((unsigned char) *input_line_pointer)); | |
2308 | c = *input_line_pointer; | |
2309 | *input_line_pointer = '\0'; | |
2310 | } | |
2311 | ||
c7a89bde | 2312 | name = xstrdup (name); |
e14994d9 ILT |
2313 | |
2314 | *input_line_pointer = c; | |
2315 | ||
2316 | seg = subseg_new (name, 0); | |
2317 | ||
2318 | if (*input_line_pointer == ',') | |
2319 | { | |
2320 | int align; | |
2321 | ||
2322 | ++input_line_pointer; | |
2323 | align = get_absolute_expression (); | |
2324 | record_alignment (seg, align); | |
2325 | } | |
2326 | ||
c7a89bde | 2327 | *type = 'C'; |
e14994d9 ILT |
2328 | if (*input_line_pointer == ',') |
2329 | { | |
2330 | c = *++input_line_pointer; | |
2331 | c = toupper ((unsigned char) c); | |
2332 | if (c == 'C' || c == 'D' || c == 'M' || c == 'R') | |
2333 | *type = c; | |
2334 | else | |
2335 | as_bad ("unrecognized section type"); | |
2336 | ++input_line_pointer; | |
2337 | ||
2338 | #ifdef BFD_ASSEMBLER | |
2339 | { | |
2340 | flagword flags; | |
2341 | ||
2342 | flags = SEC_NO_FLAGS; | |
ca232972 | 2343 | if (*type == 'C') |
c7a89bde ILT |
2344 | flags = SEC_ALLOC | SEC_LOAD | SEC_READONLY | SEC_CODE; |
2345 | else if (*type == 'D' || *type == 'M') | |
2346 | flags = SEC_ALLOC | SEC_LOAD | SEC_DATA; | |
ca232972 | 2347 | else if (*type == 'R') |
c7a89bde | 2348 | flags = SEC_ALLOC | SEC_LOAD | SEC_DATA | SEC_READONLY | SEC_ROM; |
e14994d9 ILT |
2349 | if (flags != SEC_NO_FLAGS) |
2350 | { | |
2351 | if (! bfd_set_section_flags (stdoutput, seg, flags)) | |
2352 | as_warn ("error setting flags for \"%s\": %s", | |
ca232972 | 2353 | bfd_section_name (stdoutput, seg), |
e14994d9 ILT |
2354 | bfd_errmsg (bfd_get_error ())); |
2355 | } | |
2356 | } | |
2357 | #endif | |
2358 | } | |
2359 | ||
2360 | /* Ignore the HP type. */ | |
2361 | if (*input_line_pointer == ',') | |
2362 | input_line_pointer += 2; | |
2363 | ||
2364 | demand_empty_rest_of_line (); | |
42ac8fa8 ILT |
2365 | |
2366 | #else /* ! TC_M68K */ | |
2367 | #ifdef TC_I960 | |
2368 | ||
2369 | char *name; | |
2370 | char c; | |
2371 | segT seg; | |
2372 | ||
2373 | SKIP_WHITESPACE (); | |
2374 | ||
2375 | name = input_line_pointer; | |
2376 | c = get_symbol_end (); | |
2377 | ||
c7a89bde | 2378 | name = xstrdup (name); |
42ac8fa8 ILT |
2379 | |
2380 | *input_line_pointer = c; | |
2381 | ||
2382 | seg = subseg_new (name, 0); | |
2383 | ||
2384 | if (*input_line_pointer != ',') | |
2385 | *type = 'C'; | |
2386 | else | |
2387 | { | |
2388 | char *sectype; | |
2389 | ||
2390 | ++input_line_pointer; | |
2391 | SKIP_WHITESPACE (); | |
2392 | sectype = input_line_pointer; | |
2393 | c = get_symbol_end (); | |
2394 | if (*sectype == '\0') | |
2395 | *type = 'C'; | |
2396 | else if (strcasecmp (sectype, "text") == 0) | |
2397 | *type = 'C'; | |
2398 | else if (strcasecmp (sectype, "data") == 0) | |
2399 | *type = 'D'; | |
2400 | else if (strcasecmp (sectype, "romdata") == 0) | |
2401 | *type = 'R'; | |
2402 | else | |
2403 | as_warn ("unrecognized section type `%s'", sectype); | |
2404 | *input_line_pointer = c; | |
2405 | } | |
2406 | ||
2407 | if (*input_line_pointer == ',') | |
2408 | { | |
2409 | char *seccmd; | |
2410 | ||
2411 | ++input_line_pointer; | |
2412 | SKIP_WHITESPACE (); | |
2413 | seccmd = input_line_pointer; | |
2414 | c = get_symbol_end (); | |
2415 | if (strcasecmp (seccmd, "absolute") == 0) | |
2416 | { | |
2417 | as_bad ("absolute sections are not supported"); | |
2418 | *input_line_pointer = c; | |
2419 | ignore_rest_of_line (); | |
2420 | return; | |
2421 | } | |
2422 | else if (strcasecmp (seccmd, "align") == 0) | |
2423 | { | |
2424 | int align; | |
2425 | ||
2426 | *input_line_pointer = c; | |
2427 | align = get_absolute_expression (); | |
2428 | record_alignment (seg, align); | |
2429 | } | |
2430 | else | |
2431 | { | |
2432 | as_warn ("unrecognized section command `%s'", seccmd); | |
2433 | *input_line_pointer = c; | |
2434 | } | |
2435 | } | |
2436 | ||
2437 | demand_empty_rest_of_line (); | |
2438 | ||
2439 | #else /* ! TC_I960 */ | |
2440 | /* The MRI assembler seems to use different forms of .sect for | |
2441 | different targets. */ | |
2442 | abort (); | |
2443 | #endif /* ! TC_I960 */ | |
2444 | #endif /* ! TC_M68K */ | |
2445 | } | |
2446 | ||
2447 | /* Handle the .print pseudo-op. */ | |
2448 | ||
2449 | void | |
2450 | s_print (ignore) | |
2451 | int ignore; | |
2452 | { | |
2453 | char *s; | |
2454 | int len; | |
2455 | ||
2456 | s = demand_copy_C_string (&len); | |
2457 | printf ("%s\n", s); | |
2458 | demand_empty_rest_of_line (); | |
2459 | } | |
2460 | ||
2461 | /* Handle the .purgem pseudo-op. */ | |
2462 | ||
2463 | void | |
2464 | s_purgem (ignore) | |
2465 | int ignore; | |
2466 | { | |
2467 | if (is_it_end_of_statement ()) | |
2468 | { | |
2469 | demand_empty_rest_of_line (); | |
2470 | return; | |
2471 | } | |
2472 | ||
2473 | do | |
2474 | { | |
2475 | char *name; | |
2476 | char c; | |
2477 | ||
2478 | SKIP_WHITESPACE (); | |
2479 | name = input_line_pointer; | |
2480 | c = get_symbol_end (); | |
2481 | delete_macro (name); | |
2482 | *input_line_pointer = c; | |
2483 | SKIP_WHITESPACE (); | |
2484 | } | |
2485 | while (*input_line_pointer++ == ','); | |
2486 | ||
2487 | --input_line_pointer; | |
2488 | demand_empty_rest_of_line (); | |
e14994d9 ILT |
2489 | } |
2490 | ||
7e047ac2 ILT |
2491 | /* Handle the .rept pseudo-op. */ |
2492 | ||
2493 | void | |
2494 | s_rept (ignore) | |
2495 | int ignore; | |
2496 | { | |
2497 | int count; | |
2498 | sb one; | |
2499 | sb many; | |
2500 | ||
2501 | count = get_absolute_expression (); | |
2502 | ||
2503 | sb_new (&one); | |
2504 | if (! buffer_and_nest ("REPT", "ENDR", &one, get_line_sb)) | |
2505 | { | |
2506 | as_bad ("rept without endr"); | |
2507 | return; | |
2508 | } | |
2509 | ||
2510 | sb_new (&many); | |
2511 | while (count-- > 0) | |
2512 | sb_add_sb (&many, &one); | |
2513 | ||
2514 | sb_kill (&one); | |
2515 | ||
2516 | input_scrub_include_sb (&many, input_line_pointer); | |
2517 | sb_kill (&many); | |
2518 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
2519 | } | |
2520 | ||
6efd877d | 2521 | void |
604633ae ILT |
2522 | s_set (ignore) |
2523 | int ignore; | |
6efd877d KR |
2524 | { |
2525 | register char *name; | |
2526 | register char delim; | |
2527 | register char *end_name; | |
2528 | register symbolS *symbolP; | |
2529 | ||
2530 | /* | |
c8863a58 KR |
2531 | * Especial apologies for the random logic: |
2532 | * this just grew, and could be parsed much more simply! | |
2533 | * Dean in haste. | |
2534 | */ | |
6efd877d KR |
2535 | name = input_line_pointer; |
2536 | delim = get_symbol_end (); | |
2537 | end_name = input_line_pointer; | |
2538 | *end_name = delim; | |
2539 | SKIP_WHITESPACE (); | |
f8701a3f | 2540 | |
6efd877d KR |
2541 | if (*input_line_pointer != ',') |
2542 | { | |
2543 | *end_name = 0; | |
2544 | as_bad ("Expected comma after name \"%s\"", name); | |
2545 | *end_name = delim; | |
2546 | ignore_rest_of_line (); | |
2547 | return; | |
2548 | } | |
2549 | ||
2550 | input_line_pointer++; | |
2551 | *end_name = 0; | |
2552 | ||
2553 | if (name[0] == '.' && name[1] == '\0') | |
2554 | { | |
2555 | /* Turn '. = mumble' into a .org mumble */ | |
2556 | register segT segment; | |
2557 | expressionS exp; | |
6efd877d KR |
2558 | |
2559 | segment = get_known_segmented_expression (&exp); | |
f8701a3f | 2560 | |
6efd877d | 2561 | if (!need_pass_2) |
e28c40d7 | 2562 | do_org (segment, &exp, 0); |
6efd877d KR |
2563 | |
2564 | *end_name = delim; | |
2565 | return; | |
2566 | } | |
2567 | ||
2568 | if ((symbolP = symbol_find (name)) == NULL | |
2569 | && (symbolP = md_undefined_symbol (name)) == NULL) | |
2570 | { | |
9471a360 | 2571 | symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag); |
fecd2382 | 2572 | #ifdef OBJ_COFF |
6efd877d KR |
2573 | /* "set" symbols are local unless otherwise specified. */ |
2574 | SF_SET_LOCAL (symbolP); | |
fecd2382 | 2575 | #endif /* OBJ_COFF */ |
f8701a3f | 2576 | |
6efd877d | 2577 | } /* make a new symbol */ |
f8701a3f | 2578 | |
6efd877d | 2579 | symbol_table_insert (symbolP); |
f8701a3f | 2580 | |
6efd877d KR |
2581 | *end_name = delim; |
2582 | pseudo_set (symbolP); | |
2583 | demand_empty_rest_of_line (); | |
2584 | } /* s_set() */ | |
fecd2382 | 2585 | |
6efd877d KR |
2586 | void |
2587 | s_space (mult) | |
2588 | int mult; | |
b53ccaac | 2589 | { |
cd3b81bd | 2590 | expressionS exp; |
adeab39b | 2591 | expressionS val; |
cd3b81bd | 2592 | char *p = 0; |
3dce804d ILT |
2593 | char *stop = NULL; |
2594 | char stopc; | |
a6b200da | 2595 | int bytes; |
6efd877d | 2596 | |
a2a5a4fa KR |
2597 | #ifdef md_flush_pending_output |
2598 | md_flush_pending_output (); | |
2599 | #endif | |
2600 | ||
3dce804d | 2601 | if (flag_mri) |
18c9057f | 2602 | stop = mri_comment_field (&stopc); |
3dce804d | 2603 | |
a69e5977 ILT |
2604 | /* In m68k MRI mode, we need to align to a word boundary, unless |
2605 | this is ds.b. */ | |
2606 | if (flag_m68k_mri && mult > 1) | |
2607 | { | |
2608 | if (now_seg == absolute_section) | |
2609 | { | |
2610 | abs_section_offset += abs_section_offset & 1; | |
2611 | if (line_label != NULL) | |
2612 | S_SET_VALUE (line_label, abs_section_offset); | |
2613 | } | |
2614 | else if (mri_common_symbol != NULL) | |
2615 | { | |
2616 | valueT val; | |
2617 | ||
2618 | val = S_GET_VALUE (mri_common_symbol); | |
2619 | if ((val & 1) != 0) | |
2620 | { | |
2621 | S_SET_VALUE (mri_common_symbol, val + 1); | |
2622 | if (line_label != NULL) | |
2623 | { | |
2624 | know (line_label->sy_value.X_op == O_symbol); | |
2625 | know (line_label->sy_value.X_add_symbol == mri_common_symbol); | |
2626 | line_label->sy_value.X_add_number += 1; | |
2627 | } | |
2628 | } | |
2629 | } | |
2630 | else | |
2631 | { | |
d428c89f | 2632 | do_align (1, (char *) NULL, 0, 0); |
a69e5977 ILT |
2633 | if (line_label != NULL) |
2634 | { | |
2635 | line_label->sy_frag = frag_now; | |
2636 | S_SET_VALUE (line_label, frag_now_fix ()); | |
2637 | } | |
2638 | } | |
2639 | } | |
2640 | ||
a6b200da ILT |
2641 | bytes = mult; |
2642 | ||
cd3b81bd | 2643 | expression (&exp); |
cd3b81bd | 2644 | |
adeab39b MM |
2645 | SKIP_WHITESPACE (); |
2646 | if (*input_line_pointer == ',') | |
2647 | { | |
2648 | ++input_line_pointer; | |
2649 | expression (&val); | |
2650 | } | |
2651 | else | |
2652 | { | |
2653 | val.X_op = O_constant; | |
2654 | val.X_add_number = 0; | |
2655 | } | |
cd3b81bd | 2656 | |
adeab39b MM |
2657 | if (val.X_op != O_constant |
2658 | || val.X_add_number < - 0x80 | |
2659 | || val.X_add_number > 0xff | |
2660 | || (mult != 0 && mult != 1 && val.X_add_number != 0)) | |
2661 | { | |
2662 | if (exp.X_op != O_constant) | |
2663 | as_bad ("Unsupported variable size or fill value"); | |
2664 | else | |
e28c40d7 | 2665 | { |
adeab39b | 2666 | offsetT i; |
e28c40d7 | 2667 | |
adeab39b MM |
2668 | if (mult == 0) |
2669 | mult = 1; | |
a6b200da | 2670 | bytes = mult * exp.X_add_number; |
adeab39b MM |
2671 | for (i = 0; i < exp.X_add_number; i++) |
2672 | emit_expr (&val, mult); | |
1356d77d | 2673 | } |
6efd877d KR |
2674 | } |
2675 | else | |
2676 | { | |
adeab39b | 2677 | if (exp.X_op == O_constant) |
e28c40d7 | 2678 | { |
adeab39b MM |
2679 | long repeat; |
2680 | ||
2681 | repeat = exp.X_add_number; | |
2682 | if (mult) | |
2683 | repeat *= mult; | |
a6b200da | 2684 | bytes = repeat; |
adeab39b MM |
2685 | if (repeat <= 0) |
2686 | { | |
2687 | if (! flag_mri || repeat < 0) | |
2688 | as_warn (".space repeat count is %s, ignored", | |
2689 | repeat ? "negative" : "zero"); | |
2690 | goto getout; | |
2691 | } | |
2692 | ||
2693 | /* If we are in the absolute section, just bump the offset. */ | |
2694 | if (now_seg == absolute_section) | |
2695 | { | |
2696 | abs_section_offset += repeat; | |
2697 | goto getout; | |
2698 | } | |
2699 | ||
2700 | /* If we are secretly in an MRI common section, then | |
2701 | creating space just increases the size of the common | |
2702 | symbol. */ | |
2703 | if (mri_common_symbol != NULL) | |
2704 | { | |
2705 | S_SET_VALUE (mri_common_symbol, | |
2706 | S_GET_VALUE (mri_common_symbol) + repeat); | |
2707 | goto getout; | |
2708 | } | |
2709 | ||
2710 | if (!need_pass_2) | |
2711 | p = frag_var (rs_fill, 1, 1, (relax_substateT) 0, (symbolS *) 0, | |
2712 | repeat, (char *) 0); | |
e28c40d7 | 2713 | } |
adeab39b | 2714 | else |
1356d77d | 2715 | { |
adeab39b MM |
2716 | if (now_seg == absolute_section) |
2717 | { | |
2718 | as_bad ("space allocation too complex in absolute section"); | |
2719 | subseg_set (text_section, 0); | |
2720 | } | |
2721 | if (mri_common_symbol != NULL) | |
2722 | { | |
2723 | as_bad ("space allocation too complex in common section"); | |
2724 | mri_common_symbol = NULL; | |
2725 | } | |
2726 | if (!need_pass_2) | |
2727 | p = frag_var (rs_space, 1, 1, (relax_substateT) 0, | |
2728 | make_expr_symbol (&exp), 0L, (char *) 0); | |
1356d77d | 2729 | } |
adeab39b MM |
2730 | |
2731 | if (p) | |
2732 | *p = val.X_add_number; | |
6efd877d | 2733 | } |
3dce804d ILT |
2734 | |
2735 | getout: | |
a6b200da ILT |
2736 | |
2737 | /* In MRI mode, after an odd number of bytes, we must align to an | |
2738 | even word boundary, unless the next instruction is a dc.b, ds.b | |
2739 | or dcb.b. */ | |
2740 | if (flag_mri && (bytes & 1) != 0) | |
2741 | mri_pending_align = 1; | |
2742 | ||
3dce804d | 2743 | if (flag_mri) |
18c9057f | 2744 | mri_comment_end (stop, stopc); |
3dce804d | 2745 | |
6efd877d | 2746 | demand_empty_rest_of_line (); |
cd3b81bd | 2747 | } |
fecd2382 | 2748 | |
e28c40d7 ILT |
2749 | /* This is like s_space, but the value is a floating point number with |
2750 | the given precision. This is for the MRI dcb.s pseudo-op and | |
2751 | friends. */ | |
2752 | ||
2753 | void | |
2754 | s_float_space (float_type) | |
2755 | int float_type; | |
2756 | { | |
2757 | offsetT count; | |
2758 | int flen; | |
2759 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
18c9057f ILT |
2760 | char *stop = NULL; |
2761 | char stopc; | |
2762 | ||
2763 | if (flag_mri) | |
2764 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
2765 | |
2766 | count = get_absolute_expression (); | |
2767 | ||
2768 | SKIP_WHITESPACE (); | |
2769 | if (*input_line_pointer != ',') | |
2770 | { | |
2771 | as_bad ("missing value"); | |
18c9057f ILT |
2772 | if (flag_mri) |
2773 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2774 | ignore_rest_of_line (); |
2775 | return; | |
2776 | } | |
2777 | ||
2778 | ++input_line_pointer; | |
2779 | ||
2780 | SKIP_WHITESPACE (); | |
2781 | ||
2782 | /* Skip any 0{letter} that may be present. Don't even check if the | |
2783 | * letter is legal. */ | |
2784 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) | |
2785 | input_line_pointer += 2; | |
2786 | ||
2787 | /* Accept :xxxx, where the x's are hex digits, for a floating point | |
2788 | with the exact digits specified. */ | |
2789 | if (input_line_pointer[0] == ':') | |
2790 | { | |
2791 | flen = hex_float (float_type, temp); | |
2792 | if (flen < 0) | |
2793 | { | |
18c9057f ILT |
2794 | if (flag_mri) |
2795 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2796 | ignore_rest_of_line (); |
2797 | return; | |
2798 | } | |
2799 | } | |
2800 | else | |
2801 | { | |
2802 | char *err; | |
2803 | ||
2804 | err = md_atof (float_type, temp, &flen); | |
2805 | know (flen <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
2806 | know (flen > 0); | |
2807 | if (err) | |
2808 | { | |
2809 | as_bad ("Bad floating literal: %s", err); | |
18c9057f ILT |
2810 | if (flag_mri) |
2811 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2812 | ignore_rest_of_line (); |
2813 | return; | |
2814 | } | |
2815 | } | |
2816 | ||
2817 | while (--count >= 0) | |
2818 | { | |
2819 | char *p; | |
2820 | ||
2821 | p = frag_more (flen); | |
2822 | memcpy (p, temp, (unsigned int) flen); | |
2823 | } | |
2824 | ||
18c9057f ILT |
2825 | if (flag_mri) |
2826 | mri_comment_end (stop, stopc); | |
2827 | ||
e28c40d7 ILT |
2828 | demand_empty_rest_of_line (); |
2829 | } | |
2830 | ||
2831 | /* Handle the .struct pseudo-op, as found in MIPS assemblers. */ | |
2832 | ||
2833 | void | |
2834 | s_struct (ignore) | |
2835 | int ignore; | |
2836 | { | |
18c9057f ILT |
2837 | char *stop = NULL; |
2838 | char stopc; | |
2839 | ||
2840 | if (flag_mri) | |
2841 | stop = mri_comment_field (&stopc); | |
e28c40d7 ILT |
2842 | abs_section_offset = get_absolute_expression (); |
2843 | subseg_set (absolute_section, 0); | |
18c9057f ILT |
2844 | if (flag_mri) |
2845 | mri_comment_end (stop, stopc); | |
e28c40d7 ILT |
2846 | demand_empty_rest_of_line (); |
2847 | } | |
2848 | ||
fecd2382 | 2849 | void |
604633ae ILT |
2850 | s_text (ignore) |
2851 | int ignore; | |
fecd2382 | 2852 | { |
6efd877d | 2853 | register int temp; |
f8701a3f | 2854 | |
6efd877d | 2855 | temp = get_absolute_expression (); |
9471a360 | 2856 | subseg_set (text_section, (subsegT) temp); |
6efd877d | 2857 | demand_empty_rest_of_line (); |
80d80c64 KR |
2858 | #ifdef OBJ_VMS |
2859 | const_flag &= ~IN_DEFAULT_SECTION; | |
2860 | #endif | |
6efd877d | 2861 | } /* s_text() */ |
fecd2382 | 2862 | \f |
6efd877d | 2863 | |
6efd877d KR |
2864 | void |
2865 | demand_empty_rest_of_line () | |
2866 | { | |
2867 | SKIP_WHITESPACE (); | |
58d4951d | 2868 | if (is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
2869 | { |
2870 | input_line_pointer++; | |
2871 | } | |
2872 | else | |
2873 | { | |
2874 | ignore_rest_of_line (); | |
2875 | } | |
2876 | /* Return having already swallowed end-of-line. */ | |
2877 | } /* Return pointing just after end-of-line. */ | |
fecd2382 RP |
2878 | |
2879 | void | |
6efd877d | 2880 | ignore_rest_of_line () /* For suspect lines: gives warning. */ |
fecd2382 | 2881 | { |
58d4951d | 2882 | if (!is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 2883 | { |
6efd877d KR |
2884 | if (isprint (*input_line_pointer)) |
2885 | as_bad ("Rest of line ignored. First ignored character is `%c'.", | |
f8701a3f SC |
2886 | *input_line_pointer); |
2887 | else | |
6efd877d | 2888 | as_bad ("Rest of line ignored. First ignored character valued 0x%x.", |
f8701a3f SC |
2889 | *input_line_pointer); |
2890 | while (input_line_pointer < buffer_limit | |
58d4951d | 2891 | && !is_end_of_line[(unsigned char) *input_line_pointer]) |
f8701a3f | 2892 | { |
6efd877d | 2893 | input_line_pointer++; |
f8701a3f SC |
2894 | } |
2895 | } | |
6efd877d | 2896 | input_line_pointer++; /* Return pointing just after end-of-line. */ |
58d4951d | 2897 | know (is_end_of_line[(unsigned char) input_line_pointer[-1]]); |
fecd2382 RP |
2898 | } |
2899 | ||
2900 | /* | |
2901 | * pseudo_set() | |
2902 | * | |
2903 | * In: Pointer to a symbol. | |
2904 | * Input_line_pointer->expression. | |
2905 | * | |
2906 | * Out: Input_line_pointer->just after any whitespace after expression. | |
2907 | * Tried to set symbol to value of expression. | |
2908 | * Will change symbols type, value, and frag; | |
fecd2382 RP |
2909 | */ |
2910 | void | |
f8701a3f | 2911 | pseudo_set (symbolP) |
6efd877d | 2912 | symbolS *symbolP; |
fecd2382 | 2913 | { |
6efd877d | 2914 | expressionS exp; |
daad3bbf | 2915 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
f8701a3f | 2916 | int ext; |
fecd2382 | 2917 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 2918 | |
6efd877d | 2919 | know (symbolP); /* NULL pointer is logic error. */ |
daad3bbf | 2920 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
6efd877d | 2921 | ext = S_IS_EXTERNAL (symbolP); |
fecd2382 | 2922 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
f8701a3f | 2923 | |
5ac34ac3 | 2924 | (void) expression (&exp); |
f8701a3f | 2925 | |
5ac34ac3 ILT |
2926 | if (exp.X_op == O_illegal) |
2927 | as_bad ("illegal expression; zero assumed"); | |
2928 | else if (exp.X_op == O_absent) | |
2929 | as_bad ("missing expression; zero assumed"); | |
2930 | else if (exp.X_op == O_big) | |
2931 | as_bad ("%s number invalid; zero assumed", | |
2932 | exp.X_add_number > 0 ? "bignum" : "floating point"); | |
2933 | else if (exp.X_op == O_subtract | |
2934 | && (S_GET_SEGMENT (exp.X_add_symbol) | |
2935 | == S_GET_SEGMENT (exp.X_op_symbol)) | |
2936 | && SEG_NORMAL (S_GET_SEGMENT (exp.X_add_symbol)) | |
2937 | && exp.X_add_symbol->sy_frag == exp.X_op_symbol->sy_frag) | |
9471a360 | 2938 | { |
5ac34ac3 ILT |
2939 | exp.X_op = O_constant; |
2940 | exp.X_add_number = (S_GET_VALUE (exp.X_add_symbol) | |
2941 | - S_GET_VALUE (exp.X_op_symbol)); | |
9471a360 | 2942 | } |
5ac34ac3 ILT |
2943 | |
2944 | switch (exp.X_op) | |
9471a360 | 2945 | { |
5ac34ac3 ILT |
2946 | case O_illegal: |
2947 | case O_absent: | |
2948 | case O_big: | |
2949 | exp.X_add_number = 0; | |
2950 | /* Fall through. */ | |
2951 | case O_constant: | |
9471a360 | 2952 | S_SET_SEGMENT (symbolP, absolute_section); |
daad3bbf | 2953 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
2954 | if (ext) |
2955 | S_SET_EXTERNAL (symbolP); | |
6efd877d | 2956 | else |
6efd877d | 2957 | S_CLEAR_EXTERNAL (symbolP); |
fecd2382 | 2958 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
604633ae | 2959 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
6efd877d | 2960 | symbolP->sy_frag = &zero_address_frag; |
5ac34ac3 | 2961 | break; |
f8701a3f | 2962 | |
5ac34ac3 ILT |
2963 | case O_register: |
2964 | S_SET_SEGMENT (symbolP, reg_section); | |
604633ae | 2965 | S_SET_VALUE (symbolP, (valueT) exp.X_add_number); |
5ac34ac3 ILT |
2966 | symbolP->sy_frag = &zero_address_frag; |
2967 | break; | |
2968 | ||
2969 | case O_symbol: | |
ef198870 KR |
2970 | if (S_GET_SEGMENT (exp.X_add_symbol) == undefined_section |
2971 | || exp.X_add_number != 0) | |
5ac34ac3 | 2972 | symbolP->sy_value = exp; |
6efd877d KR |
2973 | else |
2974 | { | |
80d80c64 KR |
2975 | symbolS *s = exp.X_add_symbol; |
2976 | ||
2977 | S_SET_SEGMENT (symbolP, S_GET_SEGMENT (s)); | |
daad3bbf | 2978 | #if (defined (OBJ_AOUT) || defined (OBJ_BOUT)) && ! defined (BFD_ASSEMBLER) |
5ac34ac3 ILT |
2979 | if (ext) |
2980 | S_SET_EXTERNAL (symbolP); | |
2981 | else | |
2982 | S_CLEAR_EXTERNAL (symbolP); | |
fecd2382 | 2983 | #endif /* OBJ_AOUT or OBJ_BOUT */ |
5ac34ac3 | 2984 | S_SET_VALUE (symbolP, |
80d80c64 KR |
2985 | exp.X_add_number + S_GET_VALUE (s)); |
2986 | symbolP->sy_frag = s->sy_frag; | |
ef198870 | 2987 | copy_symbol_attributes (symbolP, s); |
5ac34ac3 ILT |
2988 | } |
2989 | break; | |
f8701a3f | 2990 | |
5ac34ac3 ILT |
2991 | default: |
2992 | /* The value is some complex expression. | |
2993 | FIXME: Should we set the segment to anything? */ | |
2994 | symbolP->sy_value = exp; | |
2995 | break; | |
f8701a3f | 2996 | } |
fecd2382 RP |
2997 | } |
2998 | \f | |
2999 | /* | |
3000 | * cons() | |
3001 | * | |
3002 | * CONStruct more frag of .bytes, or .words etc. | |
3003 | * Should need_pass_2 be 1 then emit no frag(s). | |
80aab579 | 3004 | * This understands EXPRESSIONS. |
fecd2382 RP |
3005 | * |
3006 | * Bug (?) | |
3007 | * | |
3008 | * This has a split personality. We use expression() to read the | |
3009 | * value. We can detect if the value won't fit in a byte or word. | |
3010 | * But we can't detect if expression() discarded significant digits | |
3011 | * in the case of a long. Not worth the crocks required to fix it. | |
3012 | */ | |
3013 | ||
40324362 KR |
3014 | /* Select a parser for cons expressions. */ |
3015 | ||
3016 | /* Some targets need to parse the expression in various fancy ways. | |
3017 | You can define TC_PARSE_CONS_EXPRESSION to do whatever you like | |
3018 | (for example, the HPPA does this). Otherwise, you can define | |
3019 | BITFIELD_CONS_EXPRESSIONS to permit bitfields to be specified, or | |
3020 | REPEAT_CONS_EXPRESSIONS to permit repeat counts. If none of these | |
3021 | are defined, which is the normal case, then only simple expressions | |
3022 | are permitted. */ | |
3023 | ||
1356d77d ILT |
3024 | static void |
3025 | parse_mri_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
3026 | ||
40324362 KR |
3027 | #ifndef TC_PARSE_CONS_EXPRESSION |
3028 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
3029 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_bitfield_cons (EXP, NBYTES) | |
3030 | static void | |
3031 | parse_bitfield_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
3032 | #endif | |
40324362 KR |
3033 | #ifdef REPEAT_CONS_EXPRESSIONS |
3034 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) parse_repeat_cons (EXP, NBYTES) | |
3035 | static void | |
3036 | parse_repeat_cons PARAMS ((expressionS *exp, unsigned int nbytes)); | |
3037 | #endif | |
3038 | ||
3039 | /* If we haven't gotten one yet, just call expression. */ | |
3040 | #ifndef TC_PARSE_CONS_EXPRESSION | |
3041 | #define TC_PARSE_CONS_EXPRESSION(EXP, NBYTES) expression (EXP) | |
3042 | #endif | |
3043 | #endif | |
3044 | ||
6efd877d KR |
3045 | /* worker to do .byte etc statements */ |
3046 | /* clobbers input_line_pointer, checks */ | |
3047 | /* end-of-line. */ | |
86038ada ILT |
3048 | static void |
3049 | cons_worker (nbytes, rva) | |
604633ae | 3050 | register int nbytes; /* 1=.byte, 2=.word, 4=.long */ |
86038ada | 3051 | int rva; |
fecd2382 | 3052 | { |
286cb27a | 3053 | int c; |
6efd877d | 3054 | expressionS exp; |
86038ada | 3055 | char *stop = NULL; |
3dce804d | 3056 | char stopc; |
f8701a3f | 3057 | |
a2a5a4fa KR |
3058 | #ifdef md_flush_pending_output |
3059 | md_flush_pending_output (); | |
3060 | #endif | |
3061 | ||
18c9057f ILT |
3062 | if (flag_mri) |
3063 | stop = mri_comment_field (&stopc); | |
3064 | ||
40324362 | 3065 | if (is_it_end_of_statement ()) |
6efd877d | 3066 | { |
cef72a92 ILT |
3067 | if (flag_mri) |
3068 | mri_comment_end (stop, stopc); | |
40324362 KR |
3069 | demand_empty_rest_of_line (); |
3070 | return; | |
6efd877d | 3071 | } |
40324362 | 3072 | |
a69e5977 ILT |
3073 | #ifdef md_cons_align |
3074 | md_cons_align (nbytes); | |
3075 | #endif | |
3076 | ||
286cb27a | 3077 | c = 0; |
40324362 | 3078 | do |
6efd877d | 3079 | { |
cef72a92 | 3080 | if (flag_m68k_mri) |
1356d77d ILT |
3081 | parse_mri_cons (&exp, (unsigned int) nbytes); |
3082 | else | |
3083 | TC_PARSE_CONS_EXPRESSION (&exp, (unsigned int) nbytes); | |
6594d6b9 KR |
3084 | |
3085 | if (rva) | |
3086 | { | |
3087 | if (exp.X_op == O_symbol) | |
3088 | exp.X_op = O_symbol_rva; | |
3089 | else | |
3090 | as_fatal ("rva without symbol"); | |
3091 | } | |
3092 | emit_expr (&exp, (unsigned int) nbytes); | |
286cb27a | 3093 | ++c; |
40324362 | 3094 | } |
18c9057f | 3095 | while (*input_line_pointer++ == ','); |
40324362 | 3096 | |
286cb27a ILT |
3097 | /* In MRI mode, after an odd number of bytes, we must align to an |
3098 | even word boundary, unless the next instruction is a dc.b, ds.b | |
3099 | or dcb.b. */ | |
3100 | if (flag_mri && nbytes == 1 && (c & 1) != 0) | |
3101 | mri_pending_align = 1; | |
3102 | ||
40324362 | 3103 | input_line_pointer--; /* Put terminator back into stream. */ |
86038ada ILT |
3104 | |
3105 | if (flag_mri) | |
18c9057f | 3106 | mri_comment_end (stop, stopc); |
86038ada | 3107 | |
40324362 | 3108 | demand_empty_rest_of_line (); |
30d3a445 | 3109 | } |
f8701a3f | 3110 | |
86038ada ILT |
3111 | |
3112 | void | |
3113 | cons (size) | |
3114 | int size; | |
3115 | { | |
3116 | cons_worker (size, 0); | |
3117 | } | |
3118 | ||
3119 | void | |
3120 | s_rva (size) | |
3121 | int size; | |
3122 | { | |
3123 | cons_worker (size, 1); | |
3124 | } | |
3125 | ||
3126 | ||
40324362 KR |
3127 | /* Put the contents of expression EXP into the object file using |
3128 | NBYTES bytes. If need_pass_2 is 1, this does nothing. */ | |
f8701a3f | 3129 | |
40324362 KR |
3130 | void |
3131 | emit_expr (exp, nbytes) | |
3132 | expressionS *exp; | |
3133 | unsigned int nbytes; | |
3134 | { | |
5ac34ac3 | 3135 | operatorT op; |
40324362 | 3136 | register char *p; |
80aab579 | 3137 | valueT extra_digit = 0; |
f8701a3f | 3138 | |
40324362 KR |
3139 | /* Don't do anything if we are going to make another pass. */ |
3140 | if (need_pass_2) | |
3141 | return; | |
3142 | ||
5ac34ac3 | 3143 | op = exp->X_op; |
40324362 | 3144 | |
e28c40d7 ILT |
3145 | /* Allow `.word 0' in the absolute section. */ |
3146 | if (now_seg == absolute_section) | |
3147 | { | |
3148 | if (op != O_constant || exp->X_add_number != 0) | |
3149 | as_bad ("attempt to store value in absolute section"); | |
3150 | abs_section_offset += nbytes; | |
3151 | return; | |
3152 | } | |
3153 | ||
80aab579 ILT |
3154 | /* Handle a negative bignum. */ |
3155 | if (op == O_uminus | |
3156 | && exp->X_add_number == 0 | |
3157 | && exp->X_add_symbol->sy_value.X_op == O_big | |
3158 | && exp->X_add_symbol->sy_value.X_add_number > 0) | |
3159 | { | |
3160 | int i; | |
3161 | unsigned long carry; | |
3162 | ||
3163 | exp = &exp->X_add_symbol->sy_value; | |
3164 | ||
3165 | /* Negate the bignum: one's complement each digit and add 1. */ | |
3166 | carry = 1; | |
3167 | for (i = 0; i < exp->X_add_number; i++) | |
3168 | { | |
3169 | unsigned long next; | |
3170 | ||
3171 | next = (((~ (generic_bignum[i] & LITTLENUM_MASK)) | |
3172 | & LITTLENUM_MASK) | |
3173 | + carry); | |
3174 | generic_bignum[i] = next & LITTLENUM_MASK; | |
3175 | carry = next >> LITTLENUM_NUMBER_OF_BITS; | |
3176 | } | |
3177 | ||
3178 | /* We can ignore any carry out, because it will be handled by | |
3179 | extra_digit if it is needed. */ | |
3180 | ||
3181 | extra_digit = (valueT) -1; | |
3182 | op = O_big; | |
3183 | } | |
3184 | ||
5ac34ac3 | 3185 | if (op == O_absent || op == O_illegal) |
6efd877d | 3186 | { |
5ac34ac3 ILT |
3187 | as_warn ("zero assumed for missing expression"); |
3188 | exp->X_add_number = 0; | |
3189 | op = O_constant; | |
6efd877d | 3190 | } |
80aab579 | 3191 | else if (op == O_big && exp->X_add_number <= 0) |
6efd877d | 3192 | { |
80aab579 | 3193 | as_bad ("floating point number invalid; zero assumed"); |
40324362 | 3194 | exp->X_add_number = 0; |
5ac34ac3 | 3195 | op = O_constant; |
40324362 | 3196 | } |
5ac34ac3 | 3197 | else if (op == O_register) |
6efd877d | 3198 | { |
5ac34ac3 ILT |
3199 | as_warn ("register value used as expression"); |
3200 | op = O_constant; | |
40324362 | 3201 | } |
6efd877d | 3202 | |
604633ae | 3203 | p = frag_more ((int) nbytes); |
6efd877d | 3204 | |
40324362 KR |
3205 | #ifndef WORKING_DOT_WORD |
3206 | /* If we have the difference of two symbols in a word, save it on | |
3207 | the broken_words list. See the code in write.c. */ | |
5ac34ac3 | 3208 | if (op == O_subtract && nbytes == 2) |
40324362 KR |
3209 | { |
3210 | struct broken_word *x; | |
3211 | ||
3212 | x = (struct broken_word *) xmalloc (sizeof (struct broken_word)); | |
3213 | x->next_broken_word = broken_words; | |
3214 | broken_words = x; | |
3215 | x->frag = frag_now; | |
3216 | x->word_goes_here = p; | |
3217 | x->dispfrag = 0; | |
3218 | x->add = exp->X_add_symbol; | |
5ac34ac3 | 3219 | x->sub = exp->X_op_symbol; |
40324362 KR |
3220 | x->addnum = exp->X_add_number; |
3221 | x->added = 0; | |
3222 | new_broken_words++; | |
3223 | return; | |
3224 | } | |
f8701a3f | 3225 | #endif |
6efd877d | 3226 | |
80aab579 ILT |
3227 | /* If we have an integer, but the number of bytes is too large to |
3228 | pass to md_number_to_chars, handle it as a bignum. */ | |
3229 | if (op == O_constant && nbytes > sizeof (valueT)) | |
3230 | { | |
3231 | valueT val; | |
3232 | int gencnt; | |
3233 | ||
3234 | if (! exp->X_unsigned && exp->X_add_number < 0) | |
3235 | extra_digit = (valueT) -1; | |
3236 | val = (valueT) exp->X_add_number; | |
3237 | gencnt = 0; | |
3238 | do | |
3239 | { | |
3240 | generic_bignum[gencnt] = val & LITTLENUM_MASK; | |
3241 | val >>= LITTLENUM_NUMBER_OF_BITS; | |
3242 | ++gencnt; | |
3243 | } | |
3244 | while (val != 0); | |
3245 | op = exp->X_op = O_big; | |
3246 | exp->X_add_number = gencnt; | |
3247 | } | |
3248 | ||
5ac34ac3 | 3249 | if (op == O_constant) |
40324362 | 3250 | { |
44ce2f32 DE |
3251 | register valueT get; |
3252 | register valueT use; | |
3253 | register valueT mask; | |
6468dabd | 3254 | valueT hibit; |
44ce2f32 | 3255 | register valueT unmask; |
40324362 KR |
3256 | |
3257 | /* JF << of >= number of bits in the object is undefined. In | |
3258 | particular SPARC (Sun 4) has problems */ | |
44ce2f32 | 3259 | if (nbytes >= sizeof (valueT)) |
6468dabd ILT |
3260 | { |
3261 | mask = 0; | |
3262 | if (nbytes > sizeof (valueT)) | |
3263 | hibit = 0; | |
3264 | else | |
3265 | hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); | |
3266 | } | |
40324362 | 3267 | else |
6468dabd ILT |
3268 | { |
3269 | /* Don't store these bits. */ | |
3270 | mask = ~(valueT) 0 << (BITS_PER_CHAR * nbytes); | |
3271 | hibit = (valueT) 1 << (nbytes * BITS_PER_CHAR - 1); | |
3272 | } | |
6efd877d | 3273 | |
40324362 | 3274 | unmask = ~mask; /* Do store these bits. */ |
6efd877d | 3275 | |
40324362 KR |
3276 | #ifdef NEVER |
3277 | "Do this mod if you want every overflow check to assume SIGNED 2's complement data."; | |
3278 | mask = ~(unmask >> 1); /* Includes sign bit now. */ | |
3279 | #endif | |
6efd877d | 3280 | |
40324362 KR |
3281 | get = exp->X_add_number; |
3282 | use = get & unmask; | |
6468dabd ILT |
3283 | if ((get & mask) != 0 |
3284 | && ((get & mask) != mask | |
3285 | || (get & hibit) == 0)) | |
40324362 | 3286 | { /* Leading bits contain both 0s & 1s. */ |
a69e5977 ILT |
3287 | as_warn ("Value 0x%lx truncated to 0x%lx.", |
3288 | (unsigned long) get, (unsigned long) use); | |
40324362 | 3289 | } |
604633ae | 3290 | /* put bytes in right order. */ |
44ce2f32 | 3291 | md_number_to_chars (p, use, (int) nbytes); |
40324362 | 3292 | } |
80aab579 ILT |
3293 | else if (op == O_big) |
3294 | { | |
3295 | int size; | |
3296 | LITTLENUM_TYPE *nums; | |
3297 | ||
3298 | know (nbytes % CHARS_PER_LITTLENUM == 0); | |
3299 | ||
3300 | size = exp->X_add_number * CHARS_PER_LITTLENUM; | |
3301 | if (nbytes < size) | |
3302 | { | |
3303 | as_warn ("Bignum truncated to %d bytes", nbytes); | |
3304 | size = nbytes; | |
3305 | } | |
3306 | ||
3307 | if (target_big_endian) | |
3308 | { | |
3309 | while (nbytes > size) | |
3310 | { | |
3311 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
3312 | nbytes -= CHARS_PER_LITTLENUM; | |
3313 | p += CHARS_PER_LITTLENUM; | |
3314 | } | |
3315 | ||
3316 | nums = generic_bignum + size / CHARS_PER_LITTLENUM; | |
3317 | while (size > 0) | |
3318 | { | |
3319 | --nums; | |
3320 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
3321 | size -= CHARS_PER_LITTLENUM; | |
3322 | p += CHARS_PER_LITTLENUM; | |
3323 | } | |
3324 | } | |
3325 | else | |
3326 | { | |
3327 | nums = generic_bignum; | |
3328 | while (size > 0) | |
3329 | { | |
3330 | md_number_to_chars (p, (valueT) *nums, CHARS_PER_LITTLENUM); | |
3331 | ++nums; | |
3332 | size -= CHARS_PER_LITTLENUM; | |
3333 | p += CHARS_PER_LITTLENUM; | |
3334 | nbytes -= CHARS_PER_LITTLENUM; | |
3335 | } | |
3336 | ||
3337 | while (nbytes > 0) | |
3338 | { | |
3339 | md_number_to_chars (p, extra_digit, CHARS_PER_LITTLENUM); | |
3340 | nbytes -= CHARS_PER_LITTLENUM; | |
3341 | p += CHARS_PER_LITTLENUM; | |
3342 | } | |
3343 | } | |
3344 | } | |
40324362 KR |
3345 | else |
3346 | { | |
1fbfe108 | 3347 | memset (p, 0, nbytes); |
6efd877d | 3348 | |
40324362 KR |
3349 | /* Now we need to generate a fixS to record the symbol value. |
3350 | This is easy for BFD. For other targets it can be more | |
3351 | complex. For very complex cases (currently, the HPPA and | |
3352 | NS32K), you can define TC_CONS_FIX_NEW to do whatever you | |
3353 | want. For simpler cases, you can define TC_CONS_RELOC to be | |
3354 | the name of the reloc code that should be stored in the fixS. | |
3355 | If neither is defined, the code uses NO_RELOC if it is | |
3356 | defined, and otherwise uses 0. */ | |
6efd877d | 3357 | |
40324362 | 3358 | #ifdef BFD_ASSEMBLER |
4064305e SS |
3359 | #ifdef TC_CONS_FIX_NEW |
3360 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
3361 | #else | |
a69e5977 ILT |
3362 | { |
3363 | bfd_reloc_code_real_type r; | |
3364 | ||
3365 | switch (nbytes) | |
3366 | { | |
3367 | case 1: | |
3368 | r = BFD_RELOC_8; | |
3369 | break; | |
3370 | case 2: | |
3371 | r = BFD_RELOC_16; | |
3372 | break; | |
3373 | case 4: | |
3374 | r = BFD_RELOC_32; | |
3375 | break; | |
3376 | case 8: | |
3377 | r = BFD_RELOC_64; | |
3378 | break; | |
3379 | default: | |
3380 | as_bad ("unsupported BFD relocation size %u", nbytes); | |
3381 | r = BFD_RELOC_32; | |
3382 | break; | |
3383 | } | |
3384 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, | |
3385 | 0, r); | |
3386 | } | |
4064305e | 3387 | #endif |
40324362 KR |
3388 | #else |
3389 | #ifdef TC_CONS_FIX_NEW | |
3390 | TC_CONS_FIX_NEW (frag_now, p - frag_now->fr_literal, nbytes, exp); | |
3391 | #else | |
3392 | /* Figure out which reloc number to use. Use TC_CONS_RELOC if | |
3393 | it is defined, otherwise use NO_RELOC if it is defined, | |
3394 | otherwise use 0. */ | |
3395 | #ifndef TC_CONS_RELOC | |
3396 | #ifdef NO_RELOC | |
3397 | #define TC_CONS_RELOC NO_RELOC | |
3398 | #else | |
3399 | #define TC_CONS_RELOC 0 | |
3400 | #endif | |
3401 | #endif | |
80aab579 | 3402 | fix_new_exp (frag_now, p - frag_now->fr_literal, (int) nbytes, exp, 0, |
5ac34ac3 | 3403 | TC_CONS_RELOC); |
40324362 KR |
3404 | #endif /* TC_CONS_FIX_NEW */ |
3405 | #endif /* BFD_ASSEMBLER */ | |
3406 | } | |
3407 | } | |
3408 | \f | |
3409 | #ifdef BITFIELD_CONS_EXPRESSIONS | |
6efd877d | 3410 | |
40324362 KR |
3411 | /* i960 assemblers, (eg, asm960), allow bitfields after ".byte" as |
3412 | w:x,y:z, where w and y are bitwidths and x and y are values. They | |
3413 | then pack them all together. We do a little better in that we allow | |
3414 | them in words, longs, etc. and we'll pack them in target byte order | |
3415 | for you. | |
6efd877d | 3416 | |
40324362 KR |
3417 | The rules are: pack least significat bit first, if a field doesn't |
3418 | entirely fit, put it in the next unit. Overflowing the bitfield is | |
3419 | explicitly *not* even a warning. The bitwidth should be considered | |
3420 | a "mask". | |
6efd877d | 3421 | |
40324362 KR |
3422 | To use this function the tc-XXX.h file should define |
3423 | BITFIELD_CONS_EXPRESSIONS. */ | |
f8701a3f | 3424 | |
40324362 KR |
3425 | static void |
3426 | parse_bitfield_cons (exp, nbytes) | |
3427 | expressionS *exp; | |
3428 | unsigned int nbytes; | |
3429 | { | |
3430 | unsigned int bits_available = BITS_PER_CHAR * nbytes; | |
3431 | char *hold = input_line_pointer; | |
f8701a3f | 3432 | |
5ac34ac3 | 3433 | (void) expression (exp); |
f8701a3f | 3434 | |
40324362 KR |
3435 | if (*input_line_pointer == ':') |
3436 | { /* bitfields */ | |
3437 | long value = 0; | |
f8701a3f | 3438 | |
40324362 KR |
3439 | for (;;) |
3440 | { | |
3441 | unsigned long width; | |
f8701a3f | 3442 | |
40324362 KR |
3443 | if (*input_line_pointer != ':') |
3444 | { | |
3445 | input_line_pointer = hold; | |
3446 | break; | |
3447 | } /* next piece is not a bitfield */ | |
3448 | ||
3449 | /* In the general case, we can't allow | |
3450 | full expressions with symbol | |
3451 | differences and such. The relocation | |
3452 | entries for symbols not defined in this | |
3453 | assembly would require arbitrary field | |
3454 | widths, positions, and masks which most | |
3455 | of our current object formats don't | |
3456 | support. | |
cd3b81bd | 3457 | |
40324362 KR |
3458 | In the specific case where a symbol |
3459 | *is* defined in this assembly, we | |
3460 | *could* build fixups and track it, but | |
3461 | this could lead to confusion for the | |
3462 | backends. I'm lazy. I'll take any | |
3463 | SEG_ABSOLUTE. I think that means that | |
3464 | you can use a previous .set or | |
3465 | .equ type symbol. xoxorich. */ | |
3466 | ||
5ac34ac3 | 3467 | if (exp->X_op == O_absent) |
6efd877d | 3468 | { |
5ac34ac3 | 3469 | as_warn ("using a bit field width of zero"); |
40324362 | 3470 | exp->X_add_number = 0; |
5ac34ac3 | 3471 | exp->X_op = O_constant; |
40324362 KR |
3472 | } /* implied zero width bitfield */ |
3473 | ||
5ac34ac3 | 3474 | if (exp->X_op != O_constant) |
6efd877d | 3475 | { |
40324362 | 3476 | *input_line_pointer = '\0'; |
5ac34ac3 | 3477 | as_bad ("field width \"%s\" too complex for a bitfield", hold); |
40324362 KR |
3478 | *input_line_pointer = ':'; |
3479 | demand_empty_rest_of_line (); | |
3480 | return; | |
3481 | } /* too complex */ | |
3482 | ||
3483 | if ((width = exp->X_add_number) > (BITS_PER_CHAR * nbytes)) | |
9471a360 | 3484 | { |
80aab579 | 3485 | as_warn ("field width %lu too big to fit in %d bytes: truncated to %d bits", |
40324362 KR |
3486 | width, nbytes, (BITS_PER_CHAR * nbytes)); |
3487 | width = BITS_PER_CHAR * nbytes; | |
3488 | } /* too big */ | |
3489 | ||
3490 | if (width > bits_available) | |
9471a360 | 3491 | { |
40324362 KR |
3492 | /* FIXME-SOMEDAY: backing up and reparsing is wasteful. */ |
3493 | input_line_pointer = hold; | |
3494 | exp->X_add_number = value; | |
3495 | break; | |
3496 | } /* won't fit */ | |
3497 | ||
3498 | hold = ++input_line_pointer; /* skip ':' */ | |
3499 | ||
5ac34ac3 ILT |
3500 | (void) expression (exp); |
3501 | if (exp->X_op != O_constant) | |
9471a360 | 3502 | { |
40324362 KR |
3503 | char cache = *input_line_pointer; |
3504 | ||
3505 | *input_line_pointer = '\0'; | |
5ac34ac3 | 3506 | as_bad ("field value \"%s\" too complex for a bitfield", hold); |
40324362 KR |
3507 | *input_line_pointer = cache; |
3508 | demand_empty_rest_of_line (); | |
3509 | return; | |
3510 | } /* too complex */ | |
3511 | ||
5ac34ac3 ILT |
3512 | value |= ((~(-1 << width) & exp->X_add_number) |
3513 | << ((BITS_PER_CHAR * nbytes) - bits_available)); | |
40324362 KR |
3514 | |
3515 | if ((bits_available -= width) == 0 | |
3516 | || is_it_end_of_statement () | |
3517 | || *input_line_pointer != ',') | |
3518 | { | |
3519 | break; | |
3520 | } /* all the bitfields we're gonna get */ | |
3521 | ||
3522 | hold = ++input_line_pointer; | |
5ac34ac3 | 3523 | (void) expression (exp); |
40324362 KR |
3524 | } /* forever loop */ |
3525 | ||
3526 | exp->X_add_number = value; | |
5ac34ac3 | 3527 | exp->X_op = O_constant; |
80aab579 | 3528 | exp->X_unsigned = 1; |
40324362 KR |
3529 | } /* if looks like a bitfield */ |
3530 | } /* parse_bitfield_cons() */ | |
3531 | ||
3532 | #endif /* BITFIELD_CONS_EXPRESSIONS */ | |
3533 | \f | |
1356d77d | 3534 | /* Handle an MRI style string expression. */ |
40324362 KR |
3535 | |
3536 | static void | |
3537 | parse_mri_cons (exp, nbytes) | |
3538 | expressionS *exp; | |
3539 | unsigned int nbytes; | |
3540 | { | |
1356d77d ILT |
3541 | if (*input_line_pointer != '\'' |
3542 | && (input_line_pointer[1] != '\'' | |
3543 | || (*input_line_pointer != 'A' | |
3544 | && *input_line_pointer != 'E'))) | |
3545 | TC_PARSE_CONS_EXPRESSION (exp, nbytes); | |
3546 | else | |
40324362 | 3547 | { |
40324362 KR |
3548 | int scan = 0; |
3549 | unsigned int result = 0; | |
1356d77d ILT |
3550 | |
3551 | /* An MRI style string. Cut into as many bytes as will fit into | |
3552 | a nbyte chunk, left justify if necessary, and separate with | |
3553 | commas so we can try again later. */ | |
3554 | if (*input_line_pointer == 'A') | |
3555 | ++input_line_pointer; | |
3556 | else if (*input_line_pointer == 'E') | |
3557 | { | |
3558 | as_bad ("EBCDIC constants are not supported"); | |
3559 | ++input_line_pointer; | |
3560 | } | |
3561 | ||
40324362 KR |
3562 | input_line_pointer++; |
3563 | for (scan = 0; scan < nbytes; scan++) | |
3564 | { | |
3565 | if (*input_line_pointer == '\'') | |
3566 | { | |
3567 | if (input_line_pointer[1] == '\'') | |
6efd877d | 3568 | { |
40324362 | 3569 | input_line_pointer++; |
f8701a3f | 3570 | } |
40324362 KR |
3571 | else |
3572 | break; | |
9471a360 | 3573 | } |
40324362 KR |
3574 | result = (result << 8) | (*input_line_pointer++); |
3575 | } | |
f8701a3f | 3576 | |
40324362 KR |
3577 | /* Left justify */ |
3578 | while (scan < nbytes) | |
3579 | { | |
3580 | result <<= 8; | |
3581 | scan++; | |
3582 | } | |
3583 | /* Create correct expression */ | |
5ac34ac3 | 3584 | exp->X_op = O_constant; |
40324362 | 3585 | exp->X_add_number = result; |
40324362 KR |
3586 | /* Fake it so that we can read the next char too */ |
3587 | if (input_line_pointer[0] != '\'' || | |
3588 | (input_line_pointer[0] == '\'' && input_line_pointer[1] == '\'')) | |
3589 | { | |
3590 | input_line_pointer -= 2; | |
3591 | input_line_pointer[0] = ','; | |
3592 | input_line_pointer[1] = '\''; | |
3593 | } | |
3594 | else | |
3595 | input_line_pointer++; | |
3596 | } | |
40324362 | 3597 | } |
40324362 KR |
3598 | \f |
3599 | #ifdef REPEAT_CONS_EXPRESSIONS | |
3600 | ||
3601 | /* Parse a repeat expression for cons. This is used by the MIPS | |
3602 | assembler. The format is NUMBER:COUNT; NUMBER appears in the | |
3603 | object file COUNT times. | |
3604 | ||
3605 | To use this for a target, define REPEAT_CONS_EXPRESSIONS. */ | |
3606 | ||
3607 | static void | |
3608 | parse_repeat_cons (exp, nbytes) | |
3609 | expressionS *exp; | |
3610 | unsigned int nbytes; | |
3611 | { | |
3612 | expressionS count; | |
40324362 KR |
3613 | register int i; |
3614 | ||
3615 | expression (exp); | |
3616 | ||
3617 | if (*input_line_pointer != ':') | |
3618 | { | |
3619 | /* No repeat count. */ | |
3620 | return; | |
3621 | } | |
3622 | ||
3623 | ++input_line_pointer; | |
5ac34ac3 ILT |
3624 | expression (&count); |
3625 | if (count.X_op != O_constant | |
40324362 KR |
3626 | || count.X_add_number <= 0) |
3627 | { | |
3628 | as_warn ("Unresolvable or nonpositive repeat count; using 1"); | |
3629 | return; | |
3630 | } | |
3631 | ||
3632 | /* The cons function is going to output this expression once. So we | |
3633 | output it count - 1 times. */ | |
3634 | for (i = count.X_add_number - 1; i > 0; i--) | |
3635 | emit_expr (exp, nbytes); | |
3636 | } | |
3637 | ||
3638 | #endif /* REPEAT_CONS_EXPRESSIONS */ | |
fecd2382 | 3639 | \f |
e28c40d7 ILT |
3640 | /* Parse a floating point number represented as a hex constant. This |
3641 | permits users to specify the exact bits they want in the floating | |
3642 | point number. */ | |
3643 | ||
3644 | static int | |
3645 | hex_float (float_type, bytes) | |
3646 | int float_type; | |
3647 | char *bytes; | |
3648 | { | |
3649 | int length; | |
3650 | int i; | |
3651 | ||
3652 | switch (float_type) | |
3653 | { | |
3654 | case 'f': | |
3655 | case 'F': | |
3656 | case 's': | |
3657 | case 'S': | |
3658 | length = 4; | |
3659 | break; | |
3660 | ||
3661 | case 'd': | |
3662 | case 'D': | |
3663 | case 'r': | |
3664 | case 'R': | |
3665 | length = 8; | |
3666 | break; | |
3667 | ||
3668 | case 'x': | |
3669 | case 'X': | |
3670 | length = 12; | |
3671 | break; | |
3672 | ||
3673 | case 'p': | |
3674 | case 'P': | |
3675 | length = 12; | |
3676 | break; | |
3677 | ||
3678 | default: | |
3679 | as_bad ("Unknown floating type type '%c'", float_type); | |
3680 | return -1; | |
3681 | } | |
3682 | ||
3683 | /* It would be nice if we could go through expression to parse the | |
3684 | hex constant, but if we get a bignum it's a pain to sort it into | |
3685 | the buffer correctly. */ | |
3686 | i = 0; | |
3687 | while (hex_p (*input_line_pointer) || *input_line_pointer == '_') | |
3688 | { | |
3689 | int d; | |
3690 | ||
3691 | /* The MRI assembler accepts arbitrary underscores strewn about | |
3692 | through the hex constant, so we ignore them as well. */ | |
3693 | if (*input_line_pointer == '_') | |
3694 | { | |
3695 | ++input_line_pointer; | |
3696 | continue; | |
3697 | } | |
3698 | ||
3699 | if (i >= length) | |
3700 | { | |
3701 | as_warn ("Floating point constant too large"); | |
3702 | return -1; | |
3703 | } | |
3704 | d = hex_value (*input_line_pointer) << 4; | |
3705 | ++input_line_pointer; | |
3706 | while (*input_line_pointer == '_') | |
3707 | ++input_line_pointer; | |
3708 | if (hex_p (*input_line_pointer)) | |
3709 | { | |
3710 | d += hex_value (*input_line_pointer); | |
3711 | ++input_line_pointer; | |
3712 | } | |
a920b693 ILT |
3713 | if (target_big_endian) |
3714 | bytes[i] = d; | |
3715 | else | |
3716 | bytes[length - i - 1] = d; | |
3717 | ++i; | |
e28c40d7 ILT |
3718 | } |
3719 | ||
3720 | if (i < length) | |
a920b693 ILT |
3721 | { |
3722 | if (target_big_endian) | |
3723 | memset (bytes + i, 0, length - i); | |
3724 | else | |
3725 | memset (bytes, 0, length - i); | |
3726 | } | |
e28c40d7 ILT |
3727 | |
3728 | return length; | |
3729 | } | |
3730 | ||
fecd2382 RP |
3731 | /* |
3732 | * float_cons() | |
3733 | * | |
3734 | * CONStruct some more frag chars of .floats .ffloats etc. | |
3735 | * Makes 0 or more new frags. | |
3736 | * If need_pass_2 == 1, no frags are emitted. | |
3737 | * This understands only floating literals, not expressions. Sorry. | |
3738 | * | |
3739 | * A floating constant is defined by atof_generic(), except it is preceded | |
3740 | * by 0d 0f 0g or 0h. After observing the STRANGE way my BSD AS does its | |
3741 | * reading, I decided to be incompatible. This always tries to give you | |
3742 | * rounded bits to the precision of the pseudo-op. Former AS did premature | |
3743 | * truncatation, restored noisy bits instead of trailing 0s AND gave you | |
3744 | * a choice of 2 flavours of noise according to which of 2 floating-point | |
3745 | * scanners you directed AS to use. | |
3746 | * | |
3747 | * In: input_line_pointer->whitespace before, or '0' of flonum. | |
3748 | * | |
3749 | */ | |
3750 | ||
ba71c54d KR |
3751 | void |
3752 | float_cons (float_type) | |
6efd877d | 3753 | /* Clobbers input_line-pointer, checks end-of-line. */ |
f8701a3f | 3754 | register int float_type; /* 'f':.ffloat ... 'F':.float ... */ |
fecd2382 | 3755 | { |
6efd877d | 3756 | register char *p; |
6efd877d KR |
3757 | int length; /* Number of chars in an object. */ |
3758 | register char *err; /* Error from scanning floating literal. */ | |
3759 | char temp[MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT]; | |
f8701a3f | 3760 | |
6efd877d | 3761 | if (is_it_end_of_statement ()) |
f8701a3f | 3762 | { |
1e9cf565 ILT |
3763 | demand_empty_rest_of_line (); |
3764 | return; | |
f8701a3f | 3765 | } |
1e9cf565 | 3766 | |
a69e5977 ILT |
3767 | #ifdef md_flush_pending_output |
3768 | md_flush_pending_output (); | |
3769 | #endif | |
3770 | ||
1e9cf565 | 3771 | do |
f8701a3f SC |
3772 | { |
3773 | /* input_line_pointer->1st char of a flonum (we hope!). */ | |
6efd877d | 3774 | SKIP_WHITESPACE (); |
1e9cf565 | 3775 | |
f8701a3f SC |
3776 | /* Skip any 0{letter} that may be present. Don't even check if the |
3777 | * letter is legal. Someone may invent a "z" format and this routine | |
3778 | * has no use for such information. Lusers beware: you get | |
3779 | * diagnostics if your input is ill-conditioned. | |
3780 | */ | |
6efd877d KR |
3781 | if (input_line_pointer[0] == '0' && isalpha (input_line_pointer[1])) |
3782 | input_line_pointer += 2; | |
f8701a3f | 3783 | |
1356d77d ILT |
3784 | /* Accept :xxxx, where the x's are hex digits, for a floating |
3785 | point with the exact digits specified. */ | |
3786 | if (input_line_pointer[0] == ':') | |
f8701a3f | 3787 | { |
e28c40d7 ILT |
3788 | ++input_line_pointer; |
3789 | length = hex_float (float_type, temp); | |
3790 | if (length < 0) | |
1356d77d | 3791 | { |
1356d77d ILT |
3792 | ignore_rest_of_line (); |
3793 | return; | |
3794 | } | |
1356d77d ILT |
3795 | } |
3796 | else | |
3797 | { | |
3798 | err = md_atof (float_type, temp, &length); | |
3799 | know (length <= MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT); | |
3800 | know (length > 0); | |
3801 | if (err) | |
3802 | { | |
3803 | as_bad ("Bad floating literal: %s", err); | |
3804 | ignore_rest_of_line (); | |
3805 | return; | |
3806 | } | |
f8701a3f | 3807 | } |
1e9cf565 ILT |
3808 | |
3809 | if (!need_pass_2) | |
f8701a3f | 3810 | { |
1e9cf565 ILT |
3811 | int count; |
3812 | ||
3813 | count = 1; | |
3814 | ||
3815 | #ifdef REPEAT_CONS_EXPRESSIONS | |
3816 | if (*input_line_pointer == ':') | |
3817 | { | |
1e9cf565 ILT |
3818 | expressionS count_exp; |
3819 | ||
3820 | ++input_line_pointer; | |
5ac34ac3 ILT |
3821 | expression (&count_exp); |
3822 | if (count_exp.X_op != O_constant | |
1e9cf565 ILT |
3823 | || count_exp.X_add_number <= 0) |
3824 | { | |
5ac34ac3 | 3825 | as_warn ("unresolvable or nonpositive repeat count; using 1"); |
1e9cf565 ILT |
3826 | } |
3827 | else | |
3828 | count = count_exp.X_add_number; | |
3829 | } | |
3830 | #endif | |
3831 | ||
3832 | while (--count >= 0) | |
a39116f1 | 3833 | { |
f8701a3f | 3834 | p = frag_more (length); |
604633ae | 3835 | memcpy (p, temp, (unsigned int) length); |
a39116f1 | 3836 | } |
542e1629 | 3837 | } |
1e9cf565 | 3838 | SKIP_WHITESPACE (); |
f8701a3f | 3839 | } |
1e9cf565 ILT |
3840 | while (*input_line_pointer++ == ','); |
3841 | ||
3842 | --input_line_pointer; /* Put terminator back into stream. */ | |
6efd877d | 3843 | demand_empty_rest_of_line (); |
f8701a3f | 3844 | } /* float_cons() */ |
fecd2382 RP |
3845 | \f |
3846 | /* | |
3847 | * stringer() | |
3848 | * | |
3849 | * We read 0 or more ',' seperated, double-quoted strings. | |
3850 | * | |
3851 | * Caller should have checked need_pass_2 is FALSE because we don't check it. | |
3852 | */ | |
a39116f1 RP |
3853 | |
3854 | ||
6efd877d KR |
3855 | void |
3856 | stringer (append_zero) /* Worker to do .ascii etc statements. */ | |
3857 | /* Checks end-of-line. */ | |
f8701a3f | 3858 | register int append_zero; /* 0: don't append '\0', else 1 */ |
fecd2382 | 3859 | { |
f8701a3f | 3860 | register unsigned int c; |
6efd877d | 3861 | |
a2a5a4fa KR |
3862 | #ifdef md_flush_pending_output |
3863 | md_flush_pending_output (); | |
3864 | #endif | |
3865 | ||
f8701a3f SC |
3866 | /* |
3867 | * The following awkward logic is to parse ZERO or more strings, | |
3868 | * comma seperated. Recall a string expression includes spaces | |
3869 | * before the opening '\"' and spaces after the closing '\"'. | |
3870 | * We fake a leading ',' if there is (supposed to be) | |
3871 | * a 1st, expression. We keep demanding expressions for each | |
3872 | * ','. | |
3873 | */ | |
6efd877d KR |
3874 | if (is_it_end_of_statement ()) |
3875 | { | |
3876 | c = 0; /* Skip loop. */ | |
3877 | ++input_line_pointer; /* Compensate for end of loop. */ | |
3878 | } | |
f8701a3f | 3879 | else |
6efd877d KR |
3880 | { |
3881 | c = ','; /* Do loop. */ | |
3882 | } | |
3883 | while (c == ',' || c == '<' || c == '"') | |
3884 | { | |
3885 | SKIP_WHITESPACE (); | |
3886 | switch (*input_line_pointer) | |
3887 | { | |
3888 | case '\"': | |
3889 | ++input_line_pointer; /*->1st char of string. */ | |
3890 | while (is_a_char (c = next_char_of_string ())) | |
3891 | { | |
3892 | FRAG_APPEND_1_CHAR (c); | |
3893 | } | |
3894 | if (append_zero) | |
3895 | { | |
3896 | FRAG_APPEND_1_CHAR (0); | |
3897 | } | |
3898 | know (input_line_pointer[-1] == '\"'); | |
3899 | break; | |
3900 | case '<': | |
3901 | input_line_pointer++; | |
3902 | c = get_single_number (); | |
3903 | FRAG_APPEND_1_CHAR (c); | |
3904 | if (*input_line_pointer != '>') | |
3905 | { | |
3906 | as_bad ("Expected <nn>"); | |
3907 | } | |
3908 | input_line_pointer++; | |
3909 | break; | |
3910 | case ',': | |
3911 | input_line_pointer++; | |
3912 | break; | |
3913 | } | |
3914 | SKIP_WHITESPACE (); | |
3915 | c = *input_line_pointer; | |
f8701a3f | 3916 | } |
f8701a3f | 3917 | |
6efd877d KR |
3918 | demand_empty_rest_of_line (); |
3919 | } /* stringer() */ | |
fecd2382 | 3920 | \f |
6efd877d | 3921 | /* FIXME-SOMEDAY: I had trouble here on characters with the |
f8701a3f SC |
3922 | high bits set. We'll probably also have trouble with |
3923 | multibyte chars, wide chars, etc. Also be careful about | |
3924 | returning values bigger than 1 byte. xoxorich. */ | |
fecd2382 | 3925 | |
6efd877d KR |
3926 | unsigned int |
3927 | next_char_of_string () | |
3928 | { | |
3929 | register unsigned int c; | |
3930 | ||
3931 | c = *input_line_pointer++ & CHAR_MASK; | |
3932 | switch (c) | |
3933 | { | |
3934 | case '\"': | |
3935 | c = NOT_A_CHAR; | |
3936 | break; | |
3937 | ||
a69e5977 ILT |
3938 | case '\n': |
3939 | as_warn ("Unterminated string: Newline inserted."); | |
3940 | bump_line_counters (); | |
3941 | break; | |
3942 | ||
ddb393cf | 3943 | #ifndef NO_STRING_ESCAPES |
6efd877d KR |
3944 | case '\\': |
3945 | switch (c = *input_line_pointer++) | |
3946 | { | |
3947 | case 'b': | |
3948 | c = '\b'; | |
3949 | break; | |
3950 | ||
3951 | case 'f': | |
3952 | c = '\f'; | |
3953 | break; | |
3954 | ||
3955 | case 'n': | |
3956 | c = '\n'; | |
3957 | break; | |
3958 | ||
3959 | case 'r': | |
3960 | c = '\r'; | |
3961 | break; | |
3962 | ||
3963 | case 't': | |
3964 | c = '\t'; | |
3965 | break; | |
3966 | ||
6efd877d KR |
3967 | case 'v': |
3968 | c = '\013'; | |
3969 | break; | |
6efd877d KR |
3970 | |
3971 | case '\\': | |
3972 | case '"': | |
3973 | break; /* As itself. */ | |
3974 | ||
3975 | case '0': | |
3976 | case '1': | |
3977 | case '2': | |
3978 | case '3': | |
3979 | case '4': | |
3980 | case '5': | |
3981 | case '6': | |
3982 | case '7': | |
3983 | case '8': | |
3984 | case '9': | |
3985 | { | |
3986 | long number; | |
d4c8cbd8 | 3987 | int i; |
6efd877d | 3988 | |
d4c8cbd8 | 3989 | for (i = 0, number = 0; isdigit (c) && i < 3; c = *input_line_pointer++, i++) |
6efd877d KR |
3990 | { |
3991 | number = number * 8 + c - '0'; | |
3992 | } | |
3993 | c = number & 0xff; | |
3994 | } | |
3995 | --input_line_pointer; | |
3996 | break; | |
3997 | ||
d4c8cbd8 JL |
3998 | case 'x': |
3999 | case 'X': | |
4000 | { | |
4001 | long number; | |
4002 | ||
4003 | number = 0; | |
4004 | c = *input_line_pointer++; | |
4005 | while (isxdigit (c)) | |
4006 | { | |
4007 | if (isdigit (c)) | |
4008 | number = number * 16 + c - '0'; | |
4009 | else if (isupper (c)) | |
4010 | number = number * 16 + c - 'A' + 10; | |
4011 | else | |
4012 | number = number * 16 + c - 'a' + 10; | |
4013 | c = *input_line_pointer++; | |
4014 | } | |
4015 | c = number & 0xff; | |
4016 | --input_line_pointer; | |
4017 | } | |
4018 | break; | |
4019 | ||
6efd877d KR |
4020 | case '\n': |
4021 | /* To be compatible with BSD 4.2 as: give the luser a linefeed!! */ | |
4022 | as_warn ("Unterminated string: Newline inserted."); | |
4023 | c = '\n'; | |
a69e5977 | 4024 | bump_line_counters (); |
6efd877d KR |
4025 | break; |
4026 | ||
4027 | default: | |
4028 | ||
fecd2382 | 4029 | #ifdef ONLY_STANDARD_ESCAPES |
6efd877d KR |
4030 | as_bad ("Bad escaped character in string, '?' assumed"); |
4031 | c = '?'; | |
fecd2382 | 4032 | #endif /* ONLY_STANDARD_ESCAPES */ |
6efd877d KR |
4033 | |
4034 | break; | |
4035 | } /* switch on escaped char */ | |
4036 | break; | |
ddb393cf | 4037 | #endif /* ! defined (NO_STRING_ESCAPES) */ |
6efd877d KR |
4038 | |
4039 | default: | |
4040 | break; | |
4041 | } /* switch on char */ | |
4042 | return (c); | |
4043 | } /* next_char_of_string() */ | |
fecd2382 RP |
4044 | \f |
4045 | static segT | |
f8701a3f | 4046 | get_segmented_expression (expP) |
6efd877d | 4047 | register expressionS *expP; |
fecd2382 | 4048 | { |
6efd877d | 4049 | register segT retval; |
f8701a3f | 4050 | |
9471a360 | 4051 | retval = expression (expP); |
5ac34ac3 ILT |
4052 | if (expP->X_op == O_illegal |
4053 | || expP->X_op == O_absent | |
4054 | || expP->X_op == O_big) | |
f8701a3f | 4055 | { |
5ac34ac3 ILT |
4056 | as_bad ("expected address expression; zero assumed"); |
4057 | expP->X_op = O_constant; | |
6efd877d | 4058 | expP->X_add_number = 0; |
5ac34ac3 | 4059 | retval = absolute_section; |
f8701a3f | 4060 | } |
5ac34ac3 | 4061 | return retval; |
fecd2382 RP |
4062 | } |
4063 | ||
6efd877d KR |
4064 | static segT |
4065 | get_known_segmented_expression (expP) | |
4066 | register expressionS *expP; | |
fecd2382 | 4067 | { |
6efd877d | 4068 | register segT retval; |
f8701a3f | 4069 | |
9471a360 | 4070 | if ((retval = get_segmented_expression (expP)) == undefined_section) |
f8701a3f | 4071 | { |
5ac34ac3 ILT |
4072 | /* There is no easy way to extract the undefined symbol from the |
4073 | expression. */ | |
4074 | if (expP->X_add_symbol != NULL | |
4075 | && S_GET_SEGMENT (expP->X_add_symbol) != expr_section) | |
4076 | as_warn ("symbol \"%s\" undefined; zero assumed", | |
4077 | S_GET_NAME (expP->X_add_symbol)); | |
f8701a3f | 4078 | else |
5ac34ac3 ILT |
4079 | as_warn ("some symbol undefined; zero assumed"); |
4080 | retval = absolute_section; | |
4081 | expP->X_op = O_constant; | |
6efd877d | 4082 | expP->X_add_number = 0; |
f8701a3f | 4083 | } |
5ac34ac3 | 4084 | know (retval == absolute_section || SEG_NORMAL (retval)); |
f8701a3f | 4085 | return (retval); |
fecd2382 RP |
4086 | } /* get_known_segmented_expression() */ |
4087 | ||
58d4951d | 4088 | offsetT |
f8701a3f | 4089 | get_absolute_expression () |
fecd2382 | 4090 | { |
6efd877d | 4091 | expressionS exp; |
f8701a3f | 4092 | |
5ac34ac3 ILT |
4093 | expression (&exp); |
4094 | if (exp.X_op != O_constant) | |
f8701a3f | 4095 | { |
5ac34ac3 | 4096 | if (exp.X_op != O_absent) |
cd3b81bd | 4097 | as_bad ("bad or irreducible absolute expression; zero assumed"); |
6efd877d | 4098 | exp.X_add_number = 0; |
f8701a3f | 4099 | } |
5ac34ac3 | 4100 | return exp.X_add_number; |
fecd2382 RP |
4101 | } |
4102 | ||
6efd877d KR |
4103 | char /* return terminator */ |
4104 | get_absolute_expression_and_terminator (val_pointer) | |
4105 | long *val_pointer; /* return value of expression */ | |
fecd2382 | 4106 | { |
58d4951d ILT |
4107 | /* FIXME: val_pointer should probably be offsetT *. */ |
4108 | *val_pointer = (long) get_absolute_expression (); | |
6efd877d | 4109 | return (*input_line_pointer++); |
fecd2382 RP |
4110 | } |
4111 | \f | |
4112 | /* | |
4113 | * demand_copy_C_string() | |
4114 | * | |
4115 | * Like demand_copy_string, but return NULL if the string contains any '\0's. | |
4116 | * Give a warning if that happens. | |
4117 | */ | |
4118 | char * | |
f8701a3f | 4119 | demand_copy_C_string (len_pointer) |
6efd877d | 4120 | int *len_pointer; |
fecd2382 | 4121 | { |
6efd877d | 4122 | register char *s; |
f8701a3f | 4123 | |
6efd877d | 4124 | if ((s = demand_copy_string (len_pointer)) != 0) |
f8701a3f SC |
4125 | { |
4126 | register int len; | |
4127 | ||
6594d6b9 | 4128 | for (len = *len_pointer; len > 0; len--) |
f8701a3f | 4129 | { |
6efd877d | 4130 | if (*s == 0) |
fecd2382 | 4131 | { |
f8701a3f SC |
4132 | s = 0; |
4133 | len = 1; | |
6efd877d KR |
4134 | *len_pointer = 0; |
4135 | as_bad ("This string may not contain \'\\0\'"); | |
fecd2382 | 4136 | } |
f8701a3f SC |
4137 | } |
4138 | } | |
6594d6b9 | 4139 | return s; |
fecd2382 RP |
4140 | } |
4141 | \f | |
4142 | /* | |
4143 | * demand_copy_string() | |
4144 | * | |
4145 | * Demand string, but return a safe (=private) copy of the string. | |
4146 | * Return NULL if we can't read a string here. | |
4147 | */ | |
6ef37255 | 4148 | char * |
6efd877d KR |
4149 | demand_copy_string (lenP) |
4150 | int *lenP; | |
fecd2382 | 4151 | { |
6efd877d KR |
4152 | register unsigned int c; |
4153 | register int len; | |
4154 | char *retval; | |
4155 | ||
4156 | len = 0; | |
4157 | SKIP_WHITESPACE (); | |
4158 | if (*input_line_pointer == '\"') | |
4159 | { | |
4160 | input_line_pointer++; /* Skip opening quote. */ | |
4161 | ||
4162 | while (is_a_char (c = next_char_of_string ())) | |
4163 | { | |
4164 | obstack_1grow (¬es, c); | |
4165 | len++; | |
fecd2382 | 4166 | } |
42ac8fa8 ILT |
4167 | /* JF this next line is so demand_copy_C_string will return a |
4168 | null terminated string. */ | |
6efd877d KR |
4169 | obstack_1grow (¬es, '\0'); |
4170 | retval = obstack_finish (¬es); | |
4171 | } | |
4172 | else | |
4173 | { | |
4174 | as_warn ("Missing string"); | |
4175 | retval = NULL; | |
4176 | ignore_rest_of_line (); | |
4177 | } | |
4178 | *lenP = len; | |
4179 | return (retval); | |
4180 | } /* demand_copy_string() */ | |
fecd2382 RP |
4181 | \f |
4182 | /* | |
4183 | * is_it_end_of_statement() | |
4184 | * | |
4185 | * In: Input_line_pointer->next character. | |
4186 | * | |
4187 | * Do: Skip input_line_pointer over all whitespace. | |
4188 | * | |
4189 | * Out: 1 if input_line_pointer->end-of-line. | |
f8701a3f | 4190 | */ |
6efd877d KR |
4191 | int |
4192 | is_it_end_of_statement () | |
4193 | { | |
4194 | SKIP_WHITESPACE (); | |
58d4951d | 4195 | return (is_end_of_line[(unsigned char) *input_line_pointer]); |
6efd877d | 4196 | } /* is_it_end_of_statement() */ |
fecd2382 | 4197 | |
6efd877d | 4198 | void |
d428c89f | 4199 | equals (sym_name, reassign) |
6efd877d | 4200 | char *sym_name; |
d428c89f | 4201 | int reassign; |
fecd2382 | 4202 | { |
6efd877d | 4203 | register symbolS *symbolP; /* symbol we are working with */ |
86038ada | 4204 | char *stop; |
18c9057f | 4205 | char stopc; |
f8701a3f SC |
4206 | |
4207 | input_line_pointer++; | |
6efd877d | 4208 | if (*input_line_pointer == '=') |
f8701a3f SC |
4209 | input_line_pointer++; |
4210 | ||
6efd877d | 4211 | while (*input_line_pointer == ' ' || *input_line_pointer == '\t') |
f8701a3f SC |
4212 | input_line_pointer++; |
4213 | ||
86038ada | 4214 | if (flag_mri) |
18c9057f | 4215 | stop = mri_comment_field (&stopc); |
86038ada | 4216 | |
6efd877d KR |
4217 | if (sym_name[0] == '.' && sym_name[1] == '\0') |
4218 | { | |
4219 | /* Turn '. = mumble' into a .org mumble */ | |
4220 | register segT segment; | |
4221 | expressionS exp; | |
f8701a3f | 4222 | |
6efd877d KR |
4223 | segment = get_known_segmented_expression (&exp); |
4224 | if (!need_pass_2) | |
e28c40d7 | 4225 | do_org (segment, &exp, 0); |
6efd877d KR |
4226 | } |
4227 | else | |
4228 | { | |
4229 | symbolP = symbol_find_or_make (sym_name); | |
d428c89f ILT |
4230 | /* Permit register names to be redefined. */ |
4231 | if (! reassign | |
4232 | && S_IS_DEFINED (symbolP) | |
4233 | && S_GET_SEGMENT (symbolP) != reg_section) | |
4234 | as_bad ("symbol `%s' already defined", S_GET_NAME (symbolP)); | |
6efd877d KR |
4235 | pseudo_set (symbolP); |
4236 | } | |
86038ada ILT |
4237 | |
4238 | if (flag_mri) | |
18c9057f | 4239 | mri_comment_end (stop, stopc); |
6efd877d | 4240 | } /* equals() */ |
fecd2382 RP |
4241 | |
4242 | /* .include -- include a file at this point. */ | |
4243 | ||
4244 | /* ARGSUSED */ | |
6efd877d KR |
4245 | void |
4246 | s_include (arg) | |
4247 | int arg; | |
fecd2382 | 4248 | { |
f8701a3f SC |
4249 | char *newbuf; |
4250 | char *filename; | |
4251 | int i; | |
4252 | FILE *try; | |
4253 | char *path; | |
4254 | ||
cef72a92 | 4255 | if (! flag_m68k_mri) |
ca232972 ILT |
4256 | filename = demand_copy_string (&i); |
4257 | else | |
4258 | { | |
4259 | SKIP_WHITESPACE (); | |
4260 | i = 0; | |
4261 | while (! is_end_of_line[(unsigned char) *input_line_pointer] | |
4262 | && *input_line_pointer != ' ' | |
4263 | && *input_line_pointer != '\t') | |
4264 | { | |
4265 | obstack_1grow (¬es, *input_line_pointer); | |
4266 | ++input_line_pointer; | |
4267 | ++i; | |
4268 | } | |
4269 | obstack_1grow (¬es, '\0'); | |
4270 | filename = obstack_finish (¬es); | |
42ac8fa8 ILT |
4271 | while (! is_end_of_line[(unsigned char) *input_line_pointer]) |
4272 | ++input_line_pointer; | |
ca232972 | 4273 | } |
6efd877d | 4274 | demand_empty_rest_of_line (); |
604633ae | 4275 | path = xmalloc ((unsigned long) i + include_dir_maxlen + 5 /* slop */ ); |
6efd877d KR |
4276 | for (i = 0; i < include_dir_count; i++) |
4277 | { | |
4278 | strcpy (path, include_dirs[i]); | |
4279 | strcat (path, "/"); | |
4280 | strcat (path, filename); | |
f2889110 | 4281 | if (0 != (try = fopen (path, "r"))) |
6efd877d KR |
4282 | { |
4283 | fclose (try); | |
4284 | goto gotit; | |
4285 | } | |
4286 | } | |
4287 | free (path); | |
f8701a3f SC |
4288 | path = filename; |
4289 | gotit: | |
4290 | /* malloc Storage leak when file is found on path. FIXME-SOMEDAY. */ | |
4291 | newbuf = input_scrub_include_file (path, input_line_pointer); | |
4292 | buffer_limit = input_scrub_next_buffer (&input_line_pointer); | |
6efd877d | 4293 | } /* s_include() */ |
fecd2382 | 4294 | |
6efd877d KR |
4295 | void |
4296 | add_include_dir (path) | |
4297 | char *path; | |
fecd2382 | 4298 | { |
f8701a3f SC |
4299 | int i; |
4300 | ||
4301 | if (include_dir_count == 0) | |
4302 | { | |
6efd877d | 4303 | include_dirs = (char **) xmalloc (2 * sizeof (*include_dirs)); |
f8701a3f SC |
4304 | include_dirs[0] = "."; /* Current dir */ |
4305 | include_dir_count = 2; | |
4306 | } | |
4307 | else | |
4308 | { | |
4309 | include_dir_count++; | |
6efd877d KR |
4310 | include_dirs = (char **) realloc (include_dirs, |
4311 | include_dir_count * sizeof (*include_dirs)); | |
f8701a3f SC |
4312 | } |
4313 | ||
6efd877d | 4314 | include_dirs[include_dir_count - 1] = path; /* New one */ |
f8701a3f | 4315 | |
6efd877d KR |
4316 | i = strlen (path); |
4317 | if (i > include_dir_maxlen) | |
4318 | include_dir_maxlen = i; | |
4319 | } /* add_include_dir() */ | |
fecd2382 | 4320 | |
6efd877d KR |
4321 | void |
4322 | s_ignore (arg) | |
4323 | int arg; | |
fecd2382 | 4324 | { |
58d4951d | 4325 | while (!is_end_of_line[(unsigned char) *input_line_pointer]) |
6efd877d KR |
4326 | { |
4327 | ++input_line_pointer; | |
4328 | } | |
4329 | ++input_line_pointer; | |
4064305e SS |
4330 | } |
4331 | ||
604633ae | 4332 | |
6594d6b9 KR |
4333 | void |
4334 | read_print_statistics (file) | |
4335 | FILE *file; | |
4336 | { | |
4337 | hash_print_statistics (file, "pseudo-op table", po_hash); | |
4338 | } | |
4339 | ||
fecd2382 | 4340 | /* end of read.c */ |