2020-05-06 11:46:43 +08:00
|
|
|
def indent(string: str) -> str:
|
2020-11-16 21:22:16 +08:00
|
|
|
return string.replace('\n', '\n ')
|
|
|
|
|
|
|
|
|
2020-11-17 12:06:33 +08:00
|
|
|
def auto_connect(ma, mb):
|
2020-11-17 12:11:40 +08:00
|
|
|
from pyhcl import IO
|
|
|
|
assert hasattr(ma, "value") and hasattr(mb, "value")
|
|
|
|
assert type(ma.value) == IO and type(mb.value) == IO
|
|
|
|
|
2020-11-17 12:06:33 +08:00
|
|
|
for (key_left, value_left) in ma.value._ios.items():
|
|
|
|
for (key_right, value_right) in mb.value._ios.items():
|
|
|
|
from pyhcl import Input, Output
|
|
|
|
assert type(value_left) == Input or type(value_left) == Output
|
|
|
|
assert type(value_right) == Input or type(value_right) == Output
|
|
|
|
|
|
|
|
if key_left == key_right and type(value_left) != type(value_right):
|
2020-11-17 14:04:34 +08:00
|
|
|
io_left = getattr(ma, key_left)
|
|
|
|
io_right = getattr(mb, key_right)
|
2020-11-17 12:06:33 +08:00
|
|
|
if type(value_left) == Input:
|
2020-11-17 14:04:34 +08:00
|
|
|
io_left <<= io_right
|
2020-11-17 12:06:33 +08:00
|
|
|
else:
|
2020-11-17 14:04:34 +08:00
|
|
|
io_right <<= io_left
|