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 

10from collections import OrderedDict 

11 

12 

13class HierarchicalUtilizationParser: 

14 

15 """ 

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

17 """ 

18 

19 @staticmethod 

20 def get_size(report): 

21 """ 

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

23 for the specified run. 

24 

25 Arguments: 

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

27 """ 

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

29 for idx, line in enumerate(lines): 

30 # Find the table line that is the top level 

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

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

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

34 # above the row for the top level. 

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

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

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

38 headers = headers[3:-1] 

39 numbers = numbers[3:-1] 

40 # Convert numbers from string to integers 

41 numbers = [int(number) for number in numbers] 

42 return OrderedDict(zip(headers, numbers)) 

43 

44 return {}