Coverage for tsfpga/vivado/timing_parser.py: 57%

14 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-12 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 

10 

11 

12class TimingParser: 

13 """ 

14 Used for parsing the ``report_timing`` report generated by Vivado. 

15 """ 

16 

17 @staticmethod 

18 def get_slack_ns(report: str) -> float: 

19 """ 

20 Takes a timing report as a string and returns the ``slack`` number in nanoseconds (ns). 

21 

22 For example: 

23 

24 ``` 

25 ------------------------------------------------------------------- 

26 required time 2.739 

27 arrival time -6.715 

28 ------------------------------------------------------------------- 

29 slack -3.976 

30 ``` 

31 

32 Note that for a design where no clock is created, there is no line like this, 

33 and an exception is raised. 

34 

35 Arguments: 

36 report: A string containing the entire Vivado timing report. 

37 """ 

38 slack_matches = re.findall(r"^[\s]*slack\s*([-\d\.]+)(\s|$)", report, re.MULTILINE) 

39 

40 if len(slack_matches) == 0: 

41 raise FoundNoSlackError 

42 if len(slack_matches) > 1: 

43 raise FoundMultipleSlackError 

44 

45 return float(slack_matches[0][0]) 

46 

47 

48class FoundNoSlackError(Exception): 

49 pass 

50 

51 

52class FoundMultipleSlackError(Exception): 

53 pass