def main(): #Read the instruction file code = (open(sys.argv[1], r"U")).readlines() parsed_code, labels = mips_parser.mips_parse(code) #<-------TESTING MODULE----------------> #for line in parsed_code: # print line #print labels #<-------------------------------------> #Reading the data file and storing it in a list memory_data = [x.strip() for x in (open(sys.argv[2], r"U")).readlines()] #<------TESTING MODULE-----------------> #for i in memory_data: # print i #<-------------------------------------> register_data = [x.strip() for x in (open(sys.argv[3])).readlines()] #<------TESTING MODULE-----------------> #for i in register_data: # print i #Find RAW Dependenies in the passed code. #The first thing that we need to do is to get a list of destination operands before th einstruction we are looking at. #I write a function which can go thorugh the entire code in a pass and create a dictionary identifying destination operands before your level. destdict = destination_op_finder.dest_op_finder(parsed_code, labels)
def main(): #Read the instruction file code = (open(sys.argv[1], r"U")).readlines() parsed_code, labels = mips_parser.mips_parse(code) #<-------TESTING MODULE----------------> #for line in parsed_code: # print line #print labels #<-------------------------------------> print "<------------------------------------------------------->" #Reading the data file and storing it in a list memory_data = [x.strip() for x in (open(sys.argv[2], r"U")).readlines()] #<------TESTING MODULE-----------------> #for i in memory_data: # print i #<-------------------------------------> register_data = [x.strip() for x in (open(sys.argv[3])).readlines()] #<------TESTING MODULE-----------------> #for i in register_data: # print i #Find RAW Dependenies in the passed code. #The first thing that we need to do is to get a list of destination operands before th einstruction we are looking at. #I write a function which can go thorugh the entire code in a pass and create a dictionary identifying destination operands before your level. destdict = destination_op_finder.dest_op_finder(parsed_code, labels) #<-----------TESTING ROUTINE----------------------> #for i in destdict.items(): # print i #<------------------------------------------------> #FINDS RAW DEPENDENCIES raw_dict = raw_finder.raw_finder(parsed_code, destdict, labels) #THE RAW FINDER RETURNS NO ENTRIES CORRESPONDING TO THOSE WHICH HAVE NO DEPENDENCIES. ADDING NONE FOR SUCH CASE for i in range(0, len(parsed_code)): if i in raw_dict.keys(): pass else: raw_dict[i] = None #<------------------TESTING ROUTINE-----------------------> #for i in raw_dict.items(): # print i #<-----------------TESTING ROUTINE------------------------> #Find WAW HAZARDS and deal with them waw_dict = waw_finder.waw_finder(parsed_code, destdict, labels) #<-----------------TESTING MODULE-------------------------> #for i in waw_dict.items(): # print i #<--------------------------------------------------------> #FIND WAR HAZARDS BY USING PERIPHERAL INFORMATION. war_dict = war_finder.war_finder(parsed_code, destdict, labels) for i in war_dict.items(): print i
def main(): global obj_list #Read the instruction file code = (open(sys.argv[1], r"U")).readlines() parsed_code, labels = mips_parser.mips_parse(code) #<-------TESTING MODULE----------------> #for line in parsed_code: # print line #print labels #<-------------------------------------> #print "<------------------------------------------------------->" #Reading the data file and storing it in a list config =filter(lambda k: k != "", [x.strip() for x in (open(sys.argv[4], r"U")).readlines()]) latencies = [] pipelined = [] #print config for i in config: temp = i.split(":") if "," in temp[1]: temp = temp[1].split(",") #print temp else: temp = [temp[1]] #print temp temp = [x.replace(" ", "").strip() for x in temp] if len(temp) == 2: latencies.append(temp) elif len(temp) == 1: pipelined.append(int(temp[0])) #print latencies #print pipelined config = configuration(int(latencies[0][0]), int(latencies[1][0]), int(latencies[2][0]), pipelined[0], pipelined[1], pipelined[2]) fpa = fpm = fpd = False if latencies[0][1].lower() == "yes": fpa = True if latencies[1][1].lower() == "yes": fpm = True if latencies[2][1].lower() == "yes": fpd = True config.set_pipelines(fpa, fpm, fpd) #config.printconf() #<---------------SETTING GLOBALS FOR THE FIRST TIME IN THE INSTRUCTION CLASS---------------------------------------------------------------------------> #print "Creating a dummy instruction to set globals" dummy = instruction("", None, None, None, None, None) instruction.main_add_pipe = config.pipe_fpa instruction.mainmul_pipe = config.pipe_fpm instruction.maindiv_pipe = config.pipe_fpd instruction.main_add_latency = int(config.fpadder) instruction.mainmul_latency = int(config.fpmult) instruction.maindiv_latency = int(config.fpdiv) instruction.mainmemory_latency = int(config.mem) instruction.icache_latency = int(config.icac) instruction.dcache_latency = int(config.dcac) for cachecounter in range(0, 16): instruction.instruction_cache.append([None, [cachecounter, cachecounter + 16, cachecounter + 32, cachecounter + 48]]) #print "Compare the two" #print instruction.main_add_pipe #print instruction.mainmul_pipe #print instruction.maindiv_pipe #print instruction.main_add_latency #print instruction.mainmul_latency #print instruction.maindiv_latency #print instruction.mainmemory_latency #print instruction.icache_latency #print instruction.dcache_latency #print dummy.main_add_pipe #dummy_two = instruction("", None, None, None, None, None) #print dummy_two.dcache_latency #Find RAW Dependenies in the passed code. #The first thing that we need to do is to get a list of destination operands before th einstruction we are looking at. #I write a function which can go thorugh the entire code in a pass and create a dictionary identifying destination operands before your level. destdict = destination_op_finder.dest_op_finder(parsed_code, labels) #<-----------TESTING ROUTINE----------------------> #for i in destdict.items(): # print i #<------------------------------------------------> #FINDS RAW DEPENDENCIES raw_dict = raw_finder.raw_finder(parsed_code, destdict, labels) #THE RAW FINDER RETURNS NO ENTRIES CORRESPONDING TO THOSE WHICH HAVE NO DEPENDENCIES. ADDING NONE FOR SUCH CASE for i in range(0, len(parsed_code)): if i in raw_dict.keys(): pass else: raw_dict[i] = None instruction.registers = [x.strip() for x in (open(sys.argv[3], r"U")).readlines()] #<------TESTING MODULE-----------------> #for i in register_data: # print i temporary_memdata = [x.strip() for x in (open(sys.argv[2], r"U")).readlines()] mem_index = [] for i in range(0,len(temporary_memdata)): mem_index.append(256 + i * 4) instruction.memory_data = dict(zip(mem_index, temporary_memdata)) #<------TESTING MODULE-----------------> #for i in memory_data: # print i #<-------------------------------------> #<------------------TESTING ROUTINE-----------------------> #print "<--------------RAW DICTIONARY---------------->" #for i in raw_dict.items(): # print i #<-----------------TESTING ROUTINE------------------------>I #Find WAW HAZARDS and deal with them waw_dict = waw_finder.waw_finder(parsed_code, destdict, labels) #<-----------------TESTING MODULE------------------------->\ #Padding the non existing wars with None types for i in range(0, len(parsed_code)): try: temp = waw_dict[i] except: waw_dict[i] = None #print ("<-----------WAW DICTIONARY------------------>") #for i in waw_dict.items(): # print i #<--------------------------------------------------------> #FIND WAR HAZARDS BY USING PERIPHERAL INFORMATION. war_dict = war_finder.war_finder(parsed_code, destdict, labels) for i in range(0, len(parsed_code)): try: temp = war_dict[i] except: war_dict[i] = None #print ("<---------WAR DICTIONARY-------------------->") #for i in war_dict.items(): # print i #<--------------PRODUCE CLEAN CODE WITHOUT LEADING LABELS AND CREATE A LABEL DICTIONARY-------------------------------> clean_code = [] label_dict = {} for element in range(0, len(parsed_code)): if parsed_code[element][0] in labels: clean_code.append(parsed_code[element][1:]) label_dict[parsed_code[element][0]] = element else: clean_code.append(parsed_code[element]) #for line in clean_code: # print line #print label_dict.items() #<--------------INITIALIZE CODE OBJECTS IN A LIST CALLED OBJ_LIST--------------> instruction.label_dictionary = label_dict for i in range(0, len(clean_code)): obj_list.append(instruction(clean_code[i], raw_dict[i], war_dict[i], waw_dict[i], destdict[i], i )) for i in range(0, len(clean_code)): instruction.ref_objlist.append(instruction(clean_code[i], raw_dict[i], war_dict[i], waw_dict[i], destdict[i], i )) #print obj_list #print "----------------------" #print instruction.ref_objlist #print raw_dict[10] counter = 1 #while(obj_list[-1].result[0] == None): #print instruction.instruction_cache while(obj_list[-1].result[0] == None): #print "Entered while" for num in range(0, len(obj_list)): if obj_list[num].hideme == 0: obj_list[num].action(num, counter) #IF STAGE if obj_list[instruction.ifsetter].setiffalse == 1: instruction.mainif_busy = False #ID STAGE if obj_list[instruction.idsetter].setidfalse == 1: instruction.mainid_busy = False #UI if obj_list[instruction.uisetter].setuifalse == 1: instruction.mainui_busy = False #DATABUS if obj_list[instruction.databussetter].setdatabusfalse == 1: instruction.maindatabus_busy = False #ADDER if obj_list[instruction.addsetter].setaddfalse == 1: instruction.mainadd_busy = False #MULTIPLIER if obj_list[instruction.mulsetter].setmulfalse == 1: instruction.mainmul_busy = False #DIVIDER if obj_list[instruction.divsetter].setdivfalse == 1: instruction.maindiv_busy = False #WRITEBACK STAGE if obj_list[instruction.wbsetter].setwbfalse == 1: instruction.mainwb_busy = False counter = counter + 1 #if counter == 10: # break #for i in obj_list: # print i.result # print "------------" #print "---------------------------------------------------" #if counter == 50: #for number, i in enumerate(obj_list): # print "I am" + str(number) + "and my hidden bit is " + str(i.hideme) # break #print obj_list[0].result[0] #print obj_list[0].ifstage #print obj_list[0].idstage #print obj_list[0].execstage #shit = instruction.registers[0] #print instruction.registers.index(shit) #print instruction.memdata #for i in obj_list: # print i.result, # print i.hazards # print "------------" #print instruction.instruction_cache for i in obj_list: print i.result