1 # Copyright (C) 2009 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" {
75 vect_mode[vect_defs] = $2
76 vect_base[vect_defs] = $3
79 do_error("DEF_VECTOR_TYPE expected 2 arguments")
83 $1 == "DEF_POINTER_TYPE" {
87 ptr_name[ptr_defs] = $2
88 ptr_base[ptr_defs] = $3
94 cptr_name[cptr_defs] = $2
95 cptr_base[cptr_defs] = $3
98 do_error("invalid qualifier \"" $4 "\"")
101 do_error("DEF_POINTER_TYPE expected 2 or 3 arguments")
105 $1 == "DEF_FUNCTION_TYPE" {
106 func_start[func_defs] = func_args
107 for (i = 2; i < NF; ++i) {
109 func_types[func_args++] = $i
113 do_error("DEF_FUNCTION_TYPE expected at least 1 argument")
115 name = $2 "_FTYPE_VOID"
118 for (i = 3; i < NF; ++i)
122 func_name[func_defs++] = name
126 $1 == "DEF_FUNCTION_TYPE_ALIAS" {
128 if ($2 in func_hash) {
129 alias_base[alias_defs] = $2
130 alias_name[alias_defs] = $2 "_" $3
133 do_error("undefined function code " $2)
135 do_error("DEF_FUNCTION_TYPE_ALIAS expected 2 arguments")
140 do_error("unknown directive \"" $1 "\"");
147 print "/* This file is auto-generated by i386-builtin-types.awk. */\n"
149 # This first enumeration contains all of the non-function types.
150 print "enum ix86_builtin_type {"
151 for (i = 0; i < prim_defs; ++i)
152 print " IX86_BT_" prim_name[i] ","
153 print " IX86_BT_LAST_PRIM = IX86_BT_" prim_name[i-1] ","
154 for (i = 0; i < vect_defs; ++i)
155 print " IX86_BT_" vect_mode[i] ","
156 print " IX86_BT_LAST_VECT = IX86_BT_" vect_mode[i-1] ","
157 for (i = 0; i < ptr_defs; ++i)
158 print " IX86_BT_" ptr_name[i] ","
159 print " IX86_BT_LAST_PTR = IX86_BT_" ptr_name[i-1] ","
160 for (i = 0; i < cptr_defs; ++i)
161 print " IX86_BT_" cptr_name[i] ","
162 print " IX86_BT_LAST_CPTR = IX86_BT_" cptr_name[i-1] "\n}"
163 attribute_mode(prim_defs + vect_defs + ptr_defs + cptr_defs)
166 # We can't tabularize the initialization of the primitives, since
167 # at least one of them is created via a local variable. That's ok,
168 # just create a nice big macro to do all the work.
169 print "#define DEFINE_BUILTIN_PRIMITIVE_TYPES \\"
170 for (i = 0; i < prim_defs; ++i) {
171 printf " ix86_builtin_type_tab[(int)IX86_BT_" prim_name[i] \
173 if (i < prim_defs - 1)
178 # The vector types are defined via two tables defining the real
179 # machine mode and the builtin primitive type. We use two tables
180 # rather than a structure to avoid structure padding and save space.
181 print "static const enum machine_mode ix86_builtin_type_vect_mode[] = {"
182 for (i = 0; i < vect_defs; ++i) {
189 printf vect_mode[i] "mode"
193 print "static const enum ix86_builtin_type " \
194 "ix86_builtin_type_vect_base[] = {"
195 for (i = 0; i < vect_defs; ++i) {
202 printf "IX86_BT_" vect_base[i]
206 # The pointer types are defined via a single table defining the
207 # builtin primitive type. The const-ness of the pointer is taken
208 # from the enumeration value > IX86_BT_LAST_PTR.
209 print "static const enum ix86_builtin_type " \
210 "ix86_builtin_type_ptr_base[] = {"
211 for (i = 0; i < ptr_defs; ++i) {
216 printf " IX86_BT_" ptr_base[i] ","
218 print "\n /* pointer-to-constant defs start here */"
219 for (i = 0; i < cptr_defs; ++i) {
226 printf "IX86_BT_" cptr_base[i]
230 # This second enumeration contains all of the function types.
231 print "enum ix86_builtin_func_type {"
232 for (i = 0; i < func_defs; ++i)
233 print " " func_name[i] ","
234 print " IX86_BT_LAST_FUNC = " func_name[i-1] ","
235 for (i = 0; i < alias_defs; ++i)
236 print " " alias_name[i] ","
237 print " IX86_BT_LAST_ALIAS = " alias_name[i-1] "\n}"
238 attribute_mode(func_defs + alias_defs)
241 # The function types are defined via two tables. The first contains
242 # ranges consiting of the function's return type, followed by all of
243 # the function argument types. The ranges for all of the builtin
244 # functions are smooshed together in the same array. The second array
245 # contains, for each builtin, the index of the function's return type
246 # within the first array.
247 print "static const enum ix86_builtin_type ix86_builtin_func_args[] = {"
248 for (i = 0; i < func_args; ++i) {
255 printf "IX86_BT_" func_types[i]
259 print "static const unsigned short ix86_builtin_func_start[] = {"
260 for (i = 0; i < func_defs; ++i) {
263 else if (i % 10 == 0)
265 printf " " func_start[i] ","
267 print " " func_args "\n};\n\n"
269 print "static const enum ix86_builtin_func_type " \
270 "ix86_builtin_func_alias_base[] = {"
271 for (i = 0; i < alias_defs; ++i) {