コード例 #1
0
def COMPARE(i):
    (y, z) = (data.block[i].in1, data.block[i].in2)
    try:
        int(z)
        data.zprime = z
    except:
        register_allocator.getz(z)

    try:
        int(y)
        data.L = y
    except:
        # print("------------" + data.adesc[y])
        if data.zprime in data.vset and data.adesc[y] == None:
            temp = register_allocator.empty_reg(i, [])
            data.out.append("movl " + register_allocator.transform(y) + ", " + register_allocator.transform(temp))
            data.adesc[y] = temp
            data.rdesc[temp] = y
            data.L = temp
        elif data.adesc[y] != None:
            data.L = data.adesc[y]
        else:
            data.L = y
    data.out.append("cmp " + register_allocator.transform(data.L) + "," + register_allocator.transform(data.zprime))
    register_allocator.freereg(z, i)
    register_allocator.freereg(y, i)
コード例 #2
0
def STORE_ARRAY(i):
    (x, y, z) = (data.block[i].out, data.block[i].in1, data.block[i].in2)
    try:
        int(z)
        pass
    except:
        register_allocator.getz(z)
    if data.zprime == None:
        data.zprime = z
    data.out.append("movl " + register_allocator.transform(data.zprime) + ", %edi")

    try:
        int(x)
        data.out.append("movl $" + x + ", " + y + "(, %edi, 4)")
        return
    except:
        pass
    # debug(adesc = data.adesc[x])
    register_allocator.getreg(x, y, i)
    debug(Lp=data.L)
    if data.rdesc[data.L] == None:
        data.out.append("movl " + register_allocator.transform(x) + ", " + register_allocator.transform(data.L))
    data.out.append("movl " + register_allocator.transform(data.L) + ", " + y + "(, %edi, 4)")
    data.adesc[x] = data.L
    data.rdesc[data.L] = x
コード例 #3
0
def PUSH_ARG(i) :
    var = data.block[i].out
    if data.adesc[var] != None :
        place = data.adesc[var]
    else :
        place = empty_reg(var)
        data.out.append("movl " + register_allocator.transform(var) + register_allocator.transform(place))
    data.out.append("pushl %" + place)
    pass
コード例 #4
0
def PUSH_ARG(i):
    var = data.block[i].out
    if check_variable(var) and data.adesc[var] != None:
        place = data.adesc[var]
    else:
        place = register_allocator.empty_reg(var)
        data.out.append("movl  " + register_allocator.transform(var) + ", " + register_allocator.transform(place))
        data.rdesc[place] = var
    data.out.append("pushl %" + place)
    pass
コード例 #5
0
def LOAD_ARRAY(i):
    (x, y, z) = (data.block[i].out, data.block[i].in1, data.block[i].in2)
    k = register_allocator.empty_reg(i)
    try:
        int(z)
        pass
    except:
        register_allocator.getz(z)
    if data.zprime == None:
        data.zprime = z
    data.out.append("movl " + register_allocator.transform(data.zprime) + ", " + register_allocator.transform(k))
    data.L = k
    data.out.append("movl " + y + "(, %" + k + ", 4), %" + k)
    register_allocator.update(x)
コード例 #6
0
def MOD(i):
    (x, y, z) = (data.block[i].out, data.block[i].in1, data.block[i].in2)
    register_allocator.push("edx")
    data.out.append("xor %edx, %edx")
    try:
        int(z)
        data.zprime = z
        reg = register_allocator.empty_reg(i, ["eax", "edx"])
        data.out.append("mov $" + z + ", %" + reg)
        data.zprime = reg

    except:
        if data.adesc[z] == "eax":
            register_allocator.push(z)
        register_allocator.getz(z)
        pass
    register_allocator.getreg(x, y, i, "eax")
    try:
        int(y)
        data.yprime = y
    except:
        pass
    register_allocator.gety(y)
    data.out.append("idivl " + register_allocator.transform(data.zprime))
    data.L = "edx"
    register_allocator.update(x)
    register_allocator.freereg(y, i)
    register_allocator.freereg(z, i)
コード例 #7
0
def DIV(i) :
    (x, y, z) = (data.block[i].out, data.block[i].in1, data.block[i].in2)
    register_allocator.push('edx')
    data.out.append("xor %edx, %edx")
    try :
        int(z)
        reg = register_allocator.empty_reg(['edx', 'eax'], i)
        data.out.append('mov $' + z + ", %" + reg)
        data.zprime = reg
    except :
        if data.adesc[z] == 'eax':
            register_allocator.push(z)
        register_allocator.getz(z)
        pass
    register_allocator.getreg(x, y, i, 'eax')
    try :
        int(y)
        data.yprime = y
    except :
        pass
    register_allocator.gety(y)
    data.out.append("idivl " + register_allocator.transform(data.zprime))
    register_allocator.update(x)
    register_allocator.freereg(y, i)
    register_allocator.freereg(z, i)
コード例 #8
0
def RETURN(i):
    if data.block[i].out != None:
        data.out.append("movl {}, %eax".format(register_allocator.transform(data.block[i].out)))
    data.out.append("movl %ebp, %esp")
    data.out.append("popl %ebp")
    data.out.append("ret")
    data.out.append("\n")
    data.curr_scope = ""
コード例 #9
0
def ADD(i):
    (x, y, z) = (data.block[i].out, data.block[i].in1, data.block[i].in2)
    try:
        int(z)
        data.zprime = z
    except:
        register_allocator.getz(z)
        pass
    register_allocator.getreg(x, y, i)
    try:
        int(y)
        data.yprime = y
    except:
        pass
    register_allocator.gety(y)
    data.out.append("addl " + register_allocator.transform(data.zprime) + ", " + register_allocator.transform(data.L))
    register_allocator.update(x)
    register_allocator.freereg(y, i)
    register_allocator.freereg(z, i)
コード例 #10
0
def PRINT(i):
    x = data.block[i].out
    debug(x=x)
    try:
        debug(adesc=data.adesc[x])
        data.adesc[x]
        data.out.append("pushl %" + data.adesc[x])
    except:
        data.out.append("pushl " + register_allocator.transform(x))
    data.out.append("pushl $printFormat")
    register_allocator.save_to_memory()
    data.out.append("call printf")
    data.out.append("addl $8, %esp")
コード例 #11
0
def GET(i):
    data.out.append("movl %eax, " + register_allocator.transform(data.block[i].out))
    pass