import functools
import json
+import os.path
import re
# Prefix for all C variables generated by this script.
CAPABILITY_BIT_MAPPING = {}
+def make_path_to_file(f):
+ """Makes all ancestor directories to the given file, if they
+ don't yet exist.
+
+ Arguments:
+ f: The file whose ancestor directories are to be created.
+ """
+ dir = os.path.dirname(os.path.abspath(f))
+ if not os.path.isdir(dir):
+ os.makedirs(dir)
+
+
def populate_capability_bit_mapping_dict(cap_dict):
"""Populates CAPABILITY_BIT_MAPPING.
populate_capability_bit_mapping_dict(cap_dict[0])
if args.core_insts_output is not None:
+ make_path_to_file(args.core_insts_output)
+ make_path_to_file(args.operand_kinds_output)
print(generate_instruction_table(grammar['instructions'], False),
file=open(args.core_insts_output, 'w'))
print(generate_operand_kind_table(grammar['operand_kinds']),
if args.extinst_glsl_grammar is not None:
with open(args.extinst_glsl_grammar) as json_file:
grammar = json.loads(json_file.read())
+ make_path_to_file(args.glsl_insts_output)
print(generate_instruction_table(grammar['instructions'], True),
file=open(args.glsl_insts_output, 'w'))
if args.extinst_opencl_grammar is not None:
with open(args.extinst_opencl_grammar) as json_file:
grammar = json.loads(json_file.read())
+ make_path_to_file(args.opencl_insts_output)
print(generate_instruction_table(grammar['instructions'], True),
file=open(args.opencl_insts_output, 'w'))