ASIC/FPGA Design and Verification Out Source Services
A very simple perl script to put an incremental value in binary format.
-
This site shows many simple perl scripts. The scripts are
simple and targeted to help in text editing. They are
called from within vim on specified text block (mark a and b).
Firing the script is very simple:
'a,'b !perl binary_counter.pl
If you need to work on all the file, then there is no need to put any
marks. Simply use the file operator:
:% !perl ~/bin/vim_extract_c_cc_h.pl
-
The main loop of the scripts waits for line, which are sent from within
the vim editor. It uses the function sprintf to convert
to binary:
#!/bin/perl
$cnt=0;
while (<STDIN> {
chomp($_);
if($_ =~ /(.*)(4'd[0-9])(.*)/) {
$t1=$1; $t3=$3;
$bin_cnt=sprintf("%04b", $cnt);
print("$t1");
print("\"$bin_cnt\"");
print("$t3\n");
$cnt++;
}
}#while
-
The output in my case looks like:
if (status(12:9) = "0000") $display("State was Idle");
if (status(12:9) = "0001") $display("State was Ready");
if (status(12:9) = "0010") $display("State was Ident");
if (status(12:9) = "0011") $display("State was Stby");
if (status(12:9) = "0100") $display("State was Tran");
if (status(12:9) = "0101") $display("State was Data");
if (status(12:9) = "0110") $display("State was Rcv");
if (status(12:9) = "0111") $display("State was Prog");
if (status(12:9) = "1000") $display("State was Dis");
-
One can use c++ (.cpp file) to work on text from within vim in a similar
way. In the following example the string dbg is
added to each line:
- #include <iostream>
- using namespace std;
- //g++ -o cin cin.cpp
- string input_line;
- int main() {
- while(cin) {
- getline(cin, input_line);
- cout << "dbg " << input_line << endl;
- };
- return 0;
- }
|