-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcf.py
More file actions
56 lines (43 loc) · 1.28 KB
/
pcf.py
File metadata and controls
56 lines (43 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
#
# This file allows for import and manipulation
# of a pin constraints file
# as it is used in Lattice FPGA projects
#
def cmpPin(a, b):
return cmp(a[0], b[0])
def cmpSignal(a, b):
return cmp(a[1], b[1])
#
# Handles generation of a pin constraints file
# for Lattice FPGA projects (.pcf)
#
class PCF:
def __init__(self):
self.constraints = []
def addConstraint(self, signal, pin):
self.constraints += [[pin, signal]]
def sortBySignal(self):
self.constraints = sorted(self.constraints, key = lambda c: c[1])
def sortByPin(self):
self.constraints = sorted(self.constraints, key = lambda c: c[0])
def hasSignal(self, signal):
for constraint in self.constraints:
if constraint[1] == signal:
return True
return False
def hasPin(self, pin):
for constraint in self.constraints:
if constraint[0] == pin:
return True
return False
def __str__(self):
result = "\n"
for c in self.constraints:
result += "set_io {:s} {:s}\n".format(c[1], c[0])
result += "\n"
return result
def saveToFile(self, filename):
f = open(filename, "w")
f.write(str(self))
f.close()