def allocateNewReg(self,vName):
"""
get a new free reg, if full get a mem address
"""
if(isinstance(vName,Data)):
Type=vName.type.type
# if(vName in self.currentMap):
# Type=self.currentMap[vName]['Type']
elif(vName in self.registers):
if(vName=='eax'):
Type='int'
elif(vName=='st'):
Type='double'
elif(isinstance(vName,int)):
Type='int'
elif(isinstance(vName,float)):
Type='double'
else:
raise TypeError("error in allocateNewReg\n")
if(Type=='double'):
newTmp=self.tmpName+str(self.tmpNum)
self.tmpNum+=1
self.currentMap.update({newTmp:{'reg':0,'type':Type,'addr':'[esp+%d]'%(self.tmpSP)}})
newType=CType('double',8)
newTmp=Data(newTmp,False,newType)
return newTmp
reg=self.checkFull()
if(reg!=-1):
newTmp=self.tmpName+str(self.tmpNum)
self.tmpNum+=1
self.currentMap.update({newTmp:{'reg':reg,'type':Type,'addr':0}})
return reg
else:
newTmp=self.tmpName+str(self.tmpNum)
self.tmpNum+=1
self.currentMap.update({newTmp:{'reg':0,'type':Type,'addr':'[esp+%d]'%(self.tmpSP)}})
newType=CType('int',4)
newTmp=Data(newTmp,False,newType)
return newTmp