Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

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

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

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

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

8 

9import re 

10 

11 

12class LogicLevelDistributionParser: 

13 

14 """ 

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

16 by Vivado. 

17 

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 """ 

21 

22 @staticmethod 

23 def get_table(report): 

24 """ 

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

26 

27 Arguments: 

28 report (str): 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) 

35 

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

37 

38 @staticmethod 

39 def get_maximum_logic_level(table): 

40 """ 

41 Returns the maximum logic level in the table. 

42 

43 Arguments: 

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

45 

46 Returns: 

47 int: The maximum logic level. 

48 """ 

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

50 right_most_heading = header_line.split("|")[-2] 

51 maximum_logic_level = int(right_most_heading.strip()) 

52 return maximum_logic_level