]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/vms/vms.c
Convert standard builtin functions from being arrays to using a functional interface
[thirdparty/gcc.git] / gcc / config / vms / vms.c
1 /* Definitions of target machine GNU compiler. 32bit VMS version.
2 Copyright (C) 2009, 2010 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 "vms-protos.h"
26 #include "tm.h"
27 #include "ggc.h"
28
29 /* Correlation of standard CRTL names with DECCRTL function names. */
30
31 /* Name is for a function that allocate memory. Use the 64bit version
32 if -mmalloc64. */
33 #define VMS_CRTL_MALLOC (1 << 0)
34
35 /* If long pointer are enabled, use _NAME64 instead. */
36 #define VMS_CRTL_64 (1 << 1)
37
38 /* Use tNAME instead. To be applied after the previous rule. */
39 #define VMS_CRTL_FLOAT (1 << 2)
40
41 /* Prepend __bsd44__ before the name. To be applied after the P64
42 rule. */
43 #define VMS_CRTL_BSD44 (1 << 3)
44
45 /* Prepend x before the name for printf like functions. */
46 #define VMS_CRTL_PRNTF (1 << 4)
47
48 struct vms_crtl_name
49 {
50 /* The standard C name. */
51 const char *const name;
52
53 /* Flags to drive the translation. */
54 unsigned int flags;
55 };
56
57 /* Map for the translation. */
58
59 static const struct vms_crtl_name vms_crtl_names[] =
60 {
61 #include "vms-crtlmap.h"
62 };
63
64 /* Number of entires in the above array. */
65
66 #define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
67
68 /* List of aliased identifiers. They must be persistant accross gc. */
69
70 static GTY(()) VEC(tree,gc) *aliases_id;
71
72 /* Add a CRTL translation. This simply use the transparent alias
73 mechanism, which is platform independant and works with the
74 #pragma extern_prefix (which set the assembler name). */
75
76 static void
77 vms_add_crtl_xlat (const char *name, size_t nlen,
78 const char *id_str, size_t id_len)
79 {
80 tree targ;
81
82 targ = get_identifier_with_length (name, nlen);
83 gcc_assert (!IDENTIFIER_TRANSPARENT_ALIAS (targ));
84 IDENTIFIER_TRANSPARENT_ALIAS (targ) = 1;
85 TREE_CHAIN (targ) = get_identifier_with_length (id_str, id_len);
86
87 VEC_safe_push (tree, gc, aliases_id, targ);
88
89 /* printf ("vms: %s (%p) -> %.*s\n", name, targ, id_len, id_str); */
90 }
91
92 /* Do VMS specific stuff on builtins: disable the ones that are not
93 standard, mangle names. */
94
95 void
96 vms_patch_builtins (void)
97 {
98 /* enum built_in_function bi; */
99 unsigned int i;
100
101 /* Fwrite on VMS is non-standard. */
102 if (builtin_decl_implicit_p (BUILT_IN_WRITE))
103 set_builtin_decl_implicit_p (BUILT_IN_WRITE, false);
104
105 if (builtin_decl_implicit_p (BUILT_IN_WRITE_UNLOCKED))
106 set_builtin_decl_implicit_p (BUILT_IN_WRITE_UNLOCKED, false);
107
108 /* Define aliases for names. */
109 for (i = 0; i < NBR_CRTL_NAMES; i++)
110 {
111 const struct vms_crtl_name *n = &vms_crtl_names[i];
112 char res[VMS_CRTL_MAXLEN + 3 + 9 + 1 + 1];
113 int rlen;
114 int nlen;
115
116 /* Add the dec-c prefix. */
117 memcpy (res, "decc$", 5);
118 rlen = 5;
119
120 if (n->flags & VMS_CRTL_BSD44)
121 {
122 memcpy (res + rlen, "__bsd44__", 9);
123 rlen += 9;
124 }
125
126 if (n->flags & VMS_CRTL_FLOAT)
127 res[rlen++] = 't';
128
129 if (n->flags & VMS_CRTL_PRNTF)
130 res[rlen++] = 'x';
131
132 nlen = strlen (n->name);
133 memcpy (res + rlen, n->name, nlen);
134
135 if ((n->flags & VMS_CRTL_64) == 0)
136 vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen);
137 else
138 {
139 char alt[VMS_CRTL_MAXLEN + 3];
140 bool use_64;
141
142 /* Add three translations:
143 _X32 -> X
144 _X64 -> _X64
145 X -> X if short, _X64 if long. */
146 alt[0] = '_';
147 memcpy (alt + 1, n->name, nlen);
148 alt[1 + nlen + 0] = '3';
149 alt[1 + nlen + 1] = '2';
150 alt[1 + nlen + 2] = 0;
151 vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen);
152
153 use_64 = (((n->flags & VMS_CRTL_64) && POINTER_SIZE == 64)
154 || ((n->flags & VMS_CRTL_MALLOC)
155 && TARGET_MALLOC64));
156 if (!use_64)
157 vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen);
158
159 res[rlen++] = '_';
160 memcpy (res + rlen, n->name, nlen);
161 res[rlen + nlen + 0] = '6';
162 res[rlen + nlen + 1] = '4';
163
164 if (use_64)
165 vms_add_crtl_xlat (n->name, nlen, res, rlen + nlen + 2);
166
167 alt[1 + nlen + 0] = '6';
168 alt[1 + nlen + 1] = '4';
169 vms_add_crtl_xlat (alt, nlen + 3, res, rlen + nlen + 2);
170 }
171 }
172 }
173
174 #include "gt-vms.h"