Skip to content

Commit

Permalink
Merge branch 'master' into exceptions-integration
Browse files Browse the repository at this point in the history
  • Loading branch information
piotro888 committed Nov 29, 2023
2 parents 9a3c71b + 6b4dbf3 commit dfa7e9c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
2 changes: 1 addition & 1 deletion test/asm/exception_handler.asm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
li x2, 1
li x4, 987 # target fibonnaci number
li x15, 0

la x6, exception_handler
csrw mtvec, x6 # set-up handler
loop:
Expand Down
10 changes: 5 additions & 5 deletions test/transactions/test_transaction_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ def test_many_out(self):
sim.add_sync_process(self.generate_producer(i))


class MethodTransformerTestCircuit(Elaboratable):
class MethodMapTestCircuit(Elaboratable):
def __init__(self, iosize: int, use_methods: bool, use_dicts: bool):
self.iosize = iosize
self.use_methods = use_methods
Expand Down Expand Up @@ -413,7 +413,7 @@ def _(arg: Record):


class TestMethodTransformer(TestCaseWithSimulator):
m: MethodTransformerTestCircuit
m: MethodMapTestCircuit

def source(self):
for i in range(2**self.m.iosize):
Expand All @@ -426,19 +426,19 @@ def target(self, data):
return {"data": (data << 1) | (data >> (self.m.iosize - 1))}

def test_method_transformer(self):
self.m = MethodTransformerTestCircuit(4, False, False)
self.m = MethodMapTestCircuit(4, False, False)
with self.run_simulation(self.m) as sim:
sim.add_sync_process(self.source)
sim.add_sync_process(self.target)

def test_method_transformer_dicts(self):
self.m = MethodTransformerTestCircuit(4, False, True)
self.m = MethodMapTestCircuit(4, False, True)
with self.run_simulation(self.m) as sim:
sim.add_sync_process(self.source)
sim.add_sync_process(self.target)

def test_method_transformer_with_methods(self):
self.m = MethodTransformerTestCircuit(4, True, True)
self.m = MethodMapTestCircuit(4, True, True)
with self.run_simulation(self.m) as sim:
sim.add_sync_process(self.source)
sim.add_sync_process(self.target)
Expand Down
48 changes: 24 additions & 24 deletions transactron/lib/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,21 @@
from .connectors import Forwarder, ManyToOneConnectTrans, ConnectTrans

__all__ = [
"Transformer",
"MethodMap",
"MethodFilter",
"MethodProduct",
"MethodTryProduct",
"Collector",
"CatTrans",
"ConnectAndTransformTrans",
"ConnectAndMapTrans",
]


class Combiner(ABC):
"""Method combiner abstract class.
class Transformer(ABC):
"""Method transformer abstract class.
Method combiners construct a new method which utilizes other methods.
Method transformers construct a new method which utilizes other methods.
Attributes
----------
Expand All @@ -33,23 +34,23 @@ class Combiner(ABC):

def use(self, m: ModuleLike):
"""
Returns the method and adds the combiner to a module.
Returns the method and adds the transformer to a module.
Parameters
----------
m: Module or TModule
The module to which this combiner is added as a submodule.
The module to which this transformer is added as a submodule.
"""
m.submodules += self
return self.method


class MethodMap(Combiner, Elaboratable):
"""Method transformer.
class MethodMap(Transformer, Elaboratable):
"""Bidirectional map for methods.
Takes a target method and creates a transformed method which calls the
original target method, transforming the input and output values.
The transformation functions take two parameters, a `Module` and the
original target method, mapping the input and output values with
functions. The mapping functions take two parameters, a `Module` and the
`Record` being transformed. Alternatively, a `Method` can be
passed.
Expand All @@ -72,13 +73,13 @@ def __init__(
target: Method
The target method.
i_transform: (record layout, function or Method), optional
Input transformation. If specified, it should be a pair of a
Input mapping function. If specified, it should be a pair of a
function and a input layout for the transformed method.
If not present, input is not transformed.
If not present, input is passed unmodified.
o_transform: (record layout, function or Method), optional
Output transformation. If specified, it should be a pair of a
Output mapping function. If specified, it should be a pair of a
function and a output layout for the transformed method.
If not present, output is not transformed.
If not present, output is passed unmodified.
"""
if i_transform is None:
i_transform = (target.data_in.layout, lambda _, x: x)
Expand All @@ -100,7 +101,7 @@ def _(arg):
return m


class MethodFilter(Combiner, Elaboratable):
class MethodFilter(Transformer, Elaboratable):
"""Method filter.
Takes a target method and creates a method which calls the target method
Expand Down Expand Up @@ -156,7 +157,7 @@ def _(arg):
return m


class MethodProduct(Combiner, Elaboratable):
class MethodProduct(Transformer, Elaboratable):
def __init__(
self,
targets: list[Method],
Expand Down Expand Up @@ -204,7 +205,7 @@ def _(arg):
return m


class MethodTryProduct(Combiner, Elaboratable):
class MethodTryProduct(Transformer, Elaboratable):
def __init__(
self,
targets: list[Method],
Expand Down Expand Up @@ -256,7 +257,7 @@ def _(arg):
return m


class Collector(Combiner, Elaboratable):
class Collector(Transformer, Elaboratable):
"""Single result collector.
Creates method that collects results of many methods with identical
Expand Down Expand Up @@ -335,14 +336,13 @@ def elaborate(self, platform):
return m


class ConnectAndTransformTrans(Elaboratable):
"""Connecting transaction with transformations.
class ConnectAndMapTrans(Elaboratable):
"""Connecting transaction with mapping functions.
Behaves like `ConnectTrans`, but modifies the transferred data using
functions or `Method`s. Equivalent to a combination of
`ConnectTrans` and `MethodTransformer`. The transformation
functions take two parameters, a `Module` and the `Record` being
transformed.
functions or `Method`s. Equivalent to a combination of `ConnectTrans`
and `MethodMap`. The mapping functions take two parameters, a `Module`
and the `Record` being transformed.
"""

def __init__(
Expand Down

0 comments on commit dfa7e9c

Please sign in to comment.