forked from oneapi-src/unified-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson2src.py
More file actions
executable file
·67 lines (57 loc) · 3.29 KB
/
json2src.py
File metadata and controls
executable file
·67 lines (57 loc) · 3.29 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
59
60
61
62
63
64
65
66
67
#! /usr/bin/env python3
"""
Copyright (C) 2019-2021 Intel Corporation
Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions.
See LICENSE.TXT
SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
"""
import argparse
import util
import generate_code
import os, sys
import time
import json
"""
helper for adding mutually-exclusive boolean arguments "--name" and "--skip-name"
"""
def add_argument(parser, name, help, default=False):
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("--" + name, dest=name, help="Enable "+help, action="store_true")
group.add_argument("--skip-" + name, dest=name, help="Skip "+help, action="store_false")
parser.set_defaults(**{name:default})
if __name__ == '__main__':
parser = argparse.ArgumentParser()
add_argument(parser, "lib", "generation of lib files.", True)
add_argument(parser, "loader", "generation of loader files.", True)
add_argument(parser, "layers", "generation of layer files.", True)
add_argument(parser, "adapters", "generation of null adapter files.", True)
add_argument(parser, "common", "generation of common files.", True)
add_argument(parser, "tools", "generation of common files.", True)
parser.add_argument("--debug", action='store_true', help="dump intermediate data to disk.")
parser.add_argument("--sections", type=list, default=None, help="Optional list of sections for which to generate source, default is all")
parser.add_argument("--ver", type=str, default="1.0", help="specification version to generate.")
parser.add_argument('--api-json', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help="JSON file containing the API specification, by default read from stdin")
parser.add_argument("out_dir", type=str, help="Root of the loader repository.")
args = parser.parse_args()
input = json.loads(args.api_json.read())
start = time.time()
srcpath = os.path.join(args.out_dir, "source")
toolspath = os.path.join(args.out_dir, "tools")
for idx, specs in enumerate(input['specs']):
config = input['configs'][idx]
if args.sections == None or config['name'] in args.sections:
if args.lib:
generate_code.generate_lib(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.loader:
generate_code.generate_loader(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.layers:
generate_code.generate_layers(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.adapters:
generate_code.generate_adapters(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.common:
generate_code.generate_common(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.tools:
generate_code.generate_tools(toolspath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
if args.debug:
util.makoFileListWrite("generated.json")
print("\nCompleted in %.1f seconds!"%(time.time() - start))