1 /* VMS specific, C compiler specific functions.
2 Copyright (C) 2011-2023 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/>. */
21 #define IN_TARGET_CODE 1
25 #include "coretypes.h"
28 #include "c-family/c-common.h"
32 #include "c-family/c-pragma.h"
36 /* '#pragma __nostandard' is simply ignored. */
39 vms_pragma_nostandard (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
43 if (pragma_lex (&x
) != CPP_EOF
)
44 warning (OPT_Wpragmas
, "junk at end of %<#pragma __nostandard%>");
47 /* '#pragma __standard' is simply ignored. */
50 vms_pragma_standard (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
54 if (pragma_lex (&x
) != CPP_EOF
)
55 warning (OPT_Wpragmas
, "junk at end of %<#pragma __standard%>");
58 /* Saved member alignment. */
59 static int saved_member_alignment
;
61 /* Handle '#pragma member_alignment'. */
64 vms_pragma_member_alignment (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
70 tok
= pragma_lex (&x
);
74 /* Disable packing. */
75 maximum_field_alignment
= initial_max_fld_align
;
80 warning (OPT_Wpragmas
,
81 "malformed %<#pragma member_alignment%>, ignoring");
85 arg
= IDENTIFIER_POINTER (x
);
86 /* Accept '__' prefix. */
87 if (arg
[0] == '_' && arg
[1] == '_')
90 if (strcmp (arg
, "save") == 0)
91 saved_member_alignment
= maximum_field_alignment
;
92 else if (strcmp (arg
, "restore") == 0)
93 maximum_field_alignment
= saved_member_alignment
;
96 error ("unknown %<#pragma member_alignment%> name %s", arg
);
99 if (pragma_lex (&x
) != CPP_EOF
)
101 error ("malformed %<#pragma member_alignment%>");
106 /* Handle '#pragma nomember_alignment'. */
109 vms_pragma_nomember_alignment (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
114 tok
= pragma_lex (&x
);
117 const char *arg
= IDENTIFIER_POINTER (x
);
119 /* Accept '__' prefix. */
120 if (arg
[0] == '_' && arg
[1] == '_')
123 if (strcmp (arg
, "byte") == 0)
124 maximum_field_alignment
= 1 * BITS_PER_UNIT
;
125 else if (strcmp (arg
, "word") == 0)
126 maximum_field_alignment
= 2 * BITS_PER_UNIT
;
127 else if (strcmp (arg
, "longword") == 0)
128 maximum_field_alignment
= 4 * BITS_PER_UNIT
;
129 else if (strcmp (arg
, "quadword") == 0)
130 maximum_field_alignment
= 8 * BITS_PER_UNIT
;
131 else if (strcmp (arg
, "octaword") == 0)
132 maximum_field_alignment
= 16 * BITS_PER_UNIT
;
135 error ("unhandled alignment for %<#pragma nomember_alignment%>");
138 tok
= pragma_lex (&x
);
142 /* Enable packing. */
143 maximum_field_alignment
= BITS_PER_UNIT
;
148 error ("garbage at end of %<#pragma nomember_alignment%>");
153 /* The 'extern model' for public data. This drives how the following
154 declarations are handled:
158 See below for the behavior as implemented by the native compiler.
161 enum extern_model_kind
163 /* Create one overlaid section per variable. All the above declarations (1,
164 2 and 3) are handled the same way: they create an overlaid section named
165 NAME (and initialized only for 3). No global symbol is created.
166 This is the VAX C behavior. */
167 extern_model_common_block
,
169 /* Like unix: multiple not-initialized declarations are allowed.
170 Only one initialized definition (case 3) is allows, but multiple
171 uninitialize definition (case 2) are allowed.
172 For case 2, this creates both a section named NAME and a global symbol.
173 For case 3, this creates a conditional global symbol defenition and a
174 conditional section definition.
175 This is the traditional UNIX C behavior. */
176 extern_model_relaxed_refdef
,
178 /* Like -fno-common. Only one definition (cases 2 and 3) are allowed.
179 This is the ANSI-C model. */
180 extern_model_strict_refdef
,
182 /* Declarations creates symbols without storage. */
183 extern_model_globalvalue
186 /* Current and saved extern model. */
187 static enum extern_model_kind current_extern_model
;
188 static enum extern_model_kind saved_extern_model
;
190 /* Partial handling of '#pragma extern_model'. */
193 vms_pragma_extern_model (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
199 tok
= pragma_lex (&x
);
203 warning (OPT_Wpragmas
, "malformed %<#pragma extern_model%>, ignoring");
207 arg
= IDENTIFIER_POINTER (x
);
208 /* Accept "__" prefix. */
209 if (arg
[0] == '_' && arg
[1] == '_')
212 if (strcmp (arg
, "save") == 0)
213 saved_extern_model
= current_extern_model
;
214 else if (strcmp (arg
, "restore") == 0)
215 current_extern_model
= saved_extern_model
;
216 else if (strcmp (arg
, "relaxed_refdef") == 0)
217 current_extern_model
= extern_model_relaxed_refdef
;
218 else if (strcmp (arg
, "strict_refdef") == 0)
219 current_extern_model
= extern_model_strict_refdef
;
220 else if (strcmp (arg
, "common_block") == 0)
221 current_extern_model
= extern_model_common_block
;
222 else if (strcmp (arg
, "globalvalue") == 0)
224 sorry ("extern model globalvalue");
229 error ("unknown %<#pragma extern_model%> model %qs", arg
);
233 if (pragma_lex (&x
) != CPP_EOF
)
235 permerror (input_location
, "junk at end of '#pragma extern_model'");
241 /* Ignore '#pragma message'. */
244 vms_pragma_message (cpp_reader
*pfile ATTRIBUTE_UNUSED
)
246 /* Completly ignored. */
248 pedwarn (input_location
, OPT_Wpragmas
,
249 "vms '#pragma __message' is ignored");
253 /* Handle '#pragma __extern_prefix' */
255 static GTY(()) tree saved_extern_prefix
;
258 vms_pragma_extern_prefix (cpp_reader
* ARG_UNUSED (dummy
))
263 tok
= pragma_lex (&x
);
266 const char *op
= IDENTIFIER_POINTER (x
);
268 if (!strcmp (op
, "__save"))
269 saved_extern_prefix
= pragma_extern_prefix
;
270 else if (!strcmp (op
, "__restore"))
271 pragma_extern_prefix
= saved_extern_prefix
;
273 warning (OPT_Wpragmas
,
274 "malformed %<#pragma __extern_prefix%>, ignoring");
277 else if (tok
!= CPP_STRING
)
279 warning (OPT_Wpragmas
,
280 "malformed %<#pragma __extern_prefix%>, ignoring");
284 /* Note that the length includes the null terminator. */
285 pragma_extern_prefix
= (TREE_STRING_LENGTH (x
) > 1 ? x
: NULL
);
289 /* #pragma __pointer_size */
291 static machine_mode saved_pointer_mode
;
294 handle_pragma_pointer_size (const char *pragma_name
)
299 tok
= pragma_lex (&x
);
302 const char *op
= IDENTIFIER_POINTER (x
);
304 if (!strcmp (op
, "__save"))
305 saved_pointer_mode
= c_default_pointer_mode
;
306 else if (!strcmp (op
, "__restore"))
307 c_default_pointer_mode
= saved_pointer_mode
;
308 else if (!strcmp (op
, "__short"))
309 c_default_pointer_mode
= SImode
;
310 else if (!strcmp (op
, "__long"))
311 c_default_pointer_mode
= DImode
;
313 error ("malformed %<#pragma %s%>, ignoring", pragma_name
);
315 else if (tok
== CPP_NUMBER
)
319 if (TREE_CODE (x
) == INTEGER_CST
)
320 val
= TREE_INT_CST_LOW (x
);
325 c_default_pointer_mode
= SImode
;
327 c_default_pointer_mode
= DImode
;
329 error ("invalid constant in %<#pragma %s%>", pragma_name
);
333 error ("malformed %<#pragma %s%>, ignoring", pragma_name
);
338 vms_pragma_pointer_size (cpp_reader
* ARG_UNUSED (dummy
))
340 /* Ignore if no -mpointer-size option. */
341 if (flag_vms_pointer_size
== VMS_POINTER_SIZE_NONE
)
344 handle_pragma_pointer_size ("pointer_size");
348 vms_pragma_required_pointer_size (cpp_reader
* ARG_UNUSED (dummy
))
350 handle_pragma_pointer_size ("required_pointer_size");
353 /* Add vms-specific pragma. */
356 vms_c_register_pragma (void)
358 c_register_pragma (NULL
, "__nostandard", vms_pragma_nostandard
);
359 c_register_pragma (NULL
, "nostandard", vms_pragma_nostandard
);
360 c_register_pragma (NULL
, "__standard", vms_pragma_standard
);
361 c_register_pragma (NULL
, "standard", vms_pragma_standard
);
362 c_register_pragma (NULL
, "__member_alignment", vms_pragma_member_alignment
);
363 c_register_pragma (NULL
, "member_alignment", vms_pragma_member_alignment
);
364 c_register_pragma_with_expansion (NULL
, "__nomember_alignment",
365 vms_pragma_nomember_alignment
);
366 c_register_pragma_with_expansion (NULL
, "nomember_alignment",
367 vms_pragma_nomember_alignment
);
368 c_register_pragma (NULL
, "__pointer_size",
369 vms_pragma_pointer_size
);
370 c_register_pragma (NULL
, "__required_pointer_size",
371 vms_pragma_required_pointer_size
);
372 c_register_pragma (NULL
, "__extern_model", vms_pragma_extern_model
);
373 c_register_pragma (NULL
, "extern_model", vms_pragma_extern_model
);
374 c_register_pragma (NULL
, "__message", vms_pragma_message
);
375 c_register_pragma (NULL
, "__extern_prefix", vms_pragma_extern_prefix
);
378 /* Canonicalize the filename (remove directory prefix, force the .h extension),
379 and append it to the directory to create the path, but don't
380 turn / into // or // into ///; // may be a namespace escape. */
383 vms_construct_include_filename (const char *fname
, cpp_dir
*dir
)
387 const char *fbasename
= lbasename (fname
);
391 flen
= strlen (fbasename
) + 2;
392 path
= XNEWVEC (char, dlen
+ 1 + flen
+ 1);
393 memcpy (path
, dir
->name
, dlen
);
394 if (dlen
&& !IS_DIR_SEPARATOR (path
[dlen
- 1]))
396 for (i
= 0; i
< flen
; i
++)
397 if (fbasename
[i
] == '.')
400 path
[dlen
+ i
] = TOLOWER (fbasename
[i
]);
401 path
[dlen
+ i
+ 0] = '.';
402 path
[dlen
+ i
+ 1] = 'h';
403 path
[dlen
+ i
+ 2] = 0;
408 /* Standard modules list. */
409 static const char * const vms_std_modules
[] = { "rtldef", "starlet_c", NULL
};
411 /* Find include modules in the include path. */
414 vms_c_register_includes (const char *sysroot
,
415 const char *iprefix ATTRIBUTE_UNUSED
, int stdinc
)
417 static const char dir_separator_str
[] = { DIR_SEPARATOR
, 0 };
420 /* Add on standard include pathes. */
424 for (dir
= get_added_cpp_dirs (INC_SYSTEM
); dir
!= NULL
; dir
= dir
->next
)
426 const char * const *lib
;
427 for (lib
= vms_std_modules
; *lib
!= NULL
; lib
++)
433 path
= concat (sysroot
, dir
->name
, dir_separator_str
, *lib
, NULL
);
435 path
= concat (dir
->name
, dir_separator_str
, *lib
, NULL
);
437 if (stat (path
, &st
) == 0 && S_ISDIR (st
.st_mode
))
445 p
->construct
= vms_construct_include_filename
;
446 p
->user_supplied_p
= 0;
447 add_cpp_dir_path (p
, INC_SYSTEM
);
456 vms_c_common_override_options (void)
458 /* Initialize c_default_pointer_mode. */
459 switch (flag_vms_pointer_size
)
461 case VMS_POINTER_SIZE_NONE
:
463 case VMS_POINTER_SIZE_32
:
464 c_default_pointer_mode
= SImode
;
466 case VMS_POINTER_SIZE_64
:
467 c_default_pointer_mode
= DImode
;
472 /* The default value for _CRTL_VER macro. */
475 vms_c_get_crtl_ver (void)
477 return VMS_DEFAULT_CRTL_VER
;
480 /* The default value for _VMS_VER macro. */
483 vms_c_get_vms_ver (void)
485 return VMS_DEFAULT_VMS_VER
;