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 

9 

10class Constraint: 

11 """ 

12 Class for handling a constraint file. 

13 

14 Can handle the regular global constraint files as well as scoped constraints. 

15 For the latter to work the constraint file name must be the same as the .vhd file name, 

16 which must be the same as the entity name. 

17 """ 

18 

19 def __init__(self, file, used_in="all", scoped_constraint=False, processing_order="normal"): 

20 """ 

21 Arguments: 

22 file (`pathlib.Path`): Path to the constraint file. Typically ends in .xdc or .tcl. 

23 used_in (str): Optionally the constraint can be enabled only for "synth" or "impl". 

24 scoped_constraint (bool): If enabled the constraint file will be loaded with the "-ref" 

25 argument in Vivado. An entity with the same name must exist. 

26 processing_order (str): Optionally the processing order can be changed to "early" or 

27 "late". 

28 """ 

29 self.file = file 

30 self.used_in = used_in 

31 self.ref = file.stem if scoped_constraint else None 

32 self.processing_order = processing_order.lower() 

33 

34 assert self.used_in in ["all", "synth", "impl"], self.used_in 

35 assert self.processing_order in ["early", "normal", "late"], self.processing_order 

36 

37 def validate_scoped_entity(self, source_files): 

38 """ 

39 Make sure that a matching entity file exists in case this is a scoped constraint. 

40 The list of source files should be the synthesis files for the module that this 

41 constraint belongs to. 

42 """ 

43 if self.ref is not None: 

44 if not any([source_file.path.stem == self.ref] for source_file in source_files): 

45 raise FileNotFoundError( 

46 f"Could not find a matching entity file for scoped constraint file {self.file}" 

47 ) 

48 return True 

49 

50 def __str__(self): 

51 return str(self.file)