Difference between revisions of "How to get type/initial value of parameters"

From Verific Design Automation FAQ
Jump to: navigation, search
(Created page with "'''Q: Why do I get type and initial value of parameters?''' Example Perl code: #!/usr/bin/perl # push(@INC,"../../../perlmain/install"); require "Verific.pm"; #...")
 
(One intermediate revision by the same user not shown)
Line 2: Line 2:
  
 
Example Perl code:
 
Example Perl code:
 
+
<nowiki>
 
   #!/usr/bin/perl
 
   #!/usr/bin/perl
   #
+
    
 
   push(@INC,"../../../perlmain/install");
 
   push(@INC,"../../../perlmain/install");
 
   require "Verific.pm";
 
   require "Verific.pm";
   #
+
    
 
   my $filename = "test.v";
 
   my $filename = "test.v";
 
   my $mode = 4; # SystemVerilog - Verilog 2K:  my $mode = 1;
 
   my $mode = 4; # SystemVerilog - Verilog 2K:  my $mode = 1;
 
   if (!Verific::veri_file::Analyze($filename, $mode)) { die "unable to analyze file $filename and mode $mode\n"; }
 
   if (!Verific::veri_file::Analyze($filename, $mode)) { die "unable to analyze file $filename and mode $mode\n"; }
   #
+
    
 
   $top_module_name = "top";
 
   $top_module_name = "top";
   #
+
    
 
   # $top is VeriModule *  
 
   # $top is VeriModule *  
 
   my $top = Verific::veri_file::GetModule($top_module_name);
 
   my $top = Verific::veri_file::GetModule($top_module_name);
 
   if (!defined($top)) { die "module $top_mod not found\n"; }  
 
   if (!defined($top)) { die "module $top_mod not found\n"; }  
   #
+
    
 
   my $param_array = $top->GetParameters();
 
   my $param_array = $top->GetParameters();
 
   if (!defined($param_array)) { print "*** no parameters found ***\n"; exit; }
 
   if (!defined($param_array)) { print "*** no parameters found ***\n"; exit; }
   #
+
    
 
   # now let's get an Array iterator instead of using the FOREACH_ARRAY_ITEM macro
 
   # now let's get an Array iterator instead of using the FOREACH_ARRAY_ITEM macro
 
   my $param_array_iter = $param_array->Iterator("VeriIdDef");  
 
   my $param_array_iter = $param_array->Iterator("VeriIdDef");  
   #
+
    
 
   for (my $param_id = $param_array_iter->First();  
 
   for (my $param_id = $param_array_iter->First();  
 
         $param_array_iter < $param_array_iter->Size();  
 
         $param_array_iter < $param_array_iter->Size();  
 
         $param_id = $param_array_iter->Next()) {
 
         $param_id = $param_array_iter->Next()) {
   #
+
    
 
         # null check param_id..
 
         # null check param_id..
 
         if (!defined($param_id)) { next; }
 
         if (!defined($param_id)) { next; }
  #     
+
     
 
         # print param name
 
         # print param name
 
         printf "* param name: %s ***\n", $param_id->Name();
 
         printf "* param name: %s ***\n", $param_id->Name();
   #
+
    
 
         # print param type
 
         # print param type
 
         # $type, if specified, is VeriDataType *
 
         # $type, if specified, is VeriDataType *
Line 44: Line 44:
 
             print "*** type not declared ***\n";  
 
             print "*** type not declared ***\n";  
 
         }
 
         }
   #
+
    
 
         # $init_value is VeriExpression *  
 
         # $init_value is VeriExpression *  
 
         my $init_value = $param_id->GetInitialValue();
 
         my $init_value = $param_id->GetInitialValue();
   #
+
    
 
         if (defined($init_value)) {
 
         if (defined($init_value)) {
 
           my $to_string = "";
 
           my $to_string = "";
Line 54: Line 54:
 
         }
 
         }
 
   }
 
   }
   #
+
    
 
   exit;
 
   exit;
 +
</nowiki>

Revision as of 17:11, 24 August 2018

Q: Why do I get type and initial value of parameters?

Example Perl code:

  #!/usr/bin/perl
  
  push(@INC,"../../../perlmain/install");
  require "Verific.pm";
  
  my $filename = "test.v";
  my $mode = 4; # SystemVerilog - Verilog 2K:  my $mode = 1;
  if (!Verific::veri_file::Analyze($filename, $mode)) { die "unable to analyze file $filename and mode $mode\n"; }
  
  $top_module_name = "top";
  
  # $top is VeriModule * 
  my $top = Verific::veri_file::GetModule($top_module_name);
  if (!defined($top)) { die "module $top_mod not found\n"; } 
  
  my $param_array = $top->GetParameters();
  if (!defined($param_array)) { print "*** no parameters found ***\n"; exit; }
  
  # now let's get an Array iterator instead of using the FOREACH_ARRAY_ITEM macro
  my $param_array_iter = $param_array->Iterator("VeriIdDef"); 
  
  for (my $param_id = $param_array_iter->First(); 
        $param_array_iter < $param_array_iter->Size(); 
        $param_id = $param_array_iter->Next()) {
  
        # null check param_id..
        if (!defined($param_id)) { next; }
       
        # print param name
        printf "* param name: %s ***\n", $param_id->Name();
  
        # print param type
        # $type, if specified, is VeriDataType *
        my $type = $param_id->GetDataType();
        if (defined($type)) {
            my $to_string = "";
            $type->PrettyPrint(\$to_string, 0);
            print "*** type: $to_string ***\n"; 
        } else {
            print "*** type not declared ***\n"; 
        }
  
        # $init_value is VeriExpression * 
        my $init_value = $param_id->GetInitialValue();
  
        if (defined($init_value)) {
           my $to_string = "";
           $init_value->PrettyPrint(\$to_string, 0);
           print "*** initial value: $to_string ***\n"; 
        }
  }
  
  exit;