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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 707 jeremybenn
/* Handle #pragma, system V.4 style.  Supports #pragma weak and #pragma pack.
2
   Copyright (C) 1992, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
3
   2006, 2007, 2008, 2009, 2010 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 "function.h"           /* For cfun.  FIXME: Does the parser know
27
                                   when it is inside a function, so that
28
                                   we don't have to look at cfun?  */
29
#include "cpplib.h"
30
#include "c-pragma.h"
31
#include "flags.h"
32
#include "c-common.h"
33
#include "output.h"
34
#include "tm_p.h"               /* For REGISTER_TARGET_PRAGMAS (why is
35
                                   this not a target hook?).  */
36
#include "vec.h"
37
#include "vecprim.h"
38
#include "target.h"
39
#include "diagnostic.h"
40
#include "opts.h"
41
#include "plugin.h"
42
 
43
#define GCC_BAD(gmsgid) \
44
  do { warning (OPT_Wpragmas, gmsgid); return; } while (0)
45
#define GCC_BAD2(gmsgid, arg) \
46
  do { warning (OPT_Wpragmas, gmsgid, arg); return; } while (0)
47
 
48
typedef struct GTY(()) align_stack {
49
  int                  alignment;
50
  tree                 id;
51
  struct align_stack * prev;
52
} align_stack;
53
 
54
static GTY(()) struct align_stack * alignment_stack;
55
 
56
static void handle_pragma_pack (cpp_reader *);
57
 
58
/* If we have a "global" #pragma pack(<n>) in effect when the first
59
   #pragma pack(push,<n>) is encountered, this stores the value of
60
   maximum_field_alignment in effect.  When the final pop_alignment()
61
   happens, we restore the value to this, not to a value of 0 for
62
   maximum_field_alignment.  Value is in bits.  */
63
static int default_alignment;
64
#define SET_GLOBAL_ALIGNMENT(ALIGN) (maximum_field_alignment = *(alignment_stack == NULL \
65
        ? &default_alignment \
66
        : &alignment_stack->alignment) = (ALIGN))
67
 
68
static void push_alignment (int, tree);
69
static void pop_alignment (tree);
70
 
71
/* Push an alignment value onto the stack.  */
72
static void
73
push_alignment (int alignment, tree id)
74
{
75
  align_stack * entry;
76
 
77
  entry = ggc_alloc_align_stack ();
78
 
79
  entry->alignment  = alignment;
80
  entry->id         = id;
81
  entry->prev       = alignment_stack;
82
 
83
  /* The current value of maximum_field_alignment is not necessarily
84
 
85
     so that we can restore it after the final #pragma pop().  */
86
  if (alignment_stack == NULL)
87
    default_alignment = maximum_field_alignment;
88
 
89
  alignment_stack = entry;
90
 
91
  maximum_field_alignment = alignment;
92
}
93
 
94
/* Undo a push of an alignment onto the stack.  */
95
static void
96
pop_alignment (tree id)
97
{
98
  align_stack * entry;
99
 
100
  if (alignment_stack == NULL)
101
    GCC_BAD ("#pragma pack (pop) encountered without matching #pragma pack (push)");
102
 
103
  /* If we got an identifier, strip away everything above the target
104
     entry so that the next step will restore the state just below it.  */
105
  if (id)
106
    {
107
      for (entry = alignment_stack; entry; entry = entry->prev)
108
        if (entry->id == id)
109
          {
110
            alignment_stack = entry;
111
            break;
112
          }
113
      if (entry == NULL)
114
        warning (OPT_Wpragmas, "\
115
#pragma pack(pop, %E) encountered without matching #pragma pack(push, %E)"
116
                 , id, id);
117
    }
118
 
119
  entry = alignment_stack->prev;
120
 
121
  maximum_field_alignment = entry ? entry->alignment : default_alignment;
122
 
123
  alignment_stack = entry;
124
}
125
 
126
/* #pragma pack ()
127
   #pragma pack (N)
128
 
129
   #pragma pack (push)
130
   #pragma pack (push, N)
131
   #pragma pack (push, ID)
132
   #pragma pack (push, ID, N)
133
   #pragma pack (pop)
134
   #pragma pack (pop, ID) */
135
static void
136
handle_pragma_pack (cpp_reader * ARG_UNUSED (dummy))
137
{
138
  tree x, id = 0;
139
  int align = -1;
140
  enum cpp_ttype token;
141
  enum { set, push, pop } action;
142
 
143
  if (pragma_lex (&x) != CPP_OPEN_PAREN)
144
    GCC_BAD ("missing %<(%> after %<#pragma pack%> - ignored");
145
 
146
  token = pragma_lex (&x);
147
  if (token == CPP_CLOSE_PAREN)
148
    {
149
      action = set;
150
      align = initial_max_fld_align;
151
    }
152
  else if (token == CPP_NUMBER)
153
    {
154
      if (TREE_CODE (x) != INTEGER_CST)
155
        GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
156
      align = TREE_INT_CST_LOW (x);
157
      action = set;
158
      if (pragma_lex (&x) != CPP_CLOSE_PAREN)
159
        GCC_BAD ("malformed %<#pragma pack%> - ignored");
160
    }
161
  else if (token == CPP_NAME)
162
    {
163
#define GCC_BAD_ACTION do { if (action != pop) \
164
          GCC_BAD ("malformed %<#pragma pack(push[, id][, <n>])%> - ignored"); \
165
        else \
166
          GCC_BAD ("malformed %<#pragma pack(pop[, id])%> - ignored"); \
167
        } while (0)
168
 
169
      const char *op = IDENTIFIER_POINTER (x);
170
      if (!strcmp (op, "push"))
171
        action = push;
172
      else if (!strcmp (op, "pop"))
173
        action = pop;
174
      else
175
        GCC_BAD2 ("unknown action %qE for %<#pragma pack%> - ignored", x);
176
 
177
      while ((token = pragma_lex (&x)) == CPP_COMMA)
178
        {
179
          token = pragma_lex (&x);
180
          if (token == CPP_NAME && id == 0)
181
            {
182
              id = x;
183
            }
184
          else if (token == CPP_NUMBER && action == push && align == -1)
185
            {
186
              if (TREE_CODE (x) != INTEGER_CST)
187
                GCC_BAD ("invalid constant in %<#pragma pack%> - ignored");
188
              align = TREE_INT_CST_LOW (x);
189
              if (align == -1)
190
                action = set;
191
            }
192
          else
193
            GCC_BAD_ACTION;
194
        }
195
 
196
      if (token != CPP_CLOSE_PAREN)
197
        GCC_BAD_ACTION;
198
#undef GCC_BAD_ACTION
199
    }
200
  else
201
    GCC_BAD ("malformed %<#pragma pack%> - ignored");
202
 
203
  if (pragma_lex (&x) != CPP_EOF)
204
    warning (OPT_Wpragmas, "junk at end of %<#pragma pack%>");
205
 
206
  if (flag_pack_struct)
207
    GCC_BAD ("#pragma pack has no effect with -fpack-struct - ignored");
208
 
209
  if (action != pop)
210
    switch (align)
211
      {
212
      case 0:
213
      case 1:
214
      case 2:
215
      case 4:
216
      case 8:
217
      case 16:
218
        align *= BITS_PER_UNIT;
219
        break;
220
      case -1:
221
        if (action == push)
222
          {
223
            align = maximum_field_alignment;
224
            break;
225
          }
226
      default:
227
        GCC_BAD2 ("alignment must be a small power of two, not %d", align);
228
      }
229
 
230
  switch (action)
231
    {
232
    case set:   SET_GLOBAL_ALIGNMENT (align);  break;
233
    case push:  push_alignment (align, id);    break;
234
    case pop:   pop_alignment (id);            break;
235
    }
236
}
237
 
238
typedef struct GTY(()) pending_weak_d
239
{
240
  tree name;
241
  tree value;
242
} pending_weak;
243
 
244
DEF_VEC_O(pending_weak);
245
DEF_VEC_ALLOC_O(pending_weak,gc);
246
 
247
static GTY(()) VEC(pending_weak,gc) *pending_weaks;
248
 
249
static void apply_pragma_weak (tree, tree);
250
static void handle_pragma_weak (cpp_reader *);
251
 
252
static void
253
apply_pragma_weak (tree decl, tree value)
254
{
255
  if (value)
256
    {
257
      value = build_string (IDENTIFIER_LENGTH (value),
258
                            IDENTIFIER_POINTER (value));
259
      decl_attributes (&decl, build_tree_list (get_identifier ("alias"),
260
                                               build_tree_list (NULL, value)),
261
                       0);
262
    }
263
 
264
  if (SUPPORTS_WEAK && DECL_EXTERNAL (decl) && TREE_USED (decl)
265
      && !DECL_WEAK (decl) /* Don't complain about a redundant #pragma.  */
266
      && TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (decl)))
267
    warning (OPT_Wpragmas, "applying #pragma weak %q+D after first use "
268
             "results in unspecified behavior", decl);
269
 
270
  declare_weak (decl);
271
}
272
 
273
void
274
maybe_apply_pragma_weak (tree decl)
275
{
276
  tree id;
277
  int i;
278
  pending_weak *pe;
279
 
280
  /* Avoid asking for DECL_ASSEMBLER_NAME when it's not needed.  */
281
 
282
  /* No weak symbols pending, take the short-cut.  */
283
  if (!pending_weaks)
284
    return;
285
  /* If it's not visible outside this file, it doesn't matter whether
286
     it's weak.  */
287
  if (!DECL_EXTERNAL (decl) && !TREE_PUBLIC (decl))
288
    return;
289
  /* If it's not a function or a variable, it can't be weak.
290
     FIXME: what kinds of things are visible outside this file but
291
     aren't functions or variables?   Should this be an assert instead?  */
292
  if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
293
    return;
294
 
295
  id = DECL_ASSEMBLER_NAME (decl);
296
 
297
  FOR_EACH_VEC_ELT (pending_weak, pending_weaks, i, pe)
298
    if (id == pe->name)
299
      {
300
        apply_pragma_weak (decl, pe->value);
301
        VEC_unordered_remove (pending_weak, pending_weaks, i);
302
        break;
303
      }
304
}
305
 
306
/* Process all "#pragma weak A = B" directives where we have not seen
307
   a decl for A.  */
308
void
309
maybe_apply_pending_pragma_weaks (void)
310
{
311
  tree alias_id, id, decl;
312
  int i;
313
  pending_weak *pe;
314
 
315
  FOR_EACH_VEC_ELT (pending_weak, pending_weaks, i, pe)
316
    {
317
      alias_id = pe->name;
318
      id = pe->value;
319
 
320
      if (id == NULL)
321
        continue;
322
 
323
      decl = build_decl (UNKNOWN_LOCATION,
324
                         FUNCTION_DECL, alias_id, default_function_type);
325
 
326
      DECL_ARTIFICIAL (decl) = 1;
327
      TREE_PUBLIC (decl) = 1;
328
      DECL_EXTERNAL (decl) = 1;
329
      DECL_WEAK (decl) = 1;
330
 
331
      assemble_alias (decl, id);
332
    }
333
}
334
 
335
/* #pragma weak name [= value] */
336
static void
337
handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy))
338
{
339
  tree name, value, x, decl;
340
  enum cpp_ttype t;
341
 
342
  value = 0;
343
 
344
  if (pragma_lex (&name) != CPP_NAME)
345
    GCC_BAD ("malformed #pragma weak, ignored");
346
  t = pragma_lex (&x);
347
  if (t == CPP_EQ)
348
    {
349
      if (pragma_lex (&value) != CPP_NAME)
350
        GCC_BAD ("malformed #pragma weak, ignored");
351
      t = pragma_lex (&x);
352
    }
353
  if (t != CPP_EOF)
354
    warning (OPT_Wpragmas, "junk at end of %<#pragma weak%>");
355
 
356
  decl = identifier_global_value (name);
357
  if (decl && DECL_P (decl))
358
    {
359
      apply_pragma_weak (decl, value);
360
      if (value)
361
        assemble_alias (decl, value);
362
    }
363
  else
364
    {
365
      pending_weak *pe;
366
      pe = VEC_safe_push (pending_weak, gc, pending_weaks, NULL);
367
      pe->name = name;
368
      pe->value = value;
369
    }
370
}
371
 
372
/* GCC supports two #pragma directives for renaming the external
373
   symbol associated with a declaration (DECL_ASSEMBLER_NAME), for
374
   compatibility with the Solaris and Tru64 system headers.  GCC also
375
   has its own notation for this, __asm__("name") annotations.
376
 
377
   Corner cases of these features and their interaction:
378
 
379
   1) Both pragmas silently apply only to declarations with external
380
      linkage (that is, TREE_PUBLIC || DECL_EXTERNAL).  Asm labels
381
      do not have this restriction.
382
 
383
   2) In C++, both #pragmas silently apply only to extern "C" declarations.
384
      Asm labels do not have this restriction.
385
 
386
   3) If any of the three ways of changing DECL_ASSEMBLER_NAME is
387
      applied to a decl whose DECL_ASSEMBLER_NAME is already set, and the
388
      new name is different, a warning issues and the name does not change.
389
 
390
   4) The "source name" for #pragma redefine_extname is the DECL_NAME,
391
      *not* the DECL_ASSEMBLER_NAME.
392
 
393
   5) If #pragma extern_prefix is in effect and a declaration occurs
394
      with an __asm__ name, the #pragma extern_prefix is silently
395
      ignored for that declaration.
396
 
397
   6) If #pragma extern_prefix and #pragma redefine_extname apply to
398
      the same declaration, whichever triggered first wins, and a warning
399
      is issued.  (We would like to have #pragma redefine_extname always
400
      win, but it can appear either before or after the declaration, and
401
      if it appears afterward, we have no way of knowing whether a modified
402
      DECL_ASSEMBLER_NAME is due to #pragma extern_prefix.)  */
403
 
404
typedef struct GTY(()) pending_redefinition_d {
405
  tree oldname;
406
  tree newname;
407
} pending_redefinition;
408
 
409
DEF_VEC_O(pending_redefinition);
410
DEF_VEC_ALLOC_O(pending_redefinition,gc);
411
 
412
static GTY(()) VEC(pending_redefinition,gc) *pending_redefine_extname;
413
 
414
static void handle_pragma_redefine_extname (cpp_reader *);
415
 
416
/* #pragma redefine_extname oldname newname */
417
static void
418
handle_pragma_redefine_extname (cpp_reader * ARG_UNUSED (dummy))
419
{
420
  tree oldname, newname, decls, x;
421
  enum cpp_ttype t;
422
  bool found;
423
 
424
  if (pragma_lex (&oldname) != CPP_NAME)
425
    GCC_BAD ("malformed #pragma redefine_extname, ignored");
426
  if (pragma_lex (&newname) != CPP_NAME)
427
    GCC_BAD ("malformed #pragma redefine_extname, ignored");
428
  t = pragma_lex (&x);
429
  if (t != CPP_EOF)
430
    warning (OPT_Wpragmas, "junk at end of %<#pragma redefine_extname%>");
431
 
432
  found = false;
433
  for (decls = c_linkage_bindings (oldname);
434
       decls; )
435
    {
436
      tree decl;
437
      if (TREE_CODE (decls) == TREE_LIST)
438
        {
439
          decl = TREE_VALUE (decls);
440
          decls = TREE_CHAIN (decls);
441
        }
442
      else
443
        {
444
          decl = decls;
445
          decls = NULL_TREE;
446
        }
447
 
448
      if ((TREE_PUBLIC (decl) || DECL_EXTERNAL (decl))
449
          && (TREE_CODE (decl) == FUNCTION_DECL
450
              || TREE_CODE (decl) == VAR_DECL))
451
        {
452
          found = true;
453
          if (DECL_ASSEMBLER_NAME_SET_P (decl))
454
            {
455
              const char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
456
              name = targetm.strip_name_encoding (name);
457
 
458
              if (strcmp (name, IDENTIFIER_POINTER (newname)))
459
                warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
460
                         "conflict with previous rename");
461
            }
462
          else
463
            change_decl_assembler_name (decl, newname);
464
        }
465
    }
466
 
467
  if (!found)
468
    /* We have to add this to the rename list even if there's already
469
       a global value that doesn't meet the above criteria, because in
470
       C++ "struct foo {...};" puts "foo" in the current namespace but
471
       does *not* conflict with a subsequent declaration of a function
472
       or variable foo.  See g++.dg/other/pragma-re-2.C.  */
473
    add_to_renaming_pragma_list (oldname, newname);
474
}
475
 
476
/* This is called from here and from ia64.c.  */
477
void
478
add_to_renaming_pragma_list (tree oldname, tree newname)
479
{
480
  unsigned ix;
481
  pending_redefinition *p;
482
 
483
  FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
484
    if (oldname == p->oldname)
485
      {
486
        if (p->newname != newname)
487
          warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
488
                   "conflict with previous #pragma redefine_extname");
489
        return;
490
      }
491
 
492
  p = VEC_safe_push (pending_redefinition, gc, pending_redefine_extname, NULL);
493
  p->oldname = oldname;
494
  p->newname = newname;
495
}
496
 
497
/* The current prefix set by #pragma extern_prefix.  */
498
GTY(()) tree pragma_extern_prefix;
499
 
500
/* #pragma extern_prefix "prefix" */
501
static void
502
handle_pragma_extern_prefix (cpp_reader * ARG_UNUSED (dummy))
503
{
504
  tree prefix, x;
505
  enum cpp_ttype t;
506
 
507
  if (pragma_lex (&prefix) != CPP_STRING)
508
    GCC_BAD ("malformed #pragma extern_prefix, ignored");
509
  t = pragma_lex (&x);
510
  if (t != CPP_EOF)
511
    warning (OPT_Wpragmas, "junk at end of %<#pragma extern_prefix%>");
512
 
513
  if (targetm.handle_pragma_extern_prefix)
514
    /* Note that the length includes the null terminator.  */
515
    pragma_extern_prefix = (TREE_STRING_LENGTH (prefix) > 1 ? prefix : NULL);
516
  else if (warn_unknown_pragmas > in_system_header)
517
    warning (OPT_Wunknown_pragmas,
518
             "#pragma extern_prefix not supported on this target");
519
}
520
 
521
/* Hook from the front ends to apply the results of one of the preceding
522
   pragmas that rename variables.  */
523
 
524
tree
525
maybe_apply_renaming_pragma (tree decl, tree asmname)
526
{
527
  unsigned ix;
528
  pending_redefinition *p;
529
 
530
  /* The renaming pragmas are only applied to declarations with
531
     external linkage.  */
532
  if ((TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
533
      || (!TREE_PUBLIC (decl) && !DECL_EXTERNAL (decl))
534
      || !has_c_linkage (decl))
535
    return asmname;
536
 
537
  /* If the DECL_ASSEMBLER_NAME is already set, it does not change,
538
     but we may warn about a rename that conflicts.  */
539
  if (DECL_ASSEMBLER_NAME_SET_P (decl))
540
    {
541
      const char *oldname = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
542
      oldname = targetm.strip_name_encoding (oldname);
543
 
544
      if (asmname && strcmp (TREE_STRING_POINTER (asmname), oldname))
545
          warning (OPT_Wpragmas, "asm declaration ignored due to "
546
                   "conflict with previous rename");
547
 
548
      /* Take any pending redefine_extname off the list.  */
549
      FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
550
        if (DECL_NAME (decl) == p->oldname)
551
          {
552
            /* Only warn if there is a conflict.  */
553
            if (strcmp (IDENTIFIER_POINTER (p->newname), oldname))
554
              warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
555
                       "conflict with previous rename");
556
 
557
            VEC_unordered_remove (pending_redefinition,
558
                                  pending_redefine_extname, ix);
559
            break;
560
          }
561
      return 0;
562
    }
563
 
564
  /* Find out if we have a pending #pragma redefine_extname.  */
565
  FOR_EACH_VEC_ELT (pending_redefinition, pending_redefine_extname, ix, p)
566
    if (DECL_NAME (decl) == p->oldname)
567
      {
568
        tree newname = p->newname;
569
        VEC_unordered_remove (pending_redefinition,
570
                              pending_redefine_extname, ix);
571
 
572
        /* If we already have an asmname, #pragma redefine_extname is
573
           ignored (with a warning if it conflicts).  */
574
        if (asmname)
575
          {
576
            if (strcmp (TREE_STRING_POINTER (asmname),
577
                        IDENTIFIER_POINTER (newname)) != 0)
578
              warning (OPT_Wpragmas, "#pragma redefine_extname ignored due to "
579
                       "conflict with __asm__ declaration");
580
            return asmname;
581
          }
582
 
583
        /* Otherwise we use what we've got; #pragma extern_prefix is
584
           silently ignored.  */
585
        return build_string (IDENTIFIER_LENGTH (newname),
586
                             IDENTIFIER_POINTER (newname));
587
      }
588
 
589
  /* If we've got an asmname, #pragma extern_prefix is silently ignored.  */
590
  if (asmname)
591
    return asmname;
592
 
593
  /* If #pragma extern_prefix is in effect, apply it.  */
594
  if (pragma_extern_prefix)
595
    {
596
      const char *prefix = TREE_STRING_POINTER (pragma_extern_prefix);
597
      size_t plen = TREE_STRING_LENGTH (pragma_extern_prefix) - 1;
598
 
599
      const char *id = IDENTIFIER_POINTER (DECL_NAME (decl));
600
      size_t ilen = IDENTIFIER_LENGTH (DECL_NAME (decl));
601
 
602
      char *newname = (char *) alloca (plen + ilen + 1);
603
 
604
      memcpy (newname,        prefix, plen);
605
      memcpy (newname + plen, id, ilen + 1);
606
 
607
      return build_string (plen + ilen, newname);
608
    }
609
 
610
  /* Nada.  */
611
  return 0;
612
}
613
 
614
 
615
static void handle_pragma_visibility (cpp_reader *);
616
 
617
static VEC (int, heap) *visstack;
618
 
619
/* Push the visibility indicated by STR onto the top of the #pragma
620
   visibility stack.  KIND is 0 for #pragma GCC visibility, 1 for
621
   C++ namespace with visibility attribute and 2 for C++ builtin
622
   ABI namespace.  push_visibility/pop_visibility calls must have
623
   matching KIND, it is not allowed to push visibility using one
624
   KIND and pop using a different one.  */
625
 
626
void
627
push_visibility (const char *str, int kind)
628
{
629
  VEC_safe_push (int, heap, visstack,
630
                 ((int) default_visibility) | (kind << 8));
631
  if (!strcmp (str, "default"))
632
    default_visibility = VISIBILITY_DEFAULT;
633
  else if (!strcmp (str, "internal"))
634
    default_visibility = VISIBILITY_INTERNAL;
635
  else if (!strcmp (str, "hidden"))
636
    default_visibility = VISIBILITY_HIDDEN;
637
  else if (!strcmp (str, "protected"))
638
    default_visibility = VISIBILITY_PROTECTED;
639
  else
640
    GCC_BAD ("#pragma GCC visibility push() must specify default, internal, hidden or protected");
641
  visibility_options.inpragma = 1;
642
}
643
 
644
/* Pop a level of the #pragma visibility stack.  Return true if
645
   successful.  */
646
 
647
bool
648
pop_visibility (int kind)
649
{
650
  if (!VEC_length (int, visstack))
651
    return false;
652
  if ((VEC_last (int, visstack) >> 8) != kind)
653
    return false;
654
  default_visibility
655
    = (enum symbol_visibility) (VEC_pop (int, visstack) & 0xff);
656
  visibility_options.inpragma
657
    = VEC_length (int, visstack) != 0;
658
  return true;
659
}
660
 
661
/* Sets the default visibility for symbols to something other than that
662
   specified on the command line.  */
663
 
664
static void
665
handle_pragma_visibility (cpp_reader *dummy ATTRIBUTE_UNUSED)
666
{
667
  /* Form is #pragma GCC visibility push(hidden)|pop */
668
  tree x;
669
  enum cpp_ttype token;
670
  enum { bad, push, pop } action = bad;
671
 
672
  token = pragma_lex (&x);
673
  if (token == CPP_NAME)
674
    {
675
      const char *op = IDENTIFIER_POINTER (x);
676
      if (!strcmp (op, "push"))
677
        action = push;
678
      else if (!strcmp (op, "pop"))
679
        action = pop;
680
    }
681
  if (bad == action)
682
    GCC_BAD ("#pragma GCC visibility must be followed by push or pop");
683
  else
684
    {
685
      if (pop == action)
686
        {
687
          if (! pop_visibility (0))
688
            GCC_BAD ("no matching push for %<#pragma GCC visibility pop%>");
689
        }
690
      else
691
        {
692
          if (pragma_lex (&x) != CPP_OPEN_PAREN)
693
            GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
694
          token = pragma_lex (&x);
695
          if (token != CPP_NAME)
696
            GCC_BAD ("malformed #pragma GCC visibility push");
697
          else
698
            push_visibility (IDENTIFIER_POINTER (x), 0);
699
          if (pragma_lex (&x) != CPP_CLOSE_PAREN)
700
            GCC_BAD ("missing %<(%> after %<#pragma GCC visibility push%> - ignored");
701
        }
702
    }
703
  if (pragma_lex (&x) != CPP_EOF)
704
    warning (OPT_Wpragmas, "junk at end of %<#pragma GCC visibility%>");
705
}
706
 
707
static void
708
handle_pragma_diagnostic(cpp_reader *ARG_UNUSED(dummy))
709
{
710
  const char *kind_string, *option_string;
711
  unsigned int option_index;
712
  enum cpp_ttype token;
713
  diagnostic_t kind;
714
  tree x;
715
  struct cl_option_handlers handlers;
716
 
717
  token = pragma_lex (&x);
718
  if (token != CPP_NAME)
719
    GCC_BAD ("missing [error|warning|ignored] after %<#pragma GCC diagnostic%>");
720
  kind_string = IDENTIFIER_POINTER (x);
721
  if (strcmp (kind_string, "error") == 0)
722
    kind = DK_ERROR;
723
  else if (strcmp (kind_string, "warning") == 0)
724
    kind = DK_WARNING;
725
  else if (strcmp (kind_string, "ignored") == 0)
726
    kind = DK_IGNORED;
727
  else if (strcmp (kind_string, "push") == 0)
728
    {
729
      diagnostic_push_diagnostics (global_dc, input_location);
730
      return;
731
    }
732
  else if (strcmp (kind_string, "pop") == 0)
733
    {
734
      diagnostic_pop_diagnostics (global_dc, input_location);
735
      return;
736
    }
737
  else
738
    GCC_BAD ("expected [error|warning|ignored|push|pop] after %<#pragma GCC diagnostic%>");
739
 
740
  token = pragma_lex (&x);
741
  if (token != CPP_STRING)
742
    GCC_BAD ("missing option after %<#pragma GCC diagnostic%> kind");
743
  option_string = TREE_STRING_POINTER (x);
744
  set_default_handlers (&handlers);
745
  for (option_index = 0; option_index < cl_options_count; option_index++)
746
    if (strcmp (cl_options[option_index].opt_text, option_string) == 0)
747
      {
748
        control_warning_option (option_index, (int) kind, kind != DK_IGNORED,
749
                                input_location, c_family_lang_mask, &handlers,
750
                                &global_options, &global_options_set,
751
                                global_dc);
752
        return;
753
      }
754
  GCC_BAD ("unknown option after %<#pragma GCC diagnostic%> kind");
755
}
756
 
757
/*  Parse #pragma GCC target (xxx) to set target specific options.  */
758
static void
759
handle_pragma_target(cpp_reader *ARG_UNUSED(dummy))
760
{
761
  enum cpp_ttype token;
762
  tree x;
763
  bool close_paren_needed_p = false;
764
 
765
  if (cfun)
766
    {
767
      error ("#pragma GCC option is not allowed inside functions");
768
      return;
769
    }
770
 
771
  token = pragma_lex (&x);
772
  if (token == CPP_OPEN_PAREN)
773
    {
774
      close_paren_needed_p = true;
775
      token = pragma_lex (&x);
776
    }
777
 
778
  if (token != CPP_STRING)
779
    {
780
      GCC_BAD ("%<#pragma GCC option%> is not a string");
781
      return;
782
    }
783
 
784
  /* Strings are user options.  */
785
  else
786
    {
787
      tree args = NULL_TREE;
788
 
789
      do
790
        {
791
          /* Build up the strings now as a tree linked list.  Skip empty
792
             strings.  */
793
          if (TREE_STRING_LENGTH (x) > 0)
794
            args = tree_cons (NULL_TREE, x, args);
795
 
796
          token = pragma_lex (&x);
797
          while (token == CPP_COMMA)
798
            token = pragma_lex (&x);
799
        }
800
      while (token == CPP_STRING);
801
 
802
      if (close_paren_needed_p)
803
        {
804
          if (token == CPP_CLOSE_PAREN)
805
            token = pragma_lex (&x);
806
          else
807
            GCC_BAD ("%<#pragma GCC target (string [,string]...)%> does "
808
                     "not have a final %<)%>");
809
        }
810
 
811
      if (token != CPP_EOF)
812
        {
813
          error ("#pragma GCC target string... is badly formed");
814
          return;
815
        }
816
 
817
      /* put arguments in the order the user typed them.  */
818
      args = nreverse (args);
819
 
820
      if (targetm.target_option.pragma_parse (args, NULL_TREE))
821
        current_target_pragma = args;
822
    }
823
}
824
 
825
/* Handle #pragma GCC optimize to set optimization options.  */
826
static void
827
handle_pragma_optimize (cpp_reader *ARG_UNUSED(dummy))
828
{
829
  enum cpp_ttype token;
830
  tree x;
831
  bool close_paren_needed_p = false;
832
  tree optimization_previous_node = optimization_current_node;
833
 
834
  if (cfun)
835
    {
836
      error ("#pragma GCC optimize is not allowed inside functions");
837
      return;
838
    }
839
 
840
  token = pragma_lex (&x);
841
  if (token == CPP_OPEN_PAREN)
842
    {
843
      close_paren_needed_p = true;
844
      token = pragma_lex (&x);
845
    }
846
 
847
  if (token != CPP_STRING && token != CPP_NUMBER)
848
    {
849
      GCC_BAD ("%<#pragma GCC optimize%> is not a string or number");
850
      return;
851
    }
852
 
853
  /* Strings/numbers are user options.  */
854
  else
855
    {
856
      tree args = NULL_TREE;
857
 
858
      do
859
        {
860
          /* Build up the numbers/strings now as a list.  */
861
          if (token != CPP_STRING || TREE_STRING_LENGTH (x) > 0)
862
            args = tree_cons (NULL_TREE, x, args);
863
 
864
          token = pragma_lex (&x);
865
          while (token == CPP_COMMA)
866
            token = pragma_lex (&x);
867
        }
868
      while (token == CPP_STRING || token == CPP_NUMBER);
869
 
870
      if (close_paren_needed_p)
871
        {
872
          if (token == CPP_CLOSE_PAREN)
873
            token = pragma_lex (&x);
874
          else
875
            GCC_BAD ("%<#pragma GCC optimize (string [,string]...)%> does "
876
                     "not have a final %<)%>");
877
        }
878
 
879
      if (token != CPP_EOF)
880
        {
881
          error ("#pragma GCC optimize string... is badly formed");
882
          return;
883
        }
884
 
885
      /* put arguments in the order the user typed them.  */
886
      args = nreverse (args);
887
 
888
      parse_optimize_options (args, false);
889
      current_optimize_pragma = chainon (current_optimize_pragma, args);
890
      optimization_current_node = build_optimization_node ();
891
      c_cpp_builtins_optimize_pragma (parse_in,
892
                                      optimization_previous_node,
893
                                      optimization_current_node);
894
    }
895
}
896
 
897
/* Stack of the #pragma GCC options created with #pragma GCC push_option.  Save
898
   both the binary representation of the options and the TREE_LIST of
899
   strings that will be added to the function's attribute list.  */
900
typedef struct GTY(()) opt_stack {
901
  struct opt_stack *prev;
902
  tree target_binary;
903
  tree target_strings;
904
  tree optimize_binary;
905
  tree optimize_strings;
906
} opt_stack;
907
 
908
static GTY(()) struct opt_stack * options_stack;
909
 
910
/* Handle #pragma GCC push_options to save the current target and optimization
911
   options.  */
912
 
913
static void
914
handle_pragma_push_options (cpp_reader *ARG_UNUSED(dummy))
915
{
916
  enum cpp_ttype token;
917
  tree x = 0;
918
  opt_stack *p;
919
 
920
  token = pragma_lex (&x);
921
  if (token != CPP_EOF)
922
    {
923
      warning (OPT_Wpragmas, "junk at end of %<#pragma push_options%>");
924
      return;
925
    }
926
 
927
  p = ggc_alloc_opt_stack ();
928
  p->prev = options_stack;
929
  options_stack = p;
930
 
931
  /* Save optimization and target flags in binary format.  */
932
  p->optimize_binary = build_optimization_node ();
933
  p->target_binary = build_target_option_node ();
934
 
935
  /* Save optimization and target flags in string list format.  */
936
  p->optimize_strings = copy_list (current_optimize_pragma);
937
  p->target_strings = copy_list (current_target_pragma);
938
}
939
 
940
/* Handle #pragma GCC pop_options to restore the current target and
941
   optimization options from a previous push_options.  */
942
 
943
static void
944
handle_pragma_pop_options (cpp_reader *ARG_UNUSED(dummy))
945
{
946
  enum cpp_ttype token;
947
  tree x = 0;
948
  opt_stack *p;
949
 
950
  token = pragma_lex (&x);
951
  if (token != CPP_EOF)
952
    {
953
      warning (OPT_Wpragmas, "junk at end of %<#pragma pop_options%>");
954
      return;
955
    }
956
 
957
  if (! options_stack)
958
    {
959
      warning (OPT_Wpragmas,
960
               "%<#pragma GCC pop_options%> without a corresponding "
961
               "%<#pragma GCC push_options%>");
962
      return;
963
    }
964
 
965
  p = options_stack;
966
  options_stack = p->prev;
967
 
968
  if (p->target_binary != target_option_current_node)
969
    {
970
      (void) targetm.target_option.pragma_parse (NULL_TREE, p->target_binary);
971
      target_option_current_node = p->target_binary;
972
    }
973
 
974
  if (p->optimize_binary != optimization_current_node)
975
    {
976
      tree old_optimize = optimization_current_node;
977
      cl_optimization_restore (&global_options,
978
                               TREE_OPTIMIZATION (p->optimize_binary));
979
      c_cpp_builtins_optimize_pragma (parse_in, old_optimize,
980
                                      p->optimize_binary);
981
      optimization_current_node = p->optimize_binary;
982
    }
983
 
984
  current_target_pragma = p->target_strings;
985
  current_optimize_pragma = p->optimize_strings;
986
}
987
 
988
/* Handle #pragma GCC reset_options to restore the current target and
989
   optimization options to the original options used on the command line.  */
990
 
991
static void
992
handle_pragma_reset_options (cpp_reader *ARG_UNUSED(dummy))
993
{
994
  enum cpp_ttype token;
995
  tree x = 0;
996
  tree new_optimize = optimization_default_node;
997
  tree new_target = target_option_default_node;
998
 
999
  token = pragma_lex (&x);
1000
  if (token != CPP_EOF)
1001
    {
1002
      warning (OPT_Wpragmas, "junk at end of %<#pragma reset_options%>");
1003
      return;
1004
    }
1005
 
1006
  if (new_target != target_option_current_node)
1007
    {
1008
      (void) targetm.target_option.pragma_parse (NULL_TREE, new_target);
1009
      target_option_current_node = new_target;
1010
    }
1011
 
1012
  if (new_optimize != optimization_current_node)
1013
    {
1014
      tree old_optimize = optimization_current_node;
1015
      cl_optimization_restore (&global_options,
1016
                               TREE_OPTIMIZATION (new_optimize));
1017
      c_cpp_builtins_optimize_pragma (parse_in, old_optimize, new_optimize);
1018
      optimization_current_node = new_optimize;
1019
    }
1020
 
1021
  current_target_pragma = NULL_TREE;
1022
  current_optimize_pragma = NULL_TREE;
1023
}
1024
 
1025
/* Print a plain user-specified message.  */
1026
 
1027
static void
1028
handle_pragma_message (cpp_reader *ARG_UNUSED(dummy))
1029
{
1030
  enum cpp_ttype token;
1031
  tree x, message = 0;
1032
 
1033
  token = pragma_lex (&x);
1034
  if (token == CPP_OPEN_PAREN)
1035
    {
1036
      token = pragma_lex (&x);
1037
      if (token == CPP_STRING)
1038
        message = x;
1039
      else
1040
        GCC_BAD ("expected a string after %<#pragma message%>");
1041
      if (pragma_lex (&x) != CPP_CLOSE_PAREN)
1042
        GCC_BAD ("malformed %<#pragma message%>, ignored");
1043
    }
1044
  else if (token == CPP_STRING)
1045
    message = x;
1046
  else
1047
    GCC_BAD ("expected a string after %<#pragma message%>");
1048
 
1049
  gcc_assert (message);
1050
 
1051
  if (pragma_lex (&x) != CPP_EOF)
1052
    warning (OPT_Wpragmas, "junk at end of %<#pragma message%>");
1053
 
1054
  if (TREE_STRING_LENGTH (message) > 1)
1055
    inform (input_location, "#pragma message: %s", TREE_STRING_POINTER (message));
1056
}
1057
 
1058
/* Mark whether the current location is valid for a STDC pragma.  */
1059
 
1060
static bool valid_location_for_stdc_pragma;
1061
 
1062
void
1063
mark_valid_location_for_stdc_pragma (bool flag)
1064
{
1065
  valid_location_for_stdc_pragma = flag;
1066
}
1067
 
1068
/* Return true if the current location is valid for a STDC pragma.  */
1069
 
1070
bool
1071
valid_location_for_stdc_pragma_p (void)
1072
{
1073
  return valid_location_for_stdc_pragma;
1074
}
1075
 
1076
enum pragma_switch_t { PRAGMA_ON, PRAGMA_OFF, PRAGMA_DEFAULT, PRAGMA_BAD };
1077
 
1078
/* A STDC pragma must appear outside of external declarations or
1079
   preceding all explicit declarations and statements inside a compound
1080
   statement; its behavior is undefined if used in any other context.
1081
   It takes a switch of ON, OFF, or DEFAULT.  */
1082
 
1083
static enum pragma_switch_t
1084
handle_stdc_pragma (const char *pname)
1085
{
1086
  const char *arg;
1087
  tree t;
1088
  enum pragma_switch_t ret;
1089
 
1090
  if (!valid_location_for_stdc_pragma_p ())
1091
    {
1092
      warning (OPT_Wpragmas, "invalid location for %<pragma %s%>, ignored",
1093
               pname);
1094
      return PRAGMA_BAD;
1095
    }
1096
 
1097
  if (pragma_lex (&t) != CPP_NAME)
1098
    {
1099
      warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1100
      return PRAGMA_BAD;
1101
    }
1102
 
1103
  arg = IDENTIFIER_POINTER (t);
1104
 
1105
  if (!strcmp (arg, "ON"))
1106
    ret = PRAGMA_ON;
1107
  else if (!strcmp (arg, "OFF"))
1108
    ret = PRAGMA_OFF;
1109
  else if (!strcmp (arg, "DEFAULT"))
1110
    ret = PRAGMA_DEFAULT;
1111
  else
1112
    {
1113
      warning (OPT_Wpragmas, "malformed %<#pragma %s%>, ignored", pname);
1114
      return PRAGMA_BAD;
1115
    }
1116
 
1117
  if (pragma_lex (&t) != CPP_EOF)
1118
    {
1119
      warning (OPT_Wpragmas, "junk at end of %<#pragma %s%>", pname);
1120
      return PRAGMA_BAD;
1121
    }
1122
 
1123
  return ret;
1124
}
1125
 
1126
/* #pragma STDC FLOAT_CONST_DECIMAL64 ON
1127
   #pragma STDC FLOAT_CONST_DECIMAL64 OFF
1128
   #pragma STDC FLOAT_CONST_DECIMAL64 DEFAULT */
1129
 
1130
static void
1131
handle_pragma_float_const_decimal64 (cpp_reader *ARG_UNUSED (dummy))
1132
{
1133
  if (c_dialect_cxx ())
1134
    {
1135
      if (warn_unknown_pragmas > in_system_header)
1136
        warning (OPT_Wunknown_pragmas,
1137
                 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1138
                 " for C++");
1139
      return;
1140
    }
1141
 
1142
  if (!targetm.decimal_float_supported_p ())
1143
    {
1144
      if (warn_unknown_pragmas > in_system_header)
1145
        warning (OPT_Wunknown_pragmas,
1146
                 "%<#pragma STDC FLOAT_CONST_DECIMAL64%> is not supported"
1147
                 " on this target");
1148
      return;
1149
    }
1150
 
1151
  pedwarn (input_location, OPT_pedantic,
1152
           "ISO C does not support %<#pragma STDC FLOAT_CONST_DECIMAL64%>");
1153
 
1154
  switch (handle_stdc_pragma ("STDC FLOAT_CONST_DECIMAL64"))
1155
    {
1156
    case PRAGMA_ON:
1157
      set_float_const_decimal64 ();
1158
      break;
1159
    case PRAGMA_OFF:
1160
    case PRAGMA_DEFAULT:
1161
      clear_float_const_decimal64 ();
1162
      break;
1163
    case PRAGMA_BAD:
1164
      break;
1165
    }
1166
}
1167
 
1168
/* A vector of registered pragma callbacks, which is never freed.   */
1169
DEF_VEC_O (internal_pragma_handler);
1170
DEF_VEC_ALLOC_O (internal_pragma_handler, heap);
1171
 
1172
static VEC(internal_pragma_handler, heap) *registered_pragmas;
1173
 
1174
typedef struct
1175
{
1176
  const char *space;
1177
  const char *name;
1178
} pragma_ns_name;
1179
 
1180
DEF_VEC_O (pragma_ns_name);
1181
DEF_VEC_ALLOC_O (pragma_ns_name, heap);
1182
 
1183
static VEC(pragma_ns_name, heap) *registered_pp_pragmas;
1184
 
1185
struct omp_pragma_def { const char *name; unsigned int id; };
1186
static const struct omp_pragma_def omp_pragmas[] = {
1187
  { "atomic", PRAGMA_OMP_ATOMIC },
1188
  { "barrier", PRAGMA_OMP_BARRIER },
1189
  { "critical", PRAGMA_OMP_CRITICAL },
1190
  { "flush", PRAGMA_OMP_FLUSH },
1191
  { "for", PRAGMA_OMP_FOR },
1192
  { "master", PRAGMA_OMP_MASTER },
1193
  { "ordered", PRAGMA_OMP_ORDERED },
1194
  { "parallel", PRAGMA_OMP_PARALLEL },
1195
  { "section", PRAGMA_OMP_SECTION },
1196
  { "sections", PRAGMA_OMP_SECTIONS },
1197
  { "single", PRAGMA_OMP_SINGLE },
1198
  { "task", PRAGMA_OMP_TASK },
1199
  { "taskwait", PRAGMA_OMP_TASKWAIT },
1200
  { "taskyield", PRAGMA_OMP_TASKYIELD },
1201
  { "threadprivate", PRAGMA_OMP_THREADPRIVATE }
1202
};
1203
 
1204
void
1205
c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
1206
{
1207
  const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1208
  int i;
1209
 
1210
  for (i = 0; i < n_omp_pragmas; ++i)
1211
    if (omp_pragmas[i].id == id)
1212
      {
1213
        *space = "omp";
1214
        *name = omp_pragmas[i].name;
1215
        return;
1216
      }
1217
 
1218
  if (id >= PRAGMA_FIRST_EXTERNAL
1219
      && (id < PRAGMA_FIRST_EXTERNAL
1220
          + VEC_length (pragma_ns_name, registered_pp_pragmas)))
1221
    {
1222
      *space = VEC_index (pragma_ns_name, registered_pp_pragmas,
1223
                          id - PRAGMA_FIRST_EXTERNAL)->space;
1224
      *name = VEC_index (pragma_ns_name, registered_pp_pragmas,
1225
                         id - PRAGMA_FIRST_EXTERNAL)->name;
1226
      return;
1227
    }
1228
 
1229
  gcc_unreachable ();
1230
}
1231
 
1232
/* Front-end wrappers for pragma registration to avoid dragging
1233
   cpplib.h in almost everywhere.  */
1234
 
1235
static void
1236
c_register_pragma_1 (const char *space, const char *name,
1237
                     internal_pragma_handler ihandler, bool allow_expansion)
1238
{
1239
  unsigned id;
1240
 
1241
  if (flag_preprocess_only)
1242
    {
1243
      pragma_ns_name ns_name;
1244
 
1245
      if (!allow_expansion)
1246
        return;
1247
 
1248
      ns_name.space = space;
1249
      ns_name.name = name;
1250
      VEC_safe_push (pragma_ns_name, heap, registered_pp_pragmas, &ns_name);
1251
      id = VEC_length (pragma_ns_name, registered_pp_pragmas);
1252
      id += PRAGMA_FIRST_EXTERNAL - 1;
1253
    }
1254
  else
1255
    {
1256
      VEC_safe_push (internal_pragma_handler, heap, registered_pragmas,
1257
                     &ihandler);
1258
      id = VEC_length (internal_pragma_handler, registered_pragmas);
1259
      id += PRAGMA_FIRST_EXTERNAL - 1;
1260
 
1261
      /* The C++ front end allocates 6 bits in cp_token; the C front end
1262
         allocates 7 bits in c_token.  At present this is sufficient.  */
1263
      gcc_assert (id < 64);
1264
    }
1265
 
1266
  cpp_register_deferred_pragma (parse_in, space, name, id,
1267
                                allow_expansion, false);
1268
}
1269
 
1270
/* Register a C pragma handler, using a space and a name.  It disallows pragma
1271
   expansion (if you want it, use c_register_pragma_with_expansion instead).  */
1272
void
1273
c_register_pragma (const char *space, const char *name,
1274
                   pragma_handler_1arg handler)
1275
{
1276
  internal_pragma_handler ihandler;
1277
 
1278
  ihandler.handler.handler_1arg = handler;
1279
  ihandler.extra_data = false;
1280
  ihandler.data = NULL;
1281
  c_register_pragma_1 (space, name, ihandler, false);
1282
}
1283
 
1284
/* Register a C pragma handler, using a space and a name, it also carries an
1285
   extra data field which can be used by the handler.  It disallows pragma
1286
   expansion (if you want it, use c_register_pragma_with_expansion_and_data
1287
   instead).  */
1288
void
1289
c_register_pragma_with_data (const char *space, const char *name,
1290
                             pragma_handler_2arg handler, void * data)
1291
{
1292
  internal_pragma_handler ihandler;
1293
 
1294
  ihandler.handler.handler_2arg = handler;
1295
  ihandler.extra_data = true;
1296
  ihandler.data = data;
1297
  c_register_pragma_1 (space, name, ihandler, false);
1298
}
1299
 
1300
/* Register a C pragma handler, using a space and a name.  It allows pragma
1301
   expansion as in the following example:
1302
 
1303
   #define NUMBER 10
1304
   #pragma count (NUMBER)
1305
 
1306
   Name expansion is still disallowed.  */
1307
void
1308
c_register_pragma_with_expansion (const char *space, const char *name,
1309
                                  pragma_handler_1arg handler)
1310
{
1311
  internal_pragma_handler ihandler;
1312
 
1313
  ihandler.handler.handler_1arg = handler;
1314
  ihandler.extra_data = false;
1315
  ihandler.data = NULL;
1316
  c_register_pragma_1 (space, name, ihandler, true);
1317
}
1318
 
1319
/* Register a C pragma handler, using a space and a name, it also carries an
1320
   extra data field which can be used by the handler.  It allows pragma
1321
   expansion as in the following example:
1322
 
1323
   #define NUMBER 10
1324
   #pragma count (NUMBER)
1325
 
1326
   Name expansion is still disallowed.  */
1327
void
1328
c_register_pragma_with_expansion_and_data (const char *space, const char *name,
1329
                                           pragma_handler_2arg handler,
1330
                                           void *data)
1331
{
1332
  internal_pragma_handler ihandler;
1333
 
1334
  ihandler.handler.handler_2arg = handler;
1335
  ihandler.extra_data = true;
1336
  ihandler.data = data;
1337
  c_register_pragma_1 (space, name, ihandler, true);
1338
}
1339
 
1340
void
1341
c_invoke_pragma_handler (unsigned int id)
1342
{
1343
  internal_pragma_handler *ihandler;
1344
  pragma_handler_1arg handler_1arg;
1345
  pragma_handler_2arg handler_2arg;
1346
 
1347
  id -= PRAGMA_FIRST_EXTERNAL;
1348
  ihandler = VEC_index (internal_pragma_handler, registered_pragmas, id);
1349
  if (ihandler->extra_data)
1350
    {
1351
      handler_2arg = ihandler->handler.handler_2arg;
1352
      handler_2arg (parse_in, ihandler->data);
1353
    }
1354
  else
1355
    {
1356
      handler_1arg = ihandler->handler.handler_1arg;
1357
      handler_1arg (parse_in);
1358
    }
1359
}
1360
 
1361
/* Set up front-end pragmas.  */
1362
void
1363
init_pragma (void)
1364
{
1365
  if (flag_openmp)
1366
    {
1367
      const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
1368
      int i;
1369
 
1370
      for (i = 0; i < n_omp_pragmas; ++i)
1371
        cpp_register_deferred_pragma (parse_in, "omp", omp_pragmas[i].name,
1372
                                      omp_pragmas[i].id, true, true);
1373
    }
1374
 
1375
  if (!flag_preprocess_only)
1376
    cpp_register_deferred_pragma (parse_in, "GCC", "pch_preprocess",
1377
                                  PRAGMA_GCC_PCH_PREPROCESS, false, false);
1378
 
1379
#ifdef HANDLE_PRAGMA_PACK_WITH_EXPANSION
1380
  c_register_pragma_with_expansion (0, "pack", handle_pragma_pack);
1381
#else
1382
  c_register_pragma (0, "pack", handle_pragma_pack);
1383
#endif
1384
  c_register_pragma (0, "weak", handle_pragma_weak);
1385
  c_register_pragma ("GCC", "visibility", handle_pragma_visibility);
1386
 
1387
  c_register_pragma ("GCC", "diagnostic", handle_pragma_diagnostic);
1388
  c_register_pragma ("GCC", "target", handle_pragma_target);
1389
  c_register_pragma ("GCC", "optimize", handle_pragma_optimize);
1390
  c_register_pragma ("GCC", "push_options", handle_pragma_push_options);
1391
  c_register_pragma ("GCC", "pop_options", handle_pragma_pop_options);
1392
  c_register_pragma ("GCC", "reset_options", handle_pragma_reset_options);
1393
 
1394
  c_register_pragma ("STDC", "FLOAT_CONST_DECIMAL64",
1395
                     handle_pragma_float_const_decimal64);
1396
 
1397
  c_register_pragma_with_expansion (0, "redefine_extname",
1398
                                    handle_pragma_redefine_extname);
1399
  c_register_pragma (0, "extern_prefix", handle_pragma_extern_prefix);
1400
 
1401
  c_register_pragma_with_expansion (0, "message", handle_pragma_message);
1402
 
1403
#ifdef REGISTER_TARGET_PRAGMAS
1404
  REGISTER_TARGET_PRAGMAS ();
1405
#endif
1406
 
1407
  /* Allow plugins to register their own pragmas. */
1408
  invoke_plugin_callbacks (PLUGIN_PRAGMAS, NULL);
1409
}
1410
 
1411
#include "gt-c-family-c-pragma.h"

powered by: WebSVN 2.1.0

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