为了搞清楚uvm中各个类的继承关系,随手用python写了个脚本到uvm-1.2文件夹中去抓,代码如下,可能有bug。
#! /usr/bin/python import re, sys, commands tmp = commands.getoutput("grep -rh -A 5 \"class \" " + sys.argv[1] + " --include=\"*.sv*\"").split('\n') for line in tmp: if '//' in line or '--' in line or len(line) < 2 or 'endclass' in line: tmp.remove(line) tmp2 = [] for i in range(len(tmp)): if 'class ' in tmp[i]: new_line = tmp[i] if ';' in tmp[i]: tmp2.append(tmp[i]) else: for j in range(10): if (i+1) < len(tmp): i = i+1 new_line += tmp[i] if ';' in tmp[i]: tmp2.append(new_line) break tmp3 = [] for line in tmp2: if 'extends' in line: res = re.match('\s*(virtual\s)*class\s+(\S+).*extends\s+(\S+).*', line) if res: tmp3.append(res.group(2) + ' extends ' + res.group(3)) else: res = re.match('\s*(virtual\s)*class\s+(\S+).*', line) if res: tmp3.append(res.group(2)) tmp4 = {}.fromkeys(tmp3).keys() for i in range(len(tmp4)): tmp4[i] = re.sub('#\S+', '', tmp4[i]) tmp4[i] = re.sub(';', '', tmp4[i]) tmp5 = [] for i in range(len(tmp4)): if 'extends' not in tmp4[i]: hier = tmp4[i] else: res = re.match('(.*) extends (.*)', tmp4[i]) son = res.group(1) father = res.group(2) hier = father + '.' + son while True: if father is not '': son = father else: break for j in range(len(tmp4)): res = re.match(son + ' extends ' + '(.*)', tmp4[j]) if res: hier = res.group(1) + '.' + hier father = res.group(1) break else: father = '' tmp5.append(hier) tmp6 = sorted(set(tmp5)) fp = open('uvm_family.csv', 'w') for line in tmp6: fp.write(line + '\n') print line fp.close()
如果只更关心uvm_void的派生类,再筛选一下:
fp = open('uvm_void_family.csv', 'w') for line in tmp6: if 'uvm_void' in line: fp.write(line + '\n') fp.close()
处理结果大致如下:
有兴趣再处理一下的话,就是这样啦 ↓
又或者是这样(用vimdot画的图,感兴趣看下DOT语言介绍) ↓