3
# Copyright © 2020 Google, Inc.
5
# Permission is hereby granted, free of charge, to any person obtaining a
6
# copy of this software and associated documentation files (the "Software"),
7
# to deal in the Software without restriction, including without limitation
8
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
9
# and/or sell copies of the Software, and to permit persons to whom the
10
# Software is furnished to do so, subject to the following conditions:
12
# The above copyright notice and this permission notice (including the next
13
# paragraph) shall be included in all copies or substantial portions of the
16
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
from mako.template import Template
30
/* Copyright (C) 2020 Google, Inc.
32
* Permission is hereby granted, free of charge, to any person obtaining a
33
* copy of this software and associated documentation files (the "Software"),
34
* to deal in the Software without restriction, including without limitation
35
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
36
* and/or sell copies of the Software, and to permit persons to whom the
37
* Software is furnished to do so, subject to the following conditions:
39
* The above copyright notice and this permission notice (including the next
40
* paragraph) shall be included in all copies or substantial portions of the
43
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
44
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
45
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
46
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
47
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
48
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
55
* enum tables, these don't have any link back to other tables so just
56
* dump them up front before the bitset tables
59
%for name, enum in isa.enums.items():
60
static const struct isa_enum ${enum.get_c_name()} = {
61
.num_values = ${len(enum.values)},
63
% for val, display in enum.values.items():
64
{ .val = ${val}, .display = "${display}" },
71
* generated expression functions, can be linked from bitset tables, so
72
* also dump them up front
75
%for name, expr in isa.expressions.items():
77
${expr.get_c_name()}(struct decode_scope *scope)
79
% for fieldname in sorted(expr.fieldnames):
80
int64_t ${fieldname} = isa_decode_field(scope, "${fieldname}");
87
* Forward-declarations (so we don't have to figure out which order to
88
* emit various tables when they have pointers to each other)
91
%for name, bitset in isa.all_bitsets():
92
static const struct isa_bitset bitset_${bitset.get_c_name()}_gen_${bitset.gen_min};
95
%for root_name, root in isa.roots.items():
96
const struct isa_bitset *${root.get_c_name()}[];
103
%for name, bitset in isa.all_bitsets():
104
% for case in bitset.cases:
105
% for field_name, field in case.fields.items():
106
% if field.get_c_typename() == 'TYPE_BITSET':
107
% if len(field.params) > 0:
108
static const struct isa_field_params ${case.get_c_name()}_gen_${bitset.gen_min}_${field.get_c_name()} = {
109
.num_params = ${len(field.params)},
111
% for param in field.params:
112
{ .name= "${param[0]}", .as = "${param[1]}" },
120
static const struct isa_case ${case.get_c_name()}_gen_${bitset.gen_min} = {
121
% if case.expr is not None:
122
.expr = &${isa.expressions[case.expr].get_c_name()},
124
% if case.display is not None:
125
.display = "${case.display}",
127
.num_fields = ${len(case.fields)},
129
% for field_name, field in case.fields.items():
130
{ .name = "${field_name}", .low = ${field.low}, .high = ${field.high},
131
% if field.expr is not None:
132
.expr = &${isa.expressions[field.expr].get_c_name()},
134
% if field.display is not None:
135
.display = "${field.display}",
137
.type = ${field.get_c_typename()},
138
% if field.get_c_typename() == 'TYPE_BITSET':
139
.bitsets = ${isa.roots[field.type].get_c_name()},
140
% if len(field.params) > 0:
141
.params = &${case.get_c_name()}_gen_${bitset.gen_min}_${field.get_c_name()},
144
% if field.get_c_typename() == 'TYPE_ENUM':
145
.enums = &${isa.enums[field.type].get_c_name()},
147
% if field.get_c_typename() == 'TYPE_ASSERT':
148
.val.bitset = { ${', '.join(isa.split_bits(field.val))} },
155
static const struct isa_bitset bitset_${bitset.get_c_name()}_gen_${bitset.gen_min} = {
156
<% pattern = bitset.get_pattern() %>
157
% if bitset.extends is not None:
158
.parent = &bitset_${isa.bitsets[bitset.extends].get_c_name()}_gen_${isa.bitsets[bitset.extends].gen_min},
162
.min = ${bitset.get_gen_min()},
163
.max = ${bitset.get_gen_max()},
165
.match.bitset = { ${', '.join(isa.split_bits(pattern.match))} },
166
.dontcare.bitset = { ${', '.join(isa.split_bits(pattern.dontcare))} },
167
.mask.bitset = { ${', '.join(isa.split_bits(pattern.mask))} },
168
.num_cases = ${len(bitset.cases)},
170
% for case in bitset.cases:
171
&${case.get_c_name()}_gen_${bitset.gen_min},
178
* bitset hierarchy root tables (where decoding starts from):
181
%for root_name, root in isa.roots.items():
182
const struct isa_bitset *${root.get_c_name()}[] = {
183
% for leaf_name, leafs in isa.leafs.items():
185
% if leaf.get_root() == root:
186
&bitset_${leaf.get_c_name()}_gen_${leaf.gen_min},
197
/* Copyright (C) 2020 Google, Inc.
199
* Permission is hereby granted, free of charge, to any person obtaining a
200
* copy of this software and associated documentation files (the "Software"),
201
* to deal in the Software without restriction, including without limitation
202
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
203
* and/or sell copies of the Software, and to permit persons to whom the
204
* Software is furnished to do so, subject to the following conditions:
206
* The above copyright notice and this permission notice (including the next
207
* paragraph) shall be included in all copies or substantial portions of the
210
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
211
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
212
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
213
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
214
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
215
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
223
#include <util/bitset.h>
225
#define BITMASK_WORDS BITSET_WORDS(${isa.bitsize})
228
BITSET_WORD bitset[BITMASK_WORDS];
232
#define BITSET_FORMAT ${isa.format()}
233
#define BITSET_VALUE(v) ${isa.value()}
236
next_instruction(bitmask_t *instr, BITSET_WORD *start)
238
%for i in range(0, int(isa.bitsize / 32)):
239
instr->bitset[${i}] = *(start + ${i});
243
static inline uint64_t
244
bitmask_to_uint64_t(bitmask_t mask)
246
return ((uint64_t)mask.bitset[1] << 32) | mask.bitset[0];
249
static inline bitmask_t
250
uint64_t_to_bitmask(uint64_t val)
253
.bitset[0] = val & 0xffffffff,
254
.bitset[1] = (val >> 32) & 0xffffffff,
260
#endif /* _${guard}_ */
265
/* Copyright (C) 2020 Google, Inc.
267
* Permission is hereby granted, free of charge, to any person obtaining a
268
* copy of this software and associated documentation files (the "Software"),
269
* to deal in the Software without restriction, including without limitation
270
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
271
* and/or sell copies of the Software, and to permit persons to whom the
272
* Software is furnished to do so, subject to the following conditions:
274
* The above copyright notice and this permission notice (including the next
275
* paragraph) shall be included in all copies or substantial portions of the
278
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
279
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
280
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
281
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
282
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
283
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
292
#endif /* _${guard}_ */
303
with open(glue_h, 'w') as f:
304
guard = os.path.basename(glue_h).upper().replace("-", "_").replace(".", "_")
305
f.write(Template(glue).render(guard=guard, isa=os.path.basename(dst_h)))
307
with open(dst_c, 'w') as f:
308
f.write(Template(template).render(isa=isa))
310
with open(dst_h, 'w') as f:
311
guard = os.path.basename(dst_h).upper().replace("-", "_").replace(".", "_")
312
f.write(Template(header).render(isa=isa, guard=guard))