Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/freedreno/isa/decode.py
4564 views
1
#
2
# Copyright © 2020 Google, Inc.
3
#
4
# Permission is hereby granted, free of charge, to any person obtaining a
5
# copy of this software and associated documentation files (the "Software"),
6
# to deal in the Software without restriction, including without limitation
7
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
8
# and/or sell copies of the Software, and to permit persons to whom the
9
# Software is furnished to do so, subject to the following conditions:
10
#
11
# The above copyright notice and this permission notice (including the next
12
# paragraph) shall be included in all copies or substantial portions of the
13
# Software.
14
#
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21
# IN THE SOFTWARE.
22
23
from mako.template import Template
24
from isa import ISA
25
import sys
26
27
template = """\
28
/* Copyright (C) 2020 Google, Inc.
29
*
30
* Permission is hereby granted, free of charge, to any person obtaining a
31
* copy of this software and associated documentation files (the "Software"),
32
* to deal in the Software without restriction, including without limitation
33
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
34
* and/or sell copies of the Software, and to permit persons to whom the
35
* Software is furnished to do so, subject to the following conditions:
36
*
37
* The above copyright notice and this permission notice (including the next
38
* paragraph) shall be included in all copies or substantial portions of the
39
* Software.
40
*
41
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
42
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
43
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
44
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
45
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
46
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
47
* IN THE SOFTWARE.
48
*/
49
50
#include "decode.h"
51
52
/*
53
* enum tables, these don't have any link back to other tables so just
54
* dump them up front before the bitset tables
55
*/
56
57
%for name, enum in isa.enums.items():
58
static const struct isa_enum ${enum.get_c_name()} = {
59
.num_values = ${len(enum.values)},
60
.values = {
61
% for val, display in enum.values.items():
62
{ .val = ${val}, .display = "${display}" },
63
% endfor
64
},
65
};
66
%endfor
67
68
/*
69
* generated expression functions, can be linked from bitset tables, so
70
* also dump them up front
71
*/
72
73
%for name, expr in isa.expressions.items():
74
static uint64_t
75
${expr.get_c_name()}(struct decode_scope *scope)
76
{
77
% for fieldname in expr.fieldnames:
78
int64_t ${fieldname} = isa_decode_field(scope, "${fieldname}");
79
% endfor
80
return ${expr.expr};
81
}
82
%endfor
83
84
/*
85
* Forward-declarations (so we don't have to figure out which order to
86
* emit various tables when they have pointers to each other)
87
*/
88
89
%for name, bitset in isa.bitsets.items():
90
static const struct isa_bitset bitset_${bitset.get_c_name()};
91
%endfor
92
93
%for root_name, root in isa.roots.items():
94
const struct isa_bitset *${root.get_c_name()}[];
95
%endfor
96
97
/*
98
* bitset tables:
99
*/
100
101
%for name, bitset in isa.bitsets.items():
102
% for case in bitset.cases:
103
% for field_name, field in case.fields.items():
104
% if field.get_c_typename() == 'TYPE_BITSET':
105
% if len(field.params) > 0:
106
static const struct isa_field_params ${case.get_c_name()}_${field.get_c_name()} = {
107
.num_params = ${len(field.params)},
108
.params = {
109
% for param in field.params:
110
{ .name= "${param[0]}", .as = "${param[1]}" },
111
% endfor
112
113
},
114
};
115
% endif
116
% endif
117
% endfor
118
static const struct isa_case ${case.get_c_name()} = {
119
% if case.expr is not None:
120
.expr = &${isa.expressions[case.expr].get_c_name()},
121
% endif
122
% if case.display is not None:
123
.display = "${case.display}",
124
% endif
125
.num_fields = ${len(case.fields)},
126
.fields = {
127
% for field_name, field in case.fields.items():
128
{ .name = "${field_name}", .low = ${field.low}, .high = ${field.high},
129
% if field.expr is not None:
130
.expr = &${isa.expressions[field.expr].get_c_name()},
131
% endif
132
% if field.display is not None:
133
.display = "${field.display}",
134
% endif
135
.type = ${field.get_c_typename()},
136
% if field.get_c_typename() == 'TYPE_BITSET':
137
.bitsets = ${isa.roots[field.type].get_c_name()},
138
% if len(field.params) > 0:
139
.params = &${case.get_c_name()}_${field.get_c_name()},
140
% endif
141
% endif
142
% if field.get_c_typename() == 'TYPE_ENUM':
143
.enums = &${isa.enums[field.type].get_c_name()},
144
% endif
145
% if field.get_c_typename() == 'TYPE_ASSERT':
146
.val = ${field.val},
147
% endif
148
},
149
% endfor
150
},
151
};
152
% endfor
153
static const struct isa_bitset bitset_${bitset.get_c_name()} = {
154
<% pattern = bitset.get_pattern() %>
155
% if bitset.extends is not None:
156
.parent = &bitset_${isa.bitsets[bitset.extends].get_c_name()},
157
% endif
158
.name = "${name}",
159
.gen = {
160
.min = ${bitset.gen_min},
161
.max = ${bitset.gen_max},
162
},
163
.match = ${hex(pattern.match)},
164
.dontcare = ${hex(pattern.dontcare)},
165
.mask = ${hex(pattern.mask)},
166
.num_cases = ${len(bitset.cases)},
167
.cases = {
168
% for case in bitset.cases:
169
&${case.get_c_name()},
170
% endfor
171
},
172
};
173
%endfor
174
175
/*
176
* bitset hierarchy root tables (where decoding starts from):
177
*/
178
179
%for root_name, root in isa.roots.items():
180
const struct isa_bitset *${root.get_c_name()}[] = {
181
% for leaf_name, leaf in isa.leafs.items():
182
% if leaf.get_root() == root:
183
&bitset_${leaf.get_c_name()},
184
% endif
185
% endfor
186
(void *)0
187
};
188
%endfor
189
190
"""
191
192
xml = sys.argv[1]
193
dst = sys.argv[2]
194
195
isa = ISA(xml)
196
197
with open(dst, 'wb') as f:
198
f.write(Template(template, output_encoding='utf-8').render(isa=isa))
199
200