1 # Copyright (C) 2009-2015 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify it
4 # under the terms of the GNU General Public License as published by the
5 # Free Software Foundation; either version 3, or (at your option) any
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; see the file COPYING3. If not see
15 # <http://www.gnu.org/licenses/>.
17 # Generates compressed tables for types for i386 builtin functions.
19 function do_error
(string
) {
20 print FILENAME ":" FNR ": " string
> "/dev/stderr"
24 function check_type
(string
) {
25 if (!
(string in type_hash
))
26 do_error
("undefined type code " string
)
29 # We can significantly reduce the size of the read-only tables
30 # by forcing the compiler to use a smaller implementation type
31 # for the enumerations.
32 function attribute_mode
(count
) {
33 # ??? Except that we get strange "comparison always false" warnings
34 # for comparisons between different elements of the enumeration.
35 # print "#ifdef __GNUC__"
37 # print " __attribute__((__mode__(__QI__)))"
39 # print " __attribute__((__mode__(__HI__)))"
55 # Skip blank lines or comments.
60 $
1 ==
"DEF_PRIMITIVE_TYPE" {
63 prim_name
[prim_defs
] = $
2
64 prim_base
[prim_defs
] = $
3
67 do_error
("DEF_PRIMITIVE_TYPE expected 2 arguments")
71 $
1 ==
"DEF_VECTOR_TYPE" {
72 if (NF ==
4 || NF ==
5) {
75 vect_name
[vect_defs
] = $
2
76 vect_base
[vect_defs
] = $
3
77 vect_mode
[vect_defs
] =
(NF ==
5 ? $
4 : $
2)
80 do_error
("DEF_VECTOR_TYPE expected 2 arguments")
84 $
1 ==
"DEF_POINTER_TYPE" {
88 ptr_name
[ptr_defs
] = $
2
89 ptr_base
[ptr_defs
] = $
3
95 cptr_name
[cptr_defs
] = $
2
96 cptr_base
[cptr_defs
] = $
3
99 do_error
("invalid qualifier \"" $
4 "\"")
102 do_error
("DEF_POINTER_TYPE expected 2 or 3 arguments")
106 $
1 ==
"DEF_FUNCTION_TYPE" {
107 func_start
[func_defs
] = func_args
108 for (i =
2; i
< NF; ++i
) {
110 func_types
[func_args
++] = $i
114 do_error
("DEF_FUNCTION_TYPE expected at least 1 argument")
116 name = $
2 "_FTYPE_VOID"
119 for (i =
3; i
< NF; ++i
)
123 func_name
[func_defs
++] = name
127 $
1 ==
"DEF_FUNCTION_TYPE_ALIAS" {
129 if ($
2 in func_hash
) {
130 alias_base
[alias_defs
] = $
2
131 alias_name
[alias_defs
] = $
2 "_" $
3
134 do_error
("undefined function code " $
2)
136 do_error
("DEF_FUNCTION_TYPE_ALIAS expected 2 arguments")
141 do_error
("unknown directive \"" $
1 "\"");
148 print "/* This file is auto-generated by i386-builtin-types.awk. */\n"
150 # This first enumeration contains all of the non-function types.
151 print "enum ix86_builtin_type {"
152 for (i =
0; i
< prim_defs
; ++i
)
153 print " IX86_BT_" prim_name
[i
] ","
154 print " IX86_BT_LAST_PRIM = IX86_BT_" prim_name
[i
-1] ","
155 for (i =
0; i
< vect_defs
; ++i
)
156 print " IX86_BT_" vect_name
[i
] ","
157 print " IX86_BT_LAST_VECT = IX86_BT_" vect_name
[i
-1] ","
158 for (i =
0; i
< ptr_defs
; ++i
)
159 print " IX86_BT_" ptr_name
[i
] ","
160 print " IX86_BT_LAST_PTR = IX86_BT_" ptr_name
[i
-1] ","
161 for (i =
0; i
< cptr_defs
; ++i
)
162 print " IX86_BT_" cptr_name
[i
] ","
163 print " IX86_BT_LAST_CPTR = IX86_BT_" cptr_name
[i
-1] "\n}"
164 attribute_mode
(prim_defs
+ vect_defs
+ ptr_defs
+ cptr_defs
)
167 # We can't tabularize the initialization of the primitives, since
168 # at least one of them is created via a local variable. That's ok,
169 # just create a nice big macro to do all the work.
170 print "#define DEFINE_BUILTIN_PRIMITIVE_TYPES \\"
171 for (i =
0; i
< prim_defs
; ++i
) {
172 printf " ix86_builtin_type_tab[(int)IX86_BT_" prim_name
[i
] \
174 if (i
< prim_defs
- 1)
179 # The vector types are defined via two tables defining the real
180 # machine mode and the builtin primitive type. We use two tables
181 # rather than a structure to avoid structure padding and save space.
182 print "static const machine_mode ix86_builtin_type_vect_mode[] = {"
183 for (i =
0; i
< vect_defs
; ++i
) {
190 printf vect_mode
[i
] "mode"
194 print "static const enum ix86_builtin_type " \
195 "ix86_builtin_type_vect_base[] = {"
196 for (i =
0; i
< vect_defs
; ++i
) {
203 printf "IX86_BT_" vect_base
[i
]
207 # The pointer types are defined via a single table defining the
208 # builtin primitive type. The const-ness of the pointer is taken
209 # from the enumeration value > IX86_BT_LAST_PTR.
210 print "static const enum ix86_builtin_type " \
211 "ix86_builtin_type_ptr_base[] = {"
212 for (i =
0; i
< ptr_defs
; ++i
) {
217 printf " IX86_BT_" ptr_base
[i
] ","
219 print "\n /* pointer-to-constant defs start here */"
220 for (i =
0; i
< cptr_defs
; ++i
) {
227 printf "IX86_BT_" cptr_base
[i
]
231 # This second enumeration contains all of the function types.
232 print "enum ix86_builtin_func_type {"
233 for (i =
0; i
< func_defs
; ++i
)
234 print " " func_name
[i
] ","
235 print " IX86_BT_LAST_FUNC = " func_name
[i
-1] ","
236 for (i =
0; i
< alias_defs
; ++i
)
237 print " " alias_name
[i
] ","
238 print " IX86_BT_LAST_ALIAS = " alias_name
[i
-1] "\n}"
239 attribute_mode
(func_defs
+ alias_defs
)
242 # The function types are defined via two tables. The first contains
243 # ranges consiting of the function's return type, followed by all of
244 # the function argument types. The ranges for all of the builtin
245 # functions are smooshed together in the same array. The second array
246 # contains, for each builtin, the index of the function's return type
247 # within the first array.
248 print "static const enum ix86_builtin_type ix86_builtin_func_args[] = {"
249 for (i =
0; i
< func_args
; ++i
) {
256 printf "IX86_BT_" func_types
[i
]
260 print "static const unsigned short ix86_builtin_func_start[] = {"
261 for (i =
0; i
< func_defs
; ++i
) {
264 else if (i %
10 ==
0)
266 printf " " func_start
[i
] ","
268 print " " func_args
"\n};\n\n"
270 print "static const enum ix86_builtin_func_type " \
271 "ix86_builtin_func_alias_base[] = {"
272 for (i =
0; i
< alias_defs
; ++i
) {