Email: bknpk@hotmail.com Phone: +972-54-7649119


V

 

A very simple perl script to translate a verilog parameters code to specman type definition.

  1. The scripts works on a marked text and is invoked from within vim. In this case, you mark the text using vim tags (for example ma and mb for start and end of text) or work on the entire file (using vim % operator). Many examples exist for this kind of scripts in this site. For instance you may have the following lines somewhere in your code. To translate them to specman mark the text and run the script:

    :'a,'b! perl ~/bin/vim_ver_param_to_spc_type.pl fsm_usb_

    parameter WRIDLE=2'd0;
    parameter WRADDR=2'd1;
    parameter WRACKL=2'd2;
    parameter RDIDLE=2'd3;

    And the output is:
    type fsm_usb_type : [WRIDLE = 0, WRADDR = 1, WRACKL = 2, RDIDLE = 3];

  2. The script is listed below:

    1. #!/bin/perl
    2. $s="type " . $ARGV[0] . "_type : [";
    3. while (<STDIN>) {
    4.   chomp($_);
    5.   if($_ =~ /^[ \s\t]*parameter[ \s\t]*([a-zA-Z][a-zA-Z0-9_]*)[ \s\t]*=[ \s\t]*[0-9]*'([hdb])([a-fA-F0-9_]*)
    6.   {
    7.     $sig_name=$1; $sig_val=$3; $sig_rad=$2;
    8.     $ix=index($sig_rad, "d");
    9.     if($ix == 0) { #decimal
    10.      $s=$s . $sig_name . " = " . $sig_val . ", ";
    11.     } else {
    12.      $ix=index($sig_rad, "h");
    13.      if($ix == 0) { #hex
    14.       $s=$s . $sig_name . " = 0x" . $sig_val . ", ";
    15.      } else {
    16.       #binary
    17.       $sig_val =~ s/_//g; #remove delimiter if exists
    18.       $sig_val_1 = sprintf('%d', oct("0b$sig_val"));#binary to decimal conversion
    19.       $s=$s . $sig_name . " = " . $sig_val_1 . ", ";
    20.      }
    21.     }
    22.   }
    23. }#while
    24. #remove last '
    25. $l=length($s);
    26. $s=substr($s, 0, $l-2);
    27. $s=$s . "];";
    28. print("$s\n");

  ...


Home

How to change the default bash internal field space separator.

A simple c-code program to read a memory array from verilog RTL, using VPI.






Search This Site


Feedback This Site




new pages on this site