Skip to content

Commit

Permalink
debug show cost
Browse files Browse the repository at this point in the history
  • Loading branch information
charles-cooper committed Sep 20, 2024
1 parent 04314e0 commit 32a5da5
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
from vyper.venom.passes.normalization import NormalizationPass
from vyper.venom.stack_model import StackModel

DEBUG_SHOW_COST = True
if DEBUG_SHOW_COST:
import sys

# instructions which map one-to-one from venom to EVM
_ONE_TO_ONE_INSTRUCTIONS = frozenset(
[
Expand Down Expand Up @@ -278,8 +282,8 @@ def _generate_evm_for_basicblock_r(
return
self.visited_basicblocks.add(basicblock)

#import sys
# print(basicblock, file=sys.stderr)
if DEBUG_SHOW_COST:
print(basicblock, file=sys.stderr)

ref = asm
asm = []
Expand All @@ -297,8 +301,9 @@ def _generate_evm_for_basicblock_r(

asm.extend(self._generate_evm_for_instruction(inst, stack, next_liveness))

# print(" ".join(map(str, asm)), file=sys.stderr)
# print("\n", file=sys.stderr)
if DEBUG_SHOW_COST:
print(" ".join(map(str, asm)), file=sys.stderr)
print("\n", file=sys.stderr)

ref.extend(asm)

Expand Down Expand Up @@ -427,6 +432,13 @@ def _generate_evm_for_instruction(
if cost_with_swap > cost_no_swap:
operands[-1], operands[-2] = operands[-2], operands[-1]

cost = self._stack_reorder([], stack, operands, dry_run=True)
if DEBUG_SHOW_COST and cost:
print("ENTER", inst, file=sys.stderr)
print(" HAVE", stack, file=sys.stderr)
print(" WANT", operands, file=sys.stderr)
print(" COST", cost, file=sys.stderr)

# final step to get the inputs to this instruction ordered
# correctly on the stack
self._stack_reorder(assembly, stack, operands)
Expand Down

0 comments on commit 32a5da5

Please sign in to comment.