forked from foss-xtensa/xtensa-overlay
-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathvalidate.py
More file actions
executable file
·58 lines (47 loc) · 1.63 KB
/
Copy pathvalidate.py
File metadata and controls
executable file
·58 lines (47 loc) · 1.63 KB
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
#!/usr/bin/env python3
import sys
import json
import pprint
import types
js = json.load(open(sys.argv[1]),
object_hook=lambda d: types.SimpleNamespace(**d))
#pprint.pp(js.opcodes)
# Map of format -> encoded bits
format_bits = {}
# Sets of bits indexed by (format,slot) tuple
slot_bits = {}
# Format to count of slots
format_slots = {}
# First pass to initialize dicts
for op in js.opcodes:
for v in op.variants:
format_bits[v.format] = v.format_bits
format_slots[v.format] = -1
slot_bits[(v.format, v.slot)] = set()
# Second to compute them
for op in js.opcodes:
for v in op.variants:
for a in v.args:
format_slots[v.format] = max([format_slots[v.format], v.slot + 1])
for b in a.field_bits:
slot_bits[(v.format, v.slot)].add(b)
# Make sure all instances of a given format have the same bit representation
for op in js.opcodes:
for v in op.variants:
assert v.format_bits == format_bits[v.format]
# Make sure slots don't overlap with each other
for f in format_bits:
for s1 in range(format_slots[f]):
for s2 in range(s1 + 1, format_slots[f]):
b1 = slot_bits[(f, s1)]
b2 = slot_bits[(f, s2)]
assert b1.intersection(b2) == set()
# Make sure format bits don't overlap with slots. This is incomplete,
# as the data from xtensa-modules.c only records one bits. Bits
# required to be zero are effectively invisible, they look like
# "holes" to us.
for f in format_bits:
for s in range(format_slots[f]):
sb = slot_bits[(f, s)]
for fb in format_bits[f]:
assert fb not in sb