Coverage for tsfpga/vivado/build_result.py: 97%

33 statements  

« prev     ^ index     » next       coverage.py v6.5.0, created at 2022-11-29 20:01 +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://gitlab.com/tsfpga/tsfpga 

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

8 

9# Standard libraries 

10import json 

11 

12# Local folder libraries 

13from .logic_level_distribution_parser import LogicLevelDistributionParser 

14 

15 

16class BuildResult: 

17 

18 """ 

19 Attributes: 

20 project_name (`str`): The name of the build. 

21 success (`bool`): True if the build and all pre- and post hooks succeeded. 

22 synthesis_size (`dict`): A dictionary with the utilization of primitives for the 

23 synthesized design. Will be ``None`` if synthesis failed or did not run. 

24 implementation_size (`dict`): A dictionary with the utilization of primitives for 

25 the implemented design. Will be ``None`` if implementation failed or did not run. 

26 maximum_logic_level (int): The maximum level in the the logic level distribution. 

27 Will be ``None`` if synthesis failed or did not run. 

28 """ 

29 

30 def __init__(self, name): 

31 """ 

32 Arguments: 

33 name (`str`): The name of the build. 

34 """ 

35 self.name = name 

36 self.success = True 

37 self.synthesis_size = None 

38 self.implementation_size = None 

39 self._logic_level_distribution = None 

40 self.maximum_logic_level = None 

41 

42 def size_summary(self): 

43 """ 

44 Return a string with a formatted message of the size. 

45 

46 Returns: 

47 str: A human-readable message of the latest size. ``None`` if no size is set. 

48 """ 

49 build_step = None 

50 size = None 

51 

52 if self.implementation_size is not None: 

53 build_step = "implementation" 

54 size = self.implementation_size 

55 elif self.synthesis_size is not None: 

56 build_step = "synthesis" 

57 size = self.synthesis_size 

58 else: 

59 return None 

60 

61 return f"Size of {self.name} after {build_step}:\n{json.dumps(size, indent=2)}" 

62 

63 def report(self): 

64 """ 

65 Return a report of the build result. Includes all metrics and information that has been 

66 extracted from the Vivado reports. 

67 

68 Returns: 

69 str: The report. 

70 """ 

71 result = self.size_summary() 

72 

73 if self.logic_level_distribution is not None: 

74 result = f"{result}\nLogic level distribution:\n{self.logic_level_distribution}" 

75 

76 return result 

77 

78 @property 

79 def logic_level_distribution(self): 

80 """ 

81 str: A table with logic level distribution as reported by Vivado. 

82 Will be ``None`` if synthesis failed or did not run. 

83 """ 

84 # Getter for logic_level_distribution. 

85 return self._logic_level_distribution 

86 

87 @logic_level_distribution.setter 

88 def logic_level_distribution(self, value): 

89 """ 

90 Setter for logic_level_distribution that also sets the calculated maximum logic level. 

91 """ 

92 self._logic_level_distribution = value 

93 self.maximum_logic_level = LogicLevelDistributionParser.get_maximum_logic_level(value)