示例#1
0
 def Eval(self, x, state, extsignals):
     FanInList = self.getFanInList(x)
     FanInVal = dict([])
     #for i in FanInList:
     #	FanInVal[i] = state[i]
     #	FanInVal['~'+i] = func.compStr(state[i])
     for i in FanInList:
         if (i in extsignals):
             FanInVal[i] = state[i]
             FanInVal['~' + i] = func.compStr(state[i])
         else:
             temp = self.Eval(i, state, extsignals)
             FanInVal[i] = temp
             FanInVal['~' + i] = func.compStr(temp)
     comb_OrEval = 0
     set_OrEval = 0
     reset_OrEval = 0
     combAndEval = 0
     setAndEval = 0
     resetAndEval = 0
     if (len(self.circuitDict[x]['COMB']) != 0):
         combList = self.circuitDict[x]['COMB']
         comb_OrEval = 0
         for ckt in combList:
             combAndEval = 1
             for i in ckt:
                 combAndEval = combAndEval & int(FanInVal[i])
             comb_OrEval = comb_OrEval | combAndEval
     if (len(self.circuitDict[x]['SET']) != 0):
         setList = self.circuitDict[x]['SET']
         set_OrEval = 0
         for ckt in setList:
             setAndEval = 1
             for i in ckt:
                 setAndEval = setAndEval & int(FanInVal[i])
             set_OrEval = set_OrEval | setAndEval
     if (len(self.circuitDict[x]['RESET']) != 0):
         resetList = self.circuitDict[x]['RESET']
         reset_OrEval = 0
         for ckt in resetList:
             resetAndEval = 1
             for i in ckt:
                 resetAndEval = resetAndEval & int(FanInVal[i])
             reset_OrEval = reset_OrEval | resetAndEval
     if (
             len(self.circuitDict[x]['RESET']) != 0
             or len(self.circuitDict[x]['SET']) != 0
     ):  #indicates a c-element, which means it needs to be a primary output
         result = func.Celem(set_OrEval,
                             int(func.compStr(str(reset_OrEval))),
                             int(state[x]))
     else:
         result = comb_OrEval
     #result = comb_OrEval | func.Celem(set_OrEval , int(func.compStr(str(reset_OrEval))), int(state[x]))
     return str(result)
示例#2
0
	def Eval(self,x,state,extsignals):
		FanInList = self.getFanInList(x)
		FanInVal = dict([])
		#for i in FanInList:
		#	FanInVal[i] = state[i]
		#	FanInVal['~'+i] = func.compStr(state[i])
		for i in FanInList:
			if( i in extsignals ):
				FanInVal[i] = state[i]
				FanInVal['~'+i] = func.compStr(state[i])
			else:
				temp = self.Eval(i, state, extsignals)
				FanInVal[i] = temp
				FanInVal['~'+i] = func.compStr(temp)
		comb_OrEval = 0
		set_OrEval = 0
		reset_OrEval = 0
		combAndEval = 0
		setAndEval = 0
		resetAndEval = 0
		if(len(self.circuitDict[x]['COMB'])!=0):
			combList = self.circuitDict[x]['COMB']
			comb_OrEval = 0
			for ckt in combList:
				combAndEval = 1
				for i in ckt:
					combAndEval = combAndEval & int(FanInVal[i])
				comb_OrEval = comb_OrEval | combAndEval
		if(len(self.circuitDict[x]['SET'])!=0):
			setList = self.circuitDict[x]['SET']
			set_OrEval = 0
			for  ckt in setList:
				setAndEval = 1
				for i in ckt:
					setAndEval = setAndEval & int(FanInVal[i])
				set_OrEval = set_OrEval | setAndEval
		if(len(self.circuitDict[x]['RESET'])!=0):
			resetList = self.circuitDict[x]['RESET']
			reset_OrEval = 0
			for ckt in resetList:
				resetAndEval = 1
				for i in ckt:
					resetAndEval = resetAndEval & int(FanInVal[i])
				reset_OrEval = reset_OrEval | resetAndEval
		if(len(self.circuitDict[x]['RESET'])!=0 or len(self.circuitDict[x]['SET'])!=0): #indicates a c-element, which means it needs to be a primary output
			result = func.Celem(set_OrEval, int(func.compStr(str(reset_OrEval))), int(state[x]))
		else:
			result = comb_OrEval 
		#result = comb_OrEval | func.Celem(set_OrEval , int(func.compStr(str(reset_OrEval))), int(state[x]))
		return str(result)
示例#3
0
	def extend_state( self, state ):
		s = copy.deepcopy(state)
		si = copy.deepcopy(s)
		last_s = copy.deepcopy(s)
		done = 0
		ReachedExtendState = 0
		stack = []
		tempStack = []
		result = dict([])
		for i in self.outputs:	
			result[i] = 0
		Te = self.getExcitedSignals(s,1) ##passing 1 returns excitation on only outputs and internal signals
		print 'Te-extend: ', Te
		if(len(Te.keys())==0):
			ReachedExtendState = 1
			##result.append([
		while(done != 1):
			t = Te.keys()[0]
			del Te[t]
			si = copy.deepcopy(s)
			if(len(Te.keys())!=0):
				stack.append([s,Te])
			si[t] = func.compStr(s[t])
			print 'Arnab', si
			tempTe = self.getExcitedSignals(si,1)
			print 'tempte-Excitation', tempTe
			ReachedExtendState = 0
			outSig = ''
			if(len(tempTe.keys())==0):
				ReachedExtendState = 1
				#result['noExcitation'] = 0
				#result['extendState'] = copy.deepcopy(si)
				result[t] = 1
				done = 1
			else:
				for sig in self.outputs:
					if(sig in tempTe.keys()):
						ReachedExtendState = 1
						outSig = sig
						result[outSig] = 1
				if(ReachedExtendState==1):
					result[outSig] = 1
					#result['noExcitation'] = 1
				else:
					s = copy.deepcopy(si)
					Te = tempTe
				if(ReachedExtendState==1  and len(stack)!=0):
					tempStack = stack.pop()
					si = tempStack[0]
					Te = tempStack[1]
					if(Te.keys()==0):
						done = 1
				elif(ReachedExtendState==1 and len(stack)==0):
					done = 1
		print '================= from extend state ======================'
		print '------------------ state = ',state , '--------------------'
		for i, v in result.iteritems() :
			print i ,'   ', v
		print '================ end of extend state ====================='
		return result
示例#4
0
 def find_implSG(self, sgList, sgl):
     s = copy.deepcopy(self.init_state)
     si = copy.deepcopy(s)
     self.currentState = copy.deepcopy(self.init_state)
     done = 0
     stack = []
     failState = dict([])
     TRANSSET = []
     Te = self.getExcitedSignals(s, 0)
     result = []
     if (len(Te.keys()) == 0):
         result = ['DeadLock']
         return result
     while (done != 1):
         failFlag = 0
         t = Te.keys()[0]
         del Te[t]
         si = copy.deepcopy(s)
         if (len(Te) != 0):
             stack.append([s, Te])
         si[t] = func.compStr(s[t])
         tempTe = self.getExcitedSignals(si, 0)
         prevtempTe = self.getExcitedSignals(s, 0)
         if (len(tempTe.keys()) == 0):
             failFlag = 1
         else:
             for trans in prevtempTe:
                 if (trans not in self.inputs and trans not in tempTe
                         and trans !=
                         t):  ## transition has been disabled by this choice
                     failFlag = 1
                     print 'Fail Due to trans: ', t, Te, prevtempTe
         if (failFlag == 0 and [self.retState(s), t,
                                self.retState(si)] not in TRANSSET):
             TRANSSET.append([self.retState(s), t, self.retState(si)])
             Te = tempTe
             s = copy.deepcopy(si)
         else:
             if (failFlag == 1):
                 print 'FailHere: ', self.retState(s), t, self.retState(si)
                 if (tuple(self.retState(s)) not in failState):
                     failState[tuple(self.retState(s))] = []
                 if ([s, t, si] in failState[tuple(self.retState(s))]):
                     print 'Repeat'
                 else:
                     failState[tuple(self.retState(s))].append([s, t, si])
             if (len(stack) == 0):
                 done = 1
             else:
                 tempStack = stack.pop()
                 #print 'tempStack: ', tempStack
                 Te = tempStack[1]
                 s = tempStack[0]
                 if (len(Te.keys()) == 0):
                     print 'TempStack :', tempStack
                     print 'Because I was here'
                     #done = 1
     result = ['Successful', TRANSSET, failState]
     return result
示例#5
0
	def find_implSG( self, sgList, sgl):
		s = copy.deepcopy(self.init_state)
		si = copy.deepcopy(s)
		self.currentState = copy.deepcopy(self.init_state)
		done = 0
		stack = []
		failState = dict([])
		TRANSSET = []
		Te = self.getExcitedSignals(s,0)
		result = []
		if(len(Te.keys())==0):
			result = ['DeadLock']
			return result
		while(done != 1):
			failFlag = 0
			t = Te.keys()[0]
			del Te[t]
			si = copy.deepcopy(s)
			if(len(Te)!=0):
				stack.append([s,Te])
			si[t] = func.compStr(s[t])
			tempTe = self.getExcitedSignals(si,0)
			prevtempTe = self.getExcitedSignals(s,0)
			if(len(tempTe.keys())==0):
				failFlag = 1
			else:
				for trans in prevtempTe:
					if( trans not in self.inputs  and trans not in tempTe and trans!=t): ## transition has been disabled by this choice
						failFlag = 1
						print 'Fail Due to trans: ', t, Te, prevtempTe
			if(failFlag == 0 and [self.retState(s),t,self.retState(si)] not in TRANSSET):
				TRANSSET.append([self.retState(s),t,self.retState(si)])
				Te = tempTe
				s = copy.deepcopy(si)
			else:
				if(failFlag==1):
					print 'FailHere: ', self.retState(s),t,self.retState(si)
					if(tuple(self.retState(s)) not in failState):
						failState[tuple(self.retState(s))]=[]						
					if([s,t,si] in failState[tuple(self.retState(s))]):
						print 'Repeat'
					else:
						failState[tuple(self.retState(s))].append([s,t,si])
				if(len(stack)==0):
					done = 1
				else:
					tempStack = stack.pop()
					#print 'tempStack: ', tempStack
					Te = tempStack[1]
					s  = tempStack[0]
					if(len(Te.keys())==0):
						print 'TempStack :', tempStack
						print 'Because I was here'
						#done = 1
		result = ['Successful', TRANSSET, failState]
		return result
示例#6
0
 def Evaluate(self, x, state):
     FanInList = self.getFanInList(x)
     #print 'FanInList:', FanInList
     #print 'state:', state
     FanInVal = dict([])
     for i in FanInList:
         FanInVal[i] = state[i]
         FanInVal['~' + i] = func.compStr(state[i])
     comb_OrEval = 0
     set_OrEval = 0
     reset_OrEval = 0
     combAndEval = 0
     setAndEval = 0
     resetAndEval = 0
     if (len(self.circuitDict[x]['COMB']) != 0):
         combList = self.circuitDict[x]['COMB']
         comb_OrEval = 0
         for ckt in combList:
             combAndEval = 1
             for i in ckt:
                 combAndEval = combAndEval & int(FanInVal[i])
             comb_OrEval = comb_OrEval | combAndEval
     if (len(self.circuitDict[x]['SET']) != 0):
         setList = self.circuitDict[x]['SET']
         set_OrEval = 0
         for ckt in setList:
             setAndEval = 1
             for i in ckt:
                 setAndEval = setAndEval & int(FanInVal[i])
             set_OrEval = set_OrEval | setAndEval
     if (len(self.circuitDict[x]['RESET']) != 0):
         resetList = self.circuitDict[x]['RESET']
         reset_OrEval = 0
         for ckt in resetList:
             resetAndEval = 1
             for i in ckt:
                 resetAndEval = resetAndEval & int(FanInVal[i])
             reset_OrEval = reset_OrEval | resetAndEval
     result = comb_OrEval | func.Celem(
         set_OrEval, int(func.compStr(str(reset_OrEval))), int(state[x]))
     return str(result)
示例#7
0
	def Evaluate(self,x,state):
		FanInList = self.getFanInList(x)
		#print 'FanInList:', FanInList
		#print 'state:', state
		FanInVal = dict([])
		for i in FanInList:
			FanInVal[i] = state[i]
			FanInVal['~'+i] = func.compStr(state[i])
		comb_OrEval = 0
		set_OrEval = 0
		reset_OrEval = 0
		combAndEval = 0
		setAndEval = 0
		resetAndEval = 0
		if(len(self.circuitDict[x]['COMB'])!=0):
			combList = self.circuitDict[x]['COMB']
			comb_OrEval = 0
			for ckt in combList:
				combAndEval = 1
				for i in ckt:
					combAndEval = combAndEval & int(FanInVal[i])
				comb_OrEval = comb_OrEval | combAndEval
		if(len(self.circuitDict[x]['SET'])!=0):
			setList = self.circuitDict[x]['SET']
			set_OrEval = 0
			for  ckt in setList:
				setAndEval = 1
				for i in ckt:
					setAndEval = setAndEval & int(FanInVal[i])
				set_OrEval = set_OrEval | setAndEval
		if(len(self.circuitDict[x]['RESET'])!=0):
			resetList = self.circuitDict[x]['RESET']
			reset_OrEval = 0
			for ckt in resetList:
				resetAndEval = 1
				for i in ckt:
					resetAndEval = resetAndEval & int(FanInVal[i])
				reset_OrEval = reset_OrEval | resetAndEval
		result = comb_OrEval | func.Celem(set_OrEval , int(func.compStr(str(reset_OrEval))), int(state[x]))
		return str(result)
示例#8
0
    def getStateEval(self, specSignals, state, nonInput):
        sigNext = dict([])
        for sig in self.outSignals:
            sigNext[sig] = self.Eval(sig, state, specSignals)
        #for i in sigNext.keys():
        #	if(sigNext[i]==state[i]):
        #		del sigNext[i]
        if (nonInput == 1):
            return sigNext
        else:
            if (len(self.inputs) != 0):
                for i in self.inputs:
                    sigNext[i] = func.compStr(state[i])

        return sigNext
示例#9
0
    def getExcitedSignals(self, state, nonInput):
        sigNext = dict([])
        for sig in self.outSignals:
            sigNext[sig] = self.Evaluate(sig, state)
        for i in sigNext.keys():
            if (sigNext[i] == state[i]):
                del sigNext[i]
        if (nonInput == 1):
            return sigNext
        else:
            if (len(self.inputs) != 0):
                for i in self.inputs:
                    sigNext[i] = func.compStr(state[i])

        return sigNext
示例#10
0
	def getStateEval(self,specSignals, state,nonInput):
		sigNext = dict([])
		for sig in self.outSignals:
			sigNext[sig] = self.Eval(sig,state,specSignals)
		#for i in sigNext.keys():
		#	if(sigNext[i]==state[i]):
		#		del sigNext[i]
		if(nonInput==1):
			return sigNext
		else:
			if(len(self.inputs)!=0):
				for i in self.inputs:
					sigNext[i] = func.compStr(state[i])
			
		return sigNext	
示例#11
0
	def getExcitedSignals(self,state,nonInput):
		sigNext = dict([])
		for sig in self.outSignals:
			sigNext[sig] = self.Evaluate(sig,state)
		for i in sigNext.keys():
			if(sigNext[i]==state[i]):
				del sigNext[i]
		if(nonInput==1):
			return sigNext
		else:
			if(len(self.inputs)!=0):
				for i in self.inputs:
					sigNext[i] = func.compStr(state[i])
			
		return sigNext
示例#12
0
    def cktEval(self, x, state):
        fix_val = dict([])
        if (x in self.circuitDict):
            return self.Eval(x, state, self.signalSpec)
        elif (x in self.nodeSet):
            fi = self.nodeSet[x][1]
            #fi_val = dict([])
            for i in fi:
                if ('~' in i):
                    fix_val[i] = func.compStr(state[i.split('~')[1]])
                else:
                    #print 'Fi_val: ', i, fix_val, state, type(fix_val), type(state)
                    fix_val[i] = state[i]

            eval = 1
            for i in fix_val.keys():
                #print 'item: ', i, fix_val[i], type(fix_val[i])
                eval = eval & int(fix_val[i])
            return eval
示例#13
0
	def cktEval(self,x,state):
		fix_val = dict([])
		if(x in self.circuitDict):
			return self.Eval(x, state, self.signalSpec)
		elif(x in self.nodeSet):
			fi = self.nodeSet[x][1]
		#fi_val = dict([])
			for i in fi:
				if('~' in i):
					fix_val[i] = func.compStr(state[i.split('~')[1]])
				else:
					#print 'Fi_val: ', i, fix_val, state, type(fix_val), type(state)
					fix_val[i] = state[i]


			eval = 1
			for i in fix_val.keys():
				#print 'item: ', i, fix_val[i], type(fix_val[i])
				eval = eval & int(fix_val[i])
			return eval
示例#14
0
 def extend_state(self, state):
     s = copy.deepcopy(state)
     si = copy.deepcopy(s)
     last_s = copy.deepcopy(s)
     done = 0
     ReachedExtendState = 0
     stack = []
     tempStack = []
     result = dict([])
     for i in self.outputs:
         result[i] = 0
     Te = self.getExcitedSignals(
         s, 1
     )  ##passing 1 returns excitation on only outputs and internal signals
     print 'Te-extend: ', Te
     if (len(Te.keys()) == 0):
         ReachedExtendState = 1
         ##result.append([
     while (done != 1):
         t = Te.keys()[0]
         del Te[t]
         si = copy.deepcopy(s)
         if (len(Te.keys()) != 0):
             stack.append([s, Te])
         si[t] = func.compStr(s[t])
         print 'Arnab', si
         tempTe = self.getExcitedSignals(si, 1)
         print 'tempte-Excitation', tempTe
         ReachedExtendState = 0
         outSig = ''
         if (len(tempTe.keys()) == 0):
             ReachedExtendState = 1
             #result['noExcitation'] = 0
             #result['extendState'] = copy.deepcopy(si)
             result[t] = 1
             done = 1
         else:
             for sig in self.outputs:
                 if (sig in tempTe.keys()):
                     ReachedExtendState = 1
                     outSig = sig
                     result[outSig] = 1
             if (ReachedExtendState == 1):
                 result[outSig] = 1
                 #result['noExcitation'] = 1
             else:
                 s = copy.deepcopy(si)
                 Te = tempTe
             if (ReachedExtendState == 1 and len(stack) != 0):
                 tempStack = stack.pop()
                 si = tempStack[0]
                 Te = tempStack[1]
                 if (Te.keys() == 0):
                     done = 1
             elif (ReachedExtendState == 1 and len(stack) == 0):
                 done = 1
     print '================= from extend state ======================'
     print '------------------ state = ', state, '--------------------'
     for i, v in result.iteritems():
         print i, '   ', v
     print '================ end of extend state ====================='
     return result