How to get type/initial value of parameters

From Verific Design Automation FAQ
Jump to: navigation, search

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;