A very simple perl script to translate a verilog
parameters code to specman type definition.
-
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];
-
The script is listed below:
- #!/bin/perl
- $s="type " . $ARGV[0] . "_type : [";
- while (<STDIN>) {
- chomp($_);
- if($_ =~ /^[ \s\t]*parameter[ \s\t]*([a-zA-Z][a-zA-Z0-9_]*)[ \s\t]*=[ \s\t]*[0-9]*'([hdb])([a-fA-F0-9_]*)
- {
- $sig_name=$1; $sig_val=$3; $sig_rad=$2;
- $ix=index($sig_rad, "d");
- if($ix == 0) { #decimal
- $s=$s . $sig_name . " = " . $sig_val . ", ";
- } else {
- $ix=index($sig_rad, "h");
- if($ix == 0) { #hex
- $s=$s . $sig_name . " = 0x" . $sig_val . ", ";
- } else {
- #binary
- $sig_val =~ s/_//g; #remove delimiter if exists
- $sig_val_1 = sprintf('%d', oct("0b$sig_val"));#binary to decimal conversion
- $s=$s . $sig_name . " = " . $sig_val_1 . ", ";
- }
- }
- }
- }#while
- #remove last '
- $l=length($s);
- $s=substr($s, 0, $l-2);
- $s=$s . "];";
- print("$s\n");
|