aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.8/gcc/config/i386/i386-builtin-types.awk
blob: 5e3b315f59edc3d2742337921bafebe5f9d63229 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#  Copyright (C) 2009-2013 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 3, or (at your option) any
# later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING3.  If not see
# <http://www.gnu.org/licenses/>.

# Generates compressed tables for types for i386 builtin functions.

function do_error(string) {
    print FILENAME ":" FNR ": " string > "/dev/stderr"
    errors = 1
}

function check_type(string) {
    if (!(string in type_hash))
	do_error("undefined type code " string)
}

# We can significantly reduce the size of the read-only tables
# by forcing the compiler to use a smaller implementation type
# for the enumerations.
function attribute_mode(count) {
    # ??? Except that we get strange "comparison always false" warnings
    # for comparisons between different elements of the enumeration.
    #    print "#ifdef __GNUC__"
    #    if (count < 256)
    #	print "  __attribute__((__mode__(__QI__)))"
    #    else
    #	print "  __attribute__((__mode__(__HI__)))"
    #    print "#endif"
}

BEGIN {
    FS = "[() \t,]+"
   
    prim_defs = 0
    vect_defs = 0
    ptr_defs = 0
    cptr_defs = 0
    func_defs = 0
    func_args = 0
    alias_defs = 0
}

# Skip blank lines or comments.
/^[ \t]*(#|$)/ {
    next
}

$1 == "DEF_PRIMITIVE_TYPE" {
    if (NF == 4) {
	type_hash[$2] = 1
	prim_name[prim_defs] = $2
	prim_base[prim_defs] = $3
	prim_defs++
    } else
	do_error("DEF_PRIMITIVE_TYPE expected 2 arguments")
    next
}

$1 == "DEF_VECTOR_TYPE" {
    if (NF == 4 || NF == 5) {
	check_type($3)
	type_hash[$2] = 1
	vect_name[vect_defs] = $2
	vect_base[vect_defs] = $3
	vect_mode[vect_defs] = (NF == 5 ? $4 : $2)
	vect_defs++
    } else
	do_error("DEF_VECTOR_TYPE expected 2 arguments")
    next
}

$1 == "DEF_POINTER_TYPE" {
    if (NF == 4) {
	check_type($3)
	type_hash[$2] = 1
	ptr_name[ptr_defs] = $2
	ptr_base[ptr_defs] = $3
	ptr_defs++
    } else if (NF == 5) {
	check_type($3)
	if ($4 == "CONST") {
	    type_hash[$2] = 1
	    cptr_name[cptr_defs] = $2
	    cptr_base[cptr_defs] = $3
	    cptr_defs++
	} else
	    do_error("invalid qualifier \"" $4 "\"")
    }
    else
	do_error("DEF_POINTER_TYPE expected 2 or 3 arguments")
    next
}

$1 == "DEF_FUNCTION_TYPE" {
    func_start[func_defs] = func_args
    for (i = 2; i < NF; ++i) {
	check_type($i)
	func_types[func_args++] = $i
    }

    if (NF < 3)
	do_error("DEF_FUNCTION_TYPE expected at least 1 argument")
    else if (NF == 3)
	name = $2 "_FTYPE_VOID"
    else {
	name = $2 "_FTYPE"
	for (i = 3; i < NF; ++i)
	    name = name "_" $i
    }
    func_hash[name] = 1
    func_name[func_defs++] = name
    next
}

$1 == "DEF_FUNCTION_TYPE_ALIAS" {
    if (NF == 4) {
	if ($2 in func_hash) {
	    alias_base[alias_defs] = $2
	    alias_name[alias_defs] = $2 "_" $3
	    alias_defs++
	} else
	    do_error("undefined function code " $2)
    } else
	do_error("DEF_FUNCTION_TYPE_ALIAS expected 2 arguments")
    next
}

{
    do_error("unknown directive \"" $1 "\"");
}

END {
    if (errors)
	exit 1

    print "/* This file is auto-generated by i386-builtin-types.awk.  */\n"

    # This first enumeration contains all of the non-function types.
    print "enum ix86_builtin_type {"
    for (i = 0; i < prim_defs; ++i)
	print "  IX86_BT_" prim_name[i] ","
    print "  IX86_BT_LAST_PRIM = IX86_BT_" prim_name[i-1] ","
    for (i = 0; i < vect_defs; ++i)
	print "  IX86_BT_" vect_name[i] ","
    print "  IX86_BT_LAST_VECT = IX86_BT_" vect_name[i-1] ","
    for (i = 0; i < ptr_defs; ++i)
	print "  IX86_BT_" ptr_name[i] ","
    print "  IX86_BT_LAST_PTR = IX86_BT_" ptr_name[i-1] ","
    for (i = 0; i < cptr_defs; ++i)
	print "  IX86_BT_" cptr_name[i] ","
    print "  IX86_BT_LAST_CPTR = IX86_BT_" cptr_name[i-1] "\n}"
    attribute_mode(prim_defs + vect_defs + ptr_defs + cptr_defs)
    print ";\n\n"

    # We can't tabularize the initialization of the primitives, since
    # at least one of them is created via a local variable.  That's ok,
    # just create a nice big macro to do all the work.
    print "#define DEFINE_BUILTIN_PRIMITIVE_TYPES \\"
    for (i = 0; i < prim_defs; ++i) {
	printf "  ix86_builtin_type_tab[(int)IX86_BT_" prim_name[i] \
	    "] = " prim_base[i]
	if (i < prim_defs - 1)
	    print ", \\"
    }
    print "\n\n"

    # The vector types are defined via two tables defining the real
    # machine mode and the builtin primitive type.  We use two tables
    # rather than a structure to avoid structure padding and save space.
    print "static const enum machine_mode ix86_builtin_type_vect_mode[] = {"
    for (i = 0; i < vect_defs; ++i) {
	if (i == 0)
	    printf "  "
	else if (i % 6 == 0)
	    printf ",\n  "
	else
	    printf ", "
	printf vect_mode[i] "mode"
    }
    print "\n};\n\n"

    print "static const enum ix86_builtin_type " \
	"ix86_builtin_type_vect_base[] = {"
    for (i = 0; i < vect_defs; ++i) {
	if (i == 0)
	    printf "  "
	else if (i % 4 == 0)
	    printf ",\n  "
	else
	    printf ", "
	printf "IX86_BT_" vect_base[i]
    }
    print "\n};\n\n"

    # The pointer types are defined via a single table defining the
    # builtin primitive type.  The const-ness of the pointer is taken
    # from the enumeration value > IX86_BT_LAST_PTR.
    print "static const enum ix86_builtin_type " \
	"ix86_builtin_type_ptr_base[] = {"
    for (i = 0; i < ptr_defs; ++i) {
	if (i == 0)
	    printf " "
	else if (i % 4 == 0)
	    printf "\n "
	printf " IX86_BT_" ptr_base[i] ","
    }
    print "\n  /* pointer-to-constant defs start here */"
    for (i = 0; i < cptr_defs; ++i) {
	if (i == 0)
	    printf "  "
	else if (i % 4 == 0)
	    printf ",\n  "
	else
	    printf ", "
	printf "IX86_BT_" cptr_base[i]
    }
    print "\n};\n\n"

    # This second enumeration contains all of the function types.
    print "enum ix86_builtin_func_type {"
    for (i = 0; i < func_defs; ++i)
	print "  " func_name[i] ","
    print "  IX86_BT_LAST_FUNC = " func_name[i-1] ","
    for (i = 0; i < alias_defs; ++i)
	print "  " alias_name[i] ","
    print "  IX86_BT_LAST_ALIAS = " alias_name[i-1] "\n}"
    attribute_mode(func_defs + alias_defs)
    print ";\n\n"

    # The function types are defined via two tables.  The first contains
    # ranges consiting of the function's return type, followed by all of
    # the function argument types.  The ranges for all of the builtin
    # functions are smooshed together in the same array.  The second array
    # contains, for each builtin, the index of the function's return type
    # within the first array.
    print "static const enum ix86_builtin_type ix86_builtin_func_args[] = {"
    for (i = 0; i < func_args; ++i) {
	if (i == 0)
	    printf "  "
	else if (i % 4 == 0)
	    printf ",\n  "
	else
	    printf ", "
	printf "IX86_BT_" func_types[i]
    }
    print "\n};\n\n"

    print "static const unsigned short ix86_builtin_func_start[] = {"
    for (i = 0; i < func_defs; ++i) {
	if (i == 0)
	    printf " "
	else if (i % 10 == 0)
	    printf "\n "
	printf " " func_start[i] ","
    }
    print " " func_args "\n};\n\n"

    print "static const enum ix86_builtin_func_type " \
	"ix86_builtin_func_alias_base[] = {"
    for (i = 0; i < alias_defs; ++i) {
	if (i == 0)
	    printf "  "
	else
	    printf ",\n  "
	printf alias_base[i]
    }
    print "\n};"
}