Hi,

   I am currently trying to get a recursive subroutine working for myself and it's driving me mad. It's pretty simple, all it does is trace a signal through a hierarchial tree. So pick a top level signal and see where it goes

clk_cts | |--cts_inst1 |--CTB02Q |--cts_inst2 |--CTB02Q
etc.

Now the problem is that when I call the subroutine recursivly it only follows one tree but doesn't return to follow the other trees (ie cts_inst2). When I remove the recursive call I can see the other branches so I know that they are there. Here is the code

sub trace_sig_down_hier { my $vdb=shift; my $module=shift; my $signal=shift; my $instance=shift; my $level=shift; print "DEBUG: $module:$module:$signal:$instance:$level\n"; my($imod,$iname,$port,$l,@connections); SIG:foreach my $sig (sort &rvp::get_modules_signals($vdb,$module)) { next SIG if ($sig ne $signal); for (($imod,$iname,$port,$l) = &rvp::get_first_signal_port_con($vdb,$module,$sig ); $imod; ($imod,$iname,$port,$l) = &rvp::get_next_signal_port_con($vdb)) { print "DC:$imod,$iname,$port,\n"; if(&rvp::module_exists($vdb,$module)) { my $full_path = $instance . "/" . $iname; $level++; my @sub_conns = &trace_sig_down_hier($vdb,$imod,$port,$full_pa +th,$level); push @connections,@sub_conns; } my $sig_path; if ($instance) { $sig_path = $instance . "/" . $port; }else{ $sig_path = $module . "/" . $port; } push @connections, $sig_path; #print "SUB : $sig_path\n"; } } return @connections; }
Without the recursive call (to see top level tree) this is the output:
11:57_dcollins_HOME_[267]>./tk_verilog.pl HL: no_gated_clk_cts_1:no_gated_clk_cts_1: 5 : clk_cts DEBUG: no_gated_clk_cts_1:no_gated_clk_cts_1:clk_cts:no_gated_clk_cts_ +1:0 DC:cts_env_1,cts_inst,y, DC:cts_env_1,cts2_inst,y, DC:cts_env_3,cts3_inst,y,
And with the recursive call :
HL: no_gated_clk_cts_1:no_gated_clk_cts_1: 5 : clk_cts DEBUG: no_gated_clk_cts_1:no_gated_clk_cts_1:clk_cts:no_gated_clk_cts_ +1:0 DC:cts_env_1,cts_inst,y, DEBUG: cts_env_1:cts_env_1:y:no_gated_clk_cts_1/cts_inst:1 DC:CTB02Q,cts_inst,Y, DEBUG: CTB02Q:CTB02Q:Y:no_gated_clk_cts_1/cts_inst/cts_inst:2
Any ideas as to why the recursive call doesnt work as expected. Am I doing something drastically wrong?

Thanks

Diarmuid

update (broquaint): changed <pre> to <code> tags and added formatting


In reply to recursion hell. by diarmuid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.