{% macro io(node,theio) -%}
{% if not node.hasManyIOs %}{{node.nodeID}}:i{% else %}{{node.nodeID}}:{{theio.name}}{% endif %}
{%- endmacro %}

{% macro constdst(theID) -%}
{{constEdges[theID][1].owner.nodeID}}:{{constEdges[theID][1].name}}
{% endmacro -%}

{% macro delayBoxID(id) -%}{{fifos[id].src.owner.nodeID}}Delay{%- endmacro %}

{% macro delayBox(edge) -%}
{% if fifos[edge].hasDelay %}
{{delayBoxID(edge)}} [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ALIGN="CENTER" PORT="i">{{fifos[edge].delay}}</TD>
  </TR>
</TABLE>>];
{% endif %}
{%- endmacro %}

digraph structs {
    node [shape=plaintext]
{% if config.horizontal %}
    rankdir=LR
{% endif %}
    edge [arrowsize=0.5]
    fontname="times"

{% for item in nodes %}

{% if not item.hasManyIOs %}
{{item.nodeID}} [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ALIGN="CENTER" PORT="i">{{item.graphvizName}}</TD>
  </TR>
</TABLE>>];
{% else %}

{% if not config.horizontal %}

{{item.nodeID}} [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    {% for id in range(0,item.maxNbIOs) -%}
    {% if item.inputNames[id] -%}
    {% set input %}{{item.inputNames[id]}}{% endset %}
    <TD PORT="{{input}}"><FONT POINT-SIZE="9.0">{{input}}</FONT></TD>
    {% else %}
    <TD></TD>
    {%- endif %}
    {%- endfor %}
  </TR>
  <TR>
    <TD ALIGN="CENTER" COLSPAN="{{item.maxNbIOs}}">{{ item.graphvizName }}</TD>
  </TR>
  <TR>
    {% for id in range(0,item.maxNbIOs) -%}
    {% if item.outputNames[id] -%}
    {% set output %}{{item.outputNames[id]}}{% endset %}
    <TD PORT="{{output}}"><FONT POINT-SIZE="9.0">{{output}}</FONT></TD>
    {% else %}
    <TD></TD>
    {%- endif %}
    {%- endfor %}
  </TR>
</TABLE>>];
{% else %}
{{item.nodeID}} [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
{% if item.inputNames[0] is defined %}
    <TD PORT="{{item.inputNames[0]}}"><FONT POINT-SIZE="9.0">{{item.inputNames[0]}}</FONT></TD>
{% else %}
    <TD></TD>
{% endif %}
    <TD ALIGN="CENTER" ROWSPAN="{{item.maxNbIOs}}">{{ item.graphvizName }}</TD>
{% if item.outputNames[0] is defined %}
    <TD PORT="{{item.outputNames[0]}}"><FONT POINT-SIZE="9.0">{{item.outputNames[0]}}</FONT></TD>
{% else %}
    <TD></TD>
{% endif %}
  </TR>
{% for id in range(1,item.maxNbIOs) -%}
<TR>
{% if item.inputNames[id] -%}
{% set input %}{{item.inputNames[id]}}{% endset %}
<TD PORT="{{input}}"><FONT POINT-SIZE="9.0">{{input}}</FONT></TD>
{% else %} 
<TD></TD>
{%- endif %}

{% if item.outputNames[id] -%}
{% set output %}{{item.outputNames[id]}}{% endset %}
<TD PORT="{{output}}"><FONT POINT-SIZE="9.0">{{output}}</FONT></TD>
{% else %} 
<TD></TD>
{%- endif %}
</TR>
{%- endfor %}


</TABLE>>];
{% endif %}
{% endif %}
{% endfor %}


{% for id in range(nbFifos) %}
{{delayBox(id)}}
{% if fifos[id].hasDelay %}

{{io(fifos[id].src.owner,fifos[id].src)}} -> {{delayBoxID(id)}}:i [taillabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].src.nbSamples}}</FONT>
</TD></TR></TABLE>>]

{% if config.displayFIFOBuf %}
{{delayBoxID(id)}}:i -> {{io(fifos[id].dst.owner,fifos[id].dst)}} [headlabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].dst.nbSamples}}</FONT>
</TD></TR></TABLE>>,label="buf{{fifos[id].bufferID}}"]
{% else %}
{{delayBoxID(id)}}:i -> {{io(fifos[id].dst.owner,fifos[id].dst)}} [headlabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].dst.nbSamples}}</FONT>
</TD></TR></TABLE>>,label="{{fifos[id].theType.graphViztype}}({{fifos[id].length}})"]
{% endif %}

{% else %}
{% if config.displayFIFOBuf %}
{{io(fifos[id].src.owner,fifos[id].src)}} -> {{io(fifos[id].dst.owner,fifos[id].dst)}} [headlabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].dst.nbSamples}}</FONT>
</TD></TR></TABLE>>,taillabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].src.nbSamples}}</FONT>
</TD></TR></TABLE>>,label="buf{{fifos[id].bufferID}}"]
{% else %}
{{io(fifos[id].src.owner,fifos[id].src)}} -> {{io(fifos[id].dst.owner,fifos[id].dst)}} [headlabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].dst.nbSamples}}</FONT>
</TD></TR></TABLE>>,taillabel=<
<TABLE BORDER="0" CELLPADDING="2"><TR><TD><FONT COLOR="blue" POINT-SIZE="12.0" >{{fifos[id].src.nbSamples}}</FONT>
</TD></TR></TABLE>>,label="{{fifos[id].theType.graphViztype}}({{fifos[id].length}})"]
{% endif %}
{% endif %}
{% endfor %}

{% for c in constObjs %}
{{c.name}} [label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
  <TR>
    <TD ALIGN="CENTER" PORT="i">{{c.name}}</TD>
  </TR>
</TABLE>>];
{% endfor %}

{% for edgeID in range(nbConstEdges) %}
{{constEdges[edgeID][0].name}}:i -> {{constdst(edgeID)}}
{% endfor %}
}