statistics.py (c8b1e4db9cf506f40d3cbddfbd259cfecf0168b7) statistics.py (c6d439803a044ea209139672b25e35fe8d7f4aa0)
1#/usr/bin/python3
2# -*- coding: UTF-8 -*-
1#/usr/bin/python3
2# -*- coding: UTF-8 -*-
3
4#***************************************************************************************
5# Copyright (c) 2020-2021 Institute of Computing Technology, Chinese Academy of Sciences
6#
7# XiangShan is licensed under Mulan PSL v2.
8# You can use this software according to the terms and conditions of the Mulan PSL v2.
9# You may obtain a copy of Mulan PSL v2 at:
10# http://license.coscl.org.cn/MulanPSL2
11#
12# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
13# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
14# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
15#
16# See the Mulan PSL v2 for more details.
17#***************************************************************************************
18
19
3import sys
4import re
5import copy
6import pprint
7
8LINE_COVERRED = "LINE_COVERRED"
9NOT_LINE_COVERRED = "NOT_LINE_COVERRED"
10TOGGLE_COVERRED = "TOGGLE_COVERRED"

--- 5 unchanged lines hidden (view full) ---

16CHILDREN = "CHILDREN"
17MODULE = "MODULE"
18INSTANCE = "INSTANCE"
19TYPE = "TYPE"
20ROOT = "ROOT"
21NODE = "NODE"
22SELFCOVERAGE = "SELFCOVERAGE"
23TREECOVERAGE = "TREECOVERAGE"
20import sys
21import re
22import copy
23import pprint
24
25LINE_COVERRED = "LINE_COVERRED"
26NOT_LINE_COVERRED = "NOT_LINE_COVERRED"
27TOGGLE_COVERRED = "TOGGLE_COVERRED"

--- 5 unchanged lines hidden (view full) ---

33CHILDREN = "CHILDREN"
34MODULE = "MODULE"
35INSTANCE = "INSTANCE"
36TYPE = "TYPE"
37ROOT = "ROOT"
38NODE = "NODE"
39SELFCOVERAGE = "SELFCOVERAGE"
40TREECOVERAGE = "TREECOVERAGE"
24LINECOVERAGE = 0
41LINECOVERAGE = 0
25TOGGLECOVERAGE = 1
26
27def check_one_hot(l):
28 cnt = 0
29 for e in l:
30 if e:
31 cnt += 1
32 return cnt <= 1

--- 34 unchanged lines hidden (view full) ---

67 assert not (line_coverred_match and not_line_coverred_match)
68
69 toggle_coverred_match = toggle_coverred_pattern_1.search(line) or toggle_coverred_pattern_2.search(line) or \
70 toggle_coverred_pattern_3.search(line) or toggle_coverred_pattern_4.search(line)
71 not_toggle_coverred_match = not_toggle_coverred_pattern_1.search(line) or not_toggle_coverred_pattern_2.search(line) or \
72 not_toggle_coverred_pattern_3.search(line) or not_toggle_coverred_pattern_4.search(line)
73
74 assert not (toggle_coverred_match and not_toggle_coverred_match)
42TOGGLECOVERAGE = 1
43
44def check_one_hot(l):
45 cnt = 0
46 for e in l:
47 if e:
48 cnt += 1
49 return cnt <= 1

--- 34 unchanged lines hidden (view full) ---

84 assert not (line_coverred_match and not_line_coverred_match)
85
86 toggle_coverred_match = toggle_coverred_pattern_1.search(line) or toggle_coverred_pattern_2.search(line) or \
87 toggle_coverred_pattern_3.search(line) or toggle_coverred_pattern_4.search(line)
88 not_toggle_coverred_match = not_toggle_coverred_pattern_1.search(line) or not_toggle_coverred_pattern_2.search(line) or \
89 not_toggle_coverred_pattern_3.search(line) or not_toggle_coverred_pattern_4.search(line)
90
91 assert not (toggle_coverred_match and not_toggle_coverred_match)
75
92
76 all_match = (line_coverred_match, not_line_coverred_match,
77 toggle_coverred_match, not_toggle_coverred_match)
78 if not check_one_hot(all_match):
79 print("not_one_hot")
80 print(line_cnt)
81 print(all_match)
82 assert False, "This line matches multiple patterns"
83 if line_coverred_match:

--- 52 unchanged lines hidden (view full) ---

136 name = "ModuleName"
137
138 for line in lines:
139 module_match = module_pattern.search(line)
140 endmodule_match = endmodule_pattern.search(line)
141 submodule_match = submodule_pattern.search(line)
142
143 assert not (module_match and endmodule_match)
93 all_match = (line_coverred_match, not_line_coverred_match,
94 toggle_coverred_match, not_toggle_coverred_match)
95 if not check_one_hot(all_match):
96 print("not_one_hot")
97 print(line_cnt)
98 print(all_match)
99 assert False, "This line matches multiple patterns"
100 if line_coverred_match:

--- 52 unchanged lines hidden (view full) ---

153 name = "ModuleName"
154
155 for line in lines:
156 module_match = module_pattern.search(line)
157 endmodule_match = endmodule_pattern.search(line)
158 submodule_match = submodule_pattern.search(line)
159
160 assert not (module_match and endmodule_match)
144
161
145 if module_match:
146 name = module_match.group(1)
147 # print("module_match: module: %s" % name)
148 assert name not in modules
149 # [begin
150 modules[name] = {}
151 modules[name][BEGIN] = line_count
152 # the first time we see a module, we treat as a root node

--- 146 unchanged lines hidden ---
162 if module_match:
163 name = module_match.group(1)
164 # print("module_match: module: %s" % name)
165 assert name not in modules
166 # [begin
167 modules[name] = {}
168 modules[name][BEGIN] = line_count
169 # the first time we see a module, we treat as a root node

--- 146 unchanged lines hidden ---