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