forked from KhronosGroup/SPIRV-Headers
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddFieldsToGrammar.py
More file actions
30 lines (21 loc) · 886 Bytes
/
addFieldsToGrammar.py
File metadata and controls
30 lines (21 loc) · 886 Bytes
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
import json
import os
# this script adds 'hlsl_type' field to grammar file
filepath = "../../include/spirv/unified1/spirv.core.grammar.json"
filepath2 = "../../include/spirv/unified1/spirv.core.grammar2.json"
with open(filepath) as f:
d = json.load(f)
for i in range(len(d['instructions'])):
instr = d['instructions'][i]
if 'operands' in instr.keys():
for j in range(len(instr['operands'])):
op = instr['operands'][j]
type = 'uint32_t'
if 'name' in op.keys() or op['kind'] == 'IdResultType':
op['hlsl_type'] = type
default_builtin_var_type = 'static const uint32_t'
for i in range(len(d['operand_kinds'][32]['enumerants'])):
opk = d['operand_kinds'][32]['enumerants'][i]
opk['hlsl_type'] = default_builtin_var_type
with open(filepath2, 'w') as f:
json.dump(d, f, ensure_ascii=False, indent=2)