-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcount-gate-types.py
executable file
·65 lines (49 loc) · 1.24 KB
/
count-gate-types.py
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
57
58
59
60
61
62
63
64
65
#!/usr/bin/python3.5
import sys, getopt
def parseFile(ifile):
#Reading gates from input file
with open(ifile) as f:
numGates = 0
numXORGates = 0
numWires = 0
for line in f:
line = line.rstrip()
line = line.split(' ')
inputl = ''
inputr = ''
output = ''
gateType = ''
dict = {}
if len(line) == 4:
numGates += 1
inputl = line[0]
inputr = line[1]
output = line[2]
gateType = line[3]
if gateType == '0110':
numXORGates += 1
if int(output) > numWires:
numWires = int(output)
print("File: " + ifile)
print("Number of wires: " + str(numWires))
print("Number of gates: " + str(numGates))
print("Number of free XOR-gates: " + str(numXORGates))
print("Number of non-free gates: " + str(numGates - numXORGates))
def main():
inputfile = ''
try:
opts, args = getopt.getopt(sys.argv[1:],"hi:",["ifile="])
except getopt.GetoptError:
print('usage: ./count-gate-types.py -i <inputfile>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('usage: ./count-gate-types.py -i <inputfile>')
sys.exit()
elif opt in ("-i", "--ifile"):
inputfile = arg
else:
print("usage: ./count-gate-types.py -i <inputfile>")
parseFile(inputfile)
if __name__ == '__main__':
main()