Skip to content
Snippets Groups Projects
Commit fe808e6b authored by Frederik Hennig's avatar Frederik Hennig
Browse files

add additional constant folding test. Improved (de)constify.

parent 62e6ddf8
No related branches found
No related tags found
No related merge requests found
......@@ -358,13 +358,19 @@ T = TypeVar("T", bound=PsAbstractType)
def constify(t: T) -> T:
"""Adds the const qualifier to a given type."""
t_copy = copy(t)
t_copy._const = True
return t_copy
if not t.const:
t_copy = copy(t)
t_copy._const = True
return t_copy
else:
return t
def deconstify(t: T) -> T:
"""Removes the const qualifier from a given type."""
t_copy = copy(t)
t_copy._const = False
return t_copy
if t.const:
t_copy = copy(t)
t_copy._const = False
return t_copy
else:
return t
......@@ -27,6 +27,16 @@ def test_constant_folding_int(width):
assert folder(expr) == PsTypedConstant(-53, SInt(width))
expr = pb.Product(
(
PsTypedConstant(2, SInt(width)),
PsTypedConstant(-3, SInt(width)),
PsTypedConstant(4, SInt(width))
)
)
assert folder(expr) == PsTypedConstant(-24, SInt(width))
@pytest.mark.parametrize("width", (32, 64))
def test_constant_folding_float(width):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment