OSDN Git Service

2002-04-12 Eric Norum <eric.norum@usask.ca>
[pf3gnuchains/gcc-fork.git] / gcc / config / c4x / c4x-c.c
1 /* Subroutines for the C front end on the TMS320C[34]x
2    Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
3    Free Software Foundation, Inc.
4
5    Contributed by Michael Hayes (m.hayes@elec.canterbury.ac.nz)
6               and Herman Ten Brugge (Haj.Ten.Brugge@net.HCC.nl).
7
8 This file is part of GNU CC.
9
10 GNU CC is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2, or (at your option)
13 any later version.
14
15 GNU CC is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with GNU CC; see the file COPYING.  If not, write to
22 the Free Software Foundation, 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.  */
24
25 #include "config.h"
26 #include "system.h"
27 #include "tree.h"
28 #include "toplev.h"
29 #include "cpplib.h"
30 #include "c-pragma.h"
31 #include "c-lex.h"
32 #include "c4x-protos.h"
33
34 static int c4x_parse_pragma PARAMS ((const char *, tree *, tree *));
35
36 /* Handle machine specific pragmas for compatibility with existing
37    compilers for the C3x/C4x.
38
39    pragma                                  attribute
40    ----------------------------------------------------------
41    CODE_SECTION(symbol,"section")          section("section")
42    DATA_SECTION(symbol,"section")          section("section")
43    FUNC_CANNOT_INLINE(function)            
44    FUNC_EXT_CALLED(function)               
45    FUNC_IS_PURE(function)                  const
46    FUNC_IS_SYSTEM(function)                
47    FUNC_NEVER_RETURNS(function)            noreturn
48    FUNC_NO_GLOBAL_ASG(function)            
49    FUNC_NO_IND_ASG(function)               
50    INTERRUPT(function)                     interrupt
51
52    */
53
54 /* Parse a C4x pragma, of the form ( function [, "section"] ) \n.
55    FUNC is loaded with the IDENTIFIER_NODE of the function, SECT with
56    the STRING_CST node of the string.  If SECT is null, then this
57    pragma doesn't take a section string.  Returns 0 for a good pragma,
58    -1 for a malformed pragma.  */
59 #define BAD(msgid, arg) do { warning (msgid, arg); return -1; } while (0)
60
61 static int
62 c4x_parse_pragma (name, func, sect)
63      const char *name;
64      tree *func;
65      tree *sect;
66 {
67   tree f, s, x;
68
69   if (c_lex (&x) != CPP_OPEN_PAREN)
70     BAD ("missing '(' after '#pragma %s' - ignored", name);
71
72   if (c_lex (&f) != CPP_NAME)
73     BAD ("missing function name in '#pragma %s' - ignored", name);
74
75   if (sect)
76     {
77       if (c_lex (&x) != CPP_COMMA)
78         BAD ("malformed '#pragma %s' - ignored", name);
79       if (c_lex (&s) != CPP_STRING)
80         BAD ("missing section name in '#pragma %s' - ignored", name);
81       *sect = s;
82     }
83
84   if (c_lex (&x) != CPP_CLOSE_PAREN)
85     BAD ("missing ')' for '#pragma %s' - ignored", name);
86
87   if (c_lex (&x) != CPP_EOF)
88     warning ("junk at end of '#pragma %s'", name);
89
90   *func = f;
91   return 0;
92 }
93
94 void
95 c4x_pr_CODE_SECTION (pfile)
96      cpp_reader *pfile ATTRIBUTE_UNUSED;
97 {
98   tree func, sect;
99
100   if (c4x_parse_pragma ("CODE_SECTION", &func, &sect))
101     return;
102   code_tree = chainon (code_tree,
103                        build_tree_list (func,
104                                         build_tree_list (NULL_TREE, sect)));
105 }
106
107 void
108 c4x_pr_DATA_SECTION (pfile)
109      cpp_reader *pfile ATTRIBUTE_UNUSED;
110 {
111   tree func, sect;
112
113   if (c4x_parse_pragma ("DATA_SECTION", &func, &sect))
114     return;
115   data_tree = chainon (data_tree,
116                        build_tree_list (func,
117                                         build_tree_list (NULL_TREE, sect)));
118 }
119
120 void
121 c4x_pr_FUNC_IS_PURE (pfile)
122      cpp_reader *pfile ATTRIBUTE_UNUSED;
123 {
124   tree func;
125
126   if (c4x_parse_pragma ("FUNC_IS_PURE", &func, 0))
127     return;
128   pure_tree = chainon (pure_tree, build_tree_list (func, NULL_TREE));
129 }
130
131 void
132 c4x_pr_FUNC_NEVER_RETURNS (pfile)
133      cpp_reader *pfile ATTRIBUTE_UNUSED;
134 {
135   tree func;
136
137   if (c4x_parse_pragma ("FUNC_NEVER_RETURNS", &func, 0))
138     return;
139   noreturn_tree = chainon (noreturn_tree, build_tree_list (func, NULL_TREE));
140 }
141
142 void
143 c4x_pr_INTERRUPT (pfile)
144      cpp_reader *pfile ATTRIBUTE_UNUSED;
145 {
146   tree func;
147
148   if (c4x_parse_pragma ("INTERRUPT", &func, 0))
149     return;
150   interrupt_tree = chainon (interrupt_tree, build_tree_list (func, NULL_TREE));
151 }
152
153 /* Used for FUNC_CANNOT_INLINE, FUNC_EXT_CALLED, FUNC_IS_SYSTEM,
154    FUNC_NO_GLOBAL_ASG, and FUNC_NO_IND_ASG.  */
155 void
156 c4x_pr_ignored (pfile)
157      cpp_reader *pfile ATTRIBUTE_UNUSED;
158 {
159 }