1

Whenever I try to call this function in the MyHDL implementation of MD5 I've been working on I get this error:

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

Here is the entire script. If anyone has any light to shed on this or anything else that would be extremely helpful.

Thanks so much.

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
cxw
  • 16,685
  • 2
  • 45
  • 81
A Gomez
  • 11
  • 1
  • Under the `else:`, try changing `calculate(M, A, B, C, D, count)` to `return calculate(M, A, B, C, D, count)`. The return value computed in that case is never used by your current code, which would lead to an attempt to set `final = None` under the `posedge` block. Would you please also [edit your question](https://stackoverflow.com/posts/44955051/edit) and mark which lines are the ones with the errors? Thank you! – cxw Jul 06 '17 at 17:11
  • Oh - and please, *please*, change your variable names! If you ever lose your timing diagram, you will have no way to understand your own code! For example, it is not clear to me from the names whether you actually expect `calculate` to modify its parameters and return them in-place (which it can't do in Python for immutables) or whether you are planning to return new values (and, if the latter, the posedge block never actually uses those values). – cxw Jul 06 '17 at 17:21
  • thanks i'll try that and i really appreciate your advice! – A Gomez Jul 06 '17 at 17:37
  • Sure! Please let me know how it goes. – cxw Jul 06 '17 at 18:13

0 Answers0