コード例 #1
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 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)
コード例 #2
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 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)
コード例 #3
0
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
コード例 #4
0
 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))
コード例 #5
0
 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))
コード例 #6
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 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)
コード例 #7
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 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'")))
コード例 #8
0
 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
コード例 #9
0
ファイル: Allocations.py プロジェクト: Paulfx/mif08-labs18
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
コード例 #10
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 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
コード例 #11
0
 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
コード例 #12
0
ファイル: Allocations.py プロジェクト: Paulfx/mif08-labs18
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
コード例 #13
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 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
コード例 #14
0
ファイル: Allocations.py プロジェクト: Paulfx/mif08-labs18
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
コード例 #15
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 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)
コード例 #16
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 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
コード例 #17
0
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)]
コード例 #18
0
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
コード例 #19
0
ファイル: Allocations.py プロジェクト: icannos/cap-labs18
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
コード例 #20
0
ファイル: Allocations.py プロジェクト: icannos/cap-labs18
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
コード例 #21
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 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
コード例 #22
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 def addInstructionOR(self, dr, sr1, sr2orimm7):
     ins = Instru3A("or3", dr, sr1, sr2orimm7)
     # TODO ADD GEN KILL INIT IF REQUIRED
     self.add_instruction(ins)
コード例 #23
0
 def addInstructionMV(self, dr, sr):
     ins = Instru3A("mv", dr, sr)
     self.add_instruction(ins)
コード例 #24
0
 def addInstructionLD(self, dr, mem):
     ins = Instru3A("ld", dr, mem)
     self.add_instruction(ins)
コード例 #25
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 def addInstructionLET(self, dr, sr):
     ins = Instru3A("let", dr, sr)
     self.addGenKillSr2orimm(ins, dr, sr)
     self.add_instruction(ins)
コード例 #26
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 def addInstructionLETI(self, dr, imm7):
     ins = Instru3A("leti", dr, imm7)
     ins._kill.add(dr)
     self.add_instruction(ins)
コード例 #27
0
ファイル: APISaruman.py プロジェクト: Paulfx/mif08-labs18
 def addInstructionOR(self, dr, sr1, sr2orimm7):
     ins = Instru3A("or3", dr, sr1, sr2orimm7)
     self.addGenKillSr2orimm(ins, dr, sr1, sr2orimm7)
     self.add_instruction(ins)
コード例 #28
0
 def addInstructionSD(self, sr, mem):
     ins = Instru3A("sd", sr, mem)
     self.add_instruction(ins)
コード例 #29
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 def addInstructionLETI(self, dr, imm7):
     ins = Instru3A("leti", dr, imm7)
     # TODO ADD GEN KILL INIT IF REQUIRED
     self.add_instruction(ins)
コード例 #30
0
ファイル: APICode18.py プロジェクト: icannos/cap-labs18
 def addInstructionLET(self, dr, sr):
     ins = Instru3A("let", dr, sr)
     # TODO ADD GEN KILL INIT IF REQUIRED
     self.add_instruction(ins)