-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice_backup_22_59_22_05_15.py
274 lines (221 loc) · 7.97 KB
/
slice_backup_22_59_22_05_15.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
# Slicing code
# Courtesy: Stackoverflow and many other sites
from glob import iglob
import shutil
import os
import sys
#----------------------------------------------------------------------
# Fresh execution of program
print "\nFresh execution of program"
print "****************************\n"
#----------------------------------------------------------------------
# Function definitions
# Find a string between two strings
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
print "error"
return ""
'''
# Testing function find_between
s = "123vineeshabc"
a = find_between( s, "123", "abc" )
print a
'''
#----------------------------------------------------------------------
# Print the contents of a file
def print_file(file_name):
f_1 = open (file_name)
for line in f_1:
print line
print "------------------------------------------------------------"
#----------------------------------------------------------------------
# Remove spaces in a list of strings
def rem_space(list_name):
while True:
try:
list_name.remove("")
except ValueError:
print "No blank space in the string"
break
pass
#----------------------------------------------------------------------
'''
if 'Instructions' in open('full_adder.v').read():
print "True"
else:
print "False"
'''
#----------------------------------------------------------------------
lines = open("full_adder.v", 'rt').read()
#----------------------------------------------------------------------
# Junk
'''
first, second, rest = lines.split('Instructions',3)
open("output1.txt", 'wt').writelines(first)
open("output2.txt", 'wt').writelines(second)
open("output3.txt", 'wt').writelines(rest)
'''
'''
# Concatenation of two sections
destination=open("output4.txt",'wb')
shutil.copyfileobj(open("output1.txt",'rb'), destination)
shutil.copyfileobj(open("output3.txt",'rb'), destination)
destination.close()
'''
'''
#
fh=open("full_adder.v",'r')
for i in range(100):
print fh.readline()
'''
#----------------------------------------------------------------------
# Calculating the total number of slices (num_slices)
num_slices = 0
for item in lines.split("\n"):
if "// slice" in item:
# print item.strip()
num_slices += 1
'''
#----------------------------------------------------------------------
# Junk
# Split files
first, second, rest = lines.split('Instructions',num_slices+1)
open("output1.txt", 'wt').writelines(first)
open("output2.txt", 'wt').writelines(second)
open("output3.txt", 'wt').writelines(rest)
# Combine files
destination=open("output4.txt",'wb')
shutil.copyfileobj(open("output1.txt",'rb'), destination)
shutil.copyfileobj(open("output3.txt",'rb'), destination)
destination.close()
'''
#----------------------------------------------------------------------
# Creating slices
print "\nCreating slices"
print "**************\n"
for i in range(1, num_slices + 1):
slice_i = lines.split("// slice", num_slices)[i]
open("%d.txt" %(i),'wt').writelines(slice_i)
# print_file ("%d.txt" %(i))
# ---------------------------------------------------------------------
# Searching for module name
# module = sys.stdin.readline()
module = raw_input ("Give the name of the module to be tested:")
print "Searching for module and doing concatenation "
# destination = open("combined_file.txt",'w')
'''
# Simple search of module and concatenation of slices
for i in xrange (1, num_slices + 1):
if module in open('%d.txt' %(i)).read():
print "True in %d.txt" %(i)
# shutil.copyfileobj(open("%d.txt" %(i),'rb'), destination)
with open("%d.txt" %(i)) as infile:
destination.write (infile.read())
elif "default_slice" in open('%d.txt' %(i)).read():
with open("%d.txt" %(i)) as infile:
destination.write (infile.read())
else:
print "False in %d.txt" %(i)
'''
# ---------------------------------------------------------------------
#Finding out the instructions related to the module specified
print "\nFinding out the instructions related to the module specified"
print "*************************************************************\n"
full_instruction_list = ['I1', 'I2', 'I3', 'I4', 'I5', 'I6', 'I7']
selected_instruction_set = []
for i in xrange (1, num_slices + 1):
if module in open('%d.txt' %(i)).read():
print "your module is found in %d.txt" %(i)
for I in full_instruction_list:
if I in open('%d.txt' %(i)).read():
print "%s found in %d.txt" %(I, i)
selected_instruction_set.append(I)
# To accommodate for default sections of slice
# Essential part of verilog code
selected_instruction_set.append('default_slice')
#----------------------------------------------------------------------
# Checking for slices which contain elements in selected_instruction_set and combining them
print "\nJoining slices"
print "**************\n"
destination = open("combined_file.txt",'w')
for i in xrange (1, num_slices + 1):
for I in selected_instruction_set:
# The line below will make sure that the test module is not included in the combined_file.txt file, but only the slices which have connection with the test module will be included in it
if ((I in open('%d.txt' %(i)).read()) and (not (module in open('%d.txt' %(i)).read()))):
print "True in %d.txt" %(i)
with open("%d.txt" %(i)) as infile:
destination.write (infile.read())
break
destination.close()
# Check if the combined_file.txt is correct
print "printing combined_file.txt"
print_file("combined_file.txt")
#----------------------------------------------------------------------
#Extracting inputs and outputs of module to be tested
print "\nExtracting inputs and outputs of module to be tested"
print "****************************************************\n"
inputs_test_module = []
outputs_test_module = []
k = 0
for i in xrange (1, num_slices + 1):
if module in open('%d.txt' %(i)).read():
with open('%d.txt' %(i)) as f:
print "test1"
for line in f:
if "Inputs" in line:
k = 1
elif "Outputs" in line:
k = 2
while k == 1:
inputs_test_module.append (find_between (line, "(", ")"))
if "End of inputs" in line:
k = 0
break
while k == 2:
outputs_test_module.append (find_between (line, "(", ")"))
if "End of outputs" in line:
k = 0
break
'''
# There are spaces in the strings 'inputs_test_module' and 'outputs_test_module
print "inputs_test_module:"
print inputs_test_module
print "outputs_test_module:"
print outputs_test_module
'''
# -----------------------------------------------------------------------------
# Removing spaces in the strings 'inputs_test_module' and 'outputs_test_module
rem_space (inputs_test_module)
print inputs_test_module
rem_space (outputs_test_module)
print outputs_test_module
# -----------------------------------------------------------------------------
# Ignore this section. I don't know why I wrote this section. Let's figure out later
# Checking for entries if inputs_test_module in the sliced section without MUT
'''
count = 0
lines_slice = open("combined_file.txt", 'r').read()
for i in inputs_test_module:
print i
'''
'''
count = count + 1
if "(" + i + ")":
print "(%s) found at line %d" %(i,count)
break
'''
#----------------------------------------------------------------------
flist = open("combined_file.txt").readlines()
parsing = False
for line in flist:
print line
if line.startswith("\****t// Inputs"):
parsing = True
if line.startswith("\****t// End of inputs"):
parsing = False
if parsing:
print line