[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

perl recursive function

Posted on 2008-11-03
4
Medium Priority
?
531 Views
Last Modified: 2012-05-05
;&EVENT[__psmi_1](psmi, THREAD => 0, TRIGGER => &TRIGGER[__retire_1](retire, LIP => 0x203f, TRIGGER => &EVENT[__smi_1](smi, THREAD => 1, TRIGGER => &TRIGGER[__eom_1](eom, LIP => 0x203f, THREAD => 0))));

From the above string,I have a Hash which looks like this

Hash(psmi_1,THREAD) = 0
Hash(psmi_1,TRIGGER) = retire_1
Hash(psmi_1,event)=psmi
Hash(retire_1,LIP)=0x203f
Hash(retire_1,TRIGGER)=smi_1
Hash(smi_1,THREAD)=1
Hash(smi_1,TRIGGER)=eom_1
Hash(eom_1,LIP)=0x203f
Hash(eom_1,THREAD)=0
Hash(eom_1,trigger)=eom
Hash(smi_1,event)=smi
Hash(retire_1,trigger)=retire

This string can be varying quite a bit

;&EVENT[__nmi_0](nmi, THREAD => 0, TRIGGER => &TRIGGER[__nmi_0.trigger](eom, LIP => 0x2020, SELF_CHECK => 'MUST_COMPLETE', THREAD => 0));

Above is another sample string

So, basically for every event, there can be one trigger like the 2nd string example or a chain of triggers like the 1st string.

Now I want to be able to Iterate thru the entire Hash and find out what all events should happen when LIP = 0x203f, There can be multiple events and also we need to check that we are satisfying the other triggering conditions

Here is my algorithm for the 2nd string, This piece of code is in system verilog, so, please read it for my algorithm.

;&EVENT[__nmi_0](nmi, THREAD => 0, TRIGGER => &TRIGGER[__nmi_0.trigger](eom, LIP => 0x2020, SELF_CHECK => 'MUST_COMPLETE', THREAD => 0));

This a simple case where there is 1 trigger for a event, But I want to know how to handle it when the trigger is a chain of events.
   
               
       
#ass_Array is the Hash
#s is the key to the Hash
 
   
do
  begin
     if (`vmm_str_match(s, "/TRIGGER/")) begin 
           
             s = `vmm_str_backref(s, 0);
             $display(" entry1 is %s : %s\n",s,ass_array[s]);
      end
      if (`vmm_str_match(s, ",LIP")) begin
            
             $display(" entry2 is%s:%s:pre%s:post%send \n",s,ass_array[s],  `vmm_str_prematch(s),`vmm_str_postmatch(s));
             if (ass_array[s] == "0x203f") begin
                itrigger = `vmm_str_prematch(s);
                $display ("trigger name is %s ",  itrigger);
                do
                  begin
                     if(s3 == {itrigger,",trigger"})begin
                        itrigger_value = ass_array[s3];
                        if ( itrigger_value == "eom" || itrigger_value == "retire" || itrigger_value == "bom")
                          $display ("trigger value is %s", itrigger_value);
                        else begin
                           
                        end
                     end
                     $display ("printing s3 loop %s : %s:%s", s3, ass_array[s3],{itrigger,",trigger"} );
                  end 
                while (ass_array.next( s3 ));
                do
                  begin
                    if (`vmm_str_match(s1, ",TRIGGER")) begin
                       if (ass_array[s1] == itrigger)begin
                          ievent = `vmm_str_prematch(s1);
                          
                          $display ("event name is %s", ievent);
                          do
                            begin
                              if(s2 == {ievent,",event"})begin
                                 ievent_value = ass_array[s2];
                                 $display ("event value is %s", ievent_value );
                              end
         
                            end 
                          while (ass_array.next( s2 ));
                       end
                    end
                  end 
                 while (ass_array.next( s1 ));
             end//if (ass_array[s] == "0x202d") begin
         
      end
    
     
     lvl_counter = lvl_counter + 1 ;
     $display("Anu here%s:%send\n",s,  ass_array[s]);        
end 
while (ass_array.next( s ));

Open in new window

0
Comment
Question by:Anu2117
  • 2
  • 2
4 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 22872113
> what all events should happen when LIP = 0x203f,
based on the above string, what would those be?
0
 

Author Comment

by:Anu2117
ID: 22872167
Event can be smi, nmi,psmi,....
;&EVENT[__nmi_0](nmi, THREAD => 0, TRIGGER => &TRIGGER[__nmi_0.trigger](eom, LIP => 0x2020, SELF_CHECK => 'MUST_COMPLETE', THREAD => 0));

Let me explain the meaning of above string...
Event nmi should happen on thread = 0 when that thread hits eom and LIP on the thread is 0x2020. Ignore self_check for now.
My other string can be explained as....  
;&EVENT[__psmi_1](psmi, THREAD => 0, TRIGGER => &TRIGGER[__retire_1](retire, LIP => 0x203f, TRIGGER => &EVENT[__smi_1](smi, THREAD => 1, TRIGGER => &TRIGGER[__eom_1](eom, LIP => 0x203f, THREAD => 0))));
 
 #{
    my $a = &TRIGGER('eom',THREAD=>0);
    my $b = &EVENT(smi,TRIGGER=>$a,THREAD=>1);
    my $c = &TRIGGER('retire',TRIGGER=>$b);
    my $d = &EVENT(psmi,THREAD=>0,TRIGGER=>$c);
   # return $d;
}#
 
0
 

Author Comment

by:Anu2117
ID: 22872232
Oh I probably should mention that the events and triggers and threads and LIP .... basically all the elements can have various various values.
0
 
LVL 85

Accepted Solution

by:
ozo earned 2000 total points
ID: 22872939
#Do you mean something like this?

my %f=(
       EVENT=>sub{ return bless shift,'EVENT'},
       TRIGGER=>sub{ return bless shift,'TRIGGER'},
       );
use Data::Dumper;
print Dumper event('&EVENT[__psmi_1](psmi, THREAD => 0, TRIGGER => &TRIGGER[__retire_1](retire, LIP => 0x203f, TRIGGER => &EVENT[__smi_1](smi, THREAD => 1, TRIGGER => &TRIGGER[__eom_1](eom, LIP => 0x203f, THREAD => 0))));');
sub event{
    my($s,$re)=@_;
    if( !$re ){
      ($re=$s)=~s/((\()|(\))|[^()]+)/${[')','']}[!$3]\Q$1\E${['(','']}[!$2]/gs;  
      $re=qr{(?:(\w+)\s*=>\s*)?(\w+|'[^'']*'|&(\w+)\[.*?\]\((@{[join'|',map quotemeta,$s=~/$re/]})\))};

    }
    my @a;    
while( $s=~/$re/g ){
    my $k=$1||'';
    my $f=$f{$3};
    push @a,{$k => ($f?&{$f}(event($4,$re)):$2)};
}
   return \@a;
}
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question