def isregassigned(var): if (isInt(var)): g.error("File:regallocfn.py=> isregassinged(): Error Spotted:---" + str(var)) for i in range(0, 6): if (g.regalloc[i] == var): return i return "-1"
def getreg(lineno, var): # mode = 0 # if(g.splitins[lineno].op=="/" or g.splitins[lineno].op=="%"): # print("Abcd") ####NOT FOR DIV # if var not in g.nextuse[lineno-1].keys(): # return var varsinline = [] # print(lineno) # print(len(g.splitins)) # print(g.splitins[lineno-1].src1) # print(g.splitins[lineno-1].src2) # print(g.splitins[lineno-1].op) # print(g.splitins[lineno-1].dst) if (lineno <= len(g.splitins)): varsinline.append(g.splitins[lineno - 1].src1) varsinline.append(g.splitins[lineno - 1].src2) varsinline.append(g.splitins[lineno - 1].dst) varsinline.append("v_" + str(g.splitins[lineno - 1].src1index)) varsinline.append("v_" + str(g.splitins[lineno - 1].src2index)) varsinline.append("v_" + str(g.splitins[lineno - 1].dstindex)) else: g.error("Error GOT file: regallocfn.py => getreg()") # if(lineno==34): # g.splitins[lineno-1].printobj() # g.debug(varsinline) # g.debug(g.regalloc) for i in range(6): if (g.regalloc[i] == '-1'): # allocatedreg=i g.regalloc[i] = var if (not ('tempac' in var)): print("\tmovl " + var + " , " + regname(i)) return regname(i) for i in g.regalloc: if i not in g.nextuse[lineno - 1].keys() and i not in varsinline: print("\tmovl " + str(regname(isregassigned(i)) + " , " + str(i))) # print("heelw") regtoassign = isregassigned(i) g.regalloc[regtoassign] = var print("\tmovl " + var + " , " + regname(regtoassign)) return regname(regtoassign) tempvar = g.regalloc[0] tempnextuse = g.nextuse[lineno - 1][tempvar] for j in range(1, 6): i = g.regalloc[j] if i in varsinline: continue if (tempnextuse < g.nextuse[lineno - 1][i]): tempvar = i tempnextuse = g.nextuse[lineno - 1][i] # print("reg ass " + str(isregassigned(tempvar))+ " at" + regname(isregassigned(tempvar))) print("\tmovl " + str(regname(isregassigned(tempvar)) + " , " + str(tempvar))) regtoassign = isregassigned(tempvar) g.regalloc[regtoassign] = var print("\tmovl " + var + " , " + regname(regtoassign)) return regname(regtoassign)