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

15 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-21 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 

9import re 

10from collections import OrderedDict 

11 

12 

13class HierarchicalUtilizationParser: 

14 """ 

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

16 """ 

17 

18 @staticmethod 

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

20 """ 

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

22 for the specified run. 

23 

24 Arguments: 

25 report: A string containing the entire Vivado hierarchical utilization report. 

26 """ 

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

28 for idx, line in enumerate(lines): 

29 # Find the table line that is the top level 

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

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

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

33 # above the row for the top level. 

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

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

36 

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

38 headers = headers[3:-1] 

39 numbers = numbers[3:-1] 

40 

41 # Convert numbers from string to integers 

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

43 

44 return OrderedDict(zip(headers, numbers_int)) 

45 

46 return {}