Skip to content

Commit

Permalink
fix lint, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 28, 2024
1 parent 42785ed commit a367b1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
12 changes: 9 additions & 3 deletions tests/unit/compiler/venom/test_duplicate_operands.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from vyper.compiler.settings import OptimizationLevel
from vyper.venom import generate_assembly_experimental
from vyper.venom.analysis.analysis import IRAnalysesCache
from vyper.venom.context import IRContext
from vyper.venom.passes.store_expansion import StoreExpansionPass


def test_duplicate_operands():
Expand All @@ -13,7 +15,7 @@ def test_duplicate_operands():
%3 = mul %1, %2
stop
Should compile to: [PUSH1, 10, DUP1, DUP1, DUP1, ADD, MUL, POP, STOP]
Should compile to: [PUSH1, 10, DUP1, DUP2, ADD, MUL, POP, STOP]
"""
ctx = IRContext()
fn = ctx.create_function("test")
Expand All @@ -23,5 +25,9 @@ def test_duplicate_operands():
bb.append_instruction("mul", sum_, op)
bb.append_instruction("stop")

asm = generate_assembly_experimental(ctx, optimize=OptimizationLevel.GAS)
assert asm == ["PUSH1", 10, "DUP1", "DUP1", "ADD", "MUL", "POP", "STOP"]
ac = IRAnalysesCache(fn)
StoreExpansionPass(ac, fn).run_pass()

optimize = OptimizationLevel.GAS
asm = generate_assembly_experimental(ctx, optimize=optimize)
assert asm == ["PUSH1", 10, "DUP1", "DUP2", "ADD", "MUL", "POP", "STOP"]
3 changes: 2 additions & 1 deletion tests/unit/compiler/venom/test_stack_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ def test_cleanup_stack():
bb = fn.get_basic_block()
ret_val = bb.append_instruction("param")
op = bb.append_instruction("store", 10)
bb.append_instruction("add", op, op)
op2 = bb.append_instruction("store", op)
bb.append_instruction("add", op, op2)
bb.append_instruction("ret", ret_val)

asm = generate_assembly_experimental(ctx, optimize=OptimizationLevel.GAS)
Expand Down
6 changes: 3 additions & 3 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
)
from vyper.utils import MemoryPositions, OrderedSet
from vyper.venom.analysis.analysis import IRAnalysesCache
from vyper.venom.analysis.liveness import LivenessAnalysis
from vyper.venom.analysis.equivalent_vars import VarEquivalenceAnalysis
from vyper.venom.analysis.liveness import LivenessAnalysis
from vyper.venom.basicblock import (
IRBasicBlock,
IRInstruction,
Expand All @@ -26,7 +26,7 @@
from vyper.venom.passes.normalization import NormalizationPass
from vyper.venom.stack_model import StackModel

DEBUG_SHOW_COST = True
DEBUG_SHOW_COST = False
if DEBUG_SHOW_COST:
import sys

Expand Down Expand Up @@ -251,7 +251,7 @@ def _emit_input_operands(

# to validate store expansion invariant -
# each op is emitted at most once.
seen = set()
seen: set[IROperand] = set()

for op in ops:
if isinstance(op, IRLabel):
Expand Down

0 comments on commit a367b1d

Please sign in to comment.