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 "tm_p.h"
32
33 static int c4x_parse_pragma PARAMS ((const char *, tree *, tree *));
34
35 /* Handle machine specific pragmas for compatibility with existing
36 compilers for the C3x/C4x.
37
38 pragma attribute
39 ----------------------------------------------------------
40 CODE_SECTION(symbol,"section") section("section")
41 DATA_SECTION(symbol,"section") section("section")
42 FUNC_CANNOT_INLINE(function)
43 FUNC_EXT_CALLED(function)
44 FUNC_IS_PURE(function) const
45 FUNC_IS_SYSTEM(function)
46 FUNC_NEVER_RETURNS(function) noreturn
47 FUNC_NO_GLOBAL_ASG(function)
48 FUNC_NO_IND_ASG(function)
49 INTERRUPT(function) interrupt
50
51 */
52
53 /* Parse a C4x pragma, of the form ( function [, "section"] ) \n.
54 FUNC is loaded with the IDENTIFIER_NODE of the function, SECT with
55 the STRING_CST node of the string. If SECT is null, then this
56 pragma doesn't take a section string. Returns 0 for a good pragma,
57 -1 for a malformed pragma. */
58 #define BAD(msgid, arg) do { warning (msgid, arg); return -1; } while (0)
59
60 static int
c4x_parse_pragma(name,func,sect)61 c4x_parse_pragma (name, func, sect)
62 const char *name;
63 tree *func;
64 tree *sect;
65 {
66 tree f, s, x;
67
68 if (c_lex (&x) != CPP_OPEN_PAREN)
69 BAD ("missing '(' after '#pragma %s' - ignored", name);
70
71 if (c_lex (&f) != CPP_NAME)
72 BAD ("missing function name in '#pragma %s' - ignored", name);
73
74 if (sect)
75 {
76 if (c_lex (&x) != CPP_COMMA)
77 BAD ("malformed '#pragma %s' - ignored", name);
78 if (c_lex (&s) != CPP_STRING)
79 BAD ("missing section name in '#pragma %s' - ignored", name);
80 *sect = s;
81 }
82
83 if (c_lex (&x) != CPP_CLOSE_PAREN)
84 BAD ("missing ')' for '#pragma %s' - ignored", name);
85
86 if (c_lex (&x) != CPP_EOF)
87 warning ("junk at end of '#pragma %s'", name);
88
89 *func = f;
90 return 0;
91 }
92
93 void
c4x_pr_CODE_SECTION(pfile)94 c4x_pr_CODE_SECTION (pfile)
95 cpp_reader *pfile ATTRIBUTE_UNUSED;
96 {
97 tree func, sect;
98
99 if (c4x_parse_pragma ("CODE_SECTION", &func, §))
100 return;
101 code_tree = chainon (code_tree,
102 build_tree_list (func,
103 build_tree_list (NULL_TREE, sect)));
104 }
105
106 void
c4x_pr_DATA_SECTION(pfile)107 c4x_pr_DATA_SECTION (pfile)
108 cpp_reader *pfile ATTRIBUTE_UNUSED;
109 {
110 tree func, sect;
111
112 if (c4x_parse_pragma ("DATA_SECTION", &func, §))
113 return;
114 data_tree = chainon (data_tree,
115 build_tree_list (func,
116 build_tree_list (NULL_TREE, sect)));
117 }
118
119 void
c4x_pr_FUNC_IS_PURE(pfile)120 c4x_pr_FUNC_IS_PURE (pfile)
121 cpp_reader *pfile ATTRIBUTE_UNUSED;
122 {
123 tree func;
124
125 if (c4x_parse_pragma ("FUNC_IS_PURE", &func, 0))
126 return;
127 pure_tree = chainon (pure_tree, build_tree_list (func, NULL_TREE));
128 }
129
130 void
c4x_pr_FUNC_NEVER_RETURNS(pfile)131 c4x_pr_FUNC_NEVER_RETURNS (pfile)
132 cpp_reader *pfile ATTRIBUTE_UNUSED;
133 {
134 tree func;
135
136 if (c4x_parse_pragma ("FUNC_NEVER_RETURNS", &func, 0))
137 return;
138 noreturn_tree = chainon (noreturn_tree, build_tree_list (func, NULL_TREE));
139 }
140
141 void
c4x_pr_INTERRUPT(pfile)142 c4x_pr_INTERRUPT (pfile)
143 cpp_reader *pfile ATTRIBUTE_UNUSED;
144 {
145 tree func;
146
147 if (c4x_parse_pragma ("INTERRUPT", &func, 0))
148 return;
149 interrupt_tree = chainon (interrupt_tree, build_tree_list (func, NULL_TREE));
150 }
151
152 /* Used for FUNC_CANNOT_INLINE, FUNC_EXT_CALLED, FUNC_IS_SYSTEM,
153 FUNC_NO_GLOBAL_ASG, and FUNC_NO_IND_ASG. */
154 void
c4x_pr_ignored(pfile)155 c4x_pr_ignored (pfile)
156 cpp_reader *pfile ATTRIBUTE_UNUSED;
157 {
158 }
159