Skip to content

Commit 0874114

Browse files
committed
[ur] refactor more hardcoded loader-specific templates
Missed some things in #770...
1 parent a898ec9 commit 0874114

File tree

11 files changed

+204
-48
lines changed

11 files changed

+204
-48
lines changed

scripts/YaML.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,12 +238,13 @@ std::function<void(void*)> ur_callback_t;
238238
* A handle requires the following scalar fields: {`desc`, `name`}
239239
- `desc` will be used as the handles's description comment
240240
- `name` must be a unique ISO-C standard identifier, start with `$` tag, be snake_case and end with `_handle_t`
241-
* A handle may take the following optional scalar fields: {`class`, `alias`, `condition`, `ordinal`, `version`}
241+
* A handle may take the following optional scalar fields: {`class`, `alias`, `condition`, `ordinal`, `version`, `loader_only`}
242242
- `class` will be used to scope the handles declaration within the specified C++ class
243243
- `alias` will be used to declare the handle as an alias of another handle; specifically, aliases in another namespace
244244
- `condition` will be used as a C/C++ preprocessor `#if` conditional expression
245245
- `ordinal` will be used to override the default order (in which they appear) the handles appears within its section; `default="1000"`
246246
- `version` will be used to define the minimum API version in which the handles will appear; `default="1.0"` This will also affect the order in which the handles appears within its section.
247+
- `loader_only` will be used to decide whether the handle can be instantiated and managed only by the loader.
247248
* A handle may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
248249
- `details` will be used as the handle's detailed comment
249250

scripts/core/common.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ value: uint8_t
6262
type: handle
6363
desc: "Handle of a loader config object"
6464
class: $xLoaderConfig
65+
loader_only: True
6566
name: "$x_loader_config_handle_t"
6667
--- #--------------------------------------------------------------------------
6768
type: handle

scripts/json2src.py

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,6 @@ def add_argument(parser, name, help, default=False):
2323
group.add_argument("--skip-" + name, dest=name, help="Skip "+help, action="store_false")
2424
parser.set_defaults(**{name:default})
2525

26-
"""
27-
helpers to strip loader only api constructs from the json
28-
"""
29-
def strip_specs_class(specs, strip_class):
30-
for spec in specs:
31-
remove_obj = []
32-
for obj in spec["objects"]:
33-
if "class" in obj and strip_class in obj["class"]:
34-
remove_obj.append(obj)
35-
for obj in remove_obj:
36-
spec["objects"].remove(obj)
37-
38-
def strip_meta_entry(meta, entry_name, pattern):
39-
loader_entries = []
40-
for entry in meta[entry_name]:
41-
if pattern in entry:
42-
loader_entries.append(entry)
43-
44-
for entry in loader_entries:
45-
del meta[entry_name][entry]
46-
47-
def strip_loader_meta(meta):
48-
strip_meta_entry(meta, "class", "Loader")
49-
strip_meta_entry(meta, "function", "Loader")
50-
strip_meta_entry(meta, "enum", "loader")
51-
strip_meta_entry(meta, "handle", "loader")
52-
5326
if __name__ == '__main__':
5427
parser = argparse.ArgumentParser()
5528
add_argument(parser, "lib", "generation of lib files.", True)
@@ -75,9 +48,6 @@ def strip_loader_meta(meta):
7548
if args.sections == None or config['name'] in args.sections:
7649
if args.lib:
7750
generate_code.generate_lib(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
78-
# From here only generate code for functions adapters can implement.
79-
strip_specs_class(specs, "Loader")
80-
strip_loader_meta(input['meta'])
8151
if args.loader:
8252
generate_code.generate_loader(srcpath, config['name'], config['namespace'], config['tags'], args.ver, specs, input['meta'])
8353
if args.layers:

scripts/templates/helper.py

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@ def is_class(obj):
3232
except:
3333
return False
3434

35+
@staticmethod
36+
def is_handle(obj):
37+
try:
38+
return True if re.match(r"handle", obj['type']) else False
39+
except:
40+
return False
41+
3542
@staticmethod
3643
def is_experimental(obj):
3744
try:
@@ -46,7 +53,12 @@ def class_name(obj):
4653
except:
4754
return None
4855

49-
56+
@staticmethod
57+
def is_loader_only(obj):
58+
try:
59+
return obj['loader_only']
60+
except:
61+
return False
5062

5163

5264
"""
@@ -440,13 +452,6 @@ def is_global(item, tags):
440452
except:
441453
return False
442454

443-
@staticmethod
444-
def is_loader_only(item):
445-
try:
446-
return item['loader_only']
447-
except:
448-
return False
449-
450455

451456
"""
452457
Public:
@@ -555,6 +560,31 @@ def extract_objs(specs, value):
555560
objs.append(obj)
556561
return objs
557562

563+
"""
564+
Public:
565+
returns a list of all adapter functions
566+
"""
567+
def get_adapter_functions(specs):
568+
objs = []
569+
for s in specs:
570+
for obj in s['objects']:
571+
if obj_traits.is_function(obj) and not obj_traits.is_loader_only(obj):
572+
objs.append(obj)
573+
return objs
574+
575+
"""
576+
Public:
577+
returns a list of all adapter handles
578+
"""
579+
def get_adapter_handles(specs):
580+
objs = []
581+
for s in specs:
582+
for obj in s['objects']:
583+
if obj_traits.is_handle(obj) and not obj_traits.is_loader_only(obj):
584+
objs.append(obj)
585+
586+
return objs
587+
558588
"""
559589
Private:
560590
removes 'const' from c++ type
@@ -1055,8 +1085,8 @@ def get_pfntables(specs, meta, namespace, tags):
10551085
tables = []
10561086
for cname in sorted(meta['class'], key=lambda x: meta['class'][x]['ordinal']):
10571087
objs, exp_objs = get_class_function_objs_exp(specs, cname)
1058-
objs = list(filter(lambda obj: not function_traits.is_loader_only(obj), objs))
1059-
exp_objs = list(filter(lambda obj: not function_traits.is_loader_only(obj), exp_objs))
1088+
objs = list(filter(lambda obj: not obj_traits.is_loader_only(obj), objs))
1089+
exp_objs = list(filter(lambda obj: not obj_traits.is_loader_only(obj), exp_objs))
10601090

10611091
if len(objs) > 0:
10621092
name = get_table_name(namespace, tags, objs[0])

scripts/templates/ldrddi.cpp.mako

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from templates import helper as th
2424
namespace ur_loader
2525
{
2626
///////////////////////////////////////////////////////////////////////////////
27-
%for obj in th.extract_objs(specs, r"handle"):
27+
%for obj in th.get_adapter_handles(specs):
2828
%if 'class' in obj:
2929
<%
3030
_handle_t = th.subt(n, tags, obj['name'])
@@ -34,7 +34,7 @@ namespace ur_loader
3434
%endif
3535
%endfor
3636

37-
%for obj in th.extract_objs(specs, r"function"):
37+
%for obj in th.get_adapter_functions(specs):
3838
///////////////////////////////////////////////////////////////////////////////
3939
/// @brief Intercept function for ${th.make_func_name(n, tags, obj)}
4040
%if 'condition' in obj:

scripts/templates/ldrddi.hpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from templates import helper as th
2727
namespace ur_loader
2828
{
2929
///////////////////////////////////////////////////////////////////////////////
30-
%for obj in th.extract_objs(specs, r"handle"):
30+
%for obj in th.get_adapter_handles(specs):
3131
%if 'class' in obj:
3232
<%
3333
_handle_t = th.subt(n, tags, obj['name'])

scripts/templates/libapi.cpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ${th.make_func_name(n, tags, obj)}(
5656
%endfor
5757
)
5858
try {
59-
%if th.function_traits.is_loader_only(obj):
59+
%if th.obj_traits.is_loader_only(obj):
6060
return ur_lib::${th.make_func_name(n, tags, obj)}(${", ".join(th.make_param_lines(n, tags, obj, format=["name"]))} );
6161
%else:
6262
%if re.match("Init", obj['name']):

scripts/templates/nullddi.cpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ from templates import helper as th
2222

2323
namespace driver
2424
{
25-
%for obj in th.extract_objs(specs, r"function"):
25+
%for obj in th.get_adapter_functions(specs):
2626
///////////////////////////////////////////////////////////////////////////////
2727
<%
2828
fname = th.make_func_name(n, tags, obj)

scripts/templates/trcddi.cpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from templates import helper as th
2424

2525
namespace ur_tracing_layer
2626
{
27-
%for obj in th.extract_objs(specs, r"function"):
27+
%for obj in th.get_adapter_functions(specs):
2828
///////////////////////////////////////////////////////////////////////////////
2929
/// @brief Intercept function for ${th.make_func_name(n, tags, obj)}
3030
%if 'condition' in obj:

scripts/templates/valddi.cpp.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ from templates import helper as th
2424

2525
namespace ur_validation_layer
2626
{
27-
%for obj in th.extract_objs(specs, r"function"):
27+
%for obj in th.get_adapter_functions(specs):
2828
<%
2929
func_name=th.make_func_name(n, tags, obj)
3030
object_param=th.make_param_lines(n, tags, obj, format=["name"])[-1]

0 commit comments

Comments
 (0)