Skip to content

Commit

Permalink
fixes and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
harkal committed Oct 16, 2024
1 parent 9212c86 commit 414ca33
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
4 changes: 2 additions & 2 deletions vyper/venom/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
from vyper.venom.passes import (
SCCP,
AlgebraicOptimizationPass,
AllocaElimination,
BranchOptimizationPass,
DFTPass,
MakeSSA,
Mem2Var,
RemoveUnusedVariablesPass,
SimplifyCFGPass,
Stack2Mem,
StoreElimination,
StoreExpansionPass,
AllocaElimination,
Stack2Mem,
)
from vyper.venom.venom_to_assembly import VenomCompiler

Expand Down
6 changes: 4 additions & 2 deletions vyper/venom/mem_allocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __init__(self, total_size: int, start_address: int):
self.blocks = [MemoryBlock(total_size, 0)]

def allocate(self, size: int) -> int:
#print(f"Allocating {size} bytes with free memory {self.get_free_memory()}")
# print(f"Allocating {size} bytes with free memory {self.get_free_memory()}")
for block in self.blocks:
if block.is_free and block.size >= size:
if block.size > size:
Expand All @@ -32,7 +32,9 @@ def allocate(self, size: int) -> int:
block.size = size
block.is_free = False
return self.start_address + block.address
raise MemoryError(f"Memory allocation failed for size {size} with free memory {self.get_free_memory()}")
raise MemoryError(
f"Memory allocation failed for size {size} with free memory {self.get_free_memory()}"
)

def deallocate(self, address: int) -> bool:
relative_address = address - self.start_address
Expand Down
4 changes: 2 additions & 2 deletions vyper/venom/passes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .algebraic_optimization import AlgebraicOptimizationPass
from .alloca_elimination import AllocaElimination
from .branch_optimization import BranchOptimizationPass
from .dft import DFTPass
from .make_ssa import MakeSSA
Expand All @@ -7,7 +8,6 @@
from .remove_unused_variables import RemoveUnusedVariablesPass
from .sccp import SCCP
from .simplify_cfg import SimplifyCFGPass
from .stack2mem import Stack2Mem
from .store_elimination import StoreElimination
from .store_expansion import StoreExpansionPass
from .alloca_elimination import AllocaElimination
from .stack2mem import Stack2Mem
1 change: 0 additions & 1 deletion vyper/venom/passes/alloca_elimination.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from vyper.venom.basicblock import IRInstruction, IRLiteral

from vyper.venom.passes.base_pass import IRPass


Expand Down
7 changes: 5 additions & 2 deletions vyper/venom/venom_to_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,15 @@ def _generate_evm_for_instruction(

if opcode in ["jmp", "djmp", "jnz", "invoke"]:
operands = list(inst.get_non_label_operands())
elif opcode in ["alloca", "palloca"]:
#raise Exception("Alloca at assembly generation is not valid")
elif opcode == "alloca":
raise Exception("Alloca at assembly generation is not valid")
offset, _size = inst.operands

Check warning

Code scanning / CodeQL

Unreachable code Warning

This statement is unreachable.
offset = inst.parent.parent._mem_allocator.allocate(_size.value)
# print(f"Allocated {offset} for alloca {_size}")
operands = [offset]
elif opcode == "palloca":
offset, _size = inst.operands
operands = [offset]

# iload and istore are special cases because they can take a literal
# that is handled specialy with the _OFST macro. Look below, after the
Expand Down

0 comments on commit 414ca33

Please sign in to comment.