1#========================================================================= 2# StructuralRTLIRGenL3Pass_test.py 3#========================================================================= 4# Author : Peitian Pan 5# Date : May 19, 2019 6"""Test the generation of level 1 structural RTLIR.""" 7 8from pymtl3.passes.rtlir.structural.StructuralRTLIRGenL3Pass import ( 9 StructuralRTLIRGenL3Pass, 10) 11from pymtl3.passes.rtlir.structural.StructuralRTLIRSignalExpr import * 12from pymtl3.passes.testcases import ( 13 CaseArrayBits32IfcInComp, 14 CaseBits32IfcInComp, 15 CaseConnectValRdyIfcComp, 16) 17 18from ..StructuralRTLIRGenL2Pass import StructuralRTLIRGenL2Pass 19from .StructuralRTLIRGenL1Pass_test import gen_connections 20 21 22def test_L3_ifc_view_attr(): 23 a = CaseBits32IfcInComp.DUT() 24 a.elaborate() 25 a.apply( StructuralRTLIRGenL3Pass( gen_connections( a ) ) ) 26 connections = a.get_metadata( StructuralRTLIRGenL2Pass.connections ) 27 comp = CurComp(a, 's') 28 assert connections == \ 29 [(InterfaceAttr(CurCompAttr(comp, 'in_'), 'foo'), CurCompAttr(comp, 'out'))] 30 31def test_L3_ifc_view_index(): 32 a = CaseArrayBits32IfcInComp.DUT() 33 a.elaborate() 34 a.apply( StructuralRTLIRGenL3Pass( gen_connections( a ) ) ) 35 connections = a.get_metadata( StructuralRTLIRGenL2Pass.connections ) 36 comp = CurComp(a, 's') 37 assert connections == \ 38 [(InterfaceAttr(InterfaceViewIndex(CurCompAttr(comp, 'in_'), 1), 'foo'), 39 CurCompAttr(comp, 'out'))] 40 41def test_L3_ifc_view_connection(): 42 a = CaseConnectValRdyIfcComp.DUT() 43 a.elaborate() 44 a.apply( StructuralRTLIRGenL3Pass( gen_connections( a ) ) ) 45 connections = a.get_metadata( StructuralRTLIRGenL2Pass.connections ) 46 comp = CurComp(a, 's') 47 ref = \ 48 [ 49 (InterfaceAttr(CurCompAttr(comp, 'in_'), 'msg'), 50 InterfaceAttr(CurCompAttr(comp, 'out'), 'msg')), 51 (InterfaceAttr(CurCompAttr(comp, 'in_'), 'val'), 52 InterfaceAttr(CurCompAttr(comp, 'out'), 'val')), 53 (InterfaceAttr(CurCompAttr(comp, 'out'), 'rdy'), 54 InterfaceAttr(CurCompAttr(comp, 'in_'), 'rdy')), 55 ] 56 # The order of ports is non-deterministic? 57 assert connections[0] in ref 58 assert connections[1] in ref 59 assert connections[2] in ref 60