From 00ac81e373167dd2da962bb46167a147ccd0ac19 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Fri, 21 Feb 2025 13:36:24 +0100 Subject: [PATCH] feat[venom]: add varname freshener for when the varnames need to be "freshened" up. can be helpful for debugging --- vyper/venom/function.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/vyper/venom/function.py b/vyper/venom/function.py index d2148dee05..c6bc16ac3c 100644 --- a/vyper/venom/function.py +++ b/vyper/venom/function.py @@ -1,4 +1,5 @@ import textwrap +from collections import defaultdict from dataclasses import dataclass from typing import Iterator, Optional @@ -106,6 +107,19 @@ def get_next_variable(self) -> IRVariable: def get_last_variable(self) -> str: return f"%{self.last_variable}" + def freshen_varnames(self) -> None: + self.last_variable = 0 + varmap = defaultdict(self.get_next_variable) + for bb in self.get_basic_blocks(): + for inst in bb.instructions: + if inst.output: + inst.output = varmap[inst.output] + + for i, op in enumerate(inst.operands): + if not isinstance(op, IRVariable): + continue + inst.operands[i] = varmap[op] + def remove_unreachable_blocks(self) -> int: # Remove unreachable basic blocks # pre: requires CFG analysis!