Coverage for tsfpga/vivado/logic_level_distribution_parser.py: 94%

17 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 20:01 +0000

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project, a project platform for modern FPGA development. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9# Standard libraries 

10import re 

11 

12 

13class LogicLevelDistributionParser: 

14 

15 """ 

16 Used for parsing the ``report_design_analysis -logic_level_distribution`` report generated 

17 by Vivado. 

18 

19 This code is very hard coded for how the report and table is formatted. See the unit tests 

20 for examples of this formatting. 

21 """ 

22 

23 @staticmethod 

24 def get_table(report): 

25 """ 

26 Takes a report as a string and returns the table. 

27 

28 Arguments: 

29 report (str): A string containing the entire Vivado 

30 ``report_design_analysis -logic_level_distribution`` report. 

31 """ 

32 table_regexp = re.compile(r"\n(\+--.*-\+)\n", re.DOTALL) 

33 match = table_regexp.search(report) 

34 if match: 

35 return match.group(1) 

36 

37 raise ValueError(f"Could not find table in report: {report}") 

38 

39 @staticmethod 

40 def get_maximum_logic_level(table): 

41 """ 

42 Returns the maximum logic level in the table. 

43 

44 Arguments: 

45 table (str): The table as returned by :meth:`.get_table`. 

46 

47 Returns: 

48 int: The maximum logic level. 

49 """ 

50 header_line = table.split("\n")[1] 

51 # First and last items are empty, due to leading and trailing "|" in the table 

52 headings = header_line.split("|") 

53 

54 if len(headings) <= 4: 

55 # Nothing in table. Happens if there are no paths in the design. 

56 # 4 elements in list means two headings, i.e. no integer levels. 

57 # See unit test for examples of how this looks. 

58 return 0 

59 

60 right_most_heading = headings[-2] 

61 return int(right_most_heading.strip())