1 /* VMS specific, C compiler specific functions.
2 Copyright (C) 2011-2015 Free Software Foundation, Inc.
3 Contributed by Tristan Gingold (gingold@adacore.com).
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
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/>. */
23 #include "coretypes.h"
26 #include "c-family/c-common.h"
29 #include "c-family/c-pragma.h"
33 /* '#pragma __nostandard' is simply ignored. */
36 vms_pragma_nostandard (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
40 if (pragma_lex (&x
) != CPP_EOF
)
41 warning (OPT_Wpragmas
, "junk at end of #pragma __nostandard");
44 /* '#pragma __standard' is simply ignored. */
47 vms_pragma_standard (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
51 if (pragma_lex (&x
) != CPP_EOF
)
52 warning (OPT_Wpragmas
, "junk at end of #pragma __standard");
55 /* Saved member alignment. */
56 static int saved_member_alignment
;
58 /* Handle '#pragma member_alignment'. */
61 vms_pragma_member_alignment (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
67 tok
= pragma_lex (&x
);
71 /* Disable packing. */
72 maximum_field_alignment
= initial_max_fld_align
;
77 warning (OPT_Wpragmas
, "malformed '#pragma member_alignment', ignoring");
81 arg
= IDENTIFIER_POINTER (x
);
82 /* Accept '__' prefix. */
83 if (arg
[0] == '_' && arg
[1] == '_')
86 if (strcmp (arg
, "save") == 0)
87 saved_member_alignment
= maximum_field_alignment
;
88 else if (strcmp (arg
, "restore") == 0)
89 maximum_field_alignment
= saved_member_alignment
;
92 error ("unknown '#pragma member_alignment' name %s", arg
);
95 if (pragma_lex (&x
) != CPP_EOF
)
97 error ("malformed '#pragma member_alignment'");
102 /* Handle '#pragma nomember_alignment'. */
105 vms_pragma_nomember_alignment (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
110 tok
= pragma_lex (&x
);
113 const char *arg
= IDENTIFIER_POINTER (x
);
115 /* Accept '__' prefix. */
116 if (arg
[0] == '_' && arg
[1] == '_')
119 if (strcmp (arg
, "byte") == 0)
120 maximum_field_alignment
= 1 * BITS_PER_UNIT
;
121 else if (strcmp (arg
, "word") == 0)
122 maximum_field_alignment
= 2 * BITS_PER_UNIT
;
123 else if (strcmp (arg
, "longword") == 0)
124 maximum_field_alignment
= 4 * BITS_PER_UNIT
;
125 else if (strcmp (arg
, "quadword") == 0)
126 maximum_field_alignment
= 8 * BITS_PER_UNIT
;
127 else if (strcmp (arg
, "octaword") == 0)
128 maximum_field_alignment
= 16 * BITS_PER_UNIT
;
131 error ("unhandled alignment for '#pragma nomember_alignment'");
134 tok
= pragma_lex (&x
);
138 /* Enable packing. */
139 maximum_field_alignment
= BITS_PER_UNIT
;
144 error ("garbage at end of '#pragma nomember_alignment'");
149 /* The 'extern model' for public data. This drives how the following
150 declarations are handled:
154 See below for the behaviour as implemented by the native compiler.
157 enum extern_model_kind
159 /* Create one overlaid section per variable. All the above declarations (1,
160 2 and 3) are handled the same way: they create an overlaid section named
161 NAME (and initialized only for 3). No global symbol is created.
162 This is the VAX C behavior. */
163 extern_model_common_block
,
165 /* Like unix: multiple not-initialized declarations are allowed.
166 Only one initialized definition (case 3) is allows, but multiple
167 uninitialize definition (case 2) are allowed.
168 For case 2, this creates both a section named NAME and a global symbol.
169 For case 3, this creates a conditional global symbol defenition and a
170 conditional section definition.
171 This is the traditional UNIX C behavior. */
172 extern_model_relaxed_refdef
,
174 /* Like -fno-common. Only one definition (cases 2 and 3) are allowed.
175 This is the ANSI-C model. */
176 extern_model_strict_refdef
,
178 /* Declarations creates symbols without storage. */
179 extern_model_globalvalue
182 /* Current and saved extern model. */
183 static enum extern_model_kind current_extern_model
;
184 static enum extern_model_kind saved_extern_model
;
186 /* Partial handling of '#pragma extern_model'. */
189 vms_pragma_extern_model (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
195 tok
= pragma_lex (&x
);
199 warning (OPT_Wpragmas
, "malformed '#pragma extern_model', ignoring");
203 arg
= IDENTIFIER_POINTER (x
);
204 /* Accept "__" prefix. */
205 if (arg
[0] == '_' && arg
[1] == '_')
208 if (strcmp (arg
, "save") == 0)
209 saved_extern_model
= current_extern_model
;
210 else if (strcmp (arg
, "restore") == 0)
211 current_extern_model
= saved_extern_model
;
212 else if (strcmp (arg
, "relaxed_refdef") == 0)
213 current_extern_model
= extern_model_relaxed_refdef
;
214 else if (strcmp (arg
, "strict_refdef") == 0)
215 current_extern_model
= extern_model_strict_refdef
;
216 else if (strcmp (arg
, "common_block") == 0)
217 current_extern_model
= extern_model_common_block
;
218 else if (strcmp (arg
, "globalvalue") == 0)
220 sorry ("extern model globalvalue");
225 error ("unknown '#pragma extern_model' model '%s'", arg
);
229 if (pragma_lex (&x
) != CPP_EOF
)
231 permerror (input_location
, "junk at end of '#pragma extern_model'");
237 /* Ignore '#pragma message'. */
240 vms_pragma_message (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
242 /* Completly ignored. */
244 pedwarn (input_location
, OPT_Wpragmas
,
245 "vms '#pragma __message' is ignored");
249 /* Handle '#pragma __extern_prefix' */
251 static GTY(()) tree saved_extern_prefix
;
254 vms_pragma_extern_prefix (cpp_reader
* ARG_UNUSED (dummy
))
259 tok
= pragma_lex (&x
);
262 const char *op
= IDENTIFIER_POINTER (x
);
264 if (!strcmp (op
, "__save"))
265 saved_extern_prefix
= pragma_extern_prefix
;
266 else if (!strcmp (op
, "__restore"))
267 pragma_extern_prefix
= saved_extern_prefix
;
269 warning (OPT_Wpragmas
,
270 "malformed '#pragma __extern_prefix', ignoring");
273 else if (tok
!= CPP_STRING
)
275 warning (OPT_Wpragmas
,
276 "malformed '#pragma __extern_prefix', ignoring");
280 /* Note that the length includes the null terminator. */
281 pragma_extern_prefix
= (TREE_STRING_LENGTH (x
) > 1 ? x
: NULL
);
285 /* #pragma __pointer_size */
287 static machine_mode saved_pointer_mode
;
290 handle_pragma_pointer_size (const char *pragma_name
)
295 tok
= pragma_lex (&x
);
298 const char *op
= IDENTIFIER_POINTER (x
);
300 if (!strcmp (op
, "__save"))
301 saved_pointer_mode
= c_default_pointer_mode
;
302 else if (!strcmp (op
, "__restore"))
303 c_default_pointer_mode
= saved_pointer_mode
;
304 else if (!strcmp (op
, "__short"))
305 c_default_pointer_mode
= SImode
;
306 else if (!strcmp (op
, "__long"))
307 c_default_pointer_mode
= DImode
;
309 error ("malformed %<#pragma %s%>, ignoring", pragma_name
);
311 else if (tok
== CPP_NUMBER
)
315 if (TREE_CODE (x
) == INTEGER_CST
)
316 val
= TREE_INT_CST_LOW (x
);
321 c_default_pointer_mode
= SImode
;
323 c_default_pointer_mode
= DImode
;
325 error ("invalid constant in %<#pragma %s%>", pragma_name
);
329 error ("malformed %<#pragma %s%>, ignoring", pragma_name
);
334 vms_pragma_pointer_size (cpp_reader
* ARG_UNUSED (dummy
))
336 /* Ignore if no -mpointer-size option. */
337 if (flag_vms_pointer_size
== VMS_POINTER_SIZE_NONE
)
340 handle_pragma_pointer_size ("pointer_size");
344 vms_pragma_required_pointer_size (cpp_reader
* ARG_UNUSED (dummy
))
346 handle_pragma_pointer_size ("required_pointer_size");
349 /* Add vms-specific pragma. */
352 vms_c_register_pragma (void)
354 c_register_pragma (NULL
, "__nostandard", vms_pragma_nostandard
);
355 c_register_pragma (NULL
, "nostandard", vms_pragma_nostandard
);
356 c_register_pragma (NULL
, "__standard", vms_pragma_standard
);
357 c_register_pragma (NULL
, "standard", vms_pragma_standard
);
358 c_register_pragma (NULL
, "__member_alignment", vms_pragma_member_alignment
);
359 c_register_pragma (NULL
, "member_alignment", vms_pragma_member_alignment
);
360 c_register_pragma_with_expansion (NULL
, "__nomember_alignment",
361 vms_pragma_nomember_alignment
);
362 c_register_pragma_with_expansion (NULL
, "nomember_alignment",
363 vms_pragma_nomember_alignment
);
364 c_register_pragma (NULL
, "__pointer_size",
365 vms_pragma_pointer_size
);
366 c_register_pragma (NULL
, "__required_pointer_size",
367 vms_pragma_required_pointer_size
);
368 c_register_pragma (NULL
, "__extern_model", vms_pragma_extern_model
);
369 c_register_pragma (NULL
, "extern_model", vms_pragma_extern_model
);
370 c_register_pragma (NULL
, "__message", vms_pragma_message
);
371 c_register_pragma (NULL
, "__extern_prefix", vms_pragma_extern_prefix
);
374 /* Canonicalize the filename (remove directory prefix, force the .h extension),
375 and append it to the directory to create the path, but don't
376 turn / into // or // into ///; // may be a namespace escape. */
379 vms_construct_include_filename (const char *fname
, cpp_dir
*dir
)
383 const char *fbasename
= lbasename (fname
);
387 flen
= strlen (fbasename
) + 2;
388 path
= XNEWVEC (char, dlen
+ 1 + flen
+ 1);
389 memcpy (path
, dir
->name
, dlen
);
390 if (dlen
&& !IS_DIR_SEPARATOR (path
[dlen
- 1]))
392 for (i
= 0; i
< flen
; i
++)
393 if (fbasename
[i
] == '.')
396 path
[dlen
+ i
] = TOLOWER (fbasename
[i
]);
397 path
[dlen
+ i
+ 0] = '.';
398 path
[dlen
+ i
+ 1] = 'h';
399 path
[dlen
+ i
+ 2] = 0;
404 /* Standard modules list. */
405 static const char * const vms_std_modules
[] = { "rtldef", "starlet_c", NULL
};
407 /* Find include modules in the include path. */
410 vms_c_register_includes (const char *sysroot
,
411 const char *iprefix ATTRIBUTE_UNUSED
, int stdinc
)
413 static const char dir_separator_str
[] = { DIR_SEPARATOR
, 0 };
416 /* Add on standard include pathes. */
420 for (dir
= get_added_cpp_dirs (SYSTEM
); dir
!= NULL
; dir
= dir
->next
)
422 const char * const *lib
;
423 for (lib
= vms_std_modules
; *lib
!= NULL
; lib
++)
429 path
= concat (sysroot
, dir
->name
, dir_separator_str
, *lib
, NULL
);
431 path
= concat (dir
->name
, dir_separator_str
, *lib
, NULL
);
433 if (stat (path
, &st
) == 0 && S_ISDIR (st
.st_mode
))
441 p
->construct
= vms_construct_include_filename
;
442 p
->user_supplied_p
= 0;
443 add_cpp_dir_path (p
, SYSTEM
);
452 vms_c_common_override_options (void)
454 /* Allow variadic functions without parameters (as declared in starlet). */
455 flag_allow_parameterless_variadic_functions
= TRUE
;
457 /* Initialize c_default_pointer_mode. */
458 switch (flag_vms_pointer_size
)
460 case VMS_POINTER_SIZE_NONE
:
462 case VMS_POINTER_SIZE_32
:
463 c_default_pointer_mode
= SImode
;
465 case VMS_POINTER_SIZE_64
:
466 c_default_pointer_mode
= DImode
;
471 /* The default value for _CRTL_VER macro. */
474 vms_c_get_crtl_ver (void)
476 return VMS_DEFAULT_CRTL_VER
;
479 /* The default value for _VMS_VER macro. */
482 vms_c_get_vms_ver (void)
484 return VMS_DEFAULT_VMS_VER
;