* recog.c (asm_operand_ok): Allow float CONST_VECTORs for 'F'.
[official-gcc.git] / gcc / f / target.c
blob5c06368a3a56ef0b6222b52e128371a0f7948c6d
1 /* target.c -- Implementation File (module.c template V1.0)
2 Copyright (C) 1995, 1996, 1997, 1998, 2002 Free Software Foundation, Inc.
3 Contributed by James Craig Burley.
5 This file is part of GNU Fortran.
7 GNU Fortran 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.
12 GNU Fortran 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.
17 You should have received a copy of the GNU General Public License
18 along with GNU Fortran; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA.
22 Related Modules:
23 None
25 Description:
26 Implements conversion of lexer tokens to machine-dependent numerical
27 form and accordingly issues diagnostic messages when necessary.
29 Also, this module, especially its .h file, provides nearly all of the
30 information on the target machine's data type, kind type, and length
31 type capabilities. The idea is that by carefully going through
32 target.h and changing things properly, one can accomplish much
33 towards the porting of the FFE to a new machine. There are limits
34 to how much this can accomplish towards that end, however. For one
35 thing, the ffeexpr_collapse_convert function doesn't contain all the
36 conversion cases necessary, because the text file would be
37 enormous (even though most of the function would be cut during the
38 cpp phase because of the absence of the types), so when adding to
39 the number of supported kind types for a given type, one must look
40 to see if ffeexpr_collapse_convert needs modification in this area,
41 in addition to providing the appropriate macros and functions in
42 ffetarget. Note that if combinatorial explosion actually becomes a
43 problem for a given machine, one might have to modify the way conversion
44 expressions are built so that instead of just one conversion expr, a
45 series of conversion exprs are built to make a path from one type to
46 another that is not a "near neighbor". For now, however, with a handful
47 of each of the numeric types and only one character type, things appear
48 manageable.
50 A nonobvious change to ffetarget would be if the target machine was
51 not a 2's-complement machine. Any item with the word "magical" (case-
52 insensitive) in the FFE's source code (at least) indicates an assumption
53 that a 2's-complement machine is the target, and thus that there exists
54 a magnitude that can be represented as a negative number but not as
55 a positive number. It is possible that this situation can be dealt
56 with by changing only ffetarget, for example, on a 1's-complement
57 machine, perhaps #defineing ffetarget_constant_is_magical to simply
58 FALSE along with making the appropriate changes in ffetarget's number
59 parsing functions would be sufficient to effectively "comment out" code
60 in places like ffeexpr that do certain magical checks. But it is
61 possible there are other 2's-complement dependencies lurking in the
62 FFE (as possibly is true of any large program); if you find any, please
63 report them so we can replace them with dependencies on ffetarget
64 instead.
66 Modifications:
69 /* Include files. */
71 #include "proj.h"
72 #include "target.h"
73 #include "diagnostic.h"
74 #include "bad.h"
75 #include "info.h"
76 #include "lex.h"
77 #include "malloc.h"
78 #include "real.h"
80 /* Externals defined here. */
82 char ffetarget_string_[40]; /* Temp for ascii-to-double (atof). */
83 HOST_WIDE_INT ffetarget_long_val_;
84 HOST_WIDE_INT ffetarget_long_junk_;
86 /* Simple definitions and enumerations. */
89 /* Internal typedefs. */
92 /* Private include files. */
95 /* Internal structure definitions. */
98 /* Static objects accessed by functions in this module. */
101 /* Static functions (internal). */
103 static void ffetarget_print_char_ (FILE *f, unsigned char c);
105 /* Internal macros. */
107 #ifdef REAL_VALUE_ATOF
108 #define FFETARGET_ATOF_(p,m) REAL_VALUE_ATOF ((p),(m))
109 #else
110 #define FFETARGET_ATOF_(p,m) atof ((p))
111 #endif
114 /* ffetarget_print_char_ -- Print a single character (in apostrophe context)
116 See prototype.
118 Outputs char so it prints or is escaped C style. */
120 static void
121 ffetarget_print_char_ (FILE *f, unsigned char c)
123 switch (c)
125 case '\\':
126 fputs ("\\\\", f);
127 break;
129 case '\'':
130 fputs ("\\\'", f);
131 break;
133 default:
134 if (ISPRINT (c))
135 fputc (c, f);
136 else
137 fprintf (f, "\\%03o", (unsigned int) c);
138 break;
142 /* ffetarget_aggregate_info -- Determine type for aggregate storage area
144 See prototype.
146 If aggregate type is distinct, just return it. Else return a type
147 representing a common denominator for the nondistinct type (for now,
148 just return default character, since that'll work on almost all target
149 machines).
151 The rules for abt/akt are (as implemented by ffestorag_update):
153 abt == FFEINFO_basictypeANY (akt == FFEINFO_kindtypeANY also, by
154 definition): CHARACTER and non-CHARACTER types mixed.
156 abt == FFEINFO_basictypeNONE (akt == FFEINFO_kindtypeNONE also, by
157 definition): More than one non-CHARACTER type mixed, but no CHARACTER
158 types mixed in.
160 abt some other value, akt == FFEINFO_kindtypeNONE: abt indicates the
161 only basic type mixed in, but more than one kind type is mixed in.
163 abt some other value, akt some other value: abt and akt indicate the
164 only type represented in the aggregation. */
166 void
167 ffetarget_aggregate_info (ffeinfoBasictype *ebt, ffeinfoKindtype *ekt,
168 ffetargetAlign *units, ffeinfoBasictype abt,
169 ffeinfoKindtype akt)
171 ffetype type;
173 if ((abt == FFEINFO_basictypeNONE) || (abt == FFEINFO_basictypeANY)
174 || (akt == FFEINFO_kindtypeNONE))
176 *ebt = FFEINFO_basictypeCHARACTER;
177 *ekt = FFEINFO_kindtypeCHARACTERDEFAULT;
179 else
181 *ebt = abt;
182 *ekt = akt;
185 type = ffeinfo_type (*ebt, *ekt);
186 assert (type != NULL);
188 *units = ffetype_size (type);
191 /* ffetarget_align -- Align one storage area to superordinate, update super
193 See prototype.
195 updated_alignment/updated_modulo contain the already existing
196 alignment requirements for the storage area at whose offset the
197 object with alignment requirements alignment/modulo is to be placed.
198 Find the smallest pad such that the requirements are maintained and
199 return it, but only after updating the updated_alignment/_modulo
200 requirements as necessary to indicate the placement of the new object. */
202 ffetargetAlign
203 ffetarget_align (ffetargetAlign *updated_alignment,
204 ffetargetAlign *updated_modulo, ffetargetOffset offset,
205 ffetargetAlign alignment, ffetargetAlign modulo)
207 ffetargetAlign pad;
208 ffetargetAlign min_pad; /* Minimum amount of padding needed. */
209 ffetargetAlign min_m = 0; /* Minimum-padding m. */
210 ffetargetAlign ua; /* Updated alignment. */
211 ffetargetAlign um; /* Updated modulo. */
212 ffetargetAlign ucnt; /* Multiplier applied to ua. */
213 ffetargetAlign m; /* Copy of modulo. */
214 ffetargetAlign cnt; /* Multiplier applied to alignment. */
215 ffetargetAlign i;
216 ffetargetAlign j;
218 assert (alignment > 0);
219 assert (*updated_alignment > 0);
221 assert (*updated_modulo < *updated_alignment);
222 assert (modulo < alignment);
224 /* The easy case: similar alignment requirements. */
225 if (*updated_alignment == alignment)
227 if (modulo > *updated_modulo)
228 pad = alignment - (modulo - *updated_modulo);
229 else
230 pad = *updated_modulo - modulo;
231 if (offset < 0)
232 /* De-negatize offset, since % wouldn't do the expected thing. */
233 offset = alignment - ((- offset) % alignment);
234 pad = (offset + pad) % alignment;
235 if (pad != 0)
236 pad = alignment - pad;
237 return pad;
240 /* Sigh, find LCM (Least Common Multiple) for the two alignment factors. */
242 for (ua = *updated_alignment, ucnt = 1;
243 ua % alignment != 0;
244 ua += *updated_alignment)
245 ++ucnt;
247 cnt = ua / alignment;
249 if (offset < 0)
250 /* De-negatize offset, since % wouldn't do the expected thing. */
251 offset = ua - ((- offset) % ua);
253 /* Set to largest value. */
254 min_pad = ~(ffetargetAlign) 0;
256 /* Find all combinations of modulo values the two alignment requirements
257 have; pick the combination that results in the smallest padding
258 requirement. Of course, if a zero-pad requirement is encountered, just
259 use that one. */
261 for (um = *updated_modulo, i = 0; i < ucnt; um += *updated_alignment, ++i)
263 for (m = modulo, j = 0; j < cnt; m += alignment, ++j)
265 /* This code is similar to the "easy case" code above. */
266 if (m > um)
267 pad = ua - (m - um);
268 else
269 pad = um - m;
270 pad = (offset + pad) % ua;
271 if (pad == 0)
273 /* A zero pad means we've got something useful. */
274 *updated_alignment = ua;
275 *updated_modulo = um;
276 return 0;
278 pad = ua - pad;
279 if (pad < min_pad)
280 { /* New minimum padding value. */
281 min_pad = pad;
282 min_m = um;
287 *updated_alignment = ua;
288 *updated_modulo = min_m;
289 return min_pad;
292 /* Always append a null byte to the end, in case this is wanted in
293 a special case such as passing a string as a FORMAT or %REF.
294 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
295 because it isn't a "feature" that is self-documenting. Use the
296 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
297 in the code. */
299 #if FFETARGET_okCHARACTER1
300 bool
301 ffetarget_character1 (ffetargetCharacter1 *val, ffelexToken character,
302 mallocPool pool)
304 val->length = ffelex_token_length (character);
305 if (val->length == 0)
306 val->text = NULL;
307 else
309 val->text = malloc_new_kp (pool, "ffetargetCharacter1", val->length + 1);
310 memcpy (val->text, ffelex_token_text (character), val->length);
311 val->text[val->length] = '\0';
314 return TRUE;
317 #endif
318 /* Produce orderable comparison between two constants
320 Compare lengths, if equal then use memcmp. */
322 #if FFETARGET_okCHARACTER1
324 ffetarget_cmp_character1 (ffetargetCharacter1 l, ffetargetCharacter1 r)
326 if (l.length < r.length)
327 return -1;
328 if (l.length > r.length)
329 return 1;
330 if (l.length == 0)
331 return 0;
332 return memcmp (l.text, r.text, l.length);
335 #endif
336 /* ffetarget_concatenate_character1 -- Perform CONCAT op on two constants
338 Always append a null byte to the end, in case this is wanted in
339 a special case such as passing a string as a FORMAT or %REF.
340 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
341 because it isn't a "feature" that is self-documenting. Use the
342 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
343 in the code. */
345 #if FFETARGET_okCHARACTER1
346 ffebad
347 ffetarget_concatenate_character1 (ffetargetCharacter1 *res,
348 ffetargetCharacter1 l, ffetargetCharacter1 r, mallocPool pool,
349 ffetargetCharacterSize *len)
351 res->length = *len = l.length + r.length;
352 if (*len == 0)
353 res->text = NULL;
354 else
356 res->text = malloc_new_kp (pool, "ffetargetCharacter1(CONCAT)", *len + 1);
357 if (l.length != 0)
358 memcpy (res->text, l.text, l.length);
359 if (r.length != 0)
360 memcpy (res->text + l.length, r.text, r.length);
361 res->text[*len] = '\0';
364 return FFEBAD;
367 #endif
368 /* ffetarget_eq_character1 -- Perform relational comparison on char constants
370 Compare lengths, if equal then use memcmp. */
372 #if FFETARGET_okCHARACTER1
373 ffebad
374 ffetarget_eq_character1 (bool *res, ffetargetCharacter1 l,
375 ffetargetCharacter1 r)
377 assert (l.length == r.length);
378 *res = (memcmp (l.text, r.text, l.length) == 0);
379 return FFEBAD;
382 #endif
383 /* ffetarget_le_character1 -- Perform relational comparison on char constants
385 Compare lengths, if equal then use memcmp. */
387 #if FFETARGET_okCHARACTER1
388 ffebad
389 ffetarget_le_character1 (bool *res, ffetargetCharacter1 l,
390 ffetargetCharacter1 r)
392 assert (l.length == r.length);
393 *res = (memcmp (l.text, r.text, l.length) <= 0);
394 return FFEBAD;
397 #endif
398 /* ffetarget_lt_character1 -- Perform relational comparison on char constants
400 Compare lengths, if equal then use memcmp. */
402 #if FFETARGET_okCHARACTER1
403 ffebad
404 ffetarget_lt_character1 (bool *res, ffetargetCharacter1 l,
405 ffetargetCharacter1 r)
407 assert (l.length == r.length);
408 *res = (memcmp (l.text, r.text, l.length) < 0);
409 return FFEBAD;
412 #endif
413 /* ffetarget_ge_character1 -- Perform relational comparison on char constants
415 Compare lengths, if equal then use memcmp. */
417 #if FFETARGET_okCHARACTER1
418 ffebad
419 ffetarget_ge_character1 (bool *res, ffetargetCharacter1 l,
420 ffetargetCharacter1 r)
422 assert (l.length == r.length);
423 *res = (memcmp (l.text, r.text, l.length) >= 0);
424 return FFEBAD;
427 #endif
428 /* ffetarget_gt_character1 -- Perform relational comparison on char constants
430 Compare lengths, if equal then use memcmp. */
432 #if FFETARGET_okCHARACTER1
433 ffebad
434 ffetarget_gt_character1 (bool *res, ffetargetCharacter1 l,
435 ffetargetCharacter1 r)
437 assert (l.length == r.length);
438 *res = (memcmp (l.text, r.text, l.length) > 0);
439 return FFEBAD;
441 #endif
443 #if FFETARGET_okCHARACTER1
444 bool
445 ffetarget_iszero_character1 (ffetargetCharacter1 constant)
447 ffetargetCharacterSize i;
449 for (i = 0; i < constant.length; ++i)
450 if (constant.text[i] != 0)
451 return FALSE;
452 return TRUE;
454 #endif
456 bool
457 ffetarget_iszero_hollerith (ffetargetHollerith constant)
459 ffetargetHollerithSize i;
461 for (i = 0; i < constant.length; ++i)
462 if (constant.text[i] != 0)
463 return FALSE;
464 return TRUE;
467 /* ffetarget_layout -- Do storage requirement analysis for entity
469 Return the alignment/modulo requirements along with the size, given the
470 data type info and the number of elements an array (1 for a scalar). */
472 void
473 ffetarget_layout (const char *error_text UNUSED, ffetargetAlign *alignment,
474 ffetargetAlign *modulo, ffetargetOffset *size,
475 ffeinfoBasictype bt, ffeinfoKindtype kt,
476 ffetargetCharacterSize charsize,
477 ffetargetIntegerDefault num_elements)
479 bool ok; /* For character type. */
480 ffetargetOffset numele; /* Converted from num_elements. */
481 ffetype type;
483 type = ffeinfo_type (bt, kt);
484 assert (type != NULL);
486 *alignment = ffetype_alignment (type);
487 *modulo = ffetype_modulo (type);
488 if (bt == FFEINFO_basictypeCHARACTER)
490 ok = ffetarget_offset_charsize (size, charsize, ffetype_size (type));
491 #ifdef ffetarget_offset_overflow
492 if (!ok)
493 ffetarget_offset_overflow (error_text);
494 #endif
496 else
497 *size = ffetype_size (type);
499 if ((num_elements < 0)
500 || !ffetarget_offset (&numele, num_elements)
501 || !ffetarget_offset_multiply (size, *size, numele))
503 ffetarget_offset_overflow (error_text);
504 *alignment = 1;
505 *modulo = 0;
506 *size = 0;
510 /* ffetarget_ne_character1 -- Perform relational comparison on char constants
512 Compare lengths, if equal then use memcmp. */
514 #if FFETARGET_okCHARACTER1
515 ffebad
516 ffetarget_ne_character1 (bool *res, ffetargetCharacter1 l,
517 ffetargetCharacter1 r)
519 assert (l.length == r.length);
520 *res = (memcmp (l.text, r.text, l.length) != 0);
521 return FFEBAD;
524 #endif
525 /* ffetarget_substr_character1 -- Perform SUBSTR op on three constants
527 Always append a null byte to the end, in case this is wanted in
528 a special case such as passing a string as a FORMAT or %REF.
529 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
530 because it isn't a "feature" that is self-documenting. Use the
531 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
532 in the code. */
534 #if FFETARGET_okCHARACTER1
535 ffebad
536 ffetarget_substr_character1 (ffetargetCharacter1 *res,
537 ffetargetCharacter1 l,
538 ffetargetCharacterSize first,
539 ffetargetCharacterSize last, mallocPool pool,
540 ffetargetCharacterSize *len)
542 if (last < first)
544 res->length = *len = 0;
545 res->text = NULL;
547 else
549 res->length = *len = last - first + 1;
550 res->text = malloc_new_kp (pool, "ffetargetCharacter1(SUBSTR)", *len + 1);
551 memcpy (res->text, l.text + first - 1, *len);
552 res->text[*len] = '\0';
555 return FFEBAD;
558 #endif
559 /* ffetarget_cmp_hollerith -- Produce orderable comparison between two
560 constants
562 Compare lengths, if equal then use memcmp. */
565 ffetarget_cmp_hollerith (ffetargetHollerith l, ffetargetHollerith r)
567 if (l.length < r.length)
568 return -1;
569 if (l.length > r.length)
570 return 1;
571 return memcmp (l.text, r.text, l.length);
574 ffebad
575 ffetarget_convert_any_character1_ (char *res, size_t size,
576 ffetargetCharacter1 l)
578 if (size <= (size_t) l.length)
580 char *p;
581 ffetargetCharacterSize i;
583 memcpy (res, l.text, size);
584 for (p = &l.text[0] + size, i = l.length - size;
585 i > 0;
586 ++p, --i)
587 if (*p != ' ')
588 return FFEBAD_TRUNCATING_CHARACTER;
590 else
592 memcpy (res, l.text, size);
593 memset (res + l.length, ' ', size - l.length);
596 return FFEBAD;
599 ffebad
600 ffetarget_convert_any_hollerith_ (char *res, size_t size,
601 ffetargetHollerith l)
603 if (size <= (size_t) l.length)
605 char *p;
606 ffetargetCharacterSize i;
608 memcpy (res, l.text, size);
609 for (p = &l.text[0] + size, i = l.length - size;
610 i > 0;
611 ++p, --i)
612 if (*p != ' ')
613 return FFEBAD_TRUNCATING_HOLLERITH;
615 else
617 memcpy (res, l.text, size);
618 memset (res + l.length, ' ', size - l.length);
621 return FFEBAD;
624 ffebad
625 ffetarget_convert_any_typeless_ (char *res, size_t size,
626 ffetargetTypeless l)
628 unsigned long long int l1;
629 unsigned long int l2;
630 unsigned int l3;
631 unsigned short int l4;
632 unsigned char l5;
633 size_t size_of;
634 char *p;
636 if (size >= sizeof (l1))
638 l1 = l;
639 p = (char *) &l1;
640 size_of = sizeof (l1);
642 else if (size >= sizeof (l2))
644 l2 = l;
645 p = (char *) &l2;
646 size_of = sizeof (l2);
647 l1 = l2;
649 else if (size >= sizeof (l3))
651 l3 = l;
652 p = (char *) &l3;
653 size_of = sizeof (l3);
654 l1 = l3;
656 else if (size >= sizeof (l4))
658 l4 = l;
659 p = (char *) &l4;
660 size_of = sizeof (l4);
661 l1 = l4;
663 else if (size >= sizeof (l5))
665 l5 = l;
666 p = (char *) &l5;
667 size_of = sizeof (l5);
668 l1 = l5;
670 else
672 assert ("stumped by conversion from typeless!" == NULL);
673 abort ();
676 if (size <= size_of)
678 int i = size_of - size;
680 memcpy (res, p + i, size);
681 for (; i > 0; ++p, --i)
682 if (*p != '\0')
683 return FFEBAD_TRUNCATING_TYPELESS;
685 else
687 int i = size - size_of;
689 memset (res, 0, i);
690 memcpy (res + i, p, size_of);
693 if (l1 != l)
694 return FFEBAD_TRUNCATING_TYPELESS;
695 return FFEBAD;
698 /* Always append a null byte to the end, in case this is wanted in
699 a special case such as passing a string as a FORMAT or %REF.
700 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
701 because it isn't a "feature" that is self-documenting. Use the
702 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
703 in the code. */
705 #if FFETARGET_okCHARACTER1
706 ffebad
707 ffetarget_convert_character1_character1 (ffetargetCharacter1 *res,
708 ffetargetCharacterSize size,
709 ffetargetCharacter1 l,
710 mallocPool pool)
712 res->length = size;
713 if (size == 0)
714 res->text = NULL;
715 else
717 res->text = malloc_new_kp (pool, "FFETARGET cvt char1", size + 1);
718 if (size <= l.length)
719 memcpy (res->text, l.text, size);
720 else
722 memcpy (res->text, l.text, l.length);
723 memset (res->text + l.length, ' ', size - l.length);
725 res->text[size] = '\0';
728 return FFEBAD;
731 #endif
733 /* Always append a null byte to the end, in case this is wanted in
734 a special case such as passing a string as a FORMAT or %REF.
735 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
736 because it isn't a "feature" that is self-documenting. Use the
737 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
738 in the code. */
740 #if FFETARGET_okCHARACTER1
741 ffebad
742 ffetarget_convert_character1_hollerith (ffetargetCharacter1 *res,
743 ffetargetCharacterSize size,
744 ffetargetHollerith l, mallocPool pool)
746 res->length = size;
747 if (size == 0)
748 res->text = NULL;
749 else
751 res->text = malloc_new_kp (pool, "FFETARGET cvt char1", size + 1);
752 res->text[size] = '\0';
753 if (size <= l.length)
755 char *p;
756 ffetargetCharacterSize i;
758 memcpy (res->text, l.text, size);
759 for (p = &l.text[0] + size, i = l.length - size;
760 i > 0;
761 ++p, --i)
762 if (*p != ' ')
763 return FFEBAD_TRUNCATING_HOLLERITH;
765 else
767 memcpy (res->text, l.text, l.length);
768 memset (res->text + l.length, ' ', size - l.length);
772 return FFEBAD;
775 #endif
776 /* ffetarget_convert_character1_integer4 -- Raw conversion.
778 Always append a null byte to the end, in case this is wanted in
779 a special case such as passing a string as a FORMAT or %REF.
780 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
781 because it isn't a "feature" that is self-documenting. Use the
782 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
783 in the code. */
785 #if FFETARGET_okCHARACTER1
786 ffebad
787 ffetarget_convert_character1_integer4 (ffetargetCharacter1 *res,
788 ffetargetCharacterSize size,
789 ffetargetInteger4 l, mallocPool pool)
791 long long int l1;
792 long int l2;
793 int l3;
794 short int l4;
795 char l5;
796 size_t size_of;
797 char *p;
799 if (((size_t) size) >= sizeof (l1))
801 l1 = l;
802 p = (char *) &l1;
803 size_of = sizeof (l1);
805 else if (((size_t) size) >= sizeof (l2))
807 l2 = l;
808 p = (char *) &l2;
809 size_of = sizeof (l2);
810 l1 = l2;
812 else if (((size_t) size) >= sizeof (l3))
814 l3 = l;
815 p = (char *) &l3;
816 size_of = sizeof (l3);
817 l1 = l3;
819 else if (((size_t) size) >= sizeof (l4))
821 l4 = l;
822 p = (char *) &l4;
823 size_of = sizeof (l4);
824 l1 = l4;
826 else if (((size_t) size) >= sizeof (l5))
828 l5 = l;
829 p = (char *) &l5;
830 size_of = sizeof (l5);
831 l1 = l5;
833 else
835 assert ("stumped by conversion from integer1!" == NULL);
836 abort ();
839 res->length = size;
840 if (size == 0)
841 res->text = NULL;
842 else
844 res->text = malloc_new_kp (pool, "FFETARGET cvt char1", size + 1);
845 res->text[size] = '\0';
846 if (((size_t) size) <= size_of)
848 int i = size_of - size;
850 memcpy (res->text, p + i, size);
851 for (; i > 0; ++p, --i)
852 if (*p != 0)
853 return FFEBAD_TRUNCATING_NUMERIC;
855 else
857 int i = size - size_of;
859 memset (res->text, 0, i);
860 memcpy (res->text + i, p, size_of);
864 if (l1 != l)
865 return FFEBAD_TRUNCATING_NUMERIC;
866 return FFEBAD;
869 #endif
870 /* ffetarget_convert_character1_logical4 -- Raw conversion.
872 Always append a null byte to the end, in case this is wanted in
873 a special case such as passing a string as a FORMAT or %REF.
874 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
875 because it isn't a "feature" that is self-documenting. Use the
876 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
877 in the code. */
879 #if FFETARGET_okCHARACTER1
880 ffebad
881 ffetarget_convert_character1_logical4 (ffetargetCharacter1 *res,
882 ffetargetCharacterSize size,
883 ffetargetLogical4 l, mallocPool pool)
885 long long int l1;
886 long int l2;
887 int l3;
888 short int l4;
889 char l5;
890 size_t size_of;
891 char *p;
893 if (((size_t) size) >= sizeof (l1))
895 l1 = l;
896 p = (char *) &l1;
897 size_of = sizeof (l1);
899 else if (((size_t) size) >= sizeof (l2))
901 l2 = l;
902 p = (char *) &l2;
903 size_of = sizeof (l2);
904 l1 = l2;
906 else if (((size_t) size) >= sizeof (l3))
908 l3 = l;
909 p = (char *) &l3;
910 size_of = sizeof (l3);
911 l1 = l3;
913 else if (((size_t) size) >= sizeof (l4))
915 l4 = l;
916 p = (char *) &l4;
917 size_of = sizeof (l4);
918 l1 = l4;
920 else if (((size_t) size) >= sizeof (l5))
922 l5 = l;
923 p = (char *) &l5;
924 size_of = sizeof (l5);
925 l1 = l5;
927 else
929 assert ("stumped by conversion from logical1!" == NULL);
930 abort ();
933 res->length = size;
934 if (size == 0)
935 res->text = NULL;
936 else
938 res->text = malloc_new_kp (pool, "FFETARGET cvt char1", size + 1);
939 res->text[size] = '\0';
940 if (((size_t) size) <= size_of)
942 int i = size_of - size;
944 memcpy (res->text, p + i, size);
945 for (; i > 0; ++p, --i)
946 if (*p != 0)
947 return FFEBAD_TRUNCATING_NUMERIC;
949 else
951 int i = size - size_of;
953 memset (res->text, 0, i);
954 memcpy (res->text + i, p, size_of);
958 if (l1 != l)
959 return FFEBAD_TRUNCATING_NUMERIC;
960 return FFEBAD;
963 #endif
964 /* ffetarget_convert_character1_typeless -- Raw conversion.
966 Always append a null byte to the end, in case this is wanted in
967 a special case such as passing a string as a FORMAT or %REF.
968 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
969 because it isn't a "feature" that is self-documenting. Use the
970 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
971 in the code. */
973 #if FFETARGET_okCHARACTER1
974 ffebad
975 ffetarget_convert_character1_typeless (ffetargetCharacter1 *res,
976 ffetargetCharacterSize size,
977 ffetargetTypeless l, mallocPool pool)
979 unsigned long long int l1;
980 unsigned long int l2;
981 unsigned int l3;
982 unsigned short int l4;
983 unsigned char l5;
984 size_t size_of;
985 char *p;
987 if (((size_t) size) >= sizeof (l1))
989 l1 = l;
990 p = (char *) &l1;
991 size_of = sizeof (l1);
993 else if (((size_t) size) >= sizeof (l2))
995 l2 = l;
996 p = (char *) &l2;
997 size_of = sizeof (l2);
998 l1 = l2;
1000 else if (((size_t) size) >= sizeof (l3))
1002 l3 = l;
1003 p = (char *) &l3;
1004 size_of = sizeof (l3);
1005 l1 = l3;
1007 else if (((size_t) size) >= sizeof (l4))
1009 l4 = l;
1010 p = (char *) &l4;
1011 size_of = sizeof (l4);
1012 l1 = l4;
1014 else if (((size_t) size) >= sizeof (l5))
1016 l5 = l;
1017 p = (char *) &l5;
1018 size_of = sizeof (l5);
1019 l1 = l5;
1021 else
1023 assert ("stumped by conversion from typeless!" == NULL);
1024 abort ();
1027 res->length = size;
1028 if (size == 0)
1029 res->text = NULL;
1030 else
1032 res->text = malloc_new_kp (pool, "FFETARGET cvt char1", size + 1);
1033 res->text[size] = '\0';
1034 if (((size_t) size) <= size_of)
1036 int i = size_of - size;
1038 memcpy (res->text, p + i, size);
1039 for (; i > 0; ++p, --i)
1040 if (*p != 0)
1041 return FFEBAD_TRUNCATING_TYPELESS;
1043 else
1045 int i = size - size_of;
1047 memset (res->text, 0, i);
1048 memcpy (res->text + i, p, size_of);
1052 if (l1 != l)
1053 return FFEBAD_TRUNCATING_TYPELESS;
1054 return FFEBAD;
1057 #endif
1058 /* ffetarget_divide_complex1 -- Divide function
1060 See prototype. */
1062 #if FFETARGET_okCOMPLEX1
1063 ffebad
1064 ffetarget_divide_complex1 (ffetargetComplex1 *res, ffetargetComplex1 l,
1065 ffetargetComplex1 r)
1067 ffebad bad;
1068 ffetargetReal1 tmp1, tmp2, tmp3, tmp4;
1070 bad = ffetarget_multiply_real1 (&tmp1, r.real, r.real);
1071 if (bad != FFEBAD)
1072 return bad;
1073 bad = ffetarget_multiply_real1 (&tmp2, r.imaginary, r.imaginary);
1074 if (bad != FFEBAD)
1075 return bad;
1076 bad = ffetarget_add_real1 (&tmp3, tmp1, tmp2);
1077 if (bad != FFEBAD)
1078 return bad;
1080 if (ffetarget_iszero_real1 (tmp3))
1082 ffetarget_real1_zero (&(res)->real);
1083 ffetarget_real1_zero (&(res)->imaginary);
1084 return FFEBAD_DIV_BY_ZERO;
1087 bad = ffetarget_multiply_real1 (&tmp1, l.real, r.real);
1088 if (bad != FFEBAD)
1089 return bad;
1090 bad = ffetarget_multiply_real1 (&tmp2, l.imaginary, r.imaginary);
1091 if (bad != FFEBAD)
1092 return bad;
1093 bad = ffetarget_add_real1 (&tmp4, tmp1, tmp2);
1094 if (bad != FFEBAD)
1095 return bad;
1096 bad = ffetarget_divide_real1 (&res->real, tmp4, tmp3);
1097 if (bad != FFEBAD)
1098 return bad;
1100 bad = ffetarget_multiply_real1 (&tmp1, r.real, l.imaginary);
1101 if (bad != FFEBAD)
1102 return bad;
1103 bad = ffetarget_multiply_real1 (&tmp2, l.real, r.imaginary);
1104 if (bad != FFEBAD)
1105 return bad;
1106 bad = ffetarget_subtract_real1 (&tmp4, tmp1, tmp2);
1107 if (bad != FFEBAD)
1108 return bad;
1109 bad = ffetarget_divide_real1 (&res->imaginary, tmp4, tmp3);
1111 return FFEBAD;
1114 #endif
1115 /* ffetarget_divide_complex2 -- Divide function
1117 See prototype. */
1119 #if FFETARGET_okCOMPLEX2
1120 ffebad
1121 ffetarget_divide_complex2 (ffetargetComplex2 *res, ffetargetComplex2 l,
1122 ffetargetComplex2 r)
1124 ffebad bad;
1125 ffetargetReal2 tmp1, tmp2, tmp3, tmp4;
1127 bad = ffetarget_multiply_real2 (&tmp1, r.real, r.real);
1128 if (bad != FFEBAD)
1129 return bad;
1130 bad = ffetarget_multiply_real2 (&tmp2, r.imaginary, r.imaginary);
1131 if (bad != FFEBAD)
1132 return bad;
1133 bad = ffetarget_add_real2 (&tmp3, tmp1, tmp2);
1134 if (bad != FFEBAD)
1135 return bad;
1137 if (ffetarget_iszero_real2 (tmp3))
1139 ffetarget_real2_zero (&(res)->real);
1140 ffetarget_real2_zero (&(res)->imaginary);
1141 return FFEBAD_DIV_BY_ZERO;
1144 bad = ffetarget_multiply_real2 (&tmp1, l.real, r.real);
1145 if (bad != FFEBAD)
1146 return bad;
1147 bad = ffetarget_multiply_real2 (&tmp2, l.imaginary, r.imaginary);
1148 if (bad != FFEBAD)
1149 return bad;
1150 bad = ffetarget_add_real2 (&tmp4, tmp1, tmp2);
1151 if (bad != FFEBAD)
1152 return bad;
1153 bad = ffetarget_divide_real2 (&res->real, tmp4, tmp3);
1154 if (bad != FFEBAD)
1155 return bad;
1157 bad = ffetarget_multiply_real2 (&tmp1, r.real, l.imaginary);
1158 if (bad != FFEBAD)
1159 return bad;
1160 bad = ffetarget_multiply_real2 (&tmp2, l.real, r.imaginary);
1161 if (bad != FFEBAD)
1162 return bad;
1163 bad = ffetarget_subtract_real2 (&tmp4, tmp1, tmp2);
1164 if (bad != FFEBAD)
1165 return bad;
1166 bad = ffetarget_divide_real2 (&res->imaginary, tmp4, tmp3);
1168 return FFEBAD;
1171 #endif
1172 /* ffetarget_hollerith -- Convert token to a hollerith constant
1174 Always append a null byte to the end, in case this is wanted in
1175 a special case such as passing a string as a FORMAT or %REF.
1176 Done to save a bit of hassle, nothing more, but it's a kludge anyway,
1177 because it isn't a "feature" that is self-documenting. Use the
1178 string "FFETARGET-NULL-KLUDGE" to flag anyplace you use this feature
1179 in the code. */
1181 bool
1182 ffetarget_hollerith (ffetargetHollerith *val, ffelexToken integer,
1183 mallocPool pool)
1185 val->length = ffelex_token_length (integer);
1186 val->text = malloc_new_kp (pool, "ffetargetHollerith", val->length + 1);
1187 memcpy (val->text, ffelex_token_text (integer), val->length);
1188 val->text[val->length] = '\0';
1190 return TRUE;
1193 /* ffetarget_integer_bad_magical -- Complain about a magical number
1195 Just calls ffebad with the arguments. */
1197 void
1198 ffetarget_integer_bad_magical (ffelexToken t)
1200 ffebad_start (FFEBAD_BAD_MAGICAL);
1201 ffebad_here (0, ffelex_token_where_line (t), ffelex_token_where_column (t));
1202 ffebad_finish ();
1205 /* ffetarget_integer_bad_magical_binary -- Complain about a magical number
1207 Just calls ffebad with the arguments. */
1209 void
1210 ffetarget_integer_bad_magical_binary (ffelexToken integer,
1211 ffelexToken minus)
1213 ffebad_start (FFEBAD_BAD_MAGICAL_BINARY);
1214 ffebad_here (0, ffelex_token_where_line (integer),
1215 ffelex_token_where_column (integer));
1216 ffebad_here (1, ffelex_token_where_line (minus),
1217 ffelex_token_where_column (minus));
1218 ffebad_finish ();
1221 /* ffetarget_integer_bad_magical_precedence -- Complain about a magical
1222 number
1224 Just calls ffebad with the arguments. */
1226 void
1227 ffetarget_integer_bad_magical_precedence (ffelexToken integer,
1228 ffelexToken uminus,
1229 ffelexToken higher_op)
1231 ffebad_start (FFEBAD_BAD_MAGICAL_PRECEDENCE);
1232 ffebad_here (0, ffelex_token_where_line (integer),
1233 ffelex_token_where_column (integer));
1234 ffebad_here (1, ffelex_token_where_line (uminus),
1235 ffelex_token_where_column (uminus));
1236 ffebad_here (2, ffelex_token_where_line (higher_op),
1237 ffelex_token_where_column (higher_op));
1238 ffebad_finish ();
1241 /* ffetarget_integer_bad_magical_precedence_binary -- Complain...
1243 Just calls ffebad with the arguments. */
1245 void
1246 ffetarget_integer_bad_magical_precedence_binary (ffelexToken integer,
1247 ffelexToken minus,
1248 ffelexToken higher_op)
1250 ffebad_start (FFEBAD_BAD_MAGICAL_PRECEDENCE_BINARY);
1251 ffebad_here (0, ffelex_token_where_line (integer),
1252 ffelex_token_where_column (integer));
1253 ffebad_here (1, ffelex_token_where_line (minus),
1254 ffelex_token_where_column (minus));
1255 ffebad_here (2, ffelex_token_where_line (higher_op),
1256 ffelex_token_where_column (higher_op));
1257 ffebad_finish ();
1260 /* ffetarget_integer1 -- Convert token to an integer
1262 See prototype.
1264 Token use count not affected overall. */
1266 #if FFETARGET_okINTEGER1
1267 bool
1268 ffetarget_integer1 (ffetargetInteger1 *val, ffelexToken integer)
1270 ffetargetInteger1 x;
1271 char *p;
1272 char c;
1274 assert (ffelex_token_type (integer) == FFELEX_typeNUMBER);
1276 p = ffelex_token_text (integer);
1277 x = 0;
1279 /* Skip past leading zeros. */
1281 while (((c = *p) != '\0') && (c == '0'))
1282 ++p;
1284 /* Interpret rest of number. */
1286 while (c != '\0')
1288 if ((x == FFETARGET_integerALMOST_BIG_MAGICAL)
1289 && (c == '0' + FFETARGET_integerFINISH_BIG_MAGICAL)
1290 && (*(p + 1) == '\0'))
1292 *val = (ffetargetInteger1) FFETARGET_integerBIG_MAGICAL;
1293 return TRUE;
1295 else if (x == FFETARGET_integerALMOST_BIG_MAGICAL)
1297 if ((c > '0' + FFETARGET_integerFINISH_BIG_MAGICAL)
1298 || (*(p + 1) != '\0'))
1300 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1301 ffebad_here (0, ffelex_token_where_line (integer),
1302 ffelex_token_where_column (integer));
1303 ffebad_finish ();
1304 *val = 0;
1305 return FALSE;
1308 else if (x > FFETARGET_integerALMOST_BIG_MAGICAL)
1310 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1311 ffebad_here (0, ffelex_token_where_line (integer),
1312 ffelex_token_where_column (integer));
1313 ffebad_finish ();
1314 *val = 0;
1315 return FALSE;
1317 x = x * 10 + c - '0';
1318 c = *(++p);
1321 *val = x;
1322 return TRUE;
1325 #endif
1326 /* ffetarget_integerbinary -- Convert token to a binary integer
1328 ffetarget_integerbinary x;
1329 if (ffetarget_integerdefault_8(&x,integer_token))
1330 // conversion ok.
1332 Token use count not affected overall. */
1334 bool
1335 ffetarget_integerbinary (ffetargetIntegerDefault *val, ffelexToken integer)
1337 ffetargetIntegerDefault x;
1338 char *p;
1339 char c;
1340 bool bad_digit;
1342 assert ((ffelex_token_type (integer) == FFELEX_typeNAME)
1343 || (ffelex_token_type (integer) == FFELEX_typeNUMBER));
1345 p = ffelex_token_text (integer);
1346 x = 0;
1348 /* Skip past leading zeros. */
1350 while (((c = *p) != '\0') && (c == '0'))
1351 ++p;
1353 /* Interpret rest of number. */
1355 bad_digit = FALSE;
1356 while (c != '\0')
1358 if ((c >= '0') && (c <= '1'))
1359 c -= '0';
1360 else
1362 bad_digit = TRUE;
1363 c = 0;
1366 #if 0 /* Don't complain about signed overflow; just
1367 unsigned overflow. */
1368 if ((x == FFETARGET_integerALMOST_BIG_OVERFLOW_BINARY)
1369 && (c == FFETARGET_integerFINISH_BIG_OVERFLOW_BINARY)
1370 && (*(p + 1) == '\0'))
1372 *val = FFETARGET_integerBIG_OVERFLOW_BINARY;
1373 return TRUE;
1375 else
1376 #endif
1377 #if FFETARGET_integerFINISH_BIG_OVERFLOW_BINARY == 0
1378 if ((x & FFETARGET_integerALMOST_BIG_OVERFLOW_BINARY) != 0)
1379 #else
1380 if (x == FFETARGET_integerALMOST_BIG_OVERFLOW_BINARY)
1382 if ((c > FFETARGET_integerFINISH_BIG_OVERFLOW_BINARY)
1383 || (*(p + 1) != '\0'))
1385 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1386 ffebad_here (0, ffelex_token_where_line (integer),
1387 ffelex_token_where_column (integer));
1388 ffebad_finish ();
1389 *val = 0;
1390 return FALSE;
1393 else if (x > FFETARGET_integerALMOST_BIG_OVERFLOW_BINARY)
1394 #endif
1396 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1397 ffebad_here (0, ffelex_token_where_line (integer),
1398 ffelex_token_where_column (integer));
1399 ffebad_finish ();
1400 *val = 0;
1401 return FALSE;
1403 x = (x << 1) + c;
1404 c = *(++p);
1407 if (bad_digit)
1409 ffebad_start (FFEBAD_INVALID_BINARY_DIGIT);
1410 ffebad_here (0, ffelex_token_where_line (integer),
1411 ffelex_token_where_column (integer));
1412 ffebad_finish ();
1415 *val = x;
1416 return !bad_digit;
1419 /* ffetarget_integerhex -- Convert token to a hex integer
1421 ffetarget_integerhex x;
1422 if (ffetarget_integerdefault_8(&x,integer_token))
1423 // conversion ok.
1425 Token use count not affected overall. */
1427 bool
1428 ffetarget_integerhex (ffetargetIntegerDefault *val, ffelexToken integer)
1430 ffetargetIntegerDefault x;
1431 char *p;
1432 char c;
1433 bool bad_digit;
1435 assert ((ffelex_token_type (integer) == FFELEX_typeNAME)
1436 || (ffelex_token_type (integer) == FFELEX_typeNUMBER));
1438 p = ffelex_token_text (integer);
1439 x = 0;
1441 /* Skip past leading zeros. */
1443 while (((c = *p) != '\0') && (c == '0'))
1444 ++p;
1446 /* Interpret rest of number. */
1448 bad_digit = FALSE;
1449 while (c != '\0')
1451 if (hex_p (c))
1452 c = hex_value (c);
1453 else
1455 bad_digit = TRUE;
1456 c = 0;
1459 #if 0 /* Don't complain about signed overflow; just
1460 unsigned overflow. */
1461 if ((x == FFETARGET_integerALMOST_BIG_OVERFLOW_HEX)
1462 && (c == FFETARGET_integerFINISH_BIG_OVERFLOW_HEX)
1463 && (*(p + 1) == '\0'))
1465 *val = FFETARGET_integerBIG_OVERFLOW_HEX;
1466 return TRUE;
1468 else
1469 #endif
1470 #if FFETARGET_integerFINISH_BIG_OVERFLOW_HEX == 0
1471 if (x >= FFETARGET_integerALMOST_BIG_OVERFLOW_HEX)
1472 #else
1473 if (x == FFETARGET_integerALMOST_BIG_OVERFLOW_HEX)
1475 if ((c > FFETARGET_integerFINISH_BIG_OVERFLOW_HEX)
1476 || (*(p + 1) != '\0'))
1478 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1479 ffebad_here (0, ffelex_token_where_line (integer),
1480 ffelex_token_where_column (integer));
1481 ffebad_finish ();
1482 *val = 0;
1483 return FALSE;
1486 else if (x > FFETARGET_integerALMOST_BIG_OVERFLOW_HEX)
1487 #endif
1489 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1490 ffebad_here (0, ffelex_token_where_line (integer),
1491 ffelex_token_where_column (integer));
1492 ffebad_finish ();
1493 *val = 0;
1494 return FALSE;
1496 x = (x << 4) + c;
1497 c = *(++p);
1500 if (bad_digit)
1502 ffebad_start (FFEBAD_INVALID_HEX_DIGIT);
1503 ffebad_here (0, ffelex_token_where_line (integer),
1504 ffelex_token_where_column (integer));
1505 ffebad_finish ();
1508 *val = x;
1509 return !bad_digit;
1512 /* ffetarget_integeroctal -- Convert token to an octal integer
1514 ffetarget_integeroctal x;
1515 if (ffetarget_integerdefault_8(&x,integer_token))
1516 // conversion ok.
1518 Token use count not affected overall. */
1520 bool
1521 ffetarget_integeroctal (ffetargetIntegerDefault *val, ffelexToken integer)
1523 ffetargetIntegerDefault x;
1524 char *p;
1525 char c;
1526 bool bad_digit;
1528 assert ((ffelex_token_type (integer) == FFELEX_typeNAME)
1529 || (ffelex_token_type (integer) == FFELEX_typeNUMBER));
1531 p = ffelex_token_text (integer);
1532 x = 0;
1534 /* Skip past leading zeros. */
1536 while (((c = *p) != '\0') && (c == '0'))
1537 ++p;
1539 /* Interpret rest of number. */
1541 bad_digit = FALSE;
1542 while (c != '\0')
1544 if ((c >= '0') && (c <= '7'))
1545 c -= '0';
1546 else
1548 bad_digit = TRUE;
1549 c = 0;
1552 #if 0 /* Don't complain about signed overflow; just
1553 unsigned overflow. */
1554 if ((x == FFETARGET_integerALMOST_BIG_OVERFLOW_OCTAL)
1555 && (c == FFETARGET_integerFINISH_BIG_OVERFLOW_OCTAL)
1556 && (*(p + 1) == '\0'))
1558 *val = FFETARGET_integerBIG_OVERFLOW_OCTAL;
1559 return TRUE;
1561 else
1562 #endif
1563 #if FFETARGET_integerFINISH_BIG_OVERFLOW_OCTAL == 0
1564 if (x >= FFETARGET_integerALMOST_BIG_OVERFLOW_OCTAL)
1565 #else
1566 if (x == FFETARGET_integerALMOST_BIG_OVERFLOW_OCTAL)
1568 if ((c > FFETARGET_integerFINISH_BIG_OVERFLOW_OCTAL)
1569 || (*(p + 1) != '\0'))
1571 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1572 ffebad_here (0, ffelex_token_where_line (integer),
1573 ffelex_token_where_column (integer));
1574 ffebad_finish ();
1575 *val = 0;
1576 return FALSE;
1579 else if (x > FFETARGET_integerALMOST_BIG_OVERFLOW_OCTAL)
1580 #endif
1582 ffebad_start (FFEBAD_INTEGER_TOO_LARGE);
1583 ffebad_here (0, ffelex_token_where_line (integer),
1584 ffelex_token_where_column (integer));
1585 ffebad_finish ();
1586 *val = 0;
1587 return FALSE;
1589 x = (x << 3) + c;
1590 c = *(++p);
1593 if (bad_digit)
1595 ffebad_start (FFEBAD_INVALID_OCTAL_DIGIT);
1596 ffebad_here (0, ffelex_token_where_line (integer),
1597 ffelex_token_where_column (integer));
1598 ffebad_finish ();
1601 *val = x;
1602 return !bad_digit;
1605 /* ffetarget_multiply_complex1 -- Multiply function
1607 See prototype. */
1609 #if FFETARGET_okCOMPLEX1
1610 ffebad
1611 ffetarget_multiply_complex1 (ffetargetComplex1 *res, ffetargetComplex1 l,
1612 ffetargetComplex1 r)
1614 ffebad bad;
1615 ffetargetReal1 tmp1, tmp2;
1617 bad = ffetarget_multiply_real1 (&tmp1, l.real, r.real);
1618 if (bad != FFEBAD)
1619 return bad;
1620 bad = ffetarget_multiply_real1 (&tmp2, l.imaginary, r.imaginary);
1621 if (bad != FFEBAD)
1622 return bad;
1623 bad = ffetarget_subtract_real1 (&res->real, tmp1, tmp2);
1624 if (bad != FFEBAD)
1625 return bad;
1626 bad = ffetarget_multiply_real1 (&tmp1, l.imaginary, r.real);
1627 if (bad != FFEBAD)
1628 return bad;
1629 bad = ffetarget_multiply_real1 (&tmp2, l.real, r.imaginary);
1630 if (bad != FFEBAD)
1631 return bad;
1632 bad = ffetarget_add_real1 (&res->imaginary, tmp1, tmp2);
1634 return bad;
1637 #endif
1638 /* ffetarget_multiply_complex2 -- Multiply function
1640 See prototype. */
1642 #if FFETARGET_okCOMPLEX2
1643 ffebad
1644 ffetarget_multiply_complex2 (ffetargetComplex2 *res, ffetargetComplex2 l,
1645 ffetargetComplex2 r)
1647 ffebad bad;
1648 ffetargetReal2 tmp1, tmp2;
1650 bad = ffetarget_multiply_real2 (&tmp1, l.real, r.real);
1651 if (bad != FFEBAD)
1652 return bad;
1653 bad = ffetarget_multiply_real2 (&tmp2, l.imaginary, r.imaginary);
1654 if (bad != FFEBAD)
1655 return bad;
1656 bad = ffetarget_subtract_real2 (&res->real, tmp1, tmp2);
1657 if (bad != FFEBAD)
1658 return bad;
1659 bad = ffetarget_multiply_real2 (&tmp1, l.imaginary, r.real);
1660 if (bad != FFEBAD)
1661 return bad;
1662 bad = ffetarget_multiply_real2 (&tmp2, l.real, r.imaginary);
1663 if (bad != FFEBAD)
1664 return bad;
1665 bad = ffetarget_add_real2 (&res->imaginary, tmp1, tmp2);
1667 return bad;
1670 #endif
1671 /* ffetarget_power_complexdefault_integerdefault -- Power function
1673 See prototype. */
1675 ffebad
1676 ffetarget_power_complexdefault_integerdefault (ffetargetComplexDefault *res,
1677 ffetargetComplexDefault l,
1678 ffetargetIntegerDefault r)
1680 ffebad bad;
1681 ffetargetRealDefault tmp;
1682 ffetargetRealDefault tmp1;
1683 ffetargetRealDefault tmp2;
1684 ffetargetRealDefault two;
1686 if (ffetarget_iszero_real1 (l.real)
1687 && ffetarget_iszero_real1 (l.imaginary))
1689 ffetarget_real1_zero (&res->real);
1690 ffetarget_real1_zero (&res->imaginary);
1691 return FFEBAD;
1694 if (r == 0)
1696 ffetarget_real1_one (&res->real);
1697 ffetarget_real1_zero (&res->imaginary);
1698 return FFEBAD;
1701 if (r < 0)
1703 r = -r;
1704 bad = ffetarget_multiply_real1 (&tmp1, l.real, l.real);
1705 if (bad != FFEBAD)
1706 return bad;
1707 bad = ffetarget_multiply_real1 (&tmp2, l.imaginary, l.imaginary);
1708 if (bad != FFEBAD)
1709 return bad;
1710 bad = ffetarget_add_real1 (&tmp, tmp1, tmp2);
1711 if (bad != FFEBAD)
1712 return bad;
1713 bad = ffetarget_divide_real1 (&l.real, l.real, tmp);
1714 if (bad != FFEBAD)
1715 return bad;
1716 bad = ffetarget_divide_real1 (&l.imaginary, l.imaginary, tmp);
1717 if (bad != FFEBAD)
1718 return bad;
1719 bad = ffetarget_uminus_real1 (&l.imaginary, l.imaginary);
1720 if (bad != FFEBAD)
1721 return bad;
1724 ffetarget_real1_two (&two);
1726 while ((r & 1) == 0)
1728 bad = ffetarget_multiply_real1 (&tmp1, l.real, l.real);
1729 if (bad != FFEBAD)
1730 return bad;
1731 bad = ffetarget_multiply_real1 (&tmp2, l.imaginary, l.imaginary);
1732 if (bad != FFEBAD)
1733 return bad;
1734 bad = ffetarget_subtract_real1 (&tmp, tmp1, tmp2);
1735 if (bad != FFEBAD)
1736 return bad;
1737 bad = ffetarget_multiply_real1 (&l.imaginary, l.real, l.imaginary);
1738 if (bad != FFEBAD)
1739 return bad;
1740 bad = ffetarget_multiply_real1 (&l.imaginary, l.imaginary, two);
1741 if (bad != FFEBAD)
1742 return bad;
1743 l.real = tmp;
1744 r >>= 1;
1747 *res = l;
1748 r >>= 1;
1750 while (r != 0)
1752 bad = ffetarget_multiply_real1 (&tmp1, l.real, l.real);
1753 if (bad != FFEBAD)
1754 return bad;
1755 bad = ffetarget_multiply_real1 (&tmp2, l.imaginary, l.imaginary);
1756 if (bad != FFEBAD)
1757 return bad;
1758 bad = ffetarget_subtract_real1 (&tmp, tmp1, tmp2);
1759 if (bad != FFEBAD)
1760 return bad;
1761 bad = ffetarget_multiply_real1 (&l.imaginary, l.real, l.imaginary);
1762 if (bad != FFEBAD)
1763 return bad;
1764 bad = ffetarget_multiply_real1 (&l.imaginary, l.imaginary, two);
1765 if (bad != FFEBAD)
1766 return bad;
1767 l.real = tmp;
1768 if ((r & 1) == 1)
1770 bad = ffetarget_multiply_real1 (&tmp1, res->real, l.real);
1771 if (bad != FFEBAD)
1772 return bad;
1773 bad = ffetarget_multiply_real1 (&tmp2, res->imaginary,
1774 l.imaginary);
1775 if (bad != FFEBAD)
1776 return bad;
1777 bad = ffetarget_subtract_real1 (&tmp, tmp1, tmp2);
1778 if (bad != FFEBAD)
1779 return bad;
1780 bad = ffetarget_multiply_real1 (&tmp1, res->imaginary, l.real);
1781 if (bad != FFEBAD)
1782 return bad;
1783 bad = ffetarget_multiply_real1 (&tmp2, res->real, l.imaginary);
1784 if (bad != FFEBAD)
1785 return bad;
1786 bad = ffetarget_add_real1 (&res->imaginary, tmp1, tmp2);
1787 if (bad != FFEBAD)
1788 return bad;
1789 res->real = tmp;
1791 r >>= 1;
1794 return FFEBAD;
1797 /* ffetarget_power_complexdouble_integerdefault -- Power function
1799 See prototype. */
1801 #if FFETARGET_okCOMPLEXDOUBLE
1802 ffebad
1803 ffetarget_power_complexdouble_integerdefault (ffetargetComplexDouble *res,
1804 ffetargetComplexDouble l, ffetargetIntegerDefault r)
1806 ffebad bad;
1807 ffetargetRealDouble tmp;
1808 ffetargetRealDouble tmp1;
1809 ffetargetRealDouble tmp2;
1810 ffetargetRealDouble two;
1812 if (ffetarget_iszero_real2 (l.real)
1813 && ffetarget_iszero_real2 (l.imaginary))
1815 ffetarget_real2_zero (&res->real);
1816 ffetarget_real2_zero (&res->imaginary);
1817 return FFEBAD;
1820 if (r == 0)
1822 ffetarget_real2_one (&res->real);
1823 ffetarget_real2_zero (&res->imaginary);
1824 return FFEBAD;
1827 if (r < 0)
1829 r = -r;
1830 bad = ffetarget_multiply_real2 (&tmp1, l.real, l.real);
1831 if (bad != FFEBAD)
1832 return bad;
1833 bad = ffetarget_multiply_real2 (&tmp2, l.imaginary, l.imaginary);
1834 if (bad != FFEBAD)
1835 return bad;
1836 bad = ffetarget_add_real2 (&tmp, tmp1, tmp2);
1837 if (bad != FFEBAD)
1838 return bad;
1839 bad = ffetarget_divide_real2 (&l.real, l.real, tmp);
1840 if (bad != FFEBAD)
1841 return bad;
1842 bad = ffetarget_divide_real2 (&l.imaginary, l.imaginary, tmp);
1843 if (bad != FFEBAD)
1844 return bad;
1845 bad = ffetarget_uminus_real2 (&l.imaginary, l.imaginary);
1846 if (bad != FFEBAD)
1847 return bad;
1850 ffetarget_real2_two (&two);
1852 while ((r & 1) == 0)
1854 bad = ffetarget_multiply_real2 (&tmp1, l.real, l.real);
1855 if (bad != FFEBAD)
1856 return bad;
1857 bad = ffetarget_multiply_real2 (&tmp2, l.imaginary, l.imaginary);
1858 if (bad != FFEBAD)
1859 return bad;
1860 bad = ffetarget_subtract_real2 (&tmp, tmp1, tmp2);
1861 if (bad != FFEBAD)
1862 return bad;
1863 bad = ffetarget_multiply_real2 (&l.imaginary, l.real, l.imaginary);
1864 if (bad != FFEBAD)
1865 return bad;
1866 bad = ffetarget_multiply_real2 (&l.imaginary, l.imaginary, two);
1867 if (bad != FFEBAD)
1868 return bad;
1869 l.real = tmp;
1870 r >>= 1;
1873 *res = l;
1874 r >>= 1;
1876 while (r != 0)
1878 bad = ffetarget_multiply_real2 (&tmp1, l.real, l.real);
1879 if (bad != FFEBAD)
1880 return bad;
1881 bad = ffetarget_multiply_real2 (&tmp2, l.imaginary, l.imaginary);
1882 if (bad != FFEBAD)
1883 return bad;
1884 bad = ffetarget_subtract_real2 (&tmp, tmp1, tmp2);
1885 if (bad != FFEBAD)
1886 return bad;
1887 bad = ffetarget_multiply_real2 (&l.imaginary, l.real, l.imaginary);
1888 if (bad != FFEBAD)
1889 return bad;
1890 bad = ffetarget_multiply_real2 (&l.imaginary, l.imaginary, two);
1891 if (bad != FFEBAD)
1892 return bad;
1893 l.real = tmp;
1894 if ((r & 1) == 1)
1896 bad = ffetarget_multiply_real2 (&tmp1, res->real, l.real);
1897 if (bad != FFEBAD)
1898 return bad;
1899 bad = ffetarget_multiply_real2 (&tmp2, res->imaginary,
1900 l.imaginary);
1901 if (bad != FFEBAD)
1902 return bad;
1903 bad = ffetarget_subtract_real2 (&tmp, tmp1, tmp2);
1904 if (bad != FFEBAD)
1905 return bad;
1906 bad = ffetarget_multiply_real2 (&tmp1, res->imaginary, l.real);
1907 if (bad != FFEBAD)
1908 return bad;
1909 bad = ffetarget_multiply_real2 (&tmp2, res->real, l.imaginary);
1910 if (bad != FFEBAD)
1911 return bad;
1912 bad = ffetarget_add_real2 (&res->imaginary, tmp1, tmp2);
1913 if (bad != FFEBAD)
1914 return bad;
1915 res->real = tmp;
1917 r >>= 1;
1920 return FFEBAD;
1923 #endif
1924 /* ffetarget_power_integerdefault_integerdefault -- Power function
1926 See prototype. */
1928 ffebad
1929 ffetarget_power_integerdefault_integerdefault (ffetargetIntegerDefault *res,
1930 ffetargetIntegerDefault l, ffetargetIntegerDefault r)
1932 if (l == 0)
1934 *res = 0;
1935 return FFEBAD;
1938 if (r == 0)
1940 *res = 1;
1941 return FFEBAD;
1944 if (r < 0)
1946 if (l == 1)
1947 *res = 1;
1948 else if (l == 0)
1949 *res = 1;
1950 else if (l == -1)
1951 *res = ((-r) & 1) == 0 ? 1 : -1;
1952 else
1953 *res = 0;
1954 return FFEBAD;
1957 while ((r & 1) == 0)
1959 l *= l;
1960 r >>= 1;
1963 *res = l;
1964 r >>= 1;
1966 while (r != 0)
1968 l *= l;
1969 if ((r & 1) == 1)
1970 *res *= l;
1971 r >>= 1;
1974 return FFEBAD;
1977 /* ffetarget_power_realdefault_integerdefault -- Power function
1979 See prototype. */
1981 ffebad
1982 ffetarget_power_realdefault_integerdefault (ffetargetRealDefault *res,
1983 ffetargetRealDefault l, ffetargetIntegerDefault r)
1985 ffebad bad;
1987 if (ffetarget_iszero_real1 (l))
1989 ffetarget_real1_zero (res);
1990 return FFEBAD;
1993 if (r == 0)
1995 ffetarget_real1_one (res);
1996 return FFEBAD;
1999 if (r < 0)
2001 ffetargetRealDefault one;
2003 ffetarget_real1_one (&one);
2004 r = -r;
2005 bad = ffetarget_divide_real1 (&l, one, l);
2006 if (bad != FFEBAD)
2007 return bad;
2010 while ((r & 1) == 0)
2012 bad = ffetarget_multiply_real1 (&l, l, l);
2013 if (bad != FFEBAD)
2014 return bad;
2015 r >>= 1;
2018 *res = l;
2019 r >>= 1;
2021 while (r != 0)
2023 bad = ffetarget_multiply_real1 (&l, l, l);
2024 if (bad != FFEBAD)
2025 return bad;
2026 if ((r & 1) == 1)
2028 bad = ffetarget_multiply_real1 (res, *res, l);
2029 if (bad != FFEBAD)
2030 return bad;
2032 r >>= 1;
2035 return FFEBAD;
2038 /* ffetarget_power_realdouble_integerdefault -- Power function
2040 See prototype. */
2042 ffebad
2043 ffetarget_power_realdouble_integerdefault (ffetargetRealDouble *res,
2044 ffetargetRealDouble l,
2045 ffetargetIntegerDefault r)
2047 ffebad bad;
2049 if (ffetarget_iszero_real2 (l))
2051 ffetarget_real2_zero (res);
2052 return FFEBAD;
2055 if (r == 0)
2057 ffetarget_real2_one (res);
2058 return FFEBAD;
2061 if (r < 0)
2063 ffetargetRealDouble one;
2065 ffetarget_real2_one (&one);
2066 r = -r;
2067 bad = ffetarget_divide_real2 (&l, one, l);
2068 if (bad != FFEBAD)
2069 return bad;
2072 while ((r & 1) == 0)
2074 bad = ffetarget_multiply_real2 (&l, l, l);
2075 if (bad != FFEBAD)
2076 return bad;
2077 r >>= 1;
2080 *res = l;
2081 r >>= 1;
2083 while (r != 0)
2085 bad = ffetarget_multiply_real2 (&l, l, l);
2086 if (bad != FFEBAD)
2087 return bad;
2088 if ((r & 1) == 1)
2090 bad = ffetarget_multiply_real2 (res, *res, l);
2091 if (bad != FFEBAD)
2092 return bad;
2094 r >>= 1;
2097 return FFEBAD;
2100 /* ffetarget_print_binary -- Output typeless binary integer
2102 ffetargetTypeless val;
2103 ffetarget_typeless_binary(dmpout,val); */
2105 void
2106 ffetarget_print_binary (FILE *f, ffetargetTypeless value)
2108 char *p;
2109 char digits[sizeof (value) * CHAR_BIT + 1];
2111 if (f == NULL)
2112 f = dmpout;
2114 p = &digits[ARRAY_SIZE (digits) - 1];
2115 *p = '\0';
2118 *--p = (value & 1) + '0';
2119 value >>= 1;
2120 } while (value == 0);
2122 fputs (p, f);
2125 /* ffetarget_print_character1 -- Output character string
2127 ffetargetCharacter1 val;
2128 ffetarget_print_character1(dmpout,val); */
2130 void
2131 ffetarget_print_character1 (FILE *f, ffetargetCharacter1 value)
2133 unsigned char *p;
2134 ffetargetCharacterSize i;
2136 fputc ('\'', dmpout);
2137 for (i = 0, p = value.text; i < value.length; ++i, ++p)
2138 ffetarget_print_char_ (f, *p);
2139 fputc ('\'', dmpout);
2142 /* ffetarget_print_hollerith -- Output hollerith string
2144 ffetargetHollerith val;
2145 ffetarget_print_hollerith(dmpout,val); */
2147 void
2148 ffetarget_print_hollerith (FILE *f, ffetargetHollerith value)
2150 unsigned char *p;
2151 ffetargetHollerithSize i;
2153 fputc ('\'', dmpout);
2154 for (i = 0, p = value.text; i < value.length; ++i, ++p)
2155 ffetarget_print_char_ (f, *p);
2156 fputc ('\'', dmpout);
2159 /* ffetarget_print_octal -- Output typeless octal integer
2161 ffetargetTypeless val;
2162 ffetarget_print_octal(dmpout,val); */
2164 void
2165 ffetarget_print_octal (FILE *f, ffetargetTypeless value)
2167 char *p;
2168 char digits[sizeof (value) * CHAR_BIT / 3 + 1];
2170 if (f == NULL)
2171 f = dmpout;
2173 p = &digits[ARRAY_SIZE (digits) - 3];
2174 *p = '\0';
2177 *--p = (value & 3) + '0';
2178 value >>= 3;
2179 } while (value == 0);
2181 fputs (p, f);
2184 /* ffetarget_print_hex -- Output typeless hex integer
2186 ffetargetTypeless val;
2187 ffetarget_print_hex(dmpout,val); */
2189 void
2190 ffetarget_print_hex (FILE *f, ffetargetTypeless value)
2192 char *p;
2193 char digits[sizeof (value) * CHAR_BIT / 4 + 1];
2194 static const char hexdigits[16] = "0123456789ABCDEF";
2196 if (f == NULL)
2197 f = dmpout;
2199 p = &digits[ARRAY_SIZE (digits) - 3];
2200 *p = '\0';
2203 *--p = hexdigits[value & 4];
2204 value >>= 4;
2205 } while (value == 0);
2207 fputs (p, f);
2210 /* ffetarget_real1 -- Convert token to a single-precision real number
2212 See prototype.
2214 Pass NULL for any token not provided by the user, but a valid Fortran
2215 real number must be provided somehow. For example, it is ok for
2216 exponent_sign_token and exponent_digits_token to be NULL as long as
2217 exponent_token not only starts with "E" or "e" but also contains at least
2218 one digit following it. Token use counts not affected overall. */
2220 #if FFETARGET_okREAL1
2221 bool
2222 ffetarget_real1 (ffetargetReal1 *value, ffelexToken integer,
2223 ffelexToken decimal, ffelexToken fraction,
2224 ffelexToken exponent, ffelexToken exponent_sign,
2225 ffelexToken exponent_digits)
2227 size_t sz = 1; /* Allow room for '\0' byte at end. */
2228 char *ptr = &ffetarget_string_[0];
2229 char *p = ptr;
2230 char *q;
2232 #define dotok(x) if (x != NULL) ++sz;
2233 #define dotoktxt(x) if (x != NULL) sz += ffelex_token_length(x)
2235 dotoktxt (integer);
2236 dotok (decimal);
2237 dotoktxt (fraction);
2238 dotoktxt (exponent);
2239 dotok (exponent_sign);
2240 dotoktxt (exponent_digits);
2242 #undef dotok
2243 #undef dotoktxt
2245 if (sz > ARRAY_SIZE (ffetarget_string_))
2246 p = ptr = (char *) malloc_new_ks (malloc_pool_image (), "ffetarget_real1",
2247 sz);
2249 #define dotoktxt(x) if (x != NULL) \
2251 for (q = ffelex_token_text(x); *q != '\0'; ++q) \
2252 *p++ = *q; \
2255 dotoktxt (integer);
2257 if (decimal != NULL)
2258 *p++ = '.';
2260 dotoktxt (fraction);
2261 dotoktxt (exponent);
2263 if (exponent_sign != NULL)
2265 if (ffelex_token_type (exponent_sign) == FFELEX_typePLUS)
2266 *p++ = '+';
2267 else
2269 assert (ffelex_token_type (exponent_sign) == FFELEX_typeMINUS);
2270 *p++ = '-';
2274 dotoktxt (exponent_digits);
2276 #undef dotoktxt
2278 *p = '\0';
2280 ffetarget_make_real1 (value,
2281 FFETARGET_ATOF_ (ptr,
2282 SFmode));
2284 if (sz > ARRAY_SIZE (ffetarget_string_))
2285 malloc_kill_ks (malloc_pool_image (), ptr, sz);
2287 return TRUE;
2290 #endif
2291 /* ffetarget_real2 -- Convert token to a single-precision real number
2293 See prototype.
2295 Pass NULL for any token not provided by the user, but a valid Fortran
2296 real number must be provided somehow. For example, it is ok for
2297 exponent_sign_token and exponent_digits_token to be NULL as long as
2298 exponent_token not only starts with "E" or "e" but also contains at least
2299 one digit following it. Token use counts not affected overall. */
2301 #if FFETARGET_okREAL2
2302 bool
2303 ffetarget_real2 (ffetargetReal2 *value, ffelexToken integer,
2304 ffelexToken decimal, ffelexToken fraction,
2305 ffelexToken exponent, ffelexToken exponent_sign,
2306 ffelexToken exponent_digits)
2308 size_t sz = 1; /* Allow room for '\0' byte at end. */
2309 char *ptr = &ffetarget_string_[0];
2310 char *p = ptr;
2311 char *q;
2313 #define dotok(x) if (x != NULL) ++sz;
2314 #define dotoktxt(x) if (x != NULL) sz += ffelex_token_length(x)
2316 dotoktxt (integer);
2317 dotok (decimal);
2318 dotoktxt (fraction);
2319 dotoktxt (exponent);
2320 dotok (exponent_sign);
2321 dotoktxt (exponent_digits);
2323 #undef dotok
2324 #undef dotoktxt
2326 if (sz > ARRAY_SIZE (ffetarget_string_))
2327 p = ptr = (char *) malloc_new_ks (malloc_pool_image (), "ffetarget_real1", sz);
2329 #define dotoktxt(x) if (x != NULL) \
2331 for (q = ffelex_token_text(x); *q != '\0'; ++q) \
2332 *p++ = *q; \
2334 #define dotoktxtexp(x) if (x != NULL) \
2336 *p++ = 'E'; \
2337 for (q = ffelex_token_text(x) + 1; *q != '\0'; ++q) \
2338 *p++ = *q; \
2341 dotoktxt (integer);
2343 if (decimal != NULL)
2344 *p++ = '.';
2346 dotoktxt (fraction);
2347 dotoktxtexp (exponent);
2349 if (exponent_sign != NULL)
2351 if (ffelex_token_type (exponent_sign) == FFELEX_typePLUS)
2352 *p++ = '+';
2353 else
2355 assert (ffelex_token_type (exponent_sign) == FFELEX_typeMINUS);
2356 *p++ = '-';
2360 dotoktxt (exponent_digits);
2362 #undef dotoktxt
2364 *p = '\0';
2366 ffetarget_make_real2 (value,
2367 FFETARGET_ATOF_ (ptr,
2368 DFmode));
2370 if (sz > ARRAY_SIZE (ffetarget_string_))
2371 malloc_kill_ks (malloc_pool_image (), ptr, sz);
2373 return TRUE;
2376 #endif
2377 bool
2378 ffetarget_typeless_binary (ffetargetTypeless *xvalue, ffelexToken token)
2380 char *p;
2381 char c;
2382 ffetargetTypeless value = 0;
2383 ffetargetTypeless new_value = 0;
2384 bool bad_digit = FALSE;
2385 bool overflow = FALSE;
2387 p = ffelex_token_text (token);
2389 for (c = *p; c != '\0'; c = *++p)
2391 new_value <<= 1;
2392 if ((new_value >> 1) != value)
2393 overflow = TRUE;
2394 if (ISDIGIT (c))
2395 new_value += c - '0';
2396 else
2397 bad_digit = TRUE;
2398 value = new_value;
2401 if (bad_digit)
2403 ffebad_start (FFEBAD_INVALID_TYPELESS_BINARY_DIGIT);
2404 ffebad_here (0, ffelex_token_where_line (token),
2405 ffelex_token_where_column (token));
2406 ffebad_finish ();
2408 else if (overflow)
2410 ffebad_start (FFEBAD_TYPELESS_OVERFLOW);
2411 ffebad_here (0, ffelex_token_where_line (token),
2412 ffelex_token_where_column (token));
2413 ffebad_finish ();
2416 *xvalue = value;
2418 return !bad_digit && !overflow;
2421 bool
2422 ffetarget_typeless_octal (ffetargetTypeless *xvalue, ffelexToken token)
2424 char *p;
2425 char c;
2426 ffetargetTypeless value = 0;
2427 ffetargetTypeless new_value = 0;
2428 bool bad_digit = FALSE;
2429 bool overflow = FALSE;
2431 p = ffelex_token_text (token);
2433 for (c = *p; c != '\0'; c = *++p)
2435 new_value <<= 3;
2436 if ((new_value >> 3) != value)
2437 overflow = TRUE;
2438 if (ISDIGIT (c))
2439 new_value += c - '0';
2440 else
2441 bad_digit = TRUE;
2442 value = new_value;
2445 if (bad_digit)
2447 ffebad_start (FFEBAD_INVALID_TYPELESS_OCTAL_DIGIT);
2448 ffebad_here (0, ffelex_token_where_line (token),
2449 ffelex_token_where_column (token));
2450 ffebad_finish ();
2452 else if (overflow)
2454 ffebad_start (FFEBAD_TYPELESS_OVERFLOW);
2455 ffebad_here (0, ffelex_token_where_line (token),
2456 ffelex_token_where_column (token));
2457 ffebad_finish ();
2460 *xvalue = value;
2462 return !bad_digit && !overflow;
2465 bool
2466 ffetarget_typeless_hex (ffetargetTypeless *xvalue, ffelexToken token)
2468 char *p;
2469 char c;
2470 ffetargetTypeless value = 0;
2471 ffetargetTypeless new_value = 0;
2472 bool bad_digit = FALSE;
2473 bool overflow = FALSE;
2475 p = ffelex_token_text (token);
2477 for (c = *p; c != '\0'; c = *++p)
2479 new_value <<= 4;
2480 if ((new_value >> 4) != value)
2481 overflow = TRUE;
2482 if (hex_p (c))
2483 new_value += hex_value (c);
2484 else
2485 bad_digit = TRUE;
2486 value = new_value;
2489 if (bad_digit)
2491 ffebad_start (FFEBAD_INVALID_TYPELESS_HEX_DIGIT);
2492 ffebad_here (0, ffelex_token_where_line (token),
2493 ffelex_token_where_column (token));
2494 ffebad_finish ();
2496 else if (overflow)
2498 ffebad_start (FFEBAD_TYPELESS_OVERFLOW);
2499 ffebad_here (0, ffelex_token_where_line (token),
2500 ffelex_token_where_column (token));
2501 ffebad_finish ();
2504 *xvalue = value;
2506 return !bad_digit && !overflow;
2509 void
2510 ffetarget_verify_character1 (mallocPool pool, ffetargetCharacter1 val)
2512 if (val.length != 0)
2513 malloc_verify_kp (pool, val.text, val.length);
2516 /* This is like memcpy. It is needed because some systems' header files
2517 don't declare memcpy as a function but instead
2518 "#define memcpy(to,from,len) something". */
2520 void *
2521 ffetarget_memcpy_ (void *dst, void *src, size_t len)
2523 #ifdef CROSS_COMPILE
2524 int host_words_big_endian =
2525 #ifndef HOST_WORDS_BIG_ENDIAN
2527 #else
2528 HOST_WORDS_BIG_ENDIAN
2529 #endif
2532 int host_bytes_big_endian =
2533 #ifndef HOST_BYTES_BIG_ENDIAN
2535 #else
2536 HOST_BYTES_BIG_ENDIAN
2537 #endif
2540 int host_bits_big_endian =
2541 #ifndef HOST_BITS_BIG_ENDIAN
2543 #else
2544 HOST_BITS_BIG_ENDIAN
2545 #endif
2548 /* This is just hands thrown up in the air over bits coming through this
2549 function representing a number being memcpy:d as-is from host to
2550 target. We can't generally adjust endianness here since we don't
2551 know whether it's an integer or floating point number; they're passed
2552 differently. Better to not emit code at all than to emit wrong code.
2553 We will get some false hits because some data coming through here
2554 seems to be just character vectors, but often enough it's numbers,
2555 for instance in g77.f-torture/execute/980628-[4-6].f and alpha2.f.
2556 Still, we compile *some* code. FIXME: Rewrite handling of numbers. */
2557 if (!WORDS_BIG_ENDIAN != !host_words_big_endian
2558 || !BYTES_BIG_ENDIAN != !host_bytes_big_endian
2559 || !BITS_BIG_ENDIAN != !host_bits_big_endian)
2560 sorry ("data initializer on host with different endianness");
2562 #endif /* CROSS_COMPILE */
2564 return (void *) memcpy (dst, src, len);
2567 /* ffetarget_num_digits_ -- Determine number of non-space characters in token
2569 ffetarget_num_digits_(token);
2571 All non-spaces are assumed to be binary, octal, or hex digits. */
2574 ffetarget_num_digits_ (ffelexToken token)
2576 int i;
2577 char *c;
2579 switch (ffelex_token_type (token))
2581 case FFELEX_typeNAME:
2582 case FFELEX_typeNUMBER:
2583 return ffelex_token_length (token);
2585 case FFELEX_typeCHARACTER:
2586 i = 0;
2587 for (c = ffelex_token_text (token); *c != '\0'; ++c)
2589 if (*c != ' ')
2590 ++i;
2592 return i;
2594 default:
2595 assert ("weird token" == NULL);
2596 return 1;