MyHDL自由变量

时间:2017-07-06 17:03:32

标签: python myhdl

每当我尝试在MD5的MyHDL实现中调用此函数时,我一直在努力,我得到了这个错误:

File "/usr/local/lib/python2.7/dist-packages/myhdl/conversion/_misc.py", line 149, in raiseError
raise ConversionError(kind, msg, info)
myhdl.ConversionError: in file MD5-8, line 85:
Free variable should be a Signal or an int: calculate

这是整个脚本。如果有人对这个或任何其他非常有帮助的东西有所了解。

非常感谢。

from myhdl import *

def operative(M0,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12,M13,M14,M15,enable,clock):
    singletick = 0
    def toW32(x):
        return(modbv(x, min=0, max=2**32)[32:])
    def leftrotate(x, c): 
        return ((x<<c) | (x>>(32-c)) % (2**32))

    def calculate(M, A, B, C, D, count):
        KCONTENT = (0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391)
        SCONTENT = (7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22,  7, 12, 17, 22, 5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20,  5,  9, 14, 20, 4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23,  4, 11, 16, 23, 6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21,  6, 10, 15, 21)
        F = int(0)
        G = int(0)
        #get G and F
        if(count<=15):
            if(count >=0):
                F= (B&C)|((~B)&D)
                G = int(count)
        elif(count<=31):
            if(count >= 15):
                F = (D&B)|((~D)&C)
                G = int(5*count +1) % 16
        elif(count<=47):
            if(count>=32):
                F = (B^C^D)
                G = int(3*count+5) % 16
        elif(count <= 63):
            if(count >= 48):
                F = C^(B|(~D))
                G = int(7*count) % 16
        #swapping A through D and then calling again
        temp = D
        D = C
        C = B
        F = toW32(F)
        G = toW32(G)
        currentM = toW32(int(M[G]))
        currentK = toW32(int(KCONTENT[count]))
        currentS = toW32(int(SCONTENT[count]))
        #B = leftrotate((((A + F) % (2**32) + (M[G]+KCONTENT[count]) % (2**32)) % (2**32)), SCONTENT[count])
        A2 = toW32(A)
        F2 = toW32(F)
        bcomp0 = toW32((A2 + F2) % (2**32))
        bcomp1 = toW32((currentM + currentK) % (2**32))
        bcomp = toW32((bcomp0 + bcomp1) % (2**32))
        bcomp2 = (leftrotate(bcomp, currentS))

        B = toW32((B + bcomp2) % (2**32))
        A = temp
        print(B)
        if(count>=63):
            outA = (toW32((0x67452301+A) % (2**32)))
            outB = (toW32((0xefcdab89+B) % (2**32)))
            outC = (toW32((0x98badcfe+C) % (2**32)))
            outD = (toW32((0x10325476+D) % (2**32)))
            print(hex(concat(outA, outB, outC, outD)))
            return(outA, outB, outC, outD)
        else:
            count = count + 1
            calculate(M, A, B, C, D, count)





    HALF_PERIOD = delay(10)
    @always(HALF_PERIOD)
    def clockGen():
        clock.next = not clock


    M = (M0,M1,M2,M3,M4,M5,M6,M7,M8,M9,M10,M11,M12,M13,M14,M15) 
    @always(clock.posedge) 
    def central():
        if(enable == 1):
            A = toW32(0x67452301)
            B = toW32(0xefcdab89)
            C = toW32(0x98badcfe)
            D = toW32(0x10325476)
            count = toW32(0)
            final = int(0)
            final = calculate(M, A, B, C, D, count)

    return clockGen, central

0 个答案:

没有答案