Coverage for tsfpga/vivado/hierarchical_utilization_parser.py: 93%

15 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-12-10 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# -------------------------------------------------------------------------------------------------- 

8 

9# Standard libraries 

10import re 

11from collections import OrderedDict 

12 

13 

14class HierarchicalUtilizationParser: 

15 

16 """ 

17 Used for parsing the ``report_utilization -hierarchical`` report generated by Vivado. 

18 """ 

19 

20 @staticmethod 

21 def get_size(report: str) -> dict[str, int]: 

22 """ 

23 Takes a hierarchical utilization report as a string and returns the top level size 

24 for the specified run. 

25 

26 Arguments: 

27 report (str): A string containing the entire Vivado hierarchical utilization report. 

28 """ 

29 lines = report.split("\n") 

30 for idx, line in enumerate(lines): 

31 # Find the table line that is the top level 

32 if re.search(r"\(top\)", line): 

33 # Parse the report, remove uninteresting fields and create dictionary 

34 # Note that "|" is the column separator. Heading titles for the data is two lines 

35 # above the row for the top level. 

36 headers = [column_data.strip() for column_data in lines[idx - 2].split("|")] 

37 numbers = [column_data.strip() for column_data in line.split("|")] 

38 

39 # The first columns contain entity name, etc. We only want the numbers 

40 headers = headers[3:-1] 

41 numbers = numbers[3:-1] 

42 

43 # Convert numbers from string to integers 

44 numbers_int = [int(number) for number in numbers] 

45 

46 return OrderedDict(zip(headers, numbers_int)) 

47 

48 return {}