1/* Darwin support needed only by C/C++ frontends.
2   Copyright (C) 2001
3   Free Software Foundation, Inc.
4   Contributed by Apple Computer Inc.
5
6This file is part of GNU CC.
7
8GNU CC is free software; you can redistribute it and/or modify
9it under the terms of the GNU General Public License as published by
10the Free Software Foundation; either version 2, or (at your option)
11any later version.
12
13GNU CC is distributed in the hope that it will be useful,
14but WITHOUT ANY WARRANTY; without even the implied warranty of
15MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16GNU General Public License for more details.
17
18You should have received a copy of the GNU General Public License
19along with GNU CC; see the file COPYING.  If not, write to
20the Free Software Foundation, 59 Temple Place - Suite 330,
21Boston, MA 02111-1307, USA.  */
22
23#include "config.h"
24#include "system.h"
25#include "cpplib.h"
26#include "tree.h"
27#include "c-pragma.h"
28#include "c-tree.h"
29#include "toplev.h"
30#include "tm_p.h"
31
32/* Pragmas.  */
33
34#define BAD(msgid) do { warning (msgid); return; } while (0)
35
36/* Maintain a small stack of alignments.  This is similar to pragma
37   pack's stack, but simpler.  */
38
39static void push_field_alignment PARAMS ((int));
40static void pop_field_alignment PARAMS ((void));
41
42typedef struct align_stack
43{
44  int alignment;
45  struct align_stack * prev;
46} align_stack;
47
48static struct align_stack * field_align_stack = NULL;
49
50static void
51push_field_alignment (bit_alignment)
52     int bit_alignment;
53{
54  align_stack *entry = (align_stack *) xmalloc (sizeof (align_stack));
55
56  entry->alignment = maximum_field_alignment;
57  entry->prev = field_align_stack;
58  field_align_stack = entry;
59
60  maximum_field_alignment = bit_alignment;
61}
62
63static void
64pop_field_alignment ()
65{
66  if (field_align_stack)
67    {
68      align_stack *entry = field_align_stack;
69
70      maximum_field_alignment = entry->alignment;
71      field_align_stack = entry->prev;
72      free (entry);
73    }
74  else
75    error ("too many #pragma options align=reset");
76}
77
78/* Handlers for Darwin-specific pragmas.  */
79
80void
81darwin_pragma_ignore (pfile)
82     cpp_reader *pfile ATTRIBUTE_UNUSED;
83{
84  /* Do nothing.  */
85}
86
87/* #pragma options align={mac68k|power|reset} */
88
89void
90darwin_pragma_options (pfile)
91     cpp_reader *pfile ATTRIBUTE_UNUSED;
92{
93  const char *arg;
94  tree t, x;
95
96  if (c_lex (&t) != CPP_NAME)
97    BAD ("malformed '#pragma options', ignoring");
98  arg = IDENTIFIER_POINTER (t);
99  if (strcmp (arg, "align"))
100    BAD ("malformed '#pragma options', ignoring");
101  if (c_lex (&t) != CPP_EQ)
102    BAD ("malformed '#pragma options', ignoring");
103  if (c_lex (&t) != CPP_NAME)
104    BAD ("malformed '#pragma options', ignoring");
105
106  if (c_lex (&x) != CPP_EOF)
107    warning ("junk at end of '#pragma options'");
108
109  arg = IDENTIFIER_POINTER (t);
110  if (!strcmp (arg, "mac68k"))
111    push_field_alignment (16);
112  else if (!strcmp (arg, "power"))
113    push_field_alignment (0);
114  else if (!strcmp (arg, "reset"))
115    pop_field_alignment ();
116  else
117    warning ("malformed '#pragma options align={mac68k|power|reset}', ignoring");
118}
119
120/* #pragma unused ([var {, var}*]) */
121
122void
123darwin_pragma_unused (pfile)
124     cpp_reader *pfile ATTRIBUTE_UNUSED;
125{
126  tree decl, x;
127  int tok;
128
129  if (c_lex (&x) != CPP_OPEN_PAREN)
130    BAD ("missing '(' after '#pragma unused', ignoring");
131
132  while (1)
133    {
134      tok = c_lex (&decl);
135      if (tok == CPP_NAME && decl)
136	{
137	  tree local = IDENTIFIER_LOCAL_VALUE (decl);
138	  if (local && (TREE_CODE (local) == PARM_DECL
139			|| TREE_CODE (local) == VAR_DECL))
140	    TREE_USED (local) = 1;
141	  tok = c_lex (&x);
142	  if (tok != CPP_COMMA)
143	    break;
144	}
145    }
146
147  if (tok != CPP_CLOSE_PAREN)
148    BAD ("missing ')' after '#pragma unused', ignoring");
149
150  if (c_lex (&x) != CPP_EOF)
151    warning ("junk at end of '#pragma unused'");
152}
153