Example #1
0
def test_packed_unpacked():
    import _kratos
    mod = Generator("mod")
    a = mod.var("a", 2, size=2, packed=True)
    b = mod.var("b", 2, size=2)
    c = const(2, 4)
    d = mod.var("d", 4, explicit_array=True)
    try:
        a.assign(b)
        assert False
    except _kratos.exception.StmtException:
        assert True
    a.assign(4)
    try:
        b.assign(c)
        assert False
    except _kratos.exception.StmtException:
        assert True
    try:
        d.assign(a)
        assert False
    except _kratos.exception.StmtException:
        assert True

    # test for slices
    e = mod.var("e", 2, size=2, packed=True)
    e_0 = e[0]
    assert e_0.is_packed
Example #2
0
def test_enum_cast():
    from kratos import enum
    e = enum("Type", ["a", "b"])
    mod = Generator("mod")
    var = mod.enum_var("v", e)
    casted = enum(const(1, 1), e)
    assert str(casted) == "Type'(1'h1)"
    var.assign(casted)
Example #3
0
def test_const():
    a = Const[4](2)
    b = const(2, 4)
    assert str(a) == str(b)
    assert str(a) == "4'h2"