-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Scheduler.process: apply directly to program unit corresponding to Item #137
Changes from all commits
671d206
7d02d80
03a6f97
12d99c0
581ea22
d4c926c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,11 +79,35 @@ def transform_subroutine(self, routine, **kwargs): | |
""" | ||
role = kwargs.get('role') | ||
|
||
if role == 'kernel': | ||
# If applied recursively over all routines in a sourcefile, we may | ||
# visit contained member subroutines. Since these are not outward facing | ||
# it is not necessary to update their name. | ||
is_member = isinstance(routine.parent, Subroutine) | ||
|
||
# Pick out correct item for current subroutine if processed via recursion | ||
if 'items' in kwargs: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't quite understand why this is necessary. This snippet here suggests we're updating the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's due to the fact that the cleanest way of calling this transformation is via the file graph and then using the transformation's recursion to trickle down into the various nodes. However, with that the |
||
item_names = [item_.local_name for item_ in kwargs['items']] | ||
if routine.name.lower() in item_names: | ||
kwargs['item'] = kwargs['items'][item_names.index(routine.name.lower())] | ||
|
||
# If called without explicit role or target, extract from Item | ||
# We need to do this here to cache the value for targets, because | ||
# rename_calls will change this property | ||
if (item := kwargs.get('item')): | ||
if not role: | ||
kwargs['role'] = item.role | ||
role = item.role | ||
if not kwargs.get('targets'): | ||
kwargs['targets'] = item.targets | ||
|
||
if role == 'kernel' and not is_member: | ||
if routine.name.endswith(self.suffix): | ||
# This is to ensure that the transformation is idempotent if | ||
# applied more than once to a routine | ||
return | ||
# Change the name of kernel routines | ||
if routine.is_function: | ||
if not routine.result_name: | ||
self.update_result_var(routine) | ||
if routine.is_function and not routine.result_name: | ||
self.update_result_var(routine) | ||
routine.name += self.suffix | ||
|
||
self.rename_calls(routine, **kwargs) | ||
|
@@ -96,7 +120,7 @@ def transform_subroutine(self, routine, **kwargs): | |
intfs = FindNodes(Interface).visit(routine.spec) | ||
self.rename_interfaces(routine, intfs=intfs, **kwargs) | ||
|
||
if role == 'kernel' and self.mode == 'strict': | ||
if role == 'kernel' and self.mode == 'strict' and not is_member: | ||
# Re-generate C-style interface header | ||
self.generate_interfaces(routine) | ||
|
||
|
@@ -120,6 +144,8 @@ def transform_module(self, module, **kwargs): | |
Rename kernel modules and re-point module-level imports. | ||
""" | ||
role = kwargs.get('role') | ||
if not role and 'item' in kwargs: | ||
role = kwargs['item'].role | ||
|
||
if role == 'kernel': | ||
# Change the name of kernel modules | ||
|
@@ -134,6 +160,8 @@ def transform_file(self, sourcefile, **kwargs): | |
In 'module' mode perform module-wrapping for dependnecy injection. | ||
""" | ||
role = kwargs.get('role') | ||
if not role and 'item' in kwargs: | ||
role = kwargs['item'].role | ||
if role == 'kernel' and self.mode == 'module': | ||
self.module_wrap(sourcefile, **kwargs) | ||
|
||
|
@@ -144,9 +172,9 @@ def rename_calls(self, routine, **kwargs): | |
:param targets: Optional list of subroutine names for which to | ||
modify the corresponding calls. | ||
""" | ||
targets = as_tuple(kwargs.get('targets', None)) | ||
targets = as_tuple(kwargs.get('targets')) | ||
targets = as_tuple(str(t).upper() for t in targets) | ||
members = [r.name for r in routine.subroutines] | ||
members = [r.name.upper() for r in routine.subroutines] | ||
|
||
if self.replace_ignore_items: | ||
item = kwargs.get('item', None) | ||
|
@@ -159,6 +187,8 @@ def rename_calls(self, routine, **kwargs): | |
call._update(name=call.name.clone(name=f'{call.name}{self.suffix}')) | ||
|
||
for call in FindInlineCalls(unique=False).visit(routine.body): | ||
if call.name.upper() in members: | ||
continue | ||
if targets is None or call.name.upper() in targets: | ||
call.function = call.function.clone(name=f'{call.name}{self.suffix}') | ||
|
||
|
@@ -169,7 +199,9 @@ def rename_imports(self, source, imports, **kwargs): | |
:param targets: Optional list of subroutine names for which to | ||
modify the corresponding calls. | ||
""" | ||
targets = as_tuple(kwargs.get('targets', None)) | ||
targets = as_tuple(kwargs.get('targets')) | ||
if not targets and 'item' in kwargs: | ||
targets = as_tuple(kwargs['item'].targets) | ||
targets = as_tuple(str(t).upper() for t in targets) | ||
|
||
# We don't want to rename module variable imports, so we build | ||
|
@@ -234,10 +266,12 @@ def rename_interfaces(self, source, intfs, **kwargs): | |
Update explicit interfaces to actively transformed subroutines. | ||
""" | ||
|
||
targets = as_tuple(kwargs.get('targets', None)) | ||
targets = as_tuple(kwargs.get('targets')) | ||
if not targets and 'item' in kwargs: | ||
targets = as_tuple(kwargs['item'].targets) | ||
targets = as_tuple(str(t).lower() for t in targets) | ||
|
||
if self.replace_ignore_items and (item := kwargs.get('item', None)): | ||
if self.replace_ignore_items and (item := kwargs.get('item')): | ||
targets += as_tuple(str(i).lower() for i in item.ignore) | ||
|
||
# Transformer map to remove any outdated interfaces | ||
|
@@ -296,6 +330,8 @@ def module_wrap(self, sourcefile, **kwargs): | |
Wrap target subroutines in modules and replace in source file. | ||
""" | ||
targets = as_tuple(kwargs.get('targets', None)) | ||
if not targets and 'item' in kwargs: | ||
targets = as_tuple(kwargs['item'].targets) | ||
targets = as_tuple(str(t).upper() for t in targets) | ||
item = kwargs.get('item', None) | ||
|
||
|
@@ -305,7 +341,7 @@ def module_wrap(self, sourcefile, **kwargs): | |
for routine in sourcefile.subroutines: | ||
if routine not in module_routines: | ||
# Skip member functions | ||
if item and f'#{routine.name.lower()}' != item.name.lower(): | ||
if item and routine.name.lower() != item.local_name.lower(): | ||
continue | ||
|
||
# Skip internal utility routines too | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[no action] Yes it should, but I think this requires the SGraph from the scheduler rewrite to be done cleanly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed