Skip to content
Snippets Groups Projects
Commit 928c76b8 authored by Oscar Gustafsson's avatar Oscar Gustafsson :bicyclist:
Browse files

Save SFGs without duplicated operations

parent a540a3f4
No related branches found
No related tags found
No related merge requests found
...@@ -7,10 +7,10 @@ as files. ...@@ -7,10 +7,10 @@ as files.
from datetime import datetime from datetime import datetime
from inspect import signature from inspect import signature
from os import path
from b_asic.graph_component import GraphComponent from b_asic.graph_component import GraphComponent
from b_asic.signal_flow_graph import SFG from b_asic.signal_flow_graph import SFG
from b_asic.special_operations import Input, Output
def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str: def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str:
...@@ -48,6 +48,9 @@ def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str: ...@@ -48,6 +48,9 @@ def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str:
[f"{param[0]}={param[1]}" for param in params.items()] [f"{param[0]}={param[1]}" for param in params.items()]
) )
# No need to redefined I/Os
io_ops = [*sfg._input_operations, *sfg._output_operations]
result += "\n# Inputs:\n" result += "\n# Inputs:\n"
for op in sfg._input_operations: for op in sfg._input_operations:
result += f"{op.graph_id} = Input({kwarg_unpacker(op)})\n" result += f"{op.graph_id} = Input({kwarg_unpacker(op)})\n"
...@@ -58,6 +61,8 @@ def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str: ...@@ -58,6 +61,8 @@ def sfg_to_python(sfg: SFG, counter: int = 0, suffix: str = None) -> str:
result += "\n# Operations:\n" result += "\n# Operations:\n"
for op in sfg.split(): for op in sfg.split():
if op in io_ops:
continue
if isinstance(op, SFG): if isinstance(op, SFG):
counter += 1 counter += 1
result = sfg_to_python(op, counter) + result result = sfg_to_python(op, counter) + result
...@@ -114,6 +119,6 @@ def python_to_sfg(path: str) -> SFG: ...@@ -114,6 +119,6 @@ def python_to_sfg(path: str) -> SFG:
exec(code, globals(), locals()) exec(code, globals(), locals())
return ( return (
locals()["prop"]["name"], locals()["prop"]["name"] if "prop" in locals() else {},
locals()["positions"] if "positions" in locals() else {}, locals()["positions"] if "positions" in locals() else {},
) )
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment