Skip to content
Snippets Groups Projects
Commit 73e2d3ec authored by Jammer, Tim's avatar Jammer, Tim
Browse files

Added Functionality to remove/replace operations to InstructionBlock (#1)

parent bf9a7530
Branches
No related tags found
No related merge requests found
...@@ -16,8 +16,16 @@ class InstructionBlock: ...@@ -16,8 +16,16 @@ class InstructionBlock:
- `__str__(self)`: Converts the InstructionBlock instance to a string, replacing placeholders. - `__str__(self)`: Converts the InstructionBlock instance to a string, replacing placeholders.
""" """
def __init__(self): def __init__(self, name=None):
"""
Initialize an empty InstructionBlock
Parameters:
- name: The name of the block (for referencing this block with the template Manager)
May be None, does not influence the code generated
"""
self.operations = {'all': [], 'not0': [], } self.operations = {'all': [], 'not0': [], }
self.name = name
# TODO test if op also can be a list of operations # TODO test if op also can be a list of operations
def register_operation(self, op, kind='all'): def register_operation(self, op, kind='all'):
...@@ -79,3 +87,37 @@ class InstructionBlock: ...@@ -79,3 +87,37 @@ class InstructionBlock:
result_str += "}\n" result_str += "}\n"
return result_str return result_str
def get_operation(self, kind=all, index=0):
"""
Retrieve the operation registered. will Raise IndexError if not present
Parameters:
- kind ('all','not0' or integer): which ranks should execute the operation
- index (int): the index of the operation within the given kind
Returns:
str: The operation specified by kind and index
"""
return self.operations[kind][index]
def replace_operation(self, op, kind=all, index=0):
"""
Replace the operation registered. will Raise IndexError if not present
Parameters:
- op (str or MPICall) the new operation
- kind ('all','not0' or integer): which ranks should execute the operation
- index (int): the index of the operation within the given kind
"""
if len(self.operations[kind]) >= index:
raise IndexError("Operation Not Found")
self.operations[kind][index] = op
def remove_operation(self, kind=all, index=0):
"""
Removes the operation registered. will Raise IndexError if not present
Parameters:
- kind ('all','not0' or integer): which ranks should execute the operation
- index (int): the index of the operation within the given kind
"""
if len(self.operations[kind]) >= index:
raise IndexError("Operation Not Found")
del self.operations[kind][index]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment