00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "config.h"
00023 #include "system.h"
00024 #include "cpplib.h"
00025 #include "tree.h"
00026 #include "c-pragma.h"
00027 #include "c-lex.h"
00028 #include "toplev.h"
00029 #include "ggc.h"
00030 #include "tm_p.h"
00031
00032 #ifndef streq
00033 #define streq(a,b) (strcmp (a, b) == 0)
00034 #endif
00035
00036 static int pop_data_area PARAMS ((v850_data_area));
00037 static int push_data_area PARAMS ((v850_data_area));
00038 static void mark_current_function_as_interrupt PARAMS ((void));
00039
00040
00041
00042 static int
00043 push_data_area (data_area)
00044 v850_data_area data_area;
00045 {
00046 data_area_stack_element * elem;
00047
00048 elem = (data_area_stack_element *) xmalloc (sizeof (* elem));
00049
00050 if (elem == NULL)
00051 return 0;
00052
00053 elem->prev = data_area_stack;
00054 elem->data_area = data_area;
00055
00056 data_area_stack = elem;
00057
00058 return 1;
00059 }
00060
00061
00062
00063 static int
00064 pop_data_area (data_area)
00065 v850_data_area data_area;
00066 {
00067 if (data_area_stack == NULL)
00068 warning ("#pragma GHS endXXXX found without previous startXXX");
00069 else if (data_area != data_area_stack->data_area)
00070 warning ("#pragma GHS endXXX does not match previous startXXX");
00071 else
00072 {
00073 data_area_stack_element * elem;
00074
00075 elem = data_area_stack;
00076 data_area_stack = data_area_stack->prev;
00077
00078 free (elem);
00079
00080 return 1;
00081 }
00082
00083 return 0;
00084 }
00085
00086
00087
00088 static void
00089 mark_current_function_as_interrupt ()
00090 {
00091 tree name;
00092
00093 if (current_function_decl == NULL_TREE)
00094 {
00095 warning ("cannot set interrupt attribute: no current function");
00096 return;
00097 }
00098
00099 name = get_identifier ("interrupt");
00100
00101 if (name == NULL_TREE || TREE_CODE (name) != IDENTIFIER_NODE)
00102 {
00103 warning ("cannot set interrupt attribute: no such identifier");
00104 return;
00105 }
00106
00107 decl_attributes (¤t_function_decl,
00108 tree_cons (name, NULL_TREE, NULL_TREE), 0);
00109 }
00110
00111
00112
00113
00114 void
00115 ghs_pragma_section (pfile)
00116 cpp_reader *pfile ATTRIBUTE_UNUSED;
00117 {
00118 int repeat;
00119
00120
00121 do
00122 {
00123 tree x;
00124 enum cpp_ttype type;
00125 const char *sect, *alias;
00126 enum GHS_section_kind kind;
00127
00128 type = c_lex (&x);
00129
00130 if (type == CPP_EOF && !repeat)
00131 goto reset;
00132 else if (type == CPP_NAME)
00133 sect = IDENTIFIER_POINTER (x);
00134 else
00135 goto bad;
00136 repeat = 0;
00137
00138 if (c_lex (&x) != CPP_EQ)
00139 goto bad;
00140 if (c_lex (&x) != CPP_NAME)
00141 goto bad;
00142
00143 alias = IDENTIFIER_POINTER (x);
00144
00145 type = c_lex (&x);
00146 if (type == CPP_COMMA)
00147 repeat = 1;
00148 else if (type != CPP_EOF)
00149 warning ("junk at end of #pragma ghs section");
00150
00151 if (streq (sect, "data")) kind = GHS_SECTION_KIND_DATA;
00152 else if (streq (sect, "text")) kind = GHS_SECTION_KIND_TEXT;
00153 else if (streq (sect, "rodata")) kind = GHS_SECTION_KIND_RODATA;
00154 else if (streq (sect, "const")) kind = GHS_SECTION_KIND_RODATA;
00155 else if (streq (sect, "rosdata")) kind = GHS_SECTION_KIND_ROSDATA;
00156 else if (streq (sect, "rozdata")) kind = GHS_SECTION_KIND_ROZDATA;
00157 else if (streq (sect, "sdata")) kind = GHS_SECTION_KIND_SDATA;
00158 else if (streq (sect, "tdata")) kind = GHS_SECTION_KIND_TDATA;
00159 else if (streq (sect, "zdata")) kind = GHS_SECTION_KIND_ZDATA;
00160
00161
00162 else if (streq (sect, "bss")) kind = GHS_SECTION_KIND_BSS;
00163 else if (streq (sect, "zbss")) kind = GHS_SECTION_KIND_ZDATA;
00164 else
00165 {
00166 warning ("unrecognized section name \"%s\"", sect);
00167 return;
00168 }
00169
00170 if (streq (alias, "default"))
00171 GHS_current_section_names [kind] = NULL;
00172 else
00173 GHS_current_section_names [kind] =
00174 build_string (strlen (alias) + 1, alias);
00175 }
00176 while (repeat);
00177
00178 return;
00179
00180 bad:
00181 warning ("malformed #pragma ghs section");
00182 return;
00183
00184 reset:
00185
00186 {
00187 int i;
00188
00189 for (i = COUNT_OF_GHS_SECTION_KINDS; i--;)
00190 GHS_current_section_names [i] = NULL;
00191 }
00192 }
00193
00194 void
00195 ghs_pragma_interrupt (pfile)
00196 cpp_reader *pfile ATTRIBUTE_UNUSED;
00197 {
00198 tree x;
00199
00200 if (c_lex (&x) != CPP_EOF)
00201 warning ("junk at end of #pragma ghs interrupt");
00202
00203 mark_current_function_as_interrupt ();
00204 }
00205
00206 void
00207 ghs_pragma_starttda (pfile)
00208 cpp_reader *pfile ATTRIBUTE_UNUSED;
00209 {
00210 tree x;
00211
00212 if (c_lex (&x) != CPP_EOF)
00213 warning ("junk at end of #pragma ghs starttda");
00214
00215 push_data_area (DATA_AREA_TDA);
00216 }
00217
00218 void
00219 ghs_pragma_startsda (pfile)
00220 cpp_reader *pfile ATTRIBUTE_UNUSED;
00221 {
00222 tree x;
00223
00224 if (c_lex (&x) != CPP_EOF)
00225 warning ("junk at end of #pragma ghs startsda");
00226
00227 push_data_area (DATA_AREA_SDA);
00228 }
00229
00230 void
00231 ghs_pragma_startzda (pfile)
00232 cpp_reader *pfile ATTRIBUTE_UNUSED;
00233 {
00234 tree x;
00235
00236 if (c_lex (&x) != CPP_EOF)
00237 warning ("junk at end of #pragma ghs startzda");
00238
00239 push_data_area (DATA_AREA_ZDA);
00240 }
00241
00242 void
00243 ghs_pragma_endtda (pfile)
00244 cpp_reader *pfile ATTRIBUTE_UNUSED;
00245 {
00246 tree x;
00247
00248 if (c_lex (&x) != CPP_EOF)
00249 warning ("junk at end of #pragma ghs endtda");
00250
00251 pop_data_area (DATA_AREA_TDA);
00252 }
00253
00254 void
00255 ghs_pragma_endsda (pfile)
00256 cpp_reader *pfile ATTRIBUTE_UNUSED;
00257 {
00258 tree x;
00259
00260 if (c_lex (&x) != CPP_EOF)
00261 warning ("junk at end of #pragma ghs endsda");
00262
00263 pop_data_area (DATA_AREA_SDA);
00264 }
00265
00266 void
00267 ghs_pragma_endzda (pfile)
00268 cpp_reader *pfile ATTRIBUTE_UNUSED;
00269 {
00270 tree x;
00271
00272 if (c_lex (&x) != CPP_EOF)
00273 warning ("junk at end of #pragma ghs endzda");
00274
00275 pop_data_area (DATA_AREA_ZDA);
00276 }