用户工具

站点工具


linux:perl:用perl产生verilog文件

差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录前一修订版
后一修订版
前一修订版
linux:perl:用perl产生verilog文件 [2022/11/07 11:19] – [2. vpl.pl] zhangguolinux:perl:用perl产生verilog文件 [2023/10/27 22:27] (当前版本) – [1. vpl.pl] zhangguo
行 3: 行 3:
 主要是perl可以很方便支持类似1..3, a..c, A..C的 语法,对生成规律性的verilog语句很有帮助。 -- 而python没有这样的语法。 主要是perl可以很方便支持类似1..3, a..c, A..C的 语法,对生成规律性的verilog语句很有帮助。 -- 而python没有这样的语法。
  
-===== - t.pl ===== 
  
 +===== - vpl.pl =====
  
-<file perl t.pl> +专门写一个统一的脚本来处理,通过读取分析源文件,来产生需要的代码。 
-@ar = (1..3, a..c, A..C)+  * 以行首;分号开始为perl语句 
-foreach $i (@ar) { +  * 其它情况全部当做是perl的print语句,不用自己再去敲print\n这样的东西,相对来说还是比较简单,容易使用。
-    print "hello0${i}good\n"; +
-+
- +
-print "\n"; +
-@ar = reverse @ar; +
-foreach $i (@ar) { +
-    print "hello1${i}good\n"; +
-+
-</file> +
- +
-执行效果:+
  
-<code bash> 
->perl t.pl 
- 
- 
-hello01good 
-hello02good 
-hello03good 
-hello0agood 
-hello0bgood 
-hello0cgood 
-hello0Agood 
-hello0Bgood 
-hello0Cgood 
- 
-hello1Cgood 
-hello1Bgood 
-hello1Agood 
-hello1cgood 
-hello1bgood 
-hello1agood 
-hello13good 
-hello12good 
-hello11good 
-</code> 
- 
- 
-===== - vpl.pl ===== 
 <file perl vpl.pl> <file perl vpl.pl>
 +#!/usr/bin/perl
 if (scalar @ARGV < 1) { if (scalar @ARGV < 1) {
-    print "usage: perl vpl.pl xxx.vpl\n";+    print "usage: perl vpl.pl xxx.x [xxx.x.v]\n";
     exit;     exit;
 } }
  
 $ivpl = shift @ARGV; $ivpl = shift @ARGV;
-$opl = $ivpl+$opl = "$ivpl.pl"; 
-$opl =~ s/\.\w+$/.opl/+if (scalar @ARGV > 0) { 
-$vfile = $ivpl+$vfile = shift @ARGV; 
-$vfile =~ s/\.\w+$/.v/;+
 +else { 
 +$vfile = "$ivpl.v"; 
 +}
  
 open(fh, "$ivpl") || die "can not open $ivpl"; open(fh, "$ivpl") || die "can not open $ivpl";
行 87: 行 53:
 if ($ret == 0) { if ($ret == 0) {
     print "generate $vfile ok!\n";     print "generate $vfile ok!\n";
-    @ar = glob "$opl*"; +    @ar = glob "$opl";
-    #print "will delete @ar\n";+
     foreach $tmp (@ar) {     foreach $tmp (@ar) {
         unlink ($tmp);         unlink ($tmp);
行 95: 行 60:
  
 exit 0; exit 0;
 +
 </file> </file>
 +
 +
 +
 +===== - example =====
 +
 +<code bash>
 +localhost /home/user01 perl ./vpl.pl a.x
 +generate a.x.v ok!
 +</code>
 +
 +file: a.x
 +<code verilog>
 +module a(
 +    input clk,
 +
 +; for ($i=0; $i<10; $i++) {
 +    input data_$i,   
 +;}
 +
 +    output data_o
 +);
 +
 +; for ($i=0; $i<10; $i++) {
 +;     $j = 10 - $i;
 +//  10 - $j = $i;
 +; }
 +
 +
 +endmodule
 +</code>
 +
 +output a.x.v:
 +<code verilog>
 +module a(
 +    input clk,
 +
 +    input data_0,   
 +    input data_1,   
 +    input data_2,   
 +    input data_3,   
 +    input data_4,   
 +    input data_5,   
 +    input data_6,   
 +    input data_7,   
 +    input data_8,   
 +    input data_9,   
 +
 +    output data_o
 +);
 +
 +//  10 - 10 = 0;
 +//  10 - 9 = 1;
 +//  10 - 8 = 2;
 +//  10 - 7 = 3;
 +//  10 - 6 = 4;
 +//  10 - 5 = 5;
 +//  10 - 4 = 6;
 +//  10 - 3 = 7;
 +//  10 - 2 = 8;
 +//  10 - 1 = 9;
 +
 +
 +endmodule
 +</code>
 +
linux/perl/用perl产生verilog文件.1667791192.txt.gz · 最后更改: 2023/03/17 10:12 (外部编辑)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki