Ejemplo n.º 1
0
def test_types():
    op = rop.ResOperation(rop.rop.INT_ADD, [ConstInt(0), ConstInt(1)])
    op.set_forwarded(rop.VectorizationInfo(op))
    baseop = rop.ResOperation(rop.rop.CAST_FLOAT_TO_SINGLEFLOAT, [op])
    baseop.set_forwarded(rop.VectorizationInfo(baseop))
    op = rop.VecOperation(rop.rop.VEC_CAST_FLOAT_TO_SINGLEFLOAT, [op], baseop,
                          2)
    assert op.type == 'i'
    assert op.datatype == 'i'
    assert op.bytesize == 4
Ejemplo n.º 2
0
def test_unpack_1():
    op = rop.ResOperation(
        rop.rop.VEC_UNPACK_I,
        [rop.InputArgVector(), ConstInt(0),
         ConstInt(1)])
    assert (op.type, op.is_vector()) == ('i', False)
    op = rop.ResOperation(
        rop.rop.VEC_UNPACK_I,
        [rop.InputArgVector(), ConstInt(0),
         ConstInt(2)])
    assert (op.type, op.is_vector()) == ('i', True)
Ejemplo n.º 3
0
def test_instantiate():
    a = ConstInt(1)
    b = ConstInt(2)
    op = rop.ResOperation(rop.rop.INT_ADD, [a, b])
    assert op.getarglist() == [a, b]
    #assert re.match(".*= int_add(a, b)", repr(op))

    mydescr = AbstractDescr()
    op = rop.ResOperation(rop.rop.CALL_I, [a, b], descr=mydescr)
    assert op.getarglist() == [a, b]
    assert op.getdescr() is mydescr
    #assert re.match(".* = call\(a, b, descr=<.+>\)$", repr(op))

    mydescr = AbstractFailDescr()
    op = rop.ResOperation(rop.rop.GUARD_NO_EXCEPTION, [], descr=mydescr)
Ejemplo n.º 4
0
def test_cast_ops(opnum, args, kwargs):
    op = rop.ResOperation(opnum, args)
    assert op.is_typecast()
    assert op.cast_from_bytesize() == kwargs['from']
    assert op.cast_to_bytesize() == kwargs['to']
    if 'cast_to' in kwargs:
        assert op.cast_to() == kwargs['cast_to']
Ejemplo n.º 5
0
def test_get_deep_immutable_oplist():
    ops = [rop.ResOperation(rop.rop.INT_ADD, ['a', 'b'], 'c')]
    newops = rop.get_deep_immutable_oplist(ops)
    py.test.raises(TypeError, "newops.append('foobar')")
    py.test.raises(TypeError, "newops[0] = 'foobar'")
    py.test.raises(AssertionError, "newops[0].setarg(0, 'd')")
    py.test.raises(AssertionError, "newops[0].setdescr('foobar')")
Ejemplo n.º 6
0
def test_instantiate():
    op = rop.ResOperation(rop.rop.INT_ADD, ['a', 'b'], 'c')
    assert op.getarglist() == ['a', 'b']
    assert op.result == 'c'
    assert repr(op) == "c = int_add(a, b)"

    mydescr = AbstractDescr()
    op = rop.ResOperation(rop.rop.CALL, ['a', 'b'], 'c', descr=mydescr)
    assert op.getarglist() == ['a', 'b']
    assert op.result == 'c'
    assert op.getdescr() is mydescr
    assert re.match("c = call\(a, b, descr=<.+>\)$", repr(op))

    mydescr = AbstractFailDescr()
    op = rop.ResOperation(rop.rop.GUARD_NO_EXCEPTION, [], None, descr=mydescr)
    assert re.match("guard_no_exception\(descr=<.+>\)$", repr(op))
Ejemplo n.º 7
0
def test_load_singlefloat():
    descr = ArrayDescr(8, 4, None, 'S', concrete_type='f')
    args = [rop.InputArgInt(), ConstInt(0)]
    baseop = rop.ResOperation(rop.rop.RAW_LOAD_I, args, descr=descr)
    baseop.set_forwarded(rop.VectorizationInfo(baseop))
    op = rop.VecOperation(rop.rop.VEC_RAW_LOAD_I, args, baseop, 4, descr=descr)
    assert (op.type, op.datatype, op.bytesize, op.is_vector()) == ('i', 'i', 4,
                                                                   True)
Ejemplo n.º 8
0
def test_get_deep_immutable_oplist():
    a = ConstInt(1)
    b = ConstInt(2)
    ops = [rop.ResOperation(rop.rop.INT_ADD, [a, b])]
    newops = rop.get_deep_immutable_oplist(ops)
    py.test.raises(TypeError, "newops.append('foobar')")
    py.test.raises(TypeError, "newops[0] = 'foobar'")
    py.test.raises(AssertionError, "newops[0].setarg(0, 'd')")
    py.test.raises(AssertionError, "newops[0].setdescr('foobar')")
Ejemplo n.º 9
0
def test_vec_store():
    descr = ArrayDescr(0, 8, None, 'F', concrete_type='f')
    vec = rop.InputArgVector()
    args = [rop.InputArgRef(), ConstInt(0), vec]
    baseop = rop.ResOperation(rop.rop.RAW_STORE, args, descr=descr)
    baseop.set_forwarded(rop.VectorizationInfo(baseop))
    op = rop.VecOperation(rop.rop.VEC_RAW_STORE, args, baseop, 2, descr=descr)
    assert (op.type, op.datatype, op.bytesize, op.is_vector()) == ('v', 'v', 8,
                                                                   True)
Ejemplo n.º 10
0
def test_vec_guard():
    vec = rop.InputArgVector()
    vec.bytesize = 4
    vec.type = vec.datatype = 'i'
    vec.sigend = True
    baseop = rop.ResOperation(rop.rop.GUARD_TRUE, [vec])
    baseop.set_forwarded(rop.VectorizationInfo(baseop))
    op = rop.VecOperation(rop.rop.VEC_GUARD_TRUE, [vec], baseop, 4)
    assert (op.type, op.datatype, op.bytesize, op.is_vector()) == ('v', 'v', 0,
                                                                   False)
Ejemplo n.º 11
0
def test_can_malloc():
    mydescr = AbstractDescr()
    assert rop.ResOperation(rop.rop.NEW, [], 'b').can_malloc()
    call = rop.ResOperation(rop.rop.CALL, ['a', 'b'], 'c', descr=mydescr)
    assert call.can_malloc()
    assert not rop.ResOperation(rop.rop.INT_ADD, ['a', 'b'], 'c').can_malloc()