feat: better iogam
This commit is contained in:
+1
-2
@@ -7,7 +7,6 @@ Email: martinogiordano.ferrari@iter.org
|
|||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import pprint
|
|
||||||
import sys
|
import sys
|
||||||
from argparse import ArgumentParser
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
@@ -62,7 +61,7 @@ def main():
|
|||||||
f"Impossible to parse file `{args.filename}` at position ({e.line},{e.col}): {e.msg}`"
|
f"Impossible to parse file `{args.filename}` at position ({e.line},{e.col}): {e.msg}`"
|
||||||
)
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception as e:
|
except Exception:
|
||||||
logging.error(f"Sometihng went wrong with file `{args.filename}`")
|
logging.error(f"Sometihng went wrong with file `{args.filename}`")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
+116
-66
@@ -3,7 +3,6 @@ Autodoc functions
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
|
|
||||||
__PATH__ = "."
|
__PATH__ = "."
|
||||||
|
|
||||||
@@ -41,8 +40,16 @@ def __num_bytes__(sig):
|
|||||||
noe = 1 if "NumberOfElements" not in sig else int(sig["NumberOfElements"])
|
noe = 1 if "NumberOfElements" not in sig else int(sig["NumberOfElements"])
|
||||||
nod = 1 if "NumberOfDimensions" not in sig else int(sig["NumberOfDimensions"])
|
nod = 1 if "NumberOfDimensions" not in sig else int(sig["NumberOfDimensions"])
|
||||||
nod = nod if nod > 0 else 1
|
nod = nod if nod > 0 else 1
|
||||||
|
noe = noe if noe > 0 else 1
|
||||||
bytes = __type_bytes__(sig["Type"])
|
bytes = __type_bytes__(sig["Type"])
|
||||||
return noe * nod * bytes
|
tot = noe * nod
|
||||||
|
|
||||||
|
if "Ranges" in sig:
|
||||||
|
tot = 0
|
||||||
|
for i0, ie in sig["Ranges"]:
|
||||||
|
tot += int(ie) - int(i0) + 1
|
||||||
|
|
||||||
|
return tot * bytes
|
||||||
|
|
||||||
|
|
||||||
def __doc_app_state__(state, tab=" │ "):
|
def __doc_app_state__(state, tab=" │ "):
|
||||||
@@ -66,7 +73,8 @@ def __sig_type__(sig):
|
|||||||
nod = int(sig["NumberOfDimensions"]) if "NumberOfDimensions" in sig else 1
|
nod = int(sig["NumberOfDimensions"]) if "NumberOfDimensions" in sig else 1
|
||||||
nod = nod if nod > 0 else 1
|
nod = nod if nod > 0 else 1
|
||||||
dim = noe * nod
|
dim = noe * nod
|
||||||
return (type_name, dim)
|
range = sig["Ranges"] if "Ranges" in sig else []
|
||||||
|
return (type_name, dim, range)
|
||||||
|
|
||||||
|
|
||||||
def __sig_alias__(name, signal):
|
def __sig_alias__(name, signal):
|
||||||
@@ -158,59 +166,71 @@ def __doc_iogam__(id, obj, edges, thread):
|
|||||||
output_names = list(outputs.keys())
|
output_names = list(outputs.keys())
|
||||||
input_names = list(inputs.keys())
|
input_names = list(inputs.keys())
|
||||||
j = 0
|
j = 0
|
||||||
isize = 0
|
input_size = 0
|
||||||
osize = 0
|
output_size = 0
|
||||||
i = 0
|
i = 0
|
||||||
irow = ""
|
irow = ""
|
||||||
orow = ""
|
orow = ""
|
||||||
|
counter = 0
|
||||||
while i < len(inputs):
|
while i < len(inputs) and j < len(outputs):
|
||||||
in_label = input_names[i]
|
irelcount = 0
|
||||||
input = inputs[in_label]
|
orelcount = 0
|
||||||
if irow:
|
bold = False
|
||||||
irow += " | "
|
while input_size <= output_size and i < len(inputs):
|
||||||
irow += f"<in_{__sig_name__(in_label)}> {in_label}"
|
in_label = input_names[i]
|
||||||
isize += __num_bytes__(input)
|
input = inputs[in_label]
|
||||||
i += 1
|
if irow:
|
||||||
alias = __sig_alias__(in_label, input)
|
irow += " | "
|
||||||
mtype = __sig_type__(input)
|
input_size += __num_bytes__(input)
|
||||||
datasrc = input["DataSource"]
|
i += 1
|
||||||
edges.append(
|
alias = __sig_alias__(in_label, input)
|
||||||
__edge__(
|
mtype = __sig_type__(input)
|
||||||
__sig__(datasrc, alias, mtype),
|
if mtype[2]:
|
||||||
__sig__(id, in_label, mtype),
|
bold = True
|
||||||
thread,
|
irow += f"<in_{irelcount}> {__type_to_str__(mtype)}"
|
||||||
|
datasrc = input["DataSource"]
|
||||||
|
edges.append(
|
||||||
|
__edge__(
|
||||||
|
__sig__(datasrc, alias, mtype),
|
||||||
|
__sig__(f"{id}_{counter}", f"{irelcount}", mtype),
|
||||||
|
thread,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
irelcount += 1
|
||||||
while osize < isize and j < len(outputs):
|
while output_size < input_size and j < len(outputs):
|
||||||
out_label = output_names[j]
|
out_label = output_names[j]
|
||||||
output = outputs[out_label]
|
output = outputs[out_label]
|
||||||
osize += __num_bytes__(output)
|
output_size += __num_bytes__(output)
|
||||||
if orow:
|
if orow:
|
||||||
orow += " | "
|
orow += " | "
|
||||||
orow += f"<out_{__sig_name__(out_label)}> {out_label}"
|
|
||||||
j += 1
|
j += 1
|
||||||
|
|
||||||
alias = __sig_alias__(out_label, output)
|
alias = __sig_alias__(out_label, output)
|
||||||
mtype = __sig_type__(output)
|
mtype = __sig_type__(output)
|
||||||
|
if mtype[2]:
|
||||||
|
bold = True
|
||||||
|
orow += f"<out_{orelcount}> {__type_to_str__(mtype)}"
|
||||||
datasrc = output["DataSource"]
|
datasrc = output["DataSource"]
|
||||||
edges.append(
|
edges.append(
|
||||||
__edge__(
|
__edge__(
|
||||||
__sig__(id, out_label, mtype),
|
__sig__(f"{id}_{counter}", f"{orelcount}", mtype),
|
||||||
__sig__(datasrc, alias, mtype),
|
__sig__(datasrc, alias, mtype),
|
||||||
thread,
|
thread,
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
if isize == osize and irow and orow:
|
orelcount += 1
|
||||||
if node:
|
fill = "#999"
|
||||||
node += " | "
|
fsize = 14.0
|
||||||
node += "{ {" + irow + "} | {" + orow + "} }"
|
if bold or irelcount > 1 or orelcount > 1:
|
||||||
irow = ""
|
fill = "#333"
|
||||||
orow = ""
|
else:
|
||||||
if irow or orow:
|
fsize = 8.0
|
||||||
if node:
|
node += f'{id}_{counter} [tooltip=" IOGAM::{id} " label="'
|
||||||
node += " | "
|
|
||||||
node += "{ {" + irow + "} | {" + orow + "} }"
|
node += "{ {" + irow + "} | {" + orow + "} }"
|
||||||
|
node += f'", fillcolor="{fill}", color="#666", style=filled,'
|
||||||
|
node += f' fontcolor="#fff", fontsize={fsize}, height=0];\n'
|
||||||
|
irow = ""
|
||||||
|
orow = ""
|
||||||
|
counter += 1
|
||||||
return node, edges
|
return node, edges
|
||||||
|
|
||||||
|
|
||||||
@@ -222,7 +242,11 @@ def __doc_constgam__(id, obj, edges, thread):
|
|||||||
alias = __sig_alias__(l, sig)
|
alias = __sig_alias__(l, sig)
|
||||||
mtype = __sig_type__(sig)
|
mtype = __sig_type__(sig)
|
||||||
edges.append(
|
edges.append(
|
||||||
__edge__(__sig__(id, l, mtype), __sig__(datasrc, alias, mtype), thread)
|
__edge__(
|
||||||
|
__sig__(id, l, mtype),
|
||||||
|
__sig__(datasrc, alias, mtype),
|
||||||
|
thread,
|
||||||
|
)
|
||||||
)
|
)
|
||||||
if i != 0:
|
if i != 0:
|
||||||
node += " | "
|
node += " | "
|
||||||
@@ -241,7 +265,7 @@ def __doc_gam__(label, obj, edges, thread):
|
|||||||
if cls == "ConstantGAM":
|
if cls == "ConstantGAM":
|
||||||
sigs, datasources = __doc_constgam__(id, obj, edges, thread)
|
sigs, datasources = __doc_constgam__(id, obj, edges, thread)
|
||||||
elif cls == "IOGAM":
|
elif cls == "IOGAM":
|
||||||
sigs, datasources = __doc_iogam__(id, obj, edges, thread)
|
return __doc_iogam__(id, obj, edges, thread)
|
||||||
elif cls == "TriggeredIOGAM":
|
elif cls == "TriggeredIOGAM":
|
||||||
sigs, datasources = __doc_triggered_iogam__(id, obj, edges, thread)
|
sigs, datasources = __doc_triggered_iogam__(id, obj, edges, thread)
|
||||||
else:
|
else:
|
||||||
@@ -255,37 +279,48 @@ def __doc_gam__(label, obj, edges, thread):
|
|||||||
|
|
||||||
def __process_gamds__(name, signals, edges):
|
def __process_gamds__(name, signals, edges):
|
||||||
node = ""
|
node = ""
|
||||||
ok = False
|
|
||||||
outputs = {}
|
outputs = {}
|
||||||
inputs = {}
|
inputs = {}
|
||||||
for sig_name in signals:
|
done = False
|
||||||
|
while not done:
|
||||||
|
signals = {}
|
||||||
for edge in edges:
|
for edge in edges:
|
||||||
if edge[0][0] == name and edge[0][1] == sig_name:
|
if edge[0][0] == name:
|
||||||
|
sig_name = edge[0][1]
|
||||||
|
signals[sig_name] = edge[0][2]
|
||||||
if sig_name not in outputs:
|
if sig_name not in outputs:
|
||||||
outputs[sig_name] = []
|
outputs[sig_name] = []
|
||||||
outputs[sig_name].append(edge)
|
outputs[sig_name].append(edge)
|
||||||
elif edge[1][0] == name and edge[1][1] == sig_name:
|
elif edge[1][0] == name:
|
||||||
|
sig_name = edge[1][1]
|
||||||
|
signals[sig_name] = edge[1][2]
|
||||||
if sig_name not in inputs:
|
if sig_name not in inputs:
|
||||||
inputs[sig_name] = []
|
inputs[sig_name] = []
|
||||||
inputs[sig_name].append(edge)
|
inputs[sig_name].append(edge)
|
||||||
to_reduce = []
|
to_reduce = []
|
||||||
to_keep = []
|
to_keep = []
|
||||||
for sig_name in signals:
|
done = True
|
||||||
if sig_name in inputs and sig_name in outputs:
|
for sig_name in signals:
|
||||||
to_reduce.append(sig_name)
|
if sig_name in inputs and sig_name in outputs:
|
||||||
else:
|
to_reduce.append(sig_name)
|
||||||
to_keep.append(sig_name)
|
else:
|
||||||
for sig_name in to_reduce:
|
to_keep.append(sig_name)
|
||||||
ins = inputs[sig_name]
|
|
||||||
outs = outputs[sig_name]
|
for sig_name in to_reduce:
|
||||||
for edge in ins:
|
ins = inputs[sig_name]
|
||||||
edges.remove(edge)
|
outs = outputs[sig_name]
|
||||||
for edge in outs:
|
for edge in ins:
|
||||||
edges.remove(edge)
|
if edge in edges:
|
||||||
for in_edge in ins:
|
done = False
|
||||||
for out_edge in outs:
|
edges.remove(edge)
|
||||||
edge = (in_edge[0], out_edge[1], in_edge[-1])
|
for edge in outs:
|
||||||
edges.append(edge)
|
if edge in edges:
|
||||||
|
done = False
|
||||||
|
edges.remove(edge)
|
||||||
|
for in_edge in ins:
|
||||||
|
for out_edge in outs:
|
||||||
|
edge = (in_edge[0], out_edge[1], in_edge[-1])
|
||||||
|
edges.append(edge)
|
||||||
|
|
||||||
for i, sig_name in enumerate(to_keep):
|
for i, sig_name in enumerate(to_keep):
|
||||||
if i > 0:
|
if i > 0:
|
||||||
@@ -346,14 +381,26 @@ def __process_ds__(name, obj, edges):
|
|||||||
node += f"<{__sig_name__(sig_name)}> {sig_name} ({__type_to_str__(sig_type)})"
|
node += f"<{__sig_name__(sig_name)}> {sig_name} ({__type_to_str__(sig_type)})"
|
||||||
node += '", color=blue];\n'
|
node += '", color=blue];\n'
|
||||||
if not multi_thread and node:
|
if not multi_thread and node:
|
||||||
node = f"subgraph cluster_{thread}" + "{" + node + "};"
|
node = f"subgraph cluster_{thread}" + "{\n" + node + "};\n"
|
||||||
return node, edges
|
return node, edges
|
||||||
|
|
||||||
|
|
||||||
def __type_to_str__(mtype):
|
def __type_to_str__(mtype):
|
||||||
|
range = ""
|
||||||
|
if mtype[2]:
|
||||||
|
range = (
|
||||||
|
"("
|
||||||
|
+ ", ".join(
|
||||||
|
[
|
||||||
|
str(i0) if i0 == i1 else (str(i0) + ":" + str(int(i1) + 1))
|
||||||
|
for i0, i1 in mtype[2]
|
||||||
|
]
|
||||||
|
)
|
||||||
|
+ ")"
|
||||||
|
)
|
||||||
if mtype[1] != 1:
|
if mtype[1] != 1:
|
||||||
return f"{mtype[0]}[{mtype[1]}]"
|
return f"{mtype[0]}[{mtype[1]}]{range}"
|
||||||
return mtype[0]
|
return mtype[0] + range
|
||||||
|
|
||||||
|
|
||||||
def __process_edges__(edges, datasources):
|
def __process_edges__(edges, datasources):
|
||||||
@@ -387,7 +434,7 @@ def __doc_state__(label, state, app):
|
|||||||
graph += "graph [ranksep=2];\n"
|
graph += "graph [ranksep=2];\n"
|
||||||
graph += "rankdir = LR;\n"
|
graph += "rankdir = LR;\n"
|
||||||
graph += "beautify = true;\n"
|
graph += "beautify = true;\n"
|
||||||
graph += "node [shape=record];\n"
|
graph += "node [shape=Mrecord];\n"
|
||||||
graph += "\n"
|
graph += "\n"
|
||||||
arrows = ""
|
arrows = ""
|
||||||
ext = ""
|
ext = ""
|
||||||
@@ -403,7 +450,10 @@ def __doc_state__(label, state, app):
|
|||||||
obj = app["+Functions"][f"+{fn}"]
|
obj = app["+Functions"][f"+{fn}"]
|
||||||
node, edges = __doc_gam__(fn, obj, edges, tname[1:])
|
node, edges = __doc_gam__(fn, obj, edges, tname[1:])
|
||||||
graph += f"{node}\n"
|
graph += f"{node}\n"
|
||||||
graph += f' label = "{tname[1:]}";\n'
|
graph += f"\n label = < <B>{tname[1:]}</B> >;\n"
|
||||||
|
graph += " fontsize = 24.0;\n"
|
||||||
|
graph += " penwidth = 3;\n"
|
||||||
|
graph += ' color = "#0A0";\n'
|
||||||
graph += "}\n"
|
graph += "}\n"
|
||||||
if "+Data" in app:
|
if "+Data" in app:
|
||||||
for key, obj in app["+Data"].items():
|
for key, obj in app["+Data"].items():
|
||||||
|
|||||||
Reference in New Issue
Block a user