OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [c-family/] [c-cppbuiltin.c] - Blame information for rev 712

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 707 jeremybenn
/* Define builtin-in macros for the C family front ends.
2
   Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3
   Free Software Foundation, Inc.
4
 
5
This file is part of GCC.
6
 
7
GCC is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 3, or (at your option) any later
10
version.
11
 
12
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13
WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15
for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with GCC; see the file COPYING3.  If not see
19
<http://www.gnu.org/licenses/>.  */
20
 
21
#include "config.h"
22
#include "system.h"
23
#include "coretypes.h"
24
#include "tm.h"
25
#include "tree.h"
26
#include "version.h"
27
#include "flags.h"
28
#include "c-common.h"
29
#include "c-pragma.h"
30
#include "output.h"
31
#include "debug.h"              /* For dwarf2out_do_cfi_asm.  */
32
#include "tm_p.h"               /* For TARGET_CPU_CPP_BUILTINS & friends.  */
33
#include "target.h"
34
#include "common/common-target.h"
35
#include "cpp-id-data.h"
36
#include "cppbuiltin.h"
37
 
38
#ifndef TARGET_OS_CPP_BUILTINS
39
# define TARGET_OS_CPP_BUILTINS()
40
#endif
41
 
42
#ifndef TARGET_OBJFMT_CPP_BUILTINS
43
# define TARGET_OBJFMT_CPP_BUILTINS()
44
#endif
45
 
46
#ifndef REGISTER_PREFIX
47
#define REGISTER_PREFIX ""
48
#endif
49
 
50
/* Non-static as some targets don't use it.  */
51
void builtin_define_std (const char *) ATTRIBUTE_UNUSED;
52
static void builtin_define_with_int_value (const char *, HOST_WIDE_INT);
53
static void builtin_define_with_hex_fp_value (const char *, tree,
54
                                              int, const char *,
55
                                              const char *,
56
                                              const char *);
57
static void builtin_define_stdint_macros (void);
58
static void builtin_define_constants (const char *, tree);
59
static void builtin_define_type_max (const char *, tree);
60
static void builtin_define_type_minmax (const char *, const char *, tree);
61
static void builtin_define_type_sizeof (const char *, tree);
62
static void builtin_define_float_constants (const char *,
63
                                            const char *,
64
                                            const char *,
65
                                            const char *,
66
                                            tree);
67
 
68
/* Return true if MODE provides a fast multiply/add (FMA) builtin function.
69
   Originally this function used the fma optab, but that doesn't work with
70
   -save-temps, so just rely on the HAVE_fma macros for the standard floating
71
   point types.  */
72
 
73
static bool
74
mode_has_fma (enum machine_mode mode)
75
{
76
  switch (mode)
77
    {
78
#ifdef HAVE_fmasf4
79
    case SFmode:
80
      return !!HAVE_fmasf4;
81
#endif
82
 
83
#ifdef HAVE_fmadf4
84
    case DFmode:
85
      return !!HAVE_fmadf4;
86
#endif
87
 
88
#ifdef HAVE_fmaxf4
89
    case XFmode:
90
      return !!HAVE_fmaxf4;
91
#endif
92
 
93
#ifdef HAVE_fmatf4
94
    case TFmode:
95
      return !!HAVE_fmatf4;
96
#endif
97
 
98
    default:
99
      break;
100
    }
101
 
102
  return false;
103
}
104
 
105
/* Define NAME with value TYPE size_unit.  */
106
static void
107
builtin_define_type_sizeof (const char *name, tree type)
108
{
109
  builtin_define_with_int_value (name,
110
                                 tree_low_cst (TYPE_SIZE_UNIT (type), 1));
111
}
112
 
113
/* Define the float.h constants for TYPE using NAME_PREFIX, FP_SUFFIX,
114
   and FP_CAST. */
115
static void
116
builtin_define_float_constants (const char *name_prefix,
117
                                const char *fp_suffix,
118
                                const char *fp_cast,
119
                                const char *fma_suffix,
120
                                tree type)
121
{
122
  /* Used to convert radix-based values to base 10 values in several cases.
123
 
124
     In the max_exp -> max_10_exp conversion for 128-bit IEEE, we need at
125
     least 6 significant digits for correct results.  Using the fraction
126
     formed by (log(2)*1e6)/(log(10)*1e6) overflows a 32-bit integer as an
127
     intermediate; perhaps someone can find a better approximation, in the
128
     mean time, I suspect using doubles won't harm the bootstrap here.  */
129
 
130
  const double log10_2 = .30102999566398119521;
131
  double log10_b;
132
  const struct real_format *fmt;
133
  const struct real_format *ldfmt;
134
 
135
  char name[64], buf[128];
136
  int dig, min_10_exp, max_10_exp;
137
  int decimal_dig;
138
  int type_decimal_dig;
139
 
140
  fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
141
  gcc_assert (fmt->b != 10);
142
  ldfmt = REAL_MODE_FORMAT (TYPE_MODE (long_double_type_node));
143
  gcc_assert (ldfmt->b != 10);
144
 
145
  /* The radix of the exponent representation.  */
146
  if (type == float_type_node)
147
    builtin_define_with_int_value ("__FLT_RADIX__", fmt->b);
148
  log10_b = log10_2;
149
 
150
  /* The number of radix digits, p, in the floating-point significand.  */
151
  sprintf (name, "__%s_MANT_DIG__", name_prefix);
152
  builtin_define_with_int_value (name, fmt->p);
153
 
154
  /* The number of decimal digits, q, such that any floating-point number
155
     with q decimal digits can be rounded into a floating-point number with
156
     p radix b digits and back again without change to the q decimal digits,
157
 
158
        p log10 b                       if b is a power of 10
159
        floor((p - 1) log10 b)          otherwise
160
  */
161
  dig = (fmt->p - 1) * log10_b;
162
  sprintf (name, "__%s_DIG__", name_prefix);
163
  builtin_define_with_int_value (name, dig);
164
 
165
  /* The minimum negative int x such that b**(x-1) is a normalized float.  */
166
  sprintf (name, "__%s_MIN_EXP__", name_prefix);
167
  sprintf (buf, "(%d)", fmt->emin);
168
  builtin_define_with_value (name, buf, 0);
169
 
170
  /* The minimum negative int x such that 10**x is a normalized float,
171
 
172
          ceil (log10 (b ** (emin - 1)))
173
        = ceil (log10 (b) * (emin - 1))
174
 
175
     Recall that emin is negative, so the integer truncation calculates
176
     the ceiling, not the floor, in this case.  */
177
  min_10_exp = (fmt->emin - 1) * log10_b;
178
  sprintf (name, "__%s_MIN_10_EXP__", name_prefix);
179
  sprintf (buf, "(%d)", min_10_exp);
180
  builtin_define_with_value (name, buf, 0);
181
 
182
  /* The maximum int x such that b**(x-1) is a representable float.  */
183
  sprintf (name, "__%s_MAX_EXP__", name_prefix);
184
  builtin_define_with_int_value (name, fmt->emax);
185
 
186
  /* The maximum int x such that 10**x is in the range of representable
187
     finite floating-point numbers,
188
 
189
          floor (log10((1 - b**-p) * b**emax))
190
        = floor (log10(1 - b**-p) + log10(b**emax))
191
        = floor (log10(1 - b**-p) + log10(b)*emax)
192
 
193
     The safest thing to do here is to just compute this number.  But since
194
     we don't link cc1 with libm, we cannot.  We could implement log10 here
195
     a series expansion, but that seems too much effort because:
196
 
197
     Note that the first term, for all extant p, is a number exceedingly close
198
     to zero, but slightly negative.  Note that the second term is an integer
199
     scaling an irrational number, and that because of the floor we are only
200
     interested in its integral portion.
201
 
202
     In order for the first term to have any effect on the integral portion
203
     of the second term, the second term has to be exceedingly close to an
204
     integer itself (e.g. 123.000000000001 or something).  Getting a result
205
     that close to an integer requires that the irrational multiplicand have
206
     a long series of zeros in its expansion, which doesn't occur in the
207
     first 20 digits or so of log10(b).
208
 
209
     Hand-waving aside, crunching all of the sets of constants above by hand
210
     does not yield a case for which the first term is significant, which
211
     in the end is all that matters.  */
212
  max_10_exp = fmt->emax * log10_b;
213
  sprintf (name, "__%s_MAX_10_EXP__", name_prefix);
214
  builtin_define_with_int_value (name, max_10_exp);
215
 
216
  /* The number of decimal digits, n, such that any floating-point number
217
     can be rounded to n decimal digits and back again without change to
218
     the value.
219
 
220
        p * log10(b)                    if b is a power of 10
221
        ceil(1 + p * log10(b))          otherwise
222
 
223
     The only macro we care about is this number for the widest supported
224
     floating type, but we want this value for rendering constants below.  */
225
  {
226
    double d_decimal_dig
227
      = 1 + (fmt->p < ldfmt->p ? ldfmt->p : fmt->p) * log10_b;
228
    decimal_dig = d_decimal_dig;
229
    if (decimal_dig < d_decimal_dig)
230
      decimal_dig++;
231
  }
232
  /* Similar, for this type rather than long double.  */
233
  {
234
    double type_d_decimal_dig = 1 + fmt->p * log10_b;
235
    type_decimal_dig = type_d_decimal_dig;
236
    if (type_decimal_dig < type_d_decimal_dig)
237
      type_decimal_dig++;
238
  }
239
  if (type == long_double_type_node)
240
    builtin_define_with_int_value ("__DECIMAL_DIG__", decimal_dig);
241
  else
242
    {
243
      sprintf (name, "__%s_DECIMAL_DIG__", name_prefix);
244
      builtin_define_with_int_value (name, type_decimal_dig);
245
    }
246
 
247
  /* Since, for the supported formats, B is always a power of 2, we
248
     construct the following numbers directly as a hexadecimal
249
     constants.  */
250
  get_max_float (fmt, buf, sizeof (buf));
251
 
252
  sprintf (name, "__%s_MAX__", name_prefix);
253
  builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
254
 
255
  /* The minimum normalized positive floating-point number,
256
     b**(emin-1).  */
257
  sprintf (name, "__%s_MIN__", name_prefix);
258
  sprintf (buf, "0x1p%d", fmt->emin - 1);
259
  builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
260
 
261
  /* The difference between 1 and the least value greater than 1 that is
262
     representable in the given floating point type, b**(1-p).  */
263
  sprintf (name, "__%s_EPSILON__", name_prefix);
264
  if (fmt->pnan < fmt->p)
265
    /* This is an IBM extended double format, so 1.0 + any double is
266
       representable precisely.  */
267
      sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
268
    else
269
      sprintf (buf, "0x1p%d", 1 - fmt->p);
270
  builtin_define_with_hex_fp_value (name, type, decimal_dig, buf, fp_suffix, fp_cast);
271
 
272
  /* For C++ std::numeric_limits<T>::denorm_min.  The minimum denormalized
273
     positive floating-point number, b**(emin-p).  Zero for formats that
274
     don't support denormals.  */
275
  sprintf (name, "__%s_DENORM_MIN__", name_prefix);
276
  if (fmt->has_denorm)
277
    {
278
      sprintf (buf, "0x1p%d", fmt->emin - fmt->p);
279
      builtin_define_with_hex_fp_value (name, type, decimal_dig,
280
                                        buf, fp_suffix, fp_cast);
281
    }
282
  else
283
    {
284
      sprintf (buf, "0.0%s", fp_suffix);
285
      builtin_define_with_value (name, buf, 0);
286
    }
287
 
288
  sprintf (name, "__%s_HAS_DENORM__", name_prefix);
289
  builtin_define_with_value (name, fmt->has_denorm ? "1" : "0", 0);
290
 
291
  /* For C++ std::numeric_limits<T>::has_infinity.  */
292
  sprintf (name, "__%s_HAS_INFINITY__", name_prefix);
293
  builtin_define_with_int_value (name,
294
                                 MODE_HAS_INFINITIES (TYPE_MODE (type)));
295
  /* For C++ std::numeric_limits<T>::has_quiet_NaN.  We do not have a
296
     predicate to distinguish a target that has both quiet and
297
     signalling NaNs from a target that has only quiet NaNs or only
298
     signalling NaNs, so we assume that a target that has any kind of
299
     NaN has quiet NaNs.  */
300
  sprintf (name, "__%s_HAS_QUIET_NAN__", name_prefix);
301
  builtin_define_with_int_value (name, MODE_HAS_NANS (TYPE_MODE (type)));
302
 
303
  /* Note whether we have fast FMA.  */
304
  if (mode_has_fma (TYPE_MODE (type)))
305
    {
306
      sprintf (name, "__FP_FAST_FMA%s", fma_suffix);
307
      builtin_define_with_int_value (name, 1);
308
    }
309
}
310
 
311
/* Define __DECx__ constants for TYPE using NAME_PREFIX and SUFFIX. */
312
static void
313
builtin_define_decimal_float_constants (const char *name_prefix,
314
                                        const char *suffix,
315
                                        tree type)
316
{
317
  const struct real_format *fmt;
318
  char name[64], buf[128], *p;
319
  int digits;
320
 
321
  fmt = REAL_MODE_FORMAT (TYPE_MODE (type));
322
 
323
  /* The number of radix digits, p, in the significand.  */
324
  sprintf (name, "__%s_MANT_DIG__", name_prefix);
325
  builtin_define_with_int_value (name, fmt->p);
326
 
327
  /* The minimum negative int x such that b**(x-1) is a normalized float.  */
328
  sprintf (name, "__%s_MIN_EXP__", name_prefix);
329
  sprintf (buf, "(%d)", fmt->emin);
330
  builtin_define_with_value (name, buf, 0);
331
 
332
  /* The maximum int x such that b**(x-1) is a representable float.  */
333
  sprintf (name, "__%s_MAX_EXP__", name_prefix);
334
  builtin_define_with_int_value (name, fmt->emax);
335
 
336
  /* Compute the minimum representable value.  */
337
  sprintf (name, "__%s_MIN__", name_prefix);
338
  sprintf (buf, "1E%d%s", fmt->emin - 1, suffix);
339
  builtin_define_with_value (name, buf, 0);
340
 
341
  /* Compute the maximum representable value.  */
342
  sprintf (name, "__%s_MAX__", name_prefix);
343
  p = buf;
344
  for (digits = fmt->p; digits; digits--)
345
    {
346
      *p++ = '9';
347
      if (digits == fmt->p)
348
        *p++ = '.';
349
    }
350
  *p = 0;
351
  /* fmt->p plus 1, to account for the decimal point and fmt->emax
352
     minus 1 because the digits are nines, not 1.0.  */
353
  sprintf (&buf[fmt->p + 1], "E%d%s", fmt->emax - 1, suffix);
354
  builtin_define_with_value (name, buf, 0);
355
 
356
  /* Compute epsilon (the difference between 1 and least value greater
357
     than 1 representable).  */
358
  sprintf (name, "__%s_EPSILON__", name_prefix);
359
  sprintf (buf, "1E-%d%s", fmt->p - 1, suffix);
360
  builtin_define_with_value (name, buf, 0);
361
 
362
  /* Minimum subnormal positive decimal value.  */
363
  sprintf (name, "__%s_SUBNORMAL_MIN__", name_prefix);
364
  p = buf;
365
  for (digits = fmt->p; digits > 1; digits--)
366
    {
367
      *p++ = '0';
368
      if (digits == fmt->p)
369
        *p++ = '.';
370
    }
371
  *p = 0;
372
  sprintf (&buf[fmt->p], "1E%d%s", fmt->emin - 1, suffix);
373
  builtin_define_with_value (name, buf, 0);
374
}
375
 
376
/* Define fixed-point constants for TYPE using NAME_PREFIX and SUFFIX.  */
377
 
378
static void
379
builtin_define_fixed_point_constants (const char *name_prefix,
380
                                      const char *suffix,
381
                                      tree type)
382
{
383
  char name[64], buf[256], *new_buf;
384
  int i, mod;
385
 
386
  sprintf (name, "__%s_FBIT__", name_prefix);
387
  builtin_define_with_int_value (name, TYPE_FBIT (type));
388
 
389
  sprintf (name, "__%s_IBIT__", name_prefix);
390
  builtin_define_with_int_value (name, TYPE_IBIT (type));
391
 
392
  /* If there is no suffix, defines are for fixed-point modes.
393
     We just return.  */
394
  if (strcmp (suffix, "") == 0)
395
    return;
396
 
397
  if (TYPE_UNSIGNED (type))
398
    {
399
      sprintf (name, "__%s_MIN__", name_prefix);
400
      sprintf (buf, "0.0%s", suffix);
401
      builtin_define_with_value (name, buf, 0);
402
    }
403
  else
404
    {
405
      sprintf (name, "__%s_MIN__", name_prefix);
406
      if (ALL_ACCUM_MODE_P (TYPE_MODE (type)))
407
        sprintf (buf, "(-0X1P%d%s-0X1P%d%s)", TYPE_IBIT (type) - 1, suffix,
408
                 TYPE_IBIT (type) - 1, suffix);
409
      else
410
        sprintf (buf, "(-0.5%s-0.5%s)", suffix, suffix);
411
      builtin_define_with_value (name, buf, 0);
412
    }
413
 
414
  sprintf (name, "__%s_MAX__", name_prefix);
415
  sprintf (buf, "0X");
416
  new_buf = buf + 2;
417
  mod = (TYPE_FBIT (type) + TYPE_IBIT (type)) % 4;
418
  if (mod)
419
    sprintf (new_buf++, "%x", (1 << mod) - 1);
420
  for (i = 0; i < (TYPE_FBIT (type) + TYPE_IBIT (type)) / 4; i++)
421
    sprintf (new_buf++, "F");
422
  sprintf (new_buf, "P-%d%s", TYPE_FBIT (type), suffix);
423
  builtin_define_with_value (name, buf, 0);
424
 
425
  sprintf (name, "__%s_EPSILON__", name_prefix);
426
  sprintf (buf, "0x1P-%d%s", TYPE_FBIT (type), suffix);
427
  builtin_define_with_value (name, buf, 0);
428
}
429
 
430
/* Define macros used by <stdint.h>.  */
431
static void
432
builtin_define_stdint_macros (void)
433
{
434
  builtin_define_type_max ("__INTMAX_MAX__", intmax_type_node);
435
  builtin_define_constants ("__INTMAX_C", intmax_type_node);
436
  builtin_define_type_max ("__UINTMAX_MAX__", uintmax_type_node);
437
  builtin_define_constants ("__UINTMAX_C", uintmax_type_node);
438
  if (sig_atomic_type_node)
439
    builtin_define_type_minmax ("__SIG_ATOMIC_MIN__", "__SIG_ATOMIC_MAX__",
440
                                sig_atomic_type_node);
441
  if (int8_type_node)
442
    builtin_define_type_max ("__INT8_MAX__", int8_type_node);
443
  if (int16_type_node)
444
    builtin_define_type_max ("__INT16_MAX__", int16_type_node);
445
  if (int32_type_node)
446
    builtin_define_type_max ("__INT32_MAX__", int32_type_node);
447
  if (int64_type_node)
448
    builtin_define_type_max ("__INT64_MAX__", int64_type_node);
449
  if (uint8_type_node)
450
    builtin_define_type_max ("__UINT8_MAX__", uint8_type_node);
451
  if (uint16_type_node)
452
    builtin_define_type_max ("__UINT16_MAX__", uint16_type_node);
453
  if (c_uint32_type_node)
454
    builtin_define_type_max ("__UINT32_MAX__", c_uint32_type_node);
455
  if (c_uint64_type_node)
456
    builtin_define_type_max ("__UINT64_MAX__", c_uint64_type_node);
457
  if (int_least8_type_node)
458
    {
459
      builtin_define_type_max ("__INT_LEAST8_MAX__", int_least8_type_node);
460
      builtin_define_constants ("__INT8_C", int_least8_type_node);
461
    }
462
  if (int_least16_type_node)
463
    {
464
      builtin_define_type_max ("__INT_LEAST16_MAX__", int_least16_type_node);
465
      builtin_define_constants ("__INT16_C", int_least16_type_node);
466
    }
467
  if (int_least32_type_node)
468
    {
469
      builtin_define_type_max ("__INT_LEAST32_MAX__", int_least32_type_node);
470
      builtin_define_constants ("__INT32_C", int_least32_type_node);
471
    }
472
  if (int_least64_type_node)
473
    {
474
      builtin_define_type_max ("__INT_LEAST64_MAX__", int_least64_type_node);
475
      builtin_define_constants ("__INT64_C", int_least64_type_node);
476
    }
477
  if (uint_least8_type_node)
478
    {
479
      builtin_define_type_max ("__UINT_LEAST8_MAX__", uint_least8_type_node);
480
      builtin_define_constants ("__UINT8_C", uint_least8_type_node);
481
    }
482
  if (uint_least16_type_node)
483
    {
484
      builtin_define_type_max ("__UINT_LEAST16_MAX__", uint_least16_type_node);
485
      builtin_define_constants ("__UINT16_C", uint_least16_type_node);
486
    }
487
  if (uint_least32_type_node)
488
    {
489
      builtin_define_type_max ("__UINT_LEAST32_MAX__", uint_least32_type_node);
490
      builtin_define_constants ("__UINT32_C", uint_least32_type_node);
491
    }
492
  if (uint_least64_type_node)
493
    {
494
      builtin_define_type_max ("__UINT_LEAST64_MAX__", uint_least64_type_node);
495
      builtin_define_constants ("__UINT64_C", uint_least64_type_node);
496
    }
497
  if (int_fast8_type_node)
498
    builtin_define_type_max ("__INT_FAST8_MAX__", int_fast8_type_node);
499
  if (int_fast16_type_node)
500
    builtin_define_type_max ("__INT_FAST16_MAX__", int_fast16_type_node);
501
  if (int_fast32_type_node)
502
    builtin_define_type_max ("__INT_FAST32_MAX__", int_fast32_type_node);
503
  if (int_fast64_type_node)
504
    builtin_define_type_max ("__INT_FAST64_MAX__", int_fast64_type_node);
505
  if (uint_fast8_type_node)
506
    builtin_define_type_max ("__UINT_FAST8_MAX__", uint_fast8_type_node);
507
  if (uint_fast16_type_node)
508
    builtin_define_type_max ("__UINT_FAST16_MAX__", uint_fast16_type_node);
509
  if (uint_fast32_type_node)
510
    builtin_define_type_max ("__UINT_FAST32_MAX__", uint_fast32_type_node);
511
  if (uint_fast64_type_node)
512
    builtin_define_type_max ("__UINT_FAST64_MAX__", uint_fast64_type_node);
513
  if (intptr_type_node)
514
    builtin_define_type_max ("__INTPTR_MAX__", intptr_type_node);
515
  if (uintptr_type_node)
516
    builtin_define_type_max ("__UINTPTR_MAX__", uintptr_type_node);
517
}
518
 
519
/* Adjust the optimization macros when a #pragma GCC optimization is done to
520
   reflect the current level.  */
521
void
522
c_cpp_builtins_optimize_pragma (cpp_reader *pfile, tree prev_tree,
523
                                tree cur_tree)
524
{
525
  struct cl_optimization *prev = TREE_OPTIMIZATION (prev_tree);
526
  struct cl_optimization *cur  = TREE_OPTIMIZATION (cur_tree);
527
  bool prev_fast_math;
528
  bool cur_fast_math;
529
 
530
  /* -undef turns off target-specific built-ins.  */
531
  if (flag_undef)
532
    return;
533
 
534
  /* Other target-independent built-ins determined by command-line
535
     options.  */
536
  if (!prev->x_optimize_size && cur->x_optimize_size)
537
    cpp_define (pfile, "__OPTIMIZE_SIZE__");
538
  else if (prev->x_optimize_size && !cur->x_optimize_size)
539
    cpp_undef (pfile, "__OPTIMIZE_SIZE__");
540
 
541
  if (!prev->x_optimize && cur->x_optimize)
542
    cpp_define (pfile, "__OPTIMIZE__");
543
  else if (prev->x_optimize && !cur->x_optimize)
544
    cpp_undef (pfile, "__OPTIMIZE__");
545
 
546
  prev_fast_math = fast_math_flags_struct_set_p (prev);
547
  cur_fast_math  = fast_math_flags_struct_set_p (cur);
548
  if (!prev_fast_math && cur_fast_math)
549
    cpp_define (pfile, "__FAST_MATH__");
550
  else if (prev_fast_math && !cur_fast_math)
551
    cpp_undef (pfile, "__FAST_MATH__");
552
 
553
  if (!prev->x_flag_signaling_nans && cur->x_flag_signaling_nans)
554
    cpp_define (pfile, "__SUPPORT_SNAN__");
555
  else if (prev->x_flag_signaling_nans && !cur->x_flag_signaling_nans)
556
    cpp_undef (pfile, "__SUPPORT_SNAN__");
557
 
558
  if (!prev->x_flag_finite_math_only && cur->x_flag_finite_math_only)
559
    {
560
      cpp_undef (pfile, "__FINITE_MATH_ONLY__");
561
      cpp_define (pfile, "__FINITE_MATH_ONLY__=1");
562
    }
563
  else if (prev->x_flag_finite_math_only && !cur->x_flag_finite_math_only)
564
    {
565
      cpp_undef (pfile, "__FINITE_MATH_ONLY__");
566
      cpp_define (pfile, "__FINITE_MATH_ONLY__=0");
567
    }
568
}
569
 
570
 
571
/* This function will emit cpp macros to indicate the presence of various lock
572
   free atomic operations.  */
573
 
574
static void
575
cpp_atomic_builtins (cpp_reader *pfile)
576
{
577
  /* Set a flag for each size of object that compare and swap exists for up to
578
     a 16 byte object.  */
579
#define SWAP_LIMIT  17
580
  bool have_swap[SWAP_LIMIT];
581
  unsigned int psize;
582
 
583
  /* Clear the map of sizes compare_and swap exists for.  */
584
  memset (have_swap, 0, sizeof (have_swap));
585
 
586
  /* Tell source code if the compiler makes sync_compare_and_swap
587
     builtins available.  */
588
#ifndef HAVE_sync_compare_and_swapqi
589
#define HAVE_sync_compare_and_swapqi 0
590
#endif
591
#ifndef HAVE_atomic_compare_and_swapqi
592
#define HAVE_atomic_compare_and_swapqi 0
593
#endif
594
 
595
  if (HAVE_sync_compare_and_swapqi || HAVE_atomic_compare_and_swapqi)
596
    {
597
      cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1");
598
      have_swap[1] = true;
599
    }
600
 
601
#ifndef HAVE_sync_compare_and_swaphi
602
#define HAVE_sync_compare_and_swaphi 0
603
#endif
604
#ifndef HAVE_atomic_compare_and_swaphi
605
#define HAVE_atomic_compare_and_swaphi 0
606
#endif
607
  if (HAVE_sync_compare_and_swaphi || HAVE_atomic_compare_and_swaphi)
608
    {
609
      cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2");
610
      have_swap[2] = true;
611
    }
612
 
613
#ifndef HAVE_sync_compare_and_swapsi
614
#define HAVE_sync_compare_and_swapsi 0
615
#endif
616
#ifndef HAVE_atomic_compare_and_swapsi
617
#define HAVE_atomic_compare_and_swapsi 0
618
#endif
619
  if (HAVE_sync_compare_and_swapsi || HAVE_atomic_compare_and_swapsi)
620
    {
621
      cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4");
622
      have_swap[4] = true;
623
    }
624
 
625
#ifndef HAVE_sync_compare_and_swapdi
626
#define HAVE_sync_compare_and_swapdi 0
627
#endif
628
#ifndef HAVE_atomic_compare_and_swapdi
629
#define HAVE_atomic_compare_and_swapdi 0
630
#endif
631
  if (HAVE_sync_compare_and_swapdi || HAVE_atomic_compare_and_swapdi)
632
    {
633
      cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8");
634
      have_swap[8] = true;
635
    }
636
 
637
#ifndef HAVE_sync_compare_and_swapti
638
#define HAVE_sync_compare_and_swapti 0
639
#endif
640
#ifndef HAVE_atomic_compare_and_swapti
641
#define HAVE_atomic_compare_and_swapti 0
642
#endif
643
  if (HAVE_sync_compare_and_swapti || HAVE_atomic_compare_and_swapti)
644
    {
645
      cpp_define (pfile, "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_16");
646
      have_swap[16] = true;
647
    }
648
 
649
  /* Tell the source code about various types.  These map to the C++11 and C11
650
     macros where 2 indicates lock-free always, and 1 indicates sometimes
651
     lock free.  */
652
#define SIZEOF_NODE(T) (tree_low_cst (TYPE_SIZE_UNIT (T), 1))
653
#define SWAP_INDEX(T) ((SIZEOF_NODE (T) < SWAP_LIMIT) ? SIZEOF_NODE (T) : 0)
654
  builtin_define_with_int_value ("__GCC_ATOMIC_BOOL_LOCK_FREE",
655
                        (have_swap[SWAP_INDEX (boolean_type_node)]? 2 : 1));
656
  builtin_define_with_int_value ("__GCC_ATOMIC_CHAR_LOCK_FREE",
657
                        (have_swap[SWAP_INDEX (signed_char_type_node)]? 2 : 1));
658
  builtin_define_with_int_value ("__GCC_ATOMIC_CHAR16_T_LOCK_FREE",
659
                        (have_swap[SWAP_INDEX (char16_type_node)]? 2 : 1));
660
  builtin_define_with_int_value ("__GCC_ATOMIC_CHAR32_T_LOCK_FREE",
661
                        (have_swap[SWAP_INDEX (char32_type_node)]? 2 : 1));
662
  builtin_define_with_int_value ("__GCC_ATOMIC_WCHAR_T_LOCK_FREE",
663
                        (have_swap[SWAP_INDEX (wchar_type_node)]? 2 : 1));
664
  builtin_define_with_int_value ("__GCC_ATOMIC_SHORT_LOCK_FREE",
665
                      (have_swap[SWAP_INDEX (short_integer_type_node)]? 2 : 1));
666
  builtin_define_with_int_value ("__GCC_ATOMIC_INT_LOCK_FREE",
667
                        (have_swap[SWAP_INDEX (integer_type_node)]? 2 : 1));
668
  builtin_define_with_int_value ("__GCC_ATOMIC_LONG_LOCK_FREE",
669
                      (have_swap[SWAP_INDEX (long_integer_type_node)]? 2 : 1));
670
  builtin_define_with_int_value ("__GCC_ATOMIC_LLONG_LOCK_FREE",
671
                (have_swap[SWAP_INDEX (long_long_integer_type_node)]? 2 : 1));
672
 
673
  /* If we're dealing with a "set" value that doesn't exactly correspond
674
     to a boolean truth value, let the library work around that.  */
675
  builtin_define_with_int_value ("__GCC_ATOMIC_TEST_AND_SET_TRUEVAL",
676
                                 targetm.atomic_test_and_set_trueval);
677
 
678
  /* ptr_type_node can't be used here since ptr_mode is only set when
679
     toplev calls backend_init which is not done with -E  or pch.  */
680
  psize = POINTER_SIZE / BITS_PER_UNIT;
681
  if (psize >= SWAP_LIMIT)
682
    psize = 0;
683
  builtin_define_with_int_value ("__GCC_ATOMIC_POINTER_LOCK_FREE",
684
                        (have_swap[psize]? 2 : 1));
685
}
686
 
687
/* Hook that registers front end and target-specific built-ins.  */
688
void
689
c_cpp_builtins (cpp_reader *pfile)
690
{
691
  /* -undef turns off target-specific built-ins.  */
692
  if (flag_undef)
693
    return;
694
 
695
  define_language_independent_builtin_macros (pfile);
696
 
697
  if (c_dialect_cxx ())
698
  {
699
    int major;
700
    parse_basever (&major, NULL, NULL);
701
    cpp_define_formatted (pfile, "__GNUG__=%d", major);
702
  }
703
 
704
  /* For stddef.h.  They require macros defined in c-common.c.  */
705
  c_stddef_cpp_builtins ();
706
 
707
  if (c_dialect_cxx ())
708
    {
709
      if (flag_weak && SUPPORTS_ONE_ONLY)
710
        cpp_define (pfile, "__GXX_WEAK__=1");
711
      else
712
        cpp_define (pfile, "__GXX_WEAK__=0");
713
      if (warn_deprecated)
714
        cpp_define (pfile, "__DEPRECATED");
715
      if (flag_rtti)
716
        cpp_define (pfile, "__GXX_RTTI");
717
      if (cxx_dialect == cxx0x)
718
        cpp_define (pfile, "__GXX_EXPERIMENTAL_CXX0X__");
719
    }
720
  /* Note that we define this for C as well, so that we know if
721
     __attribute__((cleanup)) will interface with EH.  */
722
  if (flag_exceptions)
723
    cpp_define (pfile, "__EXCEPTIONS");
724
 
725
  /* Represents the C++ ABI version, always defined so it can be used while
726
     preprocessing C and assembler.  */
727
  if (flag_abi_version == 0)
728
    /* Use a very large value so that:
729
 
730
         #if __GXX_ABI_VERSION >= <value for version X>
731
 
732
       will work whether the user explicitly says "-fabi-version=x" or
733
       "-fabi-version=0".  Do not use INT_MAX because that will be
734
       different from system to system.  */
735
    builtin_define_with_int_value ("__GXX_ABI_VERSION", 999999);
736
  else if (flag_abi_version == 1)
737
    /* Due to a historical accident, this version had the value
738
       "102".  */
739
    builtin_define_with_int_value ("__GXX_ABI_VERSION", 102);
740
  else
741
    /* Newer versions have values 1002, 1003, ....  */
742
    builtin_define_with_int_value ("__GXX_ABI_VERSION",
743
                                   1000 + flag_abi_version);
744
 
745
  /* libgcc needs to know this.  */
746
  if (targetm_common.except_unwind_info (&global_options) == UI_SJLJ)
747
    cpp_define (pfile, "__USING_SJLJ_EXCEPTIONS__");
748
 
749
  /* limits.h and stdint.h need to know these.  */
750
  builtin_define_type_max ("__SCHAR_MAX__", signed_char_type_node);
751
  builtin_define_type_max ("__SHRT_MAX__", short_integer_type_node);
752
  builtin_define_type_max ("__INT_MAX__", integer_type_node);
753
  builtin_define_type_max ("__LONG_MAX__", long_integer_type_node);
754
  builtin_define_type_max ("__LONG_LONG_MAX__", long_long_integer_type_node);
755
  builtin_define_type_minmax ("__WCHAR_MIN__", "__WCHAR_MAX__",
756
                              underlying_wchar_type_node);
757
  builtin_define_type_minmax ("__WINT_MIN__", "__WINT_MAX__", wint_type_node);
758
  builtin_define_type_max ("__PTRDIFF_MAX__", ptrdiff_type_node);
759
  builtin_define_type_max ("__SIZE_MAX__", size_type_node);
760
 
761
  /* stdint.h and the testsuite need to know these.  */
762
  builtin_define_stdint_macros ();
763
 
764
  /* float.h needs to know this.  */
765
  builtin_define_with_int_value ("__FLT_EVAL_METHOD__",
766
                                 TARGET_FLT_EVAL_METHOD);
767
 
768
  /* And decfloat.h needs this.  */
769
  builtin_define_with_int_value ("__DEC_EVAL_METHOD__",
770
                                 TARGET_DEC_EVAL_METHOD);
771
 
772
  builtin_define_float_constants ("FLT", "F", "%s", "F", float_type_node);
773
  /* Cast the double precision constants.  This is needed when single
774
     precision constants are specified or when pragma FLOAT_CONST_DECIMAL64
775
     is used.  The correct result is computed by the compiler when using
776
     macros that include a cast.  We use a different cast for C++ to avoid
777
     problems with -Wold-style-cast.  */
778
  builtin_define_float_constants ("DBL", "L",
779
                                  (c_dialect_cxx ()
780
                                   ? "double(%s)"
781
                                   : "((double)%s)"),
782
                                  "", double_type_node);
783
  builtin_define_float_constants ("LDBL", "L", "%s", "L",
784
                                  long_double_type_node);
785
 
786
  /* For decfloat.h.  */
787
  builtin_define_decimal_float_constants ("DEC32", "DF", dfloat32_type_node);
788
  builtin_define_decimal_float_constants ("DEC64", "DD", dfloat64_type_node);
789
  builtin_define_decimal_float_constants ("DEC128", "DL", dfloat128_type_node);
790
 
791
  /* For fixed-point fibt, ibit, max, min, and epsilon.  */
792
  if (targetm.fixed_point_supported_p ())
793
    {
794
      builtin_define_fixed_point_constants ("SFRACT", "HR",
795
                                            short_fract_type_node);
796
      builtin_define_fixed_point_constants ("USFRACT", "UHR",
797
                                            unsigned_short_fract_type_node);
798
      builtin_define_fixed_point_constants ("FRACT", "R",
799
                                            fract_type_node);
800
      builtin_define_fixed_point_constants ("UFRACT", "UR",
801
                                            unsigned_fract_type_node);
802
      builtin_define_fixed_point_constants ("LFRACT", "LR",
803
                                            long_fract_type_node);
804
      builtin_define_fixed_point_constants ("ULFRACT", "ULR",
805
                                            unsigned_long_fract_type_node);
806
      builtin_define_fixed_point_constants ("LLFRACT", "LLR",
807
                                            long_long_fract_type_node);
808
      builtin_define_fixed_point_constants ("ULLFRACT", "ULLR",
809
                                            unsigned_long_long_fract_type_node);
810
      builtin_define_fixed_point_constants ("SACCUM", "HK",
811
                                            short_accum_type_node);
812
      builtin_define_fixed_point_constants ("USACCUM", "UHK",
813
                                            unsigned_short_accum_type_node);
814
      builtin_define_fixed_point_constants ("ACCUM", "K",
815
                                            accum_type_node);
816
      builtin_define_fixed_point_constants ("UACCUM", "UK",
817
                                            unsigned_accum_type_node);
818
      builtin_define_fixed_point_constants ("LACCUM", "LK",
819
                                            long_accum_type_node);
820
      builtin_define_fixed_point_constants ("ULACCUM", "ULK",
821
                                            unsigned_long_accum_type_node);
822
      builtin_define_fixed_point_constants ("LLACCUM", "LLK",
823
                                            long_long_accum_type_node);
824
      builtin_define_fixed_point_constants ("ULLACCUM", "ULLK",
825
                                            unsigned_long_long_accum_type_node);
826
 
827
      builtin_define_fixed_point_constants ("QQ", "", qq_type_node);
828
      builtin_define_fixed_point_constants ("HQ", "", hq_type_node);
829
      builtin_define_fixed_point_constants ("SQ", "", sq_type_node);
830
      builtin_define_fixed_point_constants ("DQ", "", dq_type_node);
831
      builtin_define_fixed_point_constants ("TQ", "", tq_type_node);
832
      builtin_define_fixed_point_constants ("UQQ", "", uqq_type_node);
833
      builtin_define_fixed_point_constants ("UHQ", "", uhq_type_node);
834
      builtin_define_fixed_point_constants ("USQ", "", usq_type_node);
835
      builtin_define_fixed_point_constants ("UDQ", "", udq_type_node);
836
      builtin_define_fixed_point_constants ("UTQ", "", utq_type_node);
837
      builtin_define_fixed_point_constants ("HA", "", ha_type_node);
838
      builtin_define_fixed_point_constants ("SA", "", sa_type_node);
839
      builtin_define_fixed_point_constants ("DA", "", da_type_node);
840
      builtin_define_fixed_point_constants ("TA", "", ta_type_node);
841
      builtin_define_fixed_point_constants ("UHA", "", uha_type_node);
842
      builtin_define_fixed_point_constants ("USA", "", usa_type_node);
843
      builtin_define_fixed_point_constants ("UDA", "", uda_type_node);
844
      builtin_define_fixed_point_constants ("UTA", "", uta_type_node);
845
    }
846
 
847
  /* For libgcc-internal use only.  */
848
  if (flag_building_libgcc)
849
    /* For libgcc enable-execute-stack.c.  */
850
    builtin_define_with_int_value ("__LIBGCC_TRAMPOLINE_SIZE__",
851
                                   TRAMPOLINE_SIZE);
852
 
853
  /* For use in assembly language.  */
854
  builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
855
  builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
856
 
857
  /* Misc.  */
858
  if (flag_gnu89_inline)
859
    cpp_define (pfile, "__GNUC_GNU_INLINE__");
860
  else
861
    cpp_define (pfile, "__GNUC_STDC_INLINE__");
862
 
863
  if (flag_no_inline)
864
    cpp_define (pfile, "__NO_INLINE__");
865
 
866
  if (flag_iso)
867
    cpp_define (pfile, "__STRICT_ANSI__");
868
 
869
  if (!flag_signed_char)
870
    cpp_define (pfile, "__CHAR_UNSIGNED__");
871
 
872
  if (c_dialect_cxx () && TYPE_UNSIGNED (wchar_type_node))
873
    cpp_define (pfile, "__WCHAR_UNSIGNED__");
874
 
875
  cpp_atomic_builtins (pfile);
876
 
877
#ifdef DWARF2_UNWIND_INFO
878
  if (dwarf2out_do_cfi_asm ())
879
    cpp_define (pfile, "__GCC_HAVE_DWARF2_CFI_ASM");
880
#endif
881
 
882
  /* Make the choice of ObjC runtime visible to source code.  */
883
  if (c_dialect_objc () && flag_next_runtime)
884
    cpp_define (pfile, "__NEXT_RUNTIME__");
885
 
886
  /* Show the availability of some target pragmas.  */
887
  cpp_define (pfile, "__PRAGMA_REDEFINE_EXTNAME");
888
 
889
  if (targetm.handle_pragma_extern_prefix)
890
    cpp_define (pfile, "__PRAGMA_EXTERN_PREFIX");
891
 
892
  /* Make the choice of the stack protector runtime visible to source code.
893
     The macro names and values here were chosen for compatibility with an
894
     earlier implementation, i.e. ProPolice.  */
895
  if (flag_stack_protect == 2)
896
    cpp_define (pfile, "__SSP_ALL__=2");
897
  else if (flag_stack_protect == 1)
898
    cpp_define (pfile, "__SSP__=1");
899
 
900
  if (flag_openmp)
901
    cpp_define (pfile, "_OPENMP=201107");
902
 
903
  if (int128_integer_type_node != NULL_TREE)
904
    builtin_define_type_sizeof ("__SIZEOF_INT128__",
905
                                int128_integer_type_node);
906
  builtin_define_type_sizeof ("__SIZEOF_WCHAR_T__", wchar_type_node);
907
  builtin_define_type_sizeof ("__SIZEOF_WINT_T__", wint_type_node);
908
  builtin_define_type_sizeof ("__SIZEOF_PTRDIFF_T__",
909
                              unsigned_ptrdiff_type_node);
910
 
911
  /* A straightforward target hook doesn't work, because of problems
912
     linking that hook's body when part of non-C front ends.  */
913
# define preprocessing_asm_p() (cpp_get_options (pfile)->lang == CLK_ASM)
914
# define preprocessing_trad_p() (cpp_get_options (pfile)->traditional)
915
# define builtin_define(TXT) cpp_define (pfile, TXT)
916
# define builtin_assert(TXT) cpp_assert (pfile, TXT)
917
  TARGET_CPU_CPP_BUILTINS ();
918
  TARGET_OS_CPP_BUILTINS ();
919
  TARGET_OBJFMT_CPP_BUILTINS ();
920
 
921
  /* Support the __declspec keyword by turning them into attributes.
922
     Note that the current way we do this may result in a collision
923
     with predefined attributes later on.  This can be solved by using
924
     one attribute, say __declspec__, and passing args to it.  The
925
     problem with that approach is that args are not accumulated: each
926
     new appearance would clobber any existing args.  */
927
  if (TARGET_DECLSPEC)
928
    builtin_define ("__declspec(x)=__attribute__((x))");
929
 
930
  /* If decimal floating point is supported, tell the user if the
931
     alternate format (BID) is used instead of the standard (DPD)
932
     format.  */
933
  if (ENABLE_DECIMAL_FLOAT && ENABLE_DECIMAL_BID_FORMAT)
934
    cpp_define (pfile, "__DECIMAL_BID_FORMAT__");
935
}
936
 
937
/* Pass an object-like macro.  If it doesn't lie in the user's
938
   namespace, defines it unconditionally.  Otherwise define a version
939
   with two leading underscores, and another version with two leading
940
   and trailing underscores, and define the original only if an ISO
941
   standard was not nominated.
942
 
943
   e.g. passing "unix" defines "__unix", "__unix__" and possibly
944
   "unix".  Passing "_mips" defines "__mips", "__mips__" and possibly
945
   "_mips".  */
946
void
947
builtin_define_std (const char *macro)
948
{
949
  size_t len = strlen (macro);
950
  char *buff = (char *) alloca (len + 5);
951
  char *p = buff + 2;
952
  char *q = p + len;
953
 
954
  /* prepend __ (or maybe just _) if in user's namespace.  */
955
  memcpy (p, macro, len + 1);
956
  if (!( *p == '_' && (p[1] == '_' || ISUPPER (p[1]))))
957
    {
958
      if (*p != '_')
959
        *--p = '_';
960
      if (p[1] != '_')
961
        *--p = '_';
962
    }
963
  cpp_define (parse_in, p);
964
 
965
  /* If it was in user's namespace...  */
966
  if (p != buff + 2)
967
    {
968
      /* Define the macro with leading and following __.  */
969
      if (q[-1] != '_')
970
        *q++ = '_';
971
      if (q[-2] != '_')
972
        *q++ = '_';
973
      *q = '\0';
974
      cpp_define (parse_in, p);
975
 
976
      /* Finally, define the original macro if permitted.  */
977
      if (!flag_iso)
978
        cpp_define (parse_in, macro);
979
    }
980
}
981
 
982
/* Pass an object-like macro and a value to define it to.  The third
983
   parameter says whether or not to turn the value into a string
984
   constant.  */
985
void
986
builtin_define_with_value (const char *macro, const char *expansion, int is_str)
987
{
988
  char *buf;
989
  size_t mlen = strlen (macro);
990
  size_t elen = strlen (expansion);
991
  size_t extra = 2;  /* space for an = and a NUL */
992
 
993
  if (is_str)
994
    extra += 2;  /* space for two quote marks */
995
 
996
  buf = (char *) alloca (mlen + elen + extra);
997
  if (is_str)
998
    sprintf (buf, "%s=\"%s\"", macro, expansion);
999
  else
1000
    sprintf (buf, "%s=%s", macro, expansion);
1001
 
1002
  cpp_define (parse_in, buf);
1003
}
1004
 
1005
 
1006
/* Pass an object-like macro and an integer value to define it to.  */
1007
static void
1008
builtin_define_with_int_value (const char *macro, HOST_WIDE_INT value)
1009
{
1010
  char *buf;
1011
  size_t mlen = strlen (macro);
1012
  size_t vlen = 18;
1013
  size_t extra = 2; /* space for = and NUL.  */
1014
 
1015
  buf = (char *) alloca (mlen + vlen + extra);
1016
  memcpy (buf, macro, mlen);
1017
  buf[mlen] = '=';
1018
  sprintf (buf + mlen + 1, HOST_WIDE_INT_PRINT_DEC, value);
1019
 
1020
  cpp_define (parse_in, buf);
1021
}
1022
 
1023
/* builtin_define_with_hex_fp_value is very expensive, so the following
1024
   array and function allows it to be done lazily when __DBL_MAX__
1025
   etc. is first used.  */
1026
 
1027
struct GTY(()) lazy_hex_fp_value_struct
1028
{
1029
  const char *hex_str;
1030
  cpp_macro *macro;
1031
  enum machine_mode mode;
1032
  int digits;
1033
  const char *fp_suffix;
1034
};
1035
static GTY(()) struct lazy_hex_fp_value_struct lazy_hex_fp_values[12];
1036
static GTY(()) int lazy_hex_fp_value_count;
1037
 
1038
static bool
1039
lazy_hex_fp_value (cpp_reader *pfile ATTRIBUTE_UNUSED,
1040
                   cpp_hashnode *node)
1041
{
1042
  REAL_VALUE_TYPE real;
1043
  char dec_str[64], buf1[256];
1044
  unsigned int idx;
1045
  if (node->value.builtin < BT_FIRST_USER
1046
      || (int) node->value.builtin >= BT_FIRST_USER + lazy_hex_fp_value_count)
1047
    return false;
1048
 
1049
  idx = node->value.builtin - BT_FIRST_USER;
1050
  real_from_string (&real, lazy_hex_fp_values[idx].hex_str);
1051
  real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str),
1052
                            lazy_hex_fp_values[idx].digits, 0,
1053
                            lazy_hex_fp_values[idx].mode);
1054
 
1055
  sprintf (buf1, "%s%s", dec_str, lazy_hex_fp_values[idx].fp_suffix);
1056
  node->flags &= ~(NODE_BUILTIN | NODE_USED);
1057
  node->value.macro = lazy_hex_fp_values[idx].macro;
1058
  for (idx = 0; idx < node->value.macro->count; idx++)
1059
    if (node->value.macro->exp.tokens[idx].type == CPP_NUMBER)
1060
      break;
1061
  gcc_assert (idx < node->value.macro->count);
1062
  node->value.macro->exp.tokens[idx].val.str.len = strlen (buf1);
1063
  node->value.macro->exp.tokens[idx].val.str.text
1064
    = (const unsigned char *) ggc_strdup (buf1);
1065
  return true;
1066
}
1067
 
1068
/* Pass an object-like macro a hexadecimal floating-point value.  */
1069
static void
1070
builtin_define_with_hex_fp_value (const char *macro,
1071
                                  tree type, int digits,
1072
                                  const char *hex_str,
1073
                                  const char *fp_suffix,
1074
                                  const char *fp_cast)
1075
{
1076
  REAL_VALUE_TYPE real;
1077
  char dec_str[64], buf1[256], buf2[256];
1078
 
1079
  /* This is very expensive, so if possible expand them lazily.  */
1080
  if (lazy_hex_fp_value_count < 12
1081
      && flag_dump_macros == 0
1082
      && !cpp_get_options (parse_in)->traditional)
1083
    {
1084
      struct cpp_hashnode *node;
1085
      if (lazy_hex_fp_value_count == 0)
1086
        cpp_get_callbacks (parse_in)->user_builtin_macro = lazy_hex_fp_value;
1087
      sprintf (buf2, fp_cast, "1.1");
1088
      sprintf (buf1, "%s=%s", macro, buf2);
1089
      cpp_define (parse_in, buf1);
1090
      node = C_CPP_HASHNODE (get_identifier (macro));
1091
      lazy_hex_fp_values[lazy_hex_fp_value_count].hex_str
1092
        = ggc_strdup (hex_str);
1093
      lazy_hex_fp_values[lazy_hex_fp_value_count].mode = TYPE_MODE (type);
1094
      lazy_hex_fp_values[lazy_hex_fp_value_count].digits = digits;
1095
      lazy_hex_fp_values[lazy_hex_fp_value_count].fp_suffix = fp_suffix;
1096
      lazy_hex_fp_values[lazy_hex_fp_value_count].macro = node->value.macro;
1097
      node->flags |= NODE_BUILTIN;
1098
      node->value.builtin
1099
        = (enum cpp_builtin_type) (BT_FIRST_USER + lazy_hex_fp_value_count);
1100
      lazy_hex_fp_value_count++;
1101
      return;
1102
    }
1103
 
1104
  /* Hex values are really cool and convenient, except that they're
1105
     not supported in strict ISO C90 mode.  First, the "p-" sequence
1106
     is not valid as part of a preprocessor number.  Second, we get a
1107
     pedwarn from the preprocessor, which has no context, so we can't
1108
     suppress the warning with __extension__.
1109
 
1110
     So instead what we do is construct the number in hex (because
1111
     it's easy to get the exact correct value), parse it as a real,
1112
     then print it back out as decimal.  */
1113
 
1114
  real_from_string (&real, hex_str);
1115
  real_to_decimal_for_mode (dec_str, &real, sizeof (dec_str), digits, 0,
1116
                            TYPE_MODE (type));
1117
 
1118
  /* Assemble the macro in the following fashion
1119
     macro = fp_cast [dec_str fp_suffix] */
1120
  sprintf (buf1, "%s%s", dec_str, fp_suffix);
1121
  sprintf (buf2, fp_cast, buf1);
1122
  sprintf (buf1, "%s=%s", macro, buf2);
1123
 
1124
  cpp_define (parse_in, buf1);
1125
}
1126
 
1127
/* Return a string constant for the suffix for a value of type TYPE
1128
   promoted according to the integer promotions.  The type must be one
1129
   of the standard integer type nodes.  */
1130
 
1131
static const char *
1132
type_suffix (tree type)
1133
{
1134
  static const char *const suffixes[] = { "", "U", "L", "UL", "LL", "ULL" };
1135
  int unsigned_suffix;
1136
  int is_long;
1137
 
1138
  if (type == long_long_integer_type_node
1139
      || type == long_long_unsigned_type_node)
1140
    is_long = 2;
1141
  else if (type == long_integer_type_node
1142
           || type == long_unsigned_type_node)
1143
    is_long = 1;
1144
  else if (type == integer_type_node
1145
           || type == unsigned_type_node
1146
           || type == short_integer_type_node
1147
           || type == short_unsigned_type_node
1148
           || type == signed_char_type_node
1149
           || type == unsigned_char_type_node
1150
           /* ??? "char" is not a signed or unsigned integer type and
1151
              so is not permitted for the standard typedefs, but some
1152
              systems use it anyway.  */
1153
           || type == char_type_node)
1154
    is_long = 0;
1155
  else
1156
    gcc_unreachable ();
1157
 
1158
  unsigned_suffix = TYPE_UNSIGNED (type);
1159
  if (TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node))
1160
    unsigned_suffix = 0;
1161
  return suffixes[is_long * 2 + unsigned_suffix];
1162
}
1163
 
1164
/* Define MACRO as a <stdint.h> constant-suffix macro for TYPE.  */
1165
static void
1166
builtin_define_constants (const char *macro, tree type)
1167
{
1168
  const char *suffix;
1169
  char *buf;
1170
 
1171
  suffix = type_suffix (type);
1172
 
1173
  if (suffix[0] == 0)
1174
    {
1175
      buf = (char *) alloca (strlen (macro) + 6);
1176
      sprintf (buf, "%s(c)=c", macro);
1177
    }
1178
  else
1179
    {
1180
      buf = (char *) alloca (strlen (macro) + 9 + strlen (suffix) + 1);
1181
      sprintf (buf, "%s(c)=c ## %s", macro, suffix);
1182
    }
1183
 
1184
  cpp_define (parse_in, buf);
1185
}
1186
 
1187
/* Define MAX for TYPE based on the precision of the type.  */
1188
 
1189
static void
1190
builtin_define_type_max (const char *macro, tree type)
1191
{
1192
  builtin_define_type_minmax (NULL, macro, type);
1193
}
1194
 
1195
/* Define MIN_MACRO (if not NULL) and MAX_MACRO for TYPE based on the
1196
   precision of the type.  */
1197
 
1198
static void
1199
builtin_define_type_minmax (const char *min_macro, const char *max_macro,
1200
                            tree type)
1201
{
1202
  static const char *const values[]
1203
    = { "127", "255",
1204
        "32767", "65535",
1205
        "2147483647", "4294967295",
1206
        "9223372036854775807", "18446744073709551615",
1207
        "170141183460469231731687303715884105727",
1208
        "340282366920938463463374607431768211455" };
1209
 
1210
  const char *value, *suffix;
1211
  char *buf;
1212
  size_t idx;
1213
 
1214
  /* Pre-rendering the values mean we don't have to futz with printing a
1215
     multi-word decimal value.  There are also a very limited number of
1216
     precisions that we support, so it's really a waste of time.  */
1217
  switch (TYPE_PRECISION (type))
1218
    {
1219
    case 8:     idx = 0; break;
1220
    case 16:    idx = 2; break;
1221
    case 32:    idx = 4; break;
1222
    case 64:    idx = 6; break;
1223
    case 128:   idx = 8; break;
1224
    default:    gcc_unreachable ();
1225
    }
1226
 
1227
  value = values[idx + TYPE_UNSIGNED (type)];
1228
  suffix = type_suffix (type);
1229
 
1230
  buf = (char *) alloca (strlen (max_macro) + 1 + strlen (value)
1231
                         + strlen (suffix) + 1);
1232
  sprintf (buf, "%s=%s%s", max_macro, value, suffix);
1233
 
1234
  cpp_define (parse_in, buf);
1235
 
1236
  if (min_macro)
1237
    {
1238
      if (TYPE_UNSIGNED (type))
1239
        {
1240
          buf = (char *) alloca (strlen (min_macro) + 2 + strlen (suffix) + 1);
1241
          sprintf (buf, "%s=0%s", min_macro, suffix);
1242
        }
1243
      else
1244
        {
1245
          buf = (char *) alloca (strlen (min_macro) + 3
1246
                                 + strlen (max_macro) + 6);
1247
          sprintf (buf, "%s=(-%s - 1)", min_macro, max_macro);
1248
        }
1249
      cpp_define (parse_in, buf);
1250
    }
1251
}
1252
 
1253
#include "gt-c-family-c-cppbuiltin.h"

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.