def addInstructionSUB(self, dr, sr1, sr2orimm7): if isinstance(sr2orimm7, Immediate): ins = Instru3A("sub3i", dr, sr1, sr2orimm7) else: ins = Instru3A("sub3", dr, sr1, sr2orimm7) self.addGenKillSr2orimm(ins, dr, sr1, sr2orimm7) self.add_instruction(ins)
def addInstructionSUB(self, dr, sr1, sr2orimm7): if isinstance(sr2orimm7, Immediate): ins = Instru3A("sub3i", dr, sr1, sr2orimm7) else: ins = Instru3A("sub3", dr, sr1, sr2orimm7) # TODO ADD GEN KILL INIT IF REQUIRED self.add_instruction(ins)
def replace_smart(old_i): """Replace Temporary operands with the corresponding allocated physical register OR memory location.""" before = [] after = [] ins, old_args = old_i.unfold() args = [] indice = 1 i = 1 for arg in old_args: if isinstance(arg, Temporary): arg = arg.get_alloced_loc() if isinstance(arg, Register): args.append(arg) else: if not old_i.is_read_only(): if i == 1: after = after + [Instru3A("sd", S[indice], arg)] i = 0 else: before = before + [Instru3A("ld", S[indice], arg)] else: before = before + [Instru3A("ld", S[indice], arg)] args.append(S[indice]) indice += 1 else: args.append(arg) i = Instru3A(ins, args=args) # change argument list into args return before + [i] + after
def addInstructionSUB(self, dr, sr1, sr2orimm7): if isinstance(sr2orimm7, Immediate): self.add_instruction( Instru3A("sub3i", dr, sr1, sr2orimm7)) else: self.add_instruction( Instru3A("sub3", dr, sr1, sr2orimm7))
def addInstructionADD(self, dr, sr1, sr2orimm7): # add avec 2 ops. if isinstance(sr2orimm7, Immediate): self.add_instruction( Instru3A("add3i", dr, sr1, sr2orimm7)) else: self.add_instruction( Instru3A("add3", dr, sr1, sr2orimm7))
def addInstructionADD(self, dr, sr1, sr2orimm7): if isinstance(sr2orimm7, Immediate): ins = Instru3A("add3i", dr, sr1, sr2orimm7) else: ins = Instru3A("add3", dr, sr1, sr2orimm7) # Tip : at some point you should use isinstance(..., Temporary) # TODO ADD GEN KILL INIT IF REQUIRED self.add_instruction(ins)
def addInstructionPRINT(self, expr): # a print instruction generates the temp it prints. ins = Instru3A("print signed", expr) if isinstance(expr, Temporary): # tests if the temp prints a temporary ins._gen.add(expr) self.add_instruction(ins) self.add_instruction(Instru3A("print char", Char("'\\n'")))
def addInstructionCondJUMP(self, label, op1, c, op2): assert isinstance(label, Label) assert isinstance(c, Condition) if op2 != 0: ins = Instru3A(c.__str__(), op1, op2, label) else: ins = Instru3A(c.__str__(), op1, ZERO, label) self.add_instruction(ins) self.add_edge(ins, label) return ins
def getBeforeAfterMemory(ins, indexArg, numberRegister, offset): before = [] after = [] readingTemp = False if indexArg > 0 or "print" in ins: #We need to access to this arg #So we have to load it from memory #And if indexArg is 0 (first arg) but with print, # then we also need to read this arg reg = Register(numberRegister) readingTemp = True before.append(Instru3A('getctr', SP, Indirect(reg))) before.append(Instru3A('add', reg, reg, offset.get_offset() * 16)) before.append(Instru3A('setctr', A0, Indirect(reg))) before.append(Instru3A('readse', A0, 16, reg)) elif indexArg == 0: #We need to write in this arg after.append(Instru3A('getctr', SP, Indirect(R0))) after.append(Instru3A('add', R0, R0, offset.get_offset() * 16)) after.append(Instru3A('setctr', A0, Indirect(R0))) after.append(Instru3A('write', A0, 16, R1)) reg = R1 return reg, before, after, readingTemp
def addInstructionJUMP(self, label): assert isinstance(label, Label) i = Instru3A("jump", label) # TODO: properly build the CFG: don't chain with next # TODO: instruction to add, but with the target of the jump. self.add_instruction(i) return i
def addInstructionCondJUMP(self, label, op1, c, op2): assert isinstance(label, Label) assert isinstance(c, Condition) i = Instru3A("cond_jump", args=[label, op1, c, op2]) self.add_instruction(i) self.add_edge(i, label) # useful in next lab return i
def replace_smart(old_i): """Replace Temporary operands with the corresponding allocated physical register OR memory location.""" before = [] after = [] ins, old_args = old_i.unfold() args = [] nbTempRead = 0 for (index, arg) in enumerate(old_args): newArg = arg if isinstance(arg, Temporary): #Register of offset regOrOffset = arg.get_alloced_loc() if isinstance(regOrOffset, Offset): # We store in the memory newArg, bf, aft, readingTemp = getBeforeAfterMemory( ins, index, nbTempRead, regOrOffset) if readingTemp: nbTempRead += 1 before += bf after += aft else: assert isinstance(regOrOffset, Register) newArg = regOrOffset args.append(newArg) i = Instru3A(ins, args=args) # change argument list into args return before + [i] + after
def addInstructionJUMP(self, label): assert isinstance(label, Label) i = Instru3A("jump", label) # add in list but do not link with the following node self.add_instruction(i, linkwithsucc=False) self.add_edge(i, label) return i
def replace_mem(old_i): """Replace Temporary operands with the corresponding allocated memory location. SP points to the stack""" before = [] after = [] ins, old_args = old_i.unfold() args = [] #Number of temp that we need to read (ie index > 0) nbTempRead = 0 for (index, arg) in enumerate(old_args): if isinstance(arg, Temporary): #arg is an object of type Offset offset = arg.get_alloced_loc() reg, bf, aft, readingTemp = getBeforeAfterMemory( ins, index, nbTempRead, offset) before += bf after += aft if readingTemp: nbTempRead += 1 else: reg = arg args.append(reg) i = Instru3A(ins, args=args) return before + [i] + after
def addInstructionWMEM(self, dr, sr): if isinstance(sr, Register): # Accept plain register where we expect an indirect # addressing mode. sr = Indirect(sr) ins = Instru3A("wmem", dr, sr) # TODO ADD GEN KILL INIT IF REQUIRED self.add_instruction(ins)
def addInstructionCondJUMP(self, label, op1, c, op2): assert isinstance(label, Label) assert isinstance(c, Condition) ins = Instru3A("cond_jump", args=[label, op1, c, op2]) # TODO ADD GEN KILL INIT IF REQUIRED # TODO: properly build the CFG: chain with both the next # TODO: instruction to be added and with the target of the jump. self.add_instruction(ins) return ins
def replace_reg(old_i): """Replace Temporary operands with the corresponding allocated register.""" ins, old_args = old_i.unfold() args = [] for arg in old_args: if isinstance(arg, Temporary): arg = arg.get_alloced_loc() args.append(arg) return [Instru3A(ins, args=args)]
def replace_mem(old_i): """Replace Temporary operands with the corresponding allocated memory location. FP points to the stack""" before = [] after = [] ins, old_args = old_i.unfold() args = [] numreg = 1 for arg in old_args: if isinstance(arg, Temporary) and not isinstance(arg, Register): arg = arg.get_alloced_loc() after = after + [Instru3A("sd", S[numreg], arg)] before = before + [Instru3A("ld", S[numreg], arg)] args.append(S[numreg]) numreg = numreg + 1 else: args.append(arg) i = Instru3A(ins, args=args) return before + [i] + after
def replace_mem(old_i): """Replace Temporary operands with the corresponding allocated memory location. SP points to the stack""" before = [] after = [] ins, old_args = old_i.unfold() args = [] # TODO: compute before,after,args. i = Instru3A(ins, args=args) return before + [i] + after
def replace_smart(old_i): """Replace Temporary operands with the corresponding allocated physical register OR memory location. R6 points to the stack""" before = [] after = [] ins, old_args = old_i.unfold() args = [] # TODO: compute before,after,args. This is a superset of what replace_mem does. # and now return the new list! i = Instru3A(ins, args=args) # change argument list into args return before + [i] + after
def addInstructionCondJUMP(self, label, op1, c, op2): assert isinstance(label, Label) assert isinstance(c, Condition) ins = Instru3A("cond_jump", args=[label, op1, c, op2]) if isinstance(op1, Temporary): ins._gen.add(op1) if isinstance(op2, Temporary): ins._gen.add(op2) self.add_instruction(ins) self.add_edge(ins, label) return ins
def addInstructionOR(self, dr, sr1, sr2orimm7): ins = Instru3A("or3", dr, sr1, sr2orimm7) # TODO ADD GEN KILL INIT IF REQUIRED self.add_instruction(ins)
def addInstructionMV(self, dr, sr): ins = Instru3A("mv", dr, sr) self.add_instruction(ins)
def addInstructionLD(self, dr, mem): ins = Instru3A("ld", dr, mem) self.add_instruction(ins)
def addInstructionLET(self, dr, sr): ins = Instru3A("let", dr, sr) self.addGenKillSr2orimm(ins, dr, sr) self.add_instruction(ins)
def addInstructionLETI(self, dr, imm7): ins = Instru3A("leti", dr, imm7) ins._kill.add(dr) self.add_instruction(ins)
def addInstructionOR(self, dr, sr1, sr2orimm7): ins = Instru3A("or3", dr, sr1, sr2orimm7) self.addGenKillSr2orimm(ins, dr, sr1, sr2orimm7) self.add_instruction(ins)
def addInstructionSD(self, sr, mem): ins = Instru3A("sd", sr, mem) self.add_instruction(ins)
def addInstructionLETI(self, dr, imm7): ins = Instru3A("leti", dr, imm7) # TODO ADD GEN KILL INIT IF REQUIRED self.add_instruction(ins)
def addInstructionLET(self, dr, sr): ins = Instru3A("let", dr, sr) # TODO ADD GEN KILL INIT IF REQUIRED self.add_instruction(ins)