test05.cpp revision 12855:588919e0e4aa
1/***************************************************************************** 2 3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or 4 more contributor license agreements. See the NOTICE file distributed 5 with this work for additional information regarding copyright ownership. 6 Accellera licenses this file to you under the Apache License, Version 2.0 7 (the "License"); you may not use this file except in compliance with the 8 License. You may obtain a copy of the License at 9 10 http://www.apache.org/licenses/LICENSE-2.0 11 12 Unless required by applicable law or agreed to in writing, software 13 distributed under the License is distributed on an "AS IS" BASIS, 14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 15 implied. See the License for the specific language governing 16 permissions and limitations under the License. 17 18 *****************************************************************************/ 19 20/***************************************************************************** 21 22 test05.cpp -- Test sc_vector (and its binding functions) 23 24 Original Author: Philipp A. Hartmann, OFFIS, 2010-03-05 25 26 *****************************************************************************/ 27 28/***************************************************************************** 29 30 MODIFICATION LOG - modifiers, enter your name, affiliation, date and 31 changes you are making here. 32 33 Name, Affiliation, Date: 34 Description of Modification: 35 36 *****************************************************************************/ 37 38#include <systemc.h> 39 40#include "sysc/utils/sc_vector.h" 41using sc_core::sc_vector; 42 43typedef sc_vector< sc_fifo_out<int> > port_vec; 44 45static void 46dump_port_array( const char* from, const port_vec& in ) 47{ 48 std::cout << "\n" << from << "\n"; 49 for( unsigned i=0; i<in.size(); ++i ) 50 { 51 std::cout 52 << " " 53 << in[i].name() 54 << ".size() == " << in[i].size(); 55 56 for( int j=0; j<in[i].size(); ++j) 57 { 58 std::cout 59 << " - " 60 << dynamic_cast<const sc_core::sc_object*>(in[i][j])->name() 61 << " @ " << j; 62 } 63 std::cout << std::endl; 64 } 65} 66 67SC_MODULE(sub_module) 68{ 69 port_vec in; 70 71 sub_module( sc_core::sc_module_name, unsigned n_sub ) 72 : in("in", n_sub ) {} 73 74 void before_end_of_elaboration() 75 { dump_port_array( "sub_module::before_end_of_elaboration", in ); } 76 void end_of_elaboration() 77 { dump_port_array( "sub_module::end_of_elaboration", in ); } 78}; 79 80 81SC_MODULE(module) 82{ 83 sub_module sub; 84 port_vec in; 85 86 SC_CTOR(module) 87 : sub("sub", 4), in("in",4) 88 { 89 // vector to vector binding 90 sub.in( in ); 91 } 92 93 void before_end_of_elaboration() 94 { dump_port_array( "module::before_end_of_elaboration", in ); } 95 void end_of_elaboration() 96 { dump_port_array( "module::end_of_elaboration", in ); } 97}; 98 99int sc_main( int, char*[] ) 100{ 101 102 module top("top"); 103 104 const unsigned size = 4; 105 const unsigned half = 2; 106 107 sc_assert( top.in.size() == size ); 108 109 sc_vector< sc_fifo<int> > 110 fifo_1( "src_1", half ), 111 fifo_2( "src_2", size ); 112 113 // bind full vector (smaller than target) 114 port_vec::iterator mid = top.in( fifo_1 ); 115 sc_assert( ( mid - top.in.begin() ) - half == 0 ); 116 117 // bind range, starting from last position 118 mid = top.in.bind( fifo_2.begin(), fifo_2.end(), mid ); 119 sc_assert( mid == top.in.end() ); 120 121 // bind a plain C array of channels 122 sc_fifo<int> fifo_a[ half ]; 123 top.sub.in( fifo_a, fifo_a + half ); 124 125 sc_start(); 126 return 0; 127} 128