[UVM]RAL Test中VMM类型转换到UVM类型的脚本

                RAL Test中VMM类型转换到UVM类型的脚本

 

       前言:本文主要介绍IMM Register Type向UVM转换的方法,可以用脚本实现。除此外并总结一种Perl脚本处理文件的方法,之Tie::File,通过一个List绑定到文件,操作List,就会作用到文件中,避免每次都进行open和close的操作。

 

一、脚本实现

#!/usr/bin/perl

use strict;
use Tie::File;
use autodie;

my @all_ralf = glob("*.ralf");

foreach(@all_ralf) {
  my @array = undef;
  tie(@array, 'Tie::File', "$_");
  foreach(@array) {
    if(s/access\s+ru/access ro/g) {
      s/(.*;)\s+(reset.*)/$1 volatile 1 ; $2/g unless (/volatile/);
    }
    s/access\s+a0/access w1s/g;
    s/access\s+a1/access w0c/g;
    s/access\s+other/access rw/g;
    s/access\s+user0/access rw/g;
    s/access\s+user1/access rw/g;
    s/access\s+user02/access rw/g;
    s/access\s+user3/access rw/g;
    s/access\s+dc/access rw/g;
    s/(.*;)\s+(reset.*)/$1 volatile 0; $2/g unless(/volatile/);
  }
  untie(@array);
}

 

二、语法讲解

 2.1.Tie::File

  • 建立一个list和file的关系,对list的操作会反映到file上去。
  • 基本语法如下
use Tie::File;

tie @array, 'Tie::File', filename or die ...;
  • 应用举例
use Tie::File;
tie @array, 'Tie::File', filename or die ...;

$array[13] = 'blah';     # line 13 of the file is now 'blah'
print $array[42];        # display line 42 of the file

$n_recs = @array;        # how many records are in the file?
$#array -= 2;            # chop two records off the end

for (@array) {
  s/PERL/Perl/g;         # Replace PERL with Perl everywhere in the file
}

# These are just like regular push, pop, unshift, shift, and splice
# Except that they modify the file in the way you would expect

push @array, new recs...;
my $r1 = pop @array;
unshift @array, new recs...;
my $r2 = shift @array;
@old_recs = splice @array, 3, 7, new recs...;

untie @array;            # all finished
use Tie::File;
my @array;
my $filename = "a.txt";

tie(@array,'Tie::File', $filename) or die "$!\n";
print "$array[3]\n";
print "$#array\n";

$array[3] = "hello";
$array[1] = "world";
splice(@array, 1, 0, "insert into 0 and 1 line");
delete $array[$#array];
$#array -= 2;
print pop @array;
untie($array);

 

 2.2.Perl unless语句执行分析

  • 基本语法:表达式为FALSE时执行
unless(boolean_expression){
   # 在布尔表达式 boolean_expression 为 false 执行
}
  • 使用unless意味着,要么条件为真,要么执行某块代码。这就好像使用if控制结构来判断相反的条件。另一种说法是它类似于独立的else子句。也就是说,当看不懂某个unless语句时,可以用如下的if语句来代替:

if ($fred =~ /^([A-Z_]\w*$/i) {
  //什么都不做
} else {
   print "The value of \$fred doesn't look like a Perl identifier name. \n";
}
  • 使用案例

#!/usr/bin/perl -w
unless ($mon =~ /^Feb/) {
  print "This month has at least thirty days.\n";
} lese {
  print "Do you see what's going on here?\n";
}
#如果用if语句我们可以写成这样:
if ($mon =~ /^Feb/) {
  print "Do you see what's going on here?\n";
} else {
  print "This month has at least thirty days.\n";
}

 

 

你可能感兴趣的:(Perl)