Coverage for tsfpga/vivado/logic_level_distribution_parser.py: 94%
17 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-07 20:51 +0000
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-07 20:51 +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://github.com/tsfpga/tsfpga
7# --------------------------------------------------------------------------------------------------
9# Standard libraries
10import re
13class LogicLevelDistributionParser:
14 """
15 Used for parsing the ``report_design_analysis -logic_level_distribution`` report generated
16 by Vivado.
18 This code is very hard coded for how the report and table is formatted. See the unit tests
19 for examples of this formatting.
20 """
22 @staticmethod
23 def get_table(report: str) -> str:
24 """
25 Takes a report as a string and returns the table.
27 Arguments:
28 report: A string containing the entire Vivado
29 ``report_design_analysis -logic_level_distribution`` report.
30 """
31 table_regexp = re.compile(r"\n(\+--.*-\+)\n", re.DOTALL)
32 match = table_regexp.search(report)
33 if match:
34 return match.group(1)
36 raise ValueError(f"Could not find table in report: {report}")
38 @staticmethod
39 def get_maximum_logic_level(table: str) -> int:
40 """
41 Returns the maximum logic level in the table.
43 Arguments:
44 table: The table as returned by :meth:`.get_table`.
46 Return:
47 The maximum logic level.
48 """
49 header_line = table.split("\n")[1]
50 # First and last items are empty, due to leading and trailing "|" in the table
51 headings = header_line.split("|")
53 if len(headings) <= 4:
54 # Nothing in table. Happens if there are no paths in the design.
55 # 4 elements in list means two headings, i.e. no integer levels.
56 # See unit test for examples of how this looks.
57 return 0
59 right_most_heading = headings[-2]
60 return int(right_most_heading.strip())