]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/vms/vms.c
Factor unrelated declarations out of tree.h.
[thirdparty/gcc.git] / gcc / config / vms / vms.c
1 /* Definitions of target machine GNU compiler. 32bit VMS version.
2 Copyright (C) 2009-2013 Free Software Foundation, Inc.
3 Contributed by Douglas B Rupp (rupp@gnat.com).
4
5 This file is part of GCC.
6
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)
10 any later version.
11
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.
16
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/>. */
20
21 #include "config.h"
22 #include "system.h"
23 #include "coretypes.h"
24 #include "tree.h"
25 #include "stringpool.h"
26 #include "vms-protos.h"
27 #include "ggc.h"
28 #include "target.h"
29 #include "output.h"
30 #include "tm.h"
31 #include "dwarf2out.h"
32
33 /* Correlation of standard CRTL names with DECCRTL function names. */
34
35 /* Name is for a function that allocate memory. Use the 64bit version
36 if -mmalloc64. */
37 #define VMS_CRTL_MALLOC (1 << 0)
38
39 /* If long pointer are enabled, use _NAME64 instead. */
40 #define VMS_CRTL_64 (1 << 1)
41
42 /* Prepend s/f before the name. To be applied after the previous rule.
43 use 's' for S float, 'f' for IEEE 32. */
44 #define VMS_CRTL_FLOAT32 (1 << 2)
45
46 /* Prepend t/g/d before the name. To be applied after the previous rule.
47 use 'g' for VAX G float, 'd' for VAX D float, 't' for IEEE 64. */
48 #define VMS_CRTL_FLOAT64 (1 << 3)
49
50 /* Prepend d before the name, only if using VAX fp. */
51 #define VMS_CRTL_FLOAT64_VAXD (1 << 4)
52
53 /* Prepend x before the name for if 128 bit long doubles are enabled. This
54 concern mostly 'printf'-like functions. */
55 #define VMS_CRTL_FLOAT128 (1 << 5)
56
57 /* From xxx, create xxx, xxxf, xxxl using MATH$XXX_T, MATH$XXX_S
58 and MATH$XXX{_X} if DPML is used. */
59 #define VMS_CRTL_DPML (1 << 6)
60
61 /* Together with DPML, it means that all variant (ie xxx, xxxf and xxxl) are
62 overridden by decc. Without DPML, it means this is a variant (ie xxxf
63 or xxxl) of a function. */
64 #define VMS_CRTL_NODPML (1 << 7)
65
66 /* Prepend __bsd44_ before the name. To be applied after the P64
67 rule. */
68 #define VMS_CRTL_BSD44 (1 << 8)
69
70 /* Define only in 32 bits mode, as this has no 64 bit variants.
71 Concerns getopt/getarg. */
72 #define VMS_CRTL_32ONLY (1 << 9)
73
74 /* GLobal data prefix (ga_, gl_...) */
75 #define VMS_CRTL_G_MASK (7 << 10)
76 #define VMS_CRTL_G_NONE (0 << 10)
77 #define VMS_CRTL_GA (1 << 10)
78 #define VMS_CRTL_GL (2 << 10)
79
80 /* Append '_2'. Not compatible with 64. */
81 #define VMS_CRTL_FLOATV2 (1 << 13)
82
83 struct vms_crtl_name
84 {
85 /* The standard C name. */
86 const char *const name;
87
88 /* Flags to drive the translation. */
89 unsigned int flags;
90 };
91
92 /* Map for the translation. */
93
94 static const struct vms_crtl_name vms_crtl_names[] =
95 {
96 #include "vms-crtlmap.h"
97 };
98
99 /* Number of entires in the above array. */
100
101 #define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
102
103 /* List of aliased identifiers. They must be persistent across gc. */
104
105 static GTY(()) vec<tree, va_gc> *aliases_id;
106
107 /* Add a CRTL translation. This simply use the transparent alias
108 mechanism, which is platform independent and works with the
109 #pragma extern_prefix (which set the assembler name). */
110
111 static void
112 vms_add_crtl_xlat (const char *name, size_t nlen,
113 const char *id_str, size_t id_len)
114 {
115 tree targ;
116
117 /* printf ("vms crtl: %.*s -> %.*s\n", nlen, name, id_len, id_str); */
118
119 targ = get_identifier_with_length (name, nlen);
120 gcc_assert (!IDENTIFIER_TRANSPARENT_ALIAS (targ));
121 IDENTIFIER_TRANSPARENT_ALIAS (targ) = 1;
122 TREE_CHAIN (targ) = get_identifier_with_length (id_str, id_len);
123
124 vec_safe_push (aliases_id, targ);
125 }
126
127 /* Do VMS specific stuff on builtins: disable the ones that are not
128 standard, mangle names. */
129
130 void
131 vms_patch_builtins (void)
132 {
133 /* enum built_in_function bi; */
134 unsigned int i;
135
136 /* Fwrite on VMS is non-standard. */
137 if (builtin_decl_implicit_p (BUILT_IN_FWRITE))
138 set_builtin_decl_implicit_p (BUILT_IN_FWRITE, false);
139
140 if (builtin_decl_implicit_p (BUILT_IN_FWRITE_UNLOCKED))
141 set_builtin_decl_implicit_p (BUILT_IN_FWRITE_UNLOCKED, false);
142
143 /* Define aliases for names. */
144 for (i = 0; i < NBR_CRTL_NAMES; i++)
145 {
146 const struct vms_crtl_name *n = &vms_crtl_names[i];
147 char res[VMS_CRTL_MAXLEN + 3 + 9 + 1 + 1];
148 int rlen;
149 int nlen = strlen (n->name);
150
151 /* Discard 32ONLY if using 64 bit pointers. */
152 if ((n->flags & VMS_CRTL_32ONLY)
153 && flag_vms_pointer_size == VMS_POINTER_SIZE_64)
154 continue;
155
156 /* Handle DPML unless overridden by decc. */
157 if ((n->flags & VMS_CRTL_DPML)
158 && !(n->flags & VMS_CRTL_NODPML))
159 {
160 const char *p;
161 char alt[VMS_CRTL_MAXLEN + 3];
162
163 memcpy (res, "MATH$", 5);
164 rlen = 5;
165 for (p = n->name; *p; p++)
166 res[rlen++] = TOUPPER (*p);
167 res[rlen++] = '_';
168 res[rlen++] = 'T';
169
170 /* Double version. */
171 if (!(n->flags & VMS_CRTL_FLOAT64))
172 vms_add_crtl_xlat (n->name, nlen, res, rlen);
173
174 /* Float version. */
175 res[rlen - 1] = 'S';
176 memcpy (alt, n->name, nlen);
177 alt[nlen] = 'f';
178 vms_add_crtl_xlat (alt, nlen + 1, res, rlen);
179
180 /* Long double version. */
181 res[rlen - 1] = (LONG_DOUBLE_TYPE_SIZE == 128 ? 'X' : 'T');
182 alt[nlen] = 'l';
183 vms_add_crtl_xlat (alt, nlen + 1, res, rlen);
184
185 if (!(n->flags & (VMS_CRTL_FLOAT32 | VMS_CRTL_FLOAT64)))
186 continue;
187 }
188
189 if (n->flags & VMS_CRTL_FLOAT64_VAXD)
190 continue;
191
192 /* Add the dec-c prefix. */
193 memcpy (res, "decc$", 5);
194 rlen = 5;
195
196 if (n->flags & VMS_CRTL_BSD44)
197 {
198 memcpy (res + rlen, "__bsd44_", 8);
199 rlen += 8;
200 }
201
202 if ((n->flags & VMS_CRTL_G_MASK) != VMS_CRTL_G_NONE)
203 {
204 res[rlen++] = 'g';
205 switch (n->flags & VMS_CRTL_G_MASK)
206 {
207 case VMS_CRTL_GA:
208 res[rlen++] = 'a';
209 break;
210 case VMS_CRTL_GL:
211 res[rlen++] = 'l';
212 break;
213 default:
214 gcc_unreachable ();
215 }
216 res[rlen++] = '_';
217 }
218
219 if (n->flags & VMS_CRTL_FLOAT32)
220 res[rlen++] = 'f';
221
222 if (n->flags & VMS_CRTL_FLOAT64)
223 res[rlen++] = 't';
224
225 if ((n->flags & VMS_CRTL_FLOAT128) && LONG_DOUBLE_TYPE_SIZE == 128)
226 res[rlen++] = 'x';
227
228 memcpy (res + rlen, n->name, nlen);
229
230 if ((n->flags & VMS_CRTL_64) == 0)
231 {
232 rlen += nlen;
233
234 if (n->flags & VMS_CRTL_FLOATV2)
235 {
236 res[rlen++] = '_';
237 res[rlen++] = '2';
238 }
239 vms_add_crtl_xlat (n->name, nlen, res, rlen);
240 }
241 else
242 {
243 char alt[VMS_CRTL_MAXLEN + 3];
244 bool use_64;
245
246 /* Add three translations:
247 _X32 -> X
248 _X64 -> _X64
249 X -> X if short, _X64 if long. */
250 alt[0] = '_';
251 memcpy (alt + 1, n->name, nlen);
252 alt[1 + nlen + 0] = '3';
253 alt[1 + nlen + 1] = '2';
254 alt[1 + nlen + 2] = 0;
255 vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen);
256
257 use_64 = (((n->flags & VMS_CRTL_64)
258 && flag_vms_pointer_size == VMS_POINTER_SIZE_64)
259 || ((n->flags & VMS_CRTL_MALLOC)
260 && flag_vms_malloc64
261 && flag_vms_pointer_size != VMS_POINTER_SIZE_NONE));
262 if (!use_64)
263 vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen);
264
265 res[rlen++] = '_';
266 memcpy (res + rlen, n->name, nlen);
267 res[rlen + nlen + 0] = '6';
268 res[rlen + nlen + 1] = '4';
269
270 if (use_64)
271 vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen + 2);
272
273 alt[1 + nlen + 0] = '6';
274 alt[1 + nlen + 1] = '4';
275 vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen + 2);
276 }
277 }
278 }
279
280 /* Always default to .text section. */
281
282 section *
283 vms_function_section (tree decl ATTRIBUTE_UNUSED,
284 enum node_frequency freq ATTRIBUTE_UNUSED,
285 bool startup ATTRIBUTE_UNUSED,
286 bool exit ATTRIBUTE_UNUSED)
287 {
288 return NULL;
289 }
290
291 /* Additionnal VMS specific code for start_function. */
292
293 /* Must be kept in sync with libgcc/config/vms/vms-ucrt0.c */
294 #define VMS_MAIN_FLAGS_SYMBOL "__gcc_main_flags"
295 #define MAIN_FLAG_64BIT (1 << 0)
296 #define MAIN_FLAG_POSIX (1 << 1)
297
298 void
299 vms_start_function (const char *fnname)
300 {
301 #if VMS_DEBUGGING_INFO
302 if (vms_debug_main
303 && debug_info_level > DINFO_LEVEL_NONE
304 && strncmp (vms_debug_main, fnname, strlen (vms_debug_main)) == 0)
305 {
306 targetm.asm_out.globalize_label (asm_out_file, VMS_DEBUG_MAIN_POINTER);
307 ASM_OUTPUT_DEF (asm_out_file, VMS_DEBUG_MAIN_POINTER, fnname);
308 dwarf2out_vms_debug_main_pointer ();
309 vms_debug_main = 0;
310 }
311 #endif
312
313 /* Registers flags used for function main. This is necessary for
314 crt0 code. */
315 if (strcmp (fnname, "main") == 0)
316 {
317 unsigned int flags = 0;
318
319 if (flag_vms_pointer_size == VMS_POINTER_SIZE_64)
320 flags |= MAIN_FLAG_64BIT;
321 if (!flag_vms_return_codes)
322 flags |= MAIN_FLAG_POSIX;
323
324 targetm.asm_out.globalize_label (asm_out_file, VMS_MAIN_FLAGS_SYMBOL);
325 assemble_name (asm_out_file, VMS_MAIN_FLAGS_SYMBOL);
326 fprintf (asm_out_file, " = %u\n", flags);
327 }
328 }
329
330 #include "gt-vms.h"