Merge branch 'devel' of github.com:ehw-fit/ariths-gen into devel

This commit is contained in:
Vojta Mrazek 2023-02-22 09:52:34 +01:00
commit 6dd69c5aaa
3 changed files with 23 additions and 0 deletions

View File

@ -46,6 +46,11 @@ class GeneralCircuit():
return self.pyc(*args)
def __str__(self):
return f"<{type(self).__name__} prefix={self.prefix} " + (", ".join([f"input={i}" for i in self.inputs])) + ">"
#super().__init__(prefix, name, out_N, inner_component, inputs=[a, b], signed=signed, **kwargs)
def add_component(self, component):
"""Adds a component into list of circuit's inner subcomponents.

View File

@ -80,6 +80,9 @@ class Bus():
def __getitem__(self, i):
return self.bus[i]
def __getitem__(self, i):
return self.get_wire(i)
# Connecting output wire of the inner circuit component to desired position in the described circuit's output bus
def connect(self, bus_wire_index: int, inner_component_out_wire: Wire, inserted_wire_desired_index: int = -1):
"""Connects given 'Wire' object to a 'bus_wire_index' within this bus.
@ -103,6 +106,9 @@ class Bus():
elif inserted_wire_desired_index != -1:
self.bus[bus_wire_index] = Wire(name=inner_component_out_wire.name, prefix=inner_component_out_wire.parent_bus.prefix, index=inserted_wire_index, value=inner_component_out_wire.value, parent_bus=self)
def __setitem__(self, i, v):
self.connect(i, v)
def connect_bus(self, connecting_bus: object, start_connection_pos: int = 0, end_connection_pos: int = -1, offset: int = 0):
"""Ensures connection of specified bus wires to this bus wires.
@ -144,6 +150,9 @@ class Bus():
else:
return ""
def __str__(self):
return f"<wire N={self.N} prefix={self.prefix} \"" + (",".join([str(w) for w in self.bus])) + "\">"
""" C CODE GENERATION """
def get_declaration_c(self):
"""Bus declaration in C code.

View File

@ -246,6 +246,13 @@ class Wire():
else:
return self.prefix
def __str__(self):
if self.is_const():
return f"<w={self.c_const}>"
elif self.is_buswire():
return f"<w={self.prefix}[{self.index}]>"
else:
return f"<w={self.name}>"
# Wires with constant values #
class ConstantWireValue0(Wire):
@ -281,6 +288,7 @@ class ConstantWireValue0(Wire):
return True
class ConstantWireValue1(Wire):
"""Class representing wire carrying constant value 1 used to interconnect components.
@ -312,3 +320,4 @@ class ConstantWireValue1(Wire):
bool: True, because constant wire carries a constant value 1.
"""
return True