Commit c39d03e4 authored by Samuel GAIST's avatar Samuel GAIST
Browse files

[toolchain] Implement support for loop blocks handling

parent 14b46b15
......@@ -141,14 +141,21 @@ class Toolchain(object):
channels = []
inputs = []
outputs = []
loops = []
names = {}
connections = []
loop_connections = []
self._check_datasets(channels, outputs, names)
self._check_blocks(channels, inputs, outputs, names)
self._check_loops(channels, inputs, names)
self._check_analyzers(channels, inputs, names)
self._check_connections(channels, inputs, outputs, connections)
self._check_representation(channels, names, connections)
self._check_representation(channels, names, connections, loop_connections)
def _check_datasets(self, channels, outputs, names):
"""Checks all datasets"""
......@@ -189,6 +196,31 @@ class Toolchain(object):
return channels, inputs, outputs, names
def _check_loops(self, channels, inputs, names):
""" Check all loops"""
if 'loops' not in
return channels, inputs, names
for i, loop in enumerate(['loops']):
loop_name = loop['name']
if loop_name in names:
self.errors.append("/loops/[#%d]/name: duplicated name, first " \
"occurance of '%s' happened at '%s'" % \
(i, loop_name, names[loop_name]))
names[loop_name] = "/loops/%s[#%d]" % (loop_name, i)
inputs += ['%s.%s' % (loop_name, k) for k in loop['inputs']]
if loop['synchronized_channel'] not in channels:
self.errors.append("/loopss/%s[#%d]/synchronized_channel: " \
"invalid synchronization channel '%s'" % \
(loop_name, i, loop['synchronized_channel']))
return channels, inputs, names
def _check_analyzers(self, channels, inputs, names):
"""Checks all analyzers"""
......@@ -253,7 +285,34 @@ class Toolchain(object):
self.errors.append("input(s) `%s' remain unconnected" % \
(", ".join(unconnected_inputs),))
def _check_representation(self, channels, names, connections):
def _check_loop_connections(self, loop_connections):
"""Checks loop connection consistency"""
if not 'loop_connections' in
endpoints = dict()
unconnected_endpoints = dict()
for i, connection in enumerate(['loop_connections']):
from_ = connection['from']
to_ = connection['to']
if from_ in endpoints:
connected = endpoints[to_]
self.errors.append("/loop_connection/%s->%s[#%d]/: ending on the same "
"endpoint as /loop_connection/%s->%s[#%d] is unsupported" % (
from_, to_, i,
connected['from'], connected['to'], connected['position'],
endpoints[to_] = {
"from": from_,
"position": i
loop_connections.append("%s/%s" % (from_, to_))
def _check_representation(self, channels, names, connections, loop_connections):
"""Checks the representation for this toolchain"""
# all connections must exist
......@@ -309,6 +368,14 @@ class Toolchain(object):
return dict(zip([k['name'] for k in data], data))
def loops(self):
"""All declared loops"""
data ='loops', {})
return dict(zip([k['name'] for k in data], data))
def analyzers(self):
"""All declared analyzers"""
......@@ -317,12 +384,47 @@ class Toolchain(object):
return dict(zip([k['name'] for k in data], data))
def algorithm_item(self, name):
""" Returns a block, loop or analyzer matching the name given"""
item = None
for algo_items in [self.blocks,
if name in algo_items:
item = algo_items.get(name)
return item
def get_loop_for_block(self, name):
loop = None
block = self.blocks.get(name, None)
if block is not None:
for connection in self.loop_connections:
if name in connection['from']:
loop_name = connection['to'].split('.')[0]
loop = self.loops.get(loop_name)
return loop
def connections(self):
"""All declared connections"""
def loop_connections(self):
"""All declared connections"""
return'loop_connections', {})
def dependencies(self, name):
"""Returns the block dependencies for a given block/analyzer in a set
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment