-
Notifications
You must be signed in to change notification settings - Fork 0
/
ds_output.py
129 lines (106 loc) · 3.16 KB
/
ds_output.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def get_and(k,st):
stn="("+st
for j in range(len(k)):
if k[j]=="1":
stn+=",x"+("%d"%(j+1))
elif k[j]=="0":
stn+=",~x"+("%d"%(j+1))
else:
continue
return "and"+stn+");"
def get_or(lst):
stn="or(out"
for i in range(len(lst)):
stn=stn +",y"+str(i+1)
return stn+");"
def make_func(name,lst):
F=open(name+".txt","w") #make this a
F.write("\n\n") #add this line
stn="module "+str(name)+"(out"
for i in range(len(lst[0])):
stn=stn+",x"+str(i+1)
stn=stn+");"
print stn
F.write(stn+"\n")
stn2="input"
stn2 += " x" + str(1)
for i in range(1,len(lst[0])):
stn2=stn2+",x"+str(i+1)
stn2=stn2+";"
print stn2
print "output out;"
print
F.write(stn2+"\n")
F.write("output out;\n")
F.write("\n")
for i in range(len(lst)):
print "\t"+get_and(lst[i],"y"+str(i+1))
F.write("\t"+get_and(lst[i],"y"+str(i+1))+"\n")
print "\t"+get_or (lst)
print
print "endmodule"
F.write("\t"+get_or (lst)+"\n")
F.write("\n")
F.write("endmodule")
F.close()
#make_func("decoder",['0x000','011x1','101x1','1x111','11x00','x1111','0x101','1x100','x010x','00x0x','x10x0'])
#### This part needs to be removed
##input_var = "ab"
###raw_input("Enter the variable names:\t")
##input_var = input_var.strip()
##input_varnum = len(input_var)
##
##size = []
##
##for i in xrange(input_varnum):
## size.append(2)
## #input("Enter the size of " + str(input_var[i])+"\t\t"))
##
##input_exp = [['110x','0000','xx11'],['1000','111x']]
## Till here
#raw_input("Enter the file name:\t")
## Function starts here
def out(input_var, input_exp,size,total_size):
output_file = "main_output"
F = open(output_file + ".txt", "w")
input_varnum = len(input_var)
line = "module " + output_file + "(out"
for i in xrange(input_varnum):
line += "," + input_var[i]
line += ");"
print line
F.write(line+"\n")
line = ""
for i in xrange(input_varnum):
line += "input [" + str(size[i]) + ":0] " + input_var[i] + ";\n"
print line,
F.write(line)
maxSize = len(input_exp)
line = "output [" + str(maxSize-1) + ":0]" + " out;"
print line
F.write(line + "\n")
for i in range(maxSize):
#print 'x'*input_varnum,input_exp[i]
if 'x'*total_size in input_exp[i]:
if input_exp[i][0] == 'x'*total_size:
a = input_exp[i][1]
else:
a = input_exp[i][0]
line = "assign out[" + str(i) + "] = " + a + ";"
else:
line = "out" + str(i) + " inst" + str(i) + "(out[" + str(i) + "]"
for i in xrange(input_varnum):
for j in xrange(size[i]):
line += "," + input_var[i] + '[' + str(j )+ ']'
line += ");"
print line
F.write(line + "\n")
print "endmodule"
F.write("endmodule\n")
for i in range(maxSize):
if 'x'*total_size in input_exp[i]:
continue
else:
make_func("out"+str(i), input_exp[i])
F.close()
## Function ends here