Esempio n. 1
0
def callback(self):
    try:
        getValue(self.a, self.av)
        getValue(self.b, self.bv)
        printf("%s : %s(a) + %s(b) = %s(o)\n" %
               (self.time.time, self.av.value, self.bv.value,
                self.value.value.vec))
    except Exception, e:
        printf("%s\n%s\n" % (e, traceback.print_exc()))
Esempio n. 2
0
File: 4.py Progetto: GeneKong/pyvpi
def callback(self) :
    try :
        getValue(self.a,self.av)
        getValue(self.b,self.bv)
        printf("%s : %s(a) + %s(b) = %s(o)\n" % (self.time.time,
            self.av.value,
            self.bv.value,
            self.value.value.vec))
    except Exception,e :
        printf("%s\n%s\n" % (e,traceback.print_exc()))
Esempio n. 3
0
async def task2():
    try:
        n = 0
        k = 0
        dd = Timer(1,'us')
        # for _ in range(1000):
        while(1):
            # print('T2time1=%d'%Simtime.value)
            await Timer(1.0,'us')
            # await RWSynch(0)
            # print("HAHA")
            # Simtime.value
            # time.sleep(0.001)
            n+=1
            # x.value
            pyvpi.getValue(a,x)
            # print(repr(type(x.value)))
            # print('*****')
            # # print('\n')
            x.value = x.value+1
            # k= x.value + 1
            # # # # if x.value==128:
            # # #     # x.value = 0
            # # y.value = n
            pyvpi.putValue(a,x)
            # print('value changed\n')
            # print(n)
            # print('x = %s\n'%x.value)
            # print('y = %s\n'%y.value)
            # print()
            # await Timer(4, 'us')
            # b.value = m
            # a.value = n + 1
            # print(sys.getrefcount(a._value))
            # await asyncio.sleep(0.001)
            # print(asyncio.all_tasks(new_loop))
            if(n%5000 == 0):
                print_mem()
                # print(Simtime.value)
                # print(n)
                # gc.collect()
                # print("GC: %d"%len(gc.get_objects()))
                # print('task2: ', sys.getrefcount(Regb))
                # print(sys.getrefcount(a._handle))
    except Exception as e:
        RT.append(e)
        print(RT)
Esempio n. 4
0
def test():
    """
    c = a+b;
    """
    time = pyvpi.Time()
    pyvpi.getTime(time)
    pyvpi.printf('py: hello world at %d\n' % time.time)

    handle_a = pyvpi.handleByName("top.a")
    val_a = pyvpi.Value(cons.vpiIntVal)

    pyvpi.getValue(handle_a, val_a)
    print(val_a.format)
    try:
        val_a.value += 1
        pyvpi.putValue(handle_a, val_a)
        print('py:      a = %d' % val_a.value)
    except:
        #
        pass
Esempio n. 5
0
def aes_ecb_enc():
    """
    >>> cipher = AES.new('2b7e151628aed2a6abf7158809cf4f3c'.decode('hex'))
    >>> crypted = cipher.encrypt('6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51'.decode('hex'))
    >>> crypted.encode('hex')
    '3ad77bb40d7a3660a89ecaf32466ef97f5d3d58503b9699de785895a96fdbaaf'
    """

    text = pyvpi.handleByName("top.u_pyAESECBenc.text")
    key = pyvpi.handleByName("top.u_pyAESECBenc.key")
    enc = pyvpi.handleByName("top.u_pyAESECBenc.enc")

    # if val > 32 use HexStr as string type
    val_text = pyvpi.Value(cons.vpiHexStrVal)
    val_key = pyvpi.Value(cons.vpiHexStrVal)
    val_enc = pyvpi.Value(cons.vpiHexStrVal)

    pyvpi.getValue(text, val_text)
    pyvpi.getValue(key, val_key)
    pyvpi.getValue(enc, val_enc)

    try:
        cipher = AES.new(bytes.fromhex(val_key.value))
        crypted = cipher.encrypt(bytes.fromhex(val_text.value))
        val_enc.value = crypted.hex()
        pyvpi.putValue(enc, val_enc)
        pyvpi.printf("py key:{} + text:{} = enc:{}\n".format(
            val_key.value, val_text.value, val_enc.value))
    except:
        #        print(traceback.print_exc())
        # skip if value is unknown
        pass
Esempio n. 6
0
def aes_ecb_dec():
    """
    ECB EXAMPLE:
    -------------
    NIST Special Publication 800-38A http://cryptome.org/bcm/sp800-38a.htm#F
    >>> decipher = AES.new('2b7e151628aed2a6abf7158809cf4f3c'.decode('hex'))
    >>> decipher.decrypt(crypted).encode('hex')
    '6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51'
    """

    dec = pyvpi.handleByName("top.u_pyAESECBdec.dec")
    key = pyvpi.handleByName("top.u_pyAESECBdec.key")
    text = pyvpi.handleByName("top.u_pyAESECBdec.text")

    # if val > 32 use HexStr as string type
    val_key  = pyvpi.Value(cons.vpiHexStrVal)
    val_dec  = pyvpi.Value(cons.vpiHexStrVal)
    val_text = pyvpi.Value(cons.vpiHexStrVal)

    pyvpi.getValue(text,val_text)
    pyvpi.getValue(key, val_key)
    pyvpi.getValue(dec, val_dec)

    try:
        decipher = AES.new(str(val_key.value).decode('hex'))
        decrypted = decipher.decrypt(str(val_dec.value).decode('hex'))
        val_text.value = str(decrypted.encode('hex'))
        pyvpi.putValue(text, val_text)
        pyvpi.printf("py key:{} + dec:{} = text:{}\n".format(val_key.value, val_dec.value, val_text.value))
    except:
        print traceback.print_exc()
        # skip if value is unknown
        pass
Esempio n. 7
0
def aes_ecb_enc():
    """
    >>> cipher = AES.new('2b7e151628aed2a6abf7158809cf4f3c'.decode('hex'))
    >>> crypted = cipher.encrypt('6bc1bee22e409f96e93d7e117393172aae2d8a571e03ac9c9eb76fac45af8e51'.decode('hex'))
    >>> crypted.encode('hex')
    '3ad77bb40d7a3660a89ecaf32466ef97f5d3d58503b9699de785895a96fdbaaf'
    """

    text = pyvpi.handleByName("top.u_pyAESECBenc.text")
    key = pyvpi.handleByName("top.u_pyAESECBenc.key")
    enc = pyvpi.handleByName("top.u_pyAESECBenc.enc")

    # if val > 32 use HexStr as string type
    val_text = pyvpi.Value(cons.vpiHexStrVal)
    val_key  = pyvpi.Value(cons.vpiHexStrVal)
    val_enc  = pyvpi.Value(cons.vpiHexStrVal)

    pyvpi.getValue(text,val_text)
    pyvpi.getValue(key, val_key)
    pyvpi.getValue(enc, val_enc)

    try:
        cipher = AES.new(str(val_key.value).decode('hex'))
        crypted = cipher.encrypt(str(val_text.value).decode('hex'))
        val_enc.value = str(crypted.encode('hex'))
        pyvpi.putValue(enc, val_enc)
        pyvpi.printf("py key:{} + text:{} = enc:{}\n".format(val_key.value, val_text.value, val_enc.value))
    except:
        print traceback.print_exc()
        # skip if value is unknown
        pass
Esempio n. 8
0
def test():
    """
    c = a+b;
    """

    a = pyvpi.handleByName("top.u_pyadaptor.a")
    b = pyvpi.handleByName("top.u_pyadaptor.b")
    c = pyvpi.handleByName("top.u_pyadaptor.c")
    p = pyvpi.handleByName("top.p")
    s = pyvpi.getStr(cons.vpiName, p)
    pyvpi.printf('p is {}\n'.format(s))
    st = pyvpi.getStr(cons.vpiType, p)
    pyvpi.printf('p type = {}\n'.format(st))

    it = pyvpi.iterate(cons.vpiMember, p)
    xt = pyvpi.scan(it)
    while (xt):
        st = pyvpi.getStr(cons.vpiFullName, xt)
        pyvpi.printf('P Member name = {} \n'.format(st))
        xt = pyvpi.scan(it)

    ph = pyvpi.handle(cons.vpiTypespec, p)
    p_name = pyvpi.getStr(cons.vpiName, ph)
    pyvpi.printf('p type name = {}\n'.format(p_name))

    val_a = pyvpi.Value(cons.vpiIntVal)
    val_b = pyvpi.Value(cons.vpiIntVal)
    val_c = pyvpi.Value(cons.vpiIntVal)

    pyvpi.getValue(a, val_a)
    pyvpi.getValue(b, val_b)
    pyvpi.getValue(c, val_c)

    try:
        val_c.value = val_a.value + val_b.value
        pyvpi.putValue(c, val_c)
        pyvpi.printf("py a:{} + b:{} = c:{}\n".format(val_a.value, val_b.value,
                                                      val_c.value))
    except:
        # skip if value is unknown
        pass
Esempio n. 9
0
def test():
    """
    c = a+b;
    """

    a = pyvpi.handleByName("top.u_pyadaptor.a")
    b = pyvpi.handleByName("top.u_pyadaptor.b")
    c = pyvpi.handleByName("top.u_pyadaptor.c")

    val_a = pyvpi.Value(cons.vpiIntVal)
    val_b = pyvpi.Value(cons.vpiIntVal)
    val_c = pyvpi.Value(cons.vpiIntVal)

    pyvpi.getValue(a,val_a)
    pyvpi.getValue(b,val_b)
    pyvpi.getValue(c,val_c)

    try:
        val_c.value = val_a.value + val_b.value
        pyvpi.putValue(c, val_c)
        pyvpi.printf("py a:{} + b:{} = c:{}\n".format(val_a.value, val_b.value, val_c.value))
    except:
        # skip if value is unknown
        pass
Esempio n. 10
0
File: 2.py Progetto: burt0927/pyvpi
#! python
import pyvpi
import pyvpi_cons as cons

pyvpi.setDebugLevel(30)
a = pyvpi.handleByName("test.a")
b = pyvpi.handleByName("test.b")
o = pyvpi.handleByName("test.o")
val_a = pyvpi.Value(cons.vpiVectorVal)
val_b = pyvpi.Value(cons.vpiVectorVal)
val_o = pyvpi.Value(cons.vpiVectorVal)
pyvpi.getValue(a, val_a)
pyvpi.getValue(b, val_b)
pyvpi.getValue(o, val_o)
pyvpi.printf("a{} + b{} = o{}\n".format(val_a.value.vec, val_b.value.vec,
                                        val_o.value.vec))
pyvpi.putValue(b, val_o)
Esempio n. 11
0
 def value(self):
     # print("get")
     pyvpi.getValue(self._handle, self._value)
     return self._f(self._value.value)
Esempio n. 12
0
File: 1.py Progetto: GeneKong/pyvpi
#! python
import pyvpi
import pyvpi_cons as cons
pyvpi.setDebugLevel(30)
a = pyvpi.handleByName("test.a")
b = pyvpi.handleByName("test.b")
o = pyvpi.handleByName("test.o")
val_a = pyvpi.Value()
val_b = pyvpi.Value(cons.vpiVectorVal)
val_o = pyvpi.Value(cons.vpiVectorVal)
pyvpi.getValue(a,val_a)
pyvpi.getValue(b,val_b)
pyvpi.getValue(o,val_o)
pyvpi.printf("a[{}] + b{} = o{}\n".format(val_a.value,val_b.value.vec,val_o.value.vec))