Beispiel #1
0
class Mips:
	def __init__(self):
		self.inicio()
		self.fr = FileReader()   

	def addListaMemoria(self, endereco):
		cont = -1
		for i in self.listaMemoria:
			cont = cont + 1
			if i[0] == endereco:
				del self.listaMemoria[cont]
		self.listaMemoria.append([endereco, str(eval(self.mem[endereco].valor))])
		if len(self.listaMemoria) > 4:
			self.listaMemoria = self.listaMemoria[-4:]

	def getListaMemoria(self, i):
		if len(self.listaMemoria) < i:
			return ["", ""]
		else:
			return self.listaMemoria[-i]

	def addDesbloqueio(self, destino):
		self.listaDeDesbloqueio.append(destino)

	def ClockDesbloquear(self):
		for i in self.listaDeDesbloqueio:
			i.desbloquear()
		self.listaDeDesbloqueio = []

	def read(self, filePath):
		self.fr.read(filePath)

	def inicio(self):
		self.clock = 0
		self.pc = bin(0)
		self.concluidas = 0
		self.produtividade = 0
		self.E1 = InstructionFetch(1, self)
		self.E2 = InstructionDecodeRegisterFetch(2, self)
		self.E3 = InstructionExecute(3, self)
		self.E4 = MemoryAccess(4, self)
		self.E5 = WriteBack(5, self)

		self.E1.setNop()
		self.E2.setNop()
		self.E3.setNop()
		self.E4.setNop()
		self.E5.setNop()

		self.end1 = None
		self.val1 = None
		self.end2 = None
		self.val2 = None
		self.end3 = None
		self.val3 = None
		self.end4 = None
		self.val4 = None

		self.mem = []
		for i in range(0, 2**15):
			self.mem.append(Registrador())# vc pode checar o tamanho com len(self.mem) e acessar cada posicao
							   # independentemente com self.mips.mem[i] dai para manipular os 32 bits podemos
							   # mexer com os valores binarios e decimais
		self.reg = []
		for i in range(0, 2**5):
			self.reg.append(Registrador())
		self.avancapc = False
		self.listaDeDesbloqueio = []
		self.listaMemoria = []

	def setView(self, view):
		self.view = view

	def memoryAccess(self):
		pass

	def writeBack(self):
		pass

	def proxEstagio(self):
		self.clock = self.clock + 1
		self.ClockDesbloquear()
		if not self.E5.bloqueado:
			if not self.E5.desbloqueou:
				if self.E5.instrucao.__class__.__name__ != "Nop":
					self.concluidas = self.concluidas + 1
				if not self.E4.bloqueado:
					if not self.E4.desbloqueou:
						self.E5.setInstrucao(self.E4.instrucao)
						self.E5.do()
						if not self.E3.bloqueado:
							if not self.E3.desbloqueou:
								self.E4.setInstrucao(self.E3.instrucao)
								self.E4.do()
								if not self.E2.bloqueado:
									if not self.E2.desbloqueou:
										self.E3.setInstrucao(self.E2.instrucao)
										self.E3.do()
										if not self.E1.bloqueado:
											if not self.E1.desbloqueou:
												self.E2.setInstrucao(self.E1.instrucao)
												self.E2.do()
												if not self.avancapc:
													self.avancapc = True
												else:
													self.pc = bin(eval(self.pc) + 4)	
												self.E1.setInstrucao(self.E2.decodInst(self.E1.do(eval(self.pc)/4)))
											else:
												self.E2.setNop()
												self.E1.desbloqueou = False
												self.E1.do()
										else:
											self.E2.setNop()
									else:
										self.E3.setNop()
										self.E2.desbloqueou = False
										self.E2.do()
								else:
									self.E3.setNop()
							else:
								self.E4.setNop()
								self.E3.desbloqueou = False
								self.E3.do()
						else:
							self.E4.setNop()
					else:
						self.E5.setNop()
						self.E4.desbloqueou = False
						self.E4.do()
				else:
					self.E5.setNop()
			else:
				self.E5.desbloqueou = False
				self.E5.do()

		self.produtividade = float(self.concluidas)/self.clock
		self.atualizarLabels()


	def setText(self, label, ori, none):
		if ori is not None:
			label["text"] = ori
		else:
			label["text"] = none

	def atualizarLabels(self):
		if self.view is not None:
			self.setText(self.view.E1_instrucao, self.E1.InstName, "")
			self.setText(self.view.E2_instrucao, self.E2.InstName, "")
			self.setText(self.view.E3_instrucao, self.E3.InstName, "")
			self.setText(self.view.E4_instrucao, self.E4.InstName, "")
			self.setText(self.view.E5_instrucao, self.E5.InstName, "")
			self.setText(self.view.E1_controle, self.E1.SinControle, "")
			self.setText(self.view.E2_controle, self.E2.SinControle, "")
			self.setText(self.view.E3_controle, self.E3.SinControle, "")
			self.setText(self.view.E4_controle, self.E4.SinControle, "")
			self.setText(self.view.E5_controle, self.E5.SinControle, "")

			self.view.lclock["text"] = self.clock
			self.view.lpc["text"] = str(eval(self.pc))
			self.view.lconcluidas["text"] = self.concluidas
			self.view.lprodutividade["text"] = "{0:.2f}".format(100*self.produtividade)+"%"

			self.setText(self.view.lend1, self.getListaMemoria(1)[0], "")
			self.setText(self.view.lval1, self.getListaMemoria(1)[1], "?")
			self.setText(self.view.lend2, self.getListaMemoria(2)[0], "")
			self.setText(self.view.lval2, self.getListaMemoria(2)[1], "?")
			self.setText(self.view.lend3, self.getListaMemoria(3)[0], "")
			self.setText(self.view.lval3, self.getListaMemoria(3)[1], "?")
			self.setText(self.view.lend4, self.getListaMemoria(4)[0], "")
			self.setText(self.view.lval4, self.getListaMemoria(4)[1], "?")

			self.view.lr0["text"] = str(eval(self.reg[0].valor))
			self.view.lr1["text"] = str(eval(self.reg[1].valor))
			self.view.lr2["text"] = str(eval(self.reg[2].valor))
			self.view.lr3["text"] = str(eval(self.reg[3].valor))
			self.view.lr4["text"] = str(eval(self.reg[4].valor))
			self.view.lr5["text"] = str(eval(self.reg[5].valor))
			self.view.lr6["text"] = str(eval(self.reg[6].valor))
			self.view.lr7["text"] = str(eval(self.reg[7].valor))
			self.view.lr8["text"] = str(eval(self.reg[8].valor))
			self.view.lr9["text"] = str(eval(self.reg[9].valor))
			self.view.lr10["text"] = str(eval(self.reg[10].valor))
			self.view.lr11["text"] = str(eval(self.reg[11].valor))
			self.view.lr12["text"] = str(eval(self.reg[12].valor))
			self.view.lr13["text"] = str(eval(self.reg[13].valor))
			self.view.lr14["text"] = str(eval(self.reg[14].valor))
			self.view.lr15["text"] = str(eval(self.reg[15].valor))
			self.view.lr16["text"] = str(eval(self.reg[16].valor))
			self.view.lr17["text"] = str(eval(self.reg[17].valor))
			self.view.lr18["text"] = str(eval(self.reg[18].valor))
			self.view.lr19["text"] = str(eval(self.reg[19].valor))
			self.view.lr20["text"] = str(eval(self.reg[20].valor))
			self.view.lr21["text"] = str(eval(self.reg[21].valor))
			self.view.lr22["text"] = str(eval(self.reg[22].valor))
			self.view.lr23["text"] = str(eval(self.reg[23].valor))
			self.view.lr24["text"] = str(eval(self.reg[24].valor))
			self.view.lr25["text"] = str(eval(self.reg[25].valor))
			self.view.lr26["text"] = str(eval(self.reg[26].valor))
			self.view.lr27["text"] = str(eval(self.reg[27].valor))
			self.view.lr28["text"] = str(eval(self.reg[28].valor))
			self.view.lr29["text"] = str(eval(self.reg[29].valor))
			self.view.lr30["text"] = str(eval(self.reg[30].valor))
			self.view.lr31["text"] = str(eval(self.reg[31].valor))
Beispiel #2
0
 def read(self, fs):
     """Basic file reader for multiple 32 bit colums hex files."""
     reader = FileReader(fs, fields=(('values', 'x8', self.columns), ))
     self.clear()
     for column, values in enumerate(reader.read()['values']):
         self.inject(values, column, 1)
Beispiel #3
0
 def read(self, fs):
     """Basic file reader for single column hex files."""
     reader = FileReader(fs, fields=(('values', 'x8'), ))
     values = reader.read()['values']
     self.deserialize(values)
Beispiel #4
0
def load(file):
    reader = FileReader(file)
    return reader.read()