From fabbb268d3875c76423c2cb59d1e60b54a899446 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Sun, 24 Mar 2019 10:34:40 +0000 Subject: [PATCH] add placeholder-variant pipeline stage of Record --- src/add/example_buf_pipe.py | 9 ++++-- src/add/test_buf_pipe.py | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/add/example_buf_pipe.py b/src/add/example_buf_pipe.py index 578aed8e..005dbc17 100644 --- a/src/add/example_buf_pipe.py +++ b/src/add/example_buf_pipe.py @@ -187,9 +187,14 @@ def eq(o, i): if isinstance(ao, Record): for idx, (field_name, field_shape, _) in enumerate(ao.layout): if isinstance(field_shape, Layout): - rres = eq(ao.fields[field_name], ai.fields[field_name]) + val = ai.fields else: - rres = eq(ao.fields[field_name], ai[field_name]) + val = ai + if hasattr(val, field_name): + val = getattr(val, field_name) + else: + val = val[field_name] + rres = eq(ao.fields[field_name], val) res += rres else: rres = ao.eq(ai) diff --git a/src/add/test_buf_pipe.py b/src/add/test_buf_pipe.py index 8e575dc8..f3f49da8 100644 --- a/src/add/test_buf_pipe.py +++ b/src/add/test_buf_pipe.py @@ -147,6 +147,15 @@ def test3_resultfn(o_data, expected, i, o): "%d-%d data %x not match %x\n" \ % (i, o, o_data, expected) +def data_placeholder(): + data = [] + for i in range(num_tests): + d = PlaceHolder() + d.src1 = randint(0, 1<<16-1) + d.src2 = randint(0, 1<<16-1) + data.append(d) + return data + def data_dict(): data = [] for i in range(num_tests): @@ -408,6 +417,30 @@ class ExampleAddRecordStage: 'src2': i.src2 + 1} +class ExampleAddRecordPlaceHolderStage: + """ example use of a Record, with a placeholder as the processing result + """ + + record_spec = [('src1', 16), ('src2', 16)] + def ispec(self): + """ returns a tuple of input signals which will be the incoming data + """ + return Record(self.record_spec) + + def ospec(self): + return Record(self.record_spec) + + def process(self, i): + """ process the input data (sums the values in the tuple) and returns it + """ + o = PlaceHolder() + o.src1 = i.src1 + 1 + o.src2 = i.src2 + 1 + return o + +class PlaceHolder: pass + + class ExampleAddRecordPipe(UnbufferedPipeline): """ an example of how to use the combinatorial pipeline. """ @@ -424,6 +457,23 @@ def test7_resultfn(o_data, expected, i, o): % (i, o, repr(o_data), repr(expected)) +class ExampleAddRecordPlaceHolderPipe(UnbufferedPipeline): + """ an example of how to use the combinatorial pipeline. + """ + + def __init__(self): + stage = ExampleAddRecordPlaceHolderStage() + UnbufferedPipeline.__init__(self, stage) + + +def test11_resultfn(o_data, expected, i, o): + res1 = expected.src1 + 1 + res2 = expected.src2 + 1 + assert o_data['src1'] == res1 and o_data['src2'] == res2, \ + "%d-%d data %s not match %s\n" \ + % (i, o, repr(o_data), repr(expected)) + + class Example2OpClass: """ an example of a class used to store 2 operands. requires an eq function, to conform with the pipeline stage API @@ -575,4 +625,10 @@ if __name__ == '__main__': with open("test_ltbufpipe10.il", "w") as f: f.write(vl) + print ("test 11") + dut = ExampleAddRecordPlaceHolderPipe() + data=data_placeholder() + test = Test5(dut, test11_resultfn, data=data) + run_simulation(dut, [test.send, test.rcv], vcd_name="test_addrecord.vcd") + -- 2.30.2