Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
c52246f
refactor symbol handling in assembly to have more structure
charles-cooper May 2, 2025
0932273
wip
harkal May 5, 2025
a07684c
wip
harkal May 5, 2025
e1db421
charles
harkal May 5, 2025
00db4df
fix for postambles
charles-cooper May 5, 2025
5e83ccc
more fixes
charles-cooper May 5, 2025
1f68273
sanity help
charles-cooper May 5, 2025
82b87b1
small fixes
charles-cooper May 5, 2025
b85f758
introduce a performance regression
charles-cooper May 5, 2025
75838b7
fix PUSHLABEL for runtime_begin
charles-cooper May 5, 2025
beeeca7
fix bad instruction
charles-cooper May 5, 2025
f65a94e
wip
harkal May 5, 2025
304d5ae
update optimizations
charles-cooper May 5, 2025
1f95319
fix venom_to_assembly
charles-cooper May 5, 2025
e50003d
fix off-by-ones
charles-cooper May 5, 2025
136362e
fix type error
charles-cooper May 5, 2025
338ca39
update test
charles-cooper May 5, 2025
6a661ab
venom_to_assembly fixes
charles-cooper May 5, 2025
69f5be1
comment
charles-cooper May 6, 2025
c152600
comment update
harkal May 6, 2025
4dea535
add PUSH_OFST
charles-cooper May 7, 2025
2624aa2
comment
charles-cooper May 7, 2025
952ef29
fix push_ofst
charles-cooper May 7, 2025
52e65c4
push_ofst in venom_to_assembly
charles-cooper May 7, 2025
6a8183e
remove jumpdest instruction
charles-cooper May 7, 2025
f2e5460
Merge branch 'master' into refactor/asm/labels
charles-cooper May 7, 2025
d6864fe
update comment
charles-cooper May 7, 2025
a0c48c0
wip - refactor IRnode to assembly into a class
charles-cooper May 8, 2025
d330346
more progress
charles-cooper May 9, 2025
d0dda4c
make it compile, add asm_runtime output
charles-cooper May 9, 2025
b877bb3
wip, remove RuntimeHeader and data_to_evm
charles-cooper May 11, 2025
a984ee0
wip, fix unreachable code eliminator
charles-cooper May 11, 2025
013a41e
refactor: make runtime_begin a DataHeader
charles-cooper May 11, 2025
bf226aa
update asm formatting
charles-cooper May 11, 2025
8e0ee08
formatting
charles-cooper May 11, 2025
4f4c29f
refactor cbor metadata suffix
charles-cooper May 11, 2025
211a869
fix refactor
charles-cooper May 11, 2025
a84888b
refactor: split assembly_to_evm from symbol_map construction
charles-cooper May 12, 2025
2a1befa
begin fixing lint
charles-cooper May 12, 2025
05cfb9d
wip lint
charles-cooper May 12, 2025
05251b4
update docstring
charles-cooper May 12, 2025
292276e
add source_map to CompilerData
charles-cooper May 12, 2025
cb8a36e
rename generate_evm to generate_evm_assembly
charles-cooper May 12, 2025
51a98ab
fix lint in venom_main
charles-cooper May 12, 2025
69b7c10
rename make_symbols to resolve_symbols
charles-cooper May 12, 2025
4487bf8
lint
charles-cooper May 12, 2025
a96b856
add dummy entry label
charles-cooper May 13, 2025
04d96b3
add todo
charles-cooper May 13, 2025
355b7b4
add compile_push_instruction helper
charles-cooper May 14, 2025
73a1e69
remove find_nested_opcode helper
charles-cooper May 14, 2025
1e4c89d
Merge branch 'master' into refactor/asm/recursion
charles-cooper May 23, 2025
dc2b366
start working on venom asm
charles-cooper May 23, 2025
e3a57ac
add a comment
charles-cooper May 23, 2025
a0d0651
wip: remove special "exit" instruction
charles-cooper May 24, 2025
fa443a4
add constants to venom context
charles-cooper May 24, 2025
275ccdd
Merge branch 'master' into refactor/asm/recursion
charles-cooper May 24, 2025
318bcef
fix symbol map resolution
charles-cooper May 24, 2025
3d834ec
update tests
charles-cooper May 24, 2025
27b5cf6
update some tests, remove sha3_32
charles-cooper May 24, 2025
6c1a65b
refactor: move getpos to compiler/output.py
charles-cooper May 25, 2025
653a3eb
update source map tests
charles-cooper May 25, 2025
b078d66
update asm optimizer tests
charles-cooper May 25, 2025
b9f9f42
fix test - craft assembly directly
charles-cooper May 25, 2025
8421c67
fix off by one
charles-cooper May 25, 2025
9994490
update more tests
charles-cooper May 25, 2025
f058140
update another test
charles-cooper May 25, 2025
395189a
update more tests
charles-cooper May 25, 2025
8712219
fix signature
charles-cooper May 25, 2025
694f63d
Merge branch 'master' into refactor/asm/recursion
charles-cooper May 26, 2025
d04df5c
Merge branch 'master' into refactor/asm/recursion
harkal Jun 10, 2025
11c82cf
test const add
harkal Jun 11, 2025
e4ff38b
const add implementation wip
harkal Jun 11, 2025
6acd170
lint
harkal Jun 11, 2025
4242393
max and refactor
harkal Jun 11, 2025
dbb82c5
wip
harkal Jun 11, 2025
6194490
lint
harkal Jun 11, 2025
c3f9bd8
move tests
harkal Jun 11, 2025
0ed619b
merge const_map to symbol_map
harkal Jun 11, 2025
02038b8
reorg files
harkal Jun 11, 2025
2500399
typing gymnastics
harkal Jun 11, 2025
fc9e49b
add symbols.py
harkal Jun 11, 2025
8359928
lint
harkal Jun 11, 2025
ecba4af
CONST_SUB and test
harkal Jun 11, 2025
fce50bf
Merge remote-tracking branch 'origin-vyper/master' into refactor/asm/…
harkal Jun 17, 2025
1915187
label upgrades
harkal Jun 17, 2025
c0af812
test
harkal Jun 17, 2025
201e72b
wip
harkal Jun 18, 2025
390b997
Merge remote-tracking branch 'origin-vyper/master' into refactor/asm/…
harkal Jun 18, 2025
d1dc189
Merge remote-tracking branch 'origin-vyper/master' into refactor/asm/…
harkal Jun 23, 2025
160634f
remove `dbsection`
harkal Jun 23, 2025
e6fc4e5
`db` instruction and hex operand
harkal Jun 23, 2025
2a7a750
update the venom parser
harkal Jun 23, 2025
f637987
wip
harkal Jun 23, 2025
65c8a8f
wip
harkal Jun 23, 2025
3726d61
in function data
harkal Jun 23, 2025
288ec0e
wip
harkal Jun 23, 2025
b9e6bcb
use ctx as temp
harkal Jun 24, 2025
a2d6132
refactoring to clean up the transpilation from the rest of venom
harkal Jun 24, 2025
047dd6b
refactor cont
harkal Jun 24, 2025
ddb1c4e
generate for all volatile basic blocks (the revert block is one of them)
harkal Jun 24, 2025
94f995c
remove no longer needed code
harkal Jun 24, 2025
89d774a
small test fix
harkal Jun 24, 2025
114f206
remove unused import from parser.py
harkal Jun 24, 2025
45b4f0a
test update
harkal Jun 24, 2025
dbbfa23
wip
harkal Jun 24, 2025
9faf37d
wip
harkal Jun 24, 2025
df944c1
fix optimizer
harkal Jun 24, 2025
e39dc8b
tmp
harkal Jun 24, 2025
c036dc4
make optimizer aware of the new system
harkal Jun 24, 2025
26baba0
and finaly dataheader is out
harkal Jun 24, 2025
fe03206
Merge remote-tracking branch 'origin-vyper/master' into refactor/asm/…
harkal Jun 24, 2025
dc863a1
tags for parser
harkal Jun 25, 2025
97e8011
remove dead code
harkal Jun 25, 2025
5b67b0c
is_volatile -> is_pinned and parser wip
harkal Jun 25, 2025
21f6512
remove unnecessary assertion in IRBasicBlock class
harkal Jun 25, 2025
d8e524e
instead of asserting ignore not data emiting instructions when counting
harkal Jun 25, 2025
3cce523
temp test
harkal Jun 25, 2025
fe979c8
fix assert_unreachable
harkal Jun 25, 2025
4b52a04
fix in old pipeline
harkal Jun 25, 2025
6a9244b
jumpdest detectiong hack
harkal Jun 25, 2025
9ebf29b
PUSHLABELJUMPDEST assembly instruction for pushing jump targets
harkal Jun 26, 2025
7181fa9
more data to separate function so we can place them at the bottom
harkal Jun 26, 2025
fbb2b13
cleaner output
harkal Jun 26, 2025
84ad20e
asm optimizer fixes
harkal Jun 26, 2025
067ce29
replace PUSHLABELJUMPDEST with PUSHLABEL for generic operands
harkal Jun 26, 2025
da27681
fix test
harkal Jun 26, 2025
340f349
refactor `get_data_segment_lengths()` to be easier to follow
harkal Jun 26, 2025
c547662
fix test
harkal Jun 26, 2025
330cd8e
fix tests in syntax and that revert is no longer automatic
harkal Jun 26, 2025
5071a7a
fix test
harkal Jun 26, 2025
7e718d9
proper import and move file
harkal Jun 26, 2025
bb616e6
lint
harkal Jun 26, 2025
90ac209
Merge remote-tracking branch 'origin-vyper/master' into refactor/asm/…
harkal Jun 26, 2025
d346f0b
update old pipeline
harkal Jul 2, 2025
a9efe4d
more fixes
harkal Jul 2, 2025
f3d2580
dead code tests fix
harkal Jul 2, 2025
25645f8
jump map fix
harkal Jul 2, 2025
2111c27
handle circular deps
harkal Jul 2, 2025
9011f7e
validate jumps
harkal Jul 2, 2025
28a38fa
safety
harkal Jul 2, 2025
a3ac412
lint
harkal Jul 2, 2025
36d7f07
[squash] const expr wip
harkal Jul 3, 2025
3e8c090
lint
harkal Jul 3, 2025
bc8982a
wip
harkal Jul 3, 2025
2463369
wip
harkal Jul 3, 2025
a6a8aeb
tests
harkal Jul 3, 2025
dd42b75
fix no pinned required
harkal Jul 3, 2025
ae17c97
test
harkal Jul 3, 2025
ab3d7dc
wip
harkal Jul 3, 2025
461b700
parser evaluator remove
harkal Jul 4, 2025
981a9b8
wip
harkal Jul 4, 2025
539dc65
wip
harkal Jul 4, 2025
d2a91dc
wip, lint, test passing
harkal Jul 7, 2025
6b9e3ee
refactor
harkal Jul 8, 2025
8f266bb
don't emit empty data_item
harkal Jul 9, 2025
6afe95e
refactor
harkal Jul 9, 2025
3686d92
pushsymbol wip
harkal Jul 10, 2025
847117b
refactor unresolved constant handling
harkal Jul 17, 2025
3c3c3e8
improve constant resolution logic
harkal Jul 17, 2025
e42b320
prefix refactor
harkal Jul 17, 2025
571a182
add handling for LabelRef in VenomTransformer
harkal Jul 17, 2025
7278d2f
refactor/cleanup
harkal Jul 17, 2025
49f4304
wip
harkal Jul 17, 2025
9111c8a
Add `UnresolvedConst`
harkal Jul 17, 2025
f6d07ed
lint
harkal Jul 17, 2025
3bdeb09
parser cleanup
harkal Jul 18, 2025
124f97b
venom_to_assembly cleanup
harkal Jul 18, 2025
9d32eea
cleanup
harkal Jul 18, 2025
192c757
handle empty liveness
harkal Jul 18, 2025
0e1c75a
Merge remote-tracking branch 'origin-vyper/master' into refactor/asm/…
harkal Jul 18, 2025
4dc29f4
replace leftour `store` opcode with `assign` in tests
harkal Jul 18, 2025
d7a61a4
remove PUSHSYMBOL class and its uses
harkal Jul 18, 2025
96e723d
rename is_symbol function to is_label for clarity and update references
harkal Jul 18, 2025
f7a54bb
cleanup unsused
harkal Jul 18, 2025
d6bbf5f
refactor
harkal Jul 18, 2025
808a019
extract label-dependent constants into a separate function
harkal Jul 18, 2025
3e5cc97
implement _resolve_push_ofst_value function for PUSH_OFST offset reso…
harkal Jul 18, 2025
b61c5f0
update left out is_symbol
harkal Jul 18, 2025
5cf496d
lint
harkal Jul 18, 2025
580531a
refactor to dataclasses
harkal Jul 18, 2025
c4a12eb
more dataclass refactor /split out instructions.py
harkal Jul 18, 2025
93d4980
use `len() == 0` instead of `not`
harkal Jul 18, 2025
55265df
update test assertions
harkal Aug 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions tests/functional/builtins/codegen/test_create_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@

import vyper.ir.compile_ir as compile_ir
from tests.utils import ZERO_ADDRESS
from vyper.codegen.ir_node import IRnode
from vyper.compiler import compile_code
from vyper.compiler.settings import OptimizationLevel
from vyper.ir.compile_ir import DATA_ITEM, PUSH, PUSHLABEL, Label
from vyper.utils import EIP_170_LIMIT, ERC5202_PREFIX, checksum_encode, keccak256


Expand Down Expand Up @@ -295,10 +294,19 @@ def test(code_ofst: uint256) -> address:
# deploy a blueprint contract whose contained initcode contains only
# zeroes (so no matter which offset, create_from_blueprint will
# return empty code)
ir = IRnode.from_list(["deploy", 0, ["seq"] + ["stop"] * initcode_len, 0])
bytecode, _ = compile_ir.assembly_to_evm(
compile_ir.compile_to_assembly(ir, optimize=OptimizationLevel.NONE)
)
asm = [
*PUSH(initcode_len),
PUSHLABEL(Label("end")),
*PUSH(0),
"CODECOPY",
*PUSH(initcode_len),
*PUSH(0),
"RETURN",
Label("end"),
DATA_ITEM(b"\x00" * initcode_len),
]
bytecode, _ = compile_ir.assembly_to_evm(asm)

# manually deploy the bytecode
c = env.deploy(abi=[], bytecode=bytecode)
blueprint_address = c.address
Expand Down
12 changes: 6 additions & 6 deletions tests/functional/codegen/features/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ def __init__(a: uint256):
assert c.val() == 123

# Make sure the init code does not access calldata
assembly = vyper.compile_code(code, output_formats=["asm"])["asm"].split(" ")
ir_return_idx_start = assembly.index("{")
ir_return_idx_end = assembly.index("}")
compiler_output = vyper.compile_code(code, output_formats=["asm", "asm_runtime"])
asm_deploytime = compiler_output["asm"]
asm_runtime = compiler_output["asm_runtime"]

assert "CALLDATALOAD" in assembly
assert "CALLDATACOPY" not in assembly[:ir_return_idx_start] + assembly[ir_return_idx_end:]
assert "CALLDATALOAD" not in assembly[:ir_return_idx_start] + assembly[ir_return_idx_end:]
assert "CALLDATALOAD" in asm_runtime
assert "CALLDATACOPY" not in asm_deploytime
assert "CALLDATALOAD" not in asm_deploytime


def test_init_calls_internal(get_contract, assert_compile_failed, tx_failed):
Expand Down
7 changes: 4 additions & 3 deletions tests/functional/codegen/test_selector_table_stability.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ def test_dense_jumptable_stability():
code = "\n".join(f"@external\ndef {name}():\n pass" for name in function_names)

output = compile_code(
code, output_formats=["asm"], settings=Settings(optimize=OptimizationLevel.CODESIZE)
code, output_formats=["asm_runtime"], settings=Settings(optimize=OptimizationLevel.CODESIZE)
)

# test that the selector table data is stable across different runs
# (xdist should provide different PYTHONHASHSEEDs).
expected_asm = """{ DATA _sym_BUCKET_HEADERS b\'\\x0bB\' _sym_bucket_0 b\'\\n\' b\'+\\x8d\' _sym_bucket_1 b\'\\x0c\' b\'\\x00\\x85\' _sym_bucket_2 b\'\\x08\' } { DATA _sym_bucket_1 b\'\\xd8\\xee\\xa1\\xe8\' _sym_external 6 foo6()3639517672 b\'\\x05\' b\'\\xd2\\x9e\\xe0\\xf9\' _sym_external 0 foo0()3533627641 b\'\\x05\' b\'\\x05\\xf1\\xe0_\' _sym_external 2 foo2()99737695 b\'\\x05\' b\'\\x91\\t\\xb4{\' _sym_external 23 foo23()2433332347 b\'\\x05\' b\'np3\\x7f\' _sym_external 11 foo11()1852846975 b\'\\x05\' b\'&\\xf5\\x96\\xf9\' _sym_external 13 foo13()653629177 b\'\\x05\' b\'\\x04ga\\xeb\' _sym_external 14 foo14()73884139 b\'\\x05\' b\'\\x89\\x06\\xad\\xc6\' _sym_external 17 foo17()2298916294 b\'\\x05\' b\'\\xe4%\\xac\\xd1\' _sym_external 4 foo4()3827674321 b\'\\x05\' b\'yj\\x01\\xac\' _sym_external 7 foo7()2036990380 b\'\\x05\' b\'\\xf1\\xe6K\\xe5\' _sym_external 29 foo29()4058401765 b\'\\x05\' b\'\\xd2\\x89X\\xb8\' _sym_external 3 foo3()3532216504 b\'\\x05\' } { DATA _sym_bucket_2 b\'\\x06p\\xffj\' _sym_external 25 foo25()108068714 b\'\\x05\' b\'\\x964\\x99I\' _sym_external 24 foo24()2520029513 b\'\\x05\' b\'s\\x81\\xe7\\xc1\' _sym_external 10 foo10()1937893313 b\'\\x05\' b\'\\x85\\xad\\xc11\' _sym_external 28 foo28()2242756913 b\'\\x05\' b\'\\xfa"\\xb1\\xed\' _sym_external 5 foo5()4196577773 b\'\\x05\' b\'A\\xe7[\\x05\' _sym_external 22 foo22()1105681157 b\'\\x05\' b\'\\xd3\\x89U\\xe8\' _sym_external 1 foo1()3548993000 b\'\\x05\' b\'hL\\xf8\\xf3\' _sym_external 20 foo20()1749874931 b\'\\x05\' } { DATA _sym_bucket_0 b\'\\xee\\xd9\\x1d\\xe3\' _sym_external 9 foo9()4007206371 b\'\\x05\' b\'a\\xbc\\x1ch\' _sym_external 16 foo16()1639717992 b\'\\x05\' b\'\\xd3*\\xa7\\x0c\' _sym_external 21 foo21()3542787852 b\'\\x05\' b\'\\x18iG\\xd9\' _sym_external 19 foo19()409552857 b\'\\x05\' b\'\\n\\xf1\\xf9\\x7f\' _sym_external 18 foo18()183630207 b\'\\x05\' b\')\\xda\\xd7`\' _sym_external 27 foo27()702207840 b\'\\x05\' b\'2\\xf6\\xaa\\xda\' _sym_external 12 foo12()855026394 b\'\\x05\' b\'\\xbe\\xb5\\x05\\xf5\' _sym_external 15 foo15()3199534581 b\'\\x05\' b\'\\xfc\\xa7_\\xe6\' _sym_external 8 foo8()4238827494 b\'\\x05\' b\'\\x1b\\x12C8\' _sym_external 26 foo26()454181688 b\'\\x05\' } }""" # noqa: E501, FS003
assert expected_asm in output["asm"]
expected_asm = """LABEL BUCKET_HEADERS:\n DATABYTES 0b42\n DATALABEL bucket_0\n DATABYTES 0a\n DATABYTES 2b8d\n DATALABEL bucket_1\n DATABYTES 0c\n DATABYTES 0085\n DATALABEL bucket_2\n DATABYTES 08\n\nLABEL bucket_1:\n DATABYTES d8eea1e8\n DATALABEL external 6 foo6()3639517672\n DATABYTES 05\n DATABYTES d29ee0f9\n DATALABEL external 0 foo0()3533627641\n DATABYTES 05\n DATABYTES 05f1e05f\n DATALABEL external 2 foo2()99737695\n DATABYTES 05\n DATABYTES 9109b47b\n DATALABEL external 23 foo23()2433332347\n DATABYTES 05\n DATABYTES 6e70337f\n DATALABEL external 11 foo11()1852846975\n DATABYTES 05\n DATABYTES 26f596f9\n DATALABEL external 13 foo13()653629177\n DATABYTES 05\n DATABYTES 046761eb\n DATALABEL external 14 foo14()73884139\n DATABYTES 05\n DATABYTES 8906adc6\n DATALABEL external 17 foo17()2298916294\n DATABYTES 05\n DATABYTES e425acd1\n DATALABEL external 4 foo4()3827674321\n DATABYTES 05\n DATABYTES 796a01ac\n DATALABEL external 7 foo7()2036990380\n DATABYTES 05\n DATABYTES f1e64be5\n DATALABEL external 29 foo29()4058401765\n DATABYTES 05\n DATABYTES d28958b8\n DATALABEL external 3 foo3()3532216504\n DATABYTES 05\n\nLABEL bucket_2:\n DATABYTES 0670ff6a\n DATALABEL external 25 foo25()108068714\n DATABYTES 05\n DATABYTES 96349949\n DATALABEL external 24 foo24()2520029513\n DATABYTES 05\n DATABYTES 7381e7c1\n DATALABEL external 10 foo10()1937893313\n DATABYTES 05\n DATABYTES 85adc131\n DATALABEL external 28 foo28()2242756913\n DATABYTES 05\n DATABYTES fa22b1ed\n DATALABEL external 5 foo5()4196577773\n DATABYTES 05\n DATABYTES 41e75b05\n DATALABEL external 22 foo22()1105681157\n DATABYTES 05\n DATABYTES d38955e8\n DATALABEL external 1 foo1()3548993000\n DATABYTES 05\n DATABYTES 684cf8f3\n DATALABEL external 20 foo20()1749874931\n DATABYTES 05\n\nLABEL bucket_0:\n DATABYTES eed91de3\n DATALABEL external 9 foo9()4007206371\n DATABYTES 05\n DATABYTES 61bc1c68\n DATALABEL external 16 foo16()1639717992\n DATABYTES 05\n DATABYTES d32aa70c\n DATALABEL external 21 foo21()3542787852\n DATABYTES 05\n DATABYTES 186947d9\n DATALABEL external 19 foo19()409552857\n DATABYTES 05\n DATABYTES 0af1f97f\n DATALABEL external 18 foo18()183630207\n DATABYTES 05\n DATABYTES 29dad760\n DATALABEL external 27 foo27()702207840\n DATABYTES 05\n DATABYTES 32f6aada\n DATALABEL external 12 foo12()855026394\n DATABYTES 05\n DATABYTES beb505f5\n DATALABEL external 15 foo15()3199534581\n DATABYTES 05\n DATABYTES fca75fe6\n DATALABEL external 8 foo8()4238827494\n DATABYTES 05\n DATABYTES 1b124338\n DATALABEL external 26 foo26()454181688\n DATABYTES 05""" # noqa: E501

assert expected_asm in output["asm_runtime"]


def test_sparse_jumptable_stability():
Expand Down
170 changes: 139 additions & 31 deletions tests/functional/venom/parser/test_parsing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tests.venom_utils import assert_bb_eq, assert_ctx_eq
from vyper.venom.basicblock import IRBasicBlock, IRLabel, IRLiteral, IRVariable
from vyper.venom.context import DataItem, DataSection, IRContext
from vyper.venom.context import IRContext
from vyper.venom.function import IRFunction
from vyper.venom.parser import parse_venom

Expand Down Expand Up @@ -87,8 +87,8 @@ def test_data_section():
stop
}

data readonly {
dbsection selector_buckets:
function selector_buckets {
selector_buckets:
db @selector_bucket_0
db @fallback
db @selector_bucket_2
Expand All @@ -104,20 +104,17 @@ def test_data_section():
expected_ctx.add_function(entry_fn := IRFunction(IRLabel("entry")))
entry_fn.get_basic_block("entry").append_instruction("stop")

expected_ctx.data_segment = [
DataSection(
IRLabel("selector_buckets"),
[
DataItem(IRLabel("selector_bucket_0")),
DataItem(IRLabel("fallback")),
DataItem(IRLabel("selector_bucket_2")),
DataItem(IRLabel("selector_bucket_3")),
DataItem(IRLabel("fallback")),
DataItem(IRLabel("selector_bucket_5")),
DataItem(IRLabel("selector_bucket_6")),
],
)
]
expected_ctx.add_function(data_fn := IRFunction(IRLabel("selector_buckets")))
data_fn.clear_basic_blocks()
data_bb = IRBasicBlock(IRLabel("selector_buckets"), data_fn)
data_fn.append_basic_block(data_bb)
data_bb.append_instruction("db", IRLabel("selector_bucket_0"))
data_bb.append_instruction("db", IRLabel("fallback"))
data_bb.append_instruction("db", IRLabel("selector_bucket_2"))
data_bb.append_instruction("db", IRLabel("selector_bucket_3"))
data_bb.append_instruction("db", IRLabel("fallback"))
data_bb.append_instruction("db", IRLabel("selector_bucket_5"))
data_bb.append_instruction("db", IRLabel("selector_bucket_6"))

assert_ctx_eq(parsed_ctx, expected_ctx)

Expand Down Expand Up @@ -198,8 +195,8 @@ def test_multi_function_and_data():
revert 0, 0
}

data readonly {
dbsection selector_buckets:
function selector_buckets {
selector_buckets:
db @selector_bucket_0
db @fallback
db @selector_bucket_2
Expand Down Expand Up @@ -234,18 +231,16 @@ def test_multi_function_and_data():
check_fn.append_basic_block(value_bb := IRBasicBlock(IRLabel("has_value"), check_fn))
value_bb.append_instruction("revert", IRLiteral(0), IRLiteral(0))

expected_ctx.data_segment = [
DataSection(
IRLabel("selector_buckets"),
[
DataItem(IRLabel("selector_bucket_0")),
DataItem(IRLabel("fallback")),
DataItem(IRLabel("selector_bucket_2")),
DataItem(IRLabel("selector_bucket_3")),
DataItem(IRLabel("selector_bucket_6")),
],
)
]
# Data segment is now converted to a function
expected_ctx.add_function(data_fn := IRFunction(IRLabel("selector_buckets")))
data_fn.clear_basic_blocks()
data_bb = IRBasicBlock(IRLabel("selector_buckets"), data_fn)
data_fn.append_basic_block(data_bb)
data_bb.append_instruction("db", IRLabel("selector_bucket_0"))
data_bb.append_instruction("db", IRLabel("fallback"))
data_bb.append_instruction("db", IRLabel("selector_bucket_2"))
data_bb.append_instruction("db", IRLabel("selector_bucket_3"))
data_bb.append_instruction("db", IRLabel("selector_bucket_6"))

assert_ctx_eq(parsed_ctx, expected_ctx)

Expand Down Expand Up @@ -366,3 +361,116 @@ def test_phis():

parsed_fn = next(iter(ctx.functions.values()))
assert_bb_eq(parsed_fn.get_basic_block(expect_bb.label.name), expect_bb)


def test_global_vars():
source = """

global_var: 10

function main {
main:
%1 = 1
%2 = 2
%3 = add %1, %2
}
"""
ctx = parse_venom(source)

print(ctx)

expected_ctx = IRContext()
expected_ctx.add_function(main_fn := IRFunction(IRLabel("main")))
main_bb = main_fn.get_basic_block("main")
main_bb.append_instruction("assign", IRLiteral(1), ret=IRVariable("1"))
main_bb.append_instruction("assign", IRLiteral(2), ret=IRVariable("2"))
main_bb.append_instruction("add", IRVariable("2"), IRVariable("1"), ret=IRVariable("3"))

assert_ctx_eq(ctx, expected_ctx)


def test_labels_with_addresses():
source = """
my_global: 0x1000

function main {
main:
%1 = 1
jmp @other_block
other_block:
%2 = 2
%3 = add %1, %2
}
"""
ctx = parse_venom(source)

assert "my_global" in ctx.global_labels
assert ctx.global_labels["my_global"] == 0x1000

main_fn = ctx.get_function(IRLabel("main"))
assert main_fn is not None

# Labels inside functions are just regular labels
main_bb = main_fn.get_basic_block("main")
assert main_bb is not None

other_bb = main_fn.get_basic_block("other_block")
assert other_bb is not None


def test_labels_with_addresses_used_in_function():
source = """
my_global: 0x1000

function main {
main:
%1 = 1
jmp @other_block
other_block:
%3 = add %1, @my_global
}
"""
ctx = parse_venom(source)

assert "my_global" in ctx.global_labels
assert ctx.global_labels["my_global"] == 0x1000

main_fn = ctx.get_function(IRLabel("main"))
assert main_fn is not None

other_bb = main_fn.get_basic_block("other_block")
assert other_bb is not None

add_inst = other_bb.instructions[0]
assert add_inst.opcode == "add"
assert add_inst.operands[0].value == "my_global"


def test_labels_with_tags():
source = """
function main {
start:
nop
revert: [pinned]
revert 0, 0
special: [tag1, pinned, tag2]
nop
normal:
stop
}
"""

parsed_ctx = parse_venom(source)
fn = list(parsed_ctx.functions.values())[0]

start_bb = fn.get_basic_block("start")
assert not start_bb.is_pinned, "start block should not be volatile"

revert_bb = fn.get_basic_block("revert")
assert revert_bb.is_pinned, "revert block should be volatile due to pinned tag"

special_bb = fn.get_basic_block("special")
assert special_bb.is_pinned, "special block should be volatile due to pinned tag"

normal_bb = fn.get_basic_block("normal")
assert not normal_bb.is_pinned, "normal block should not be volatile"
39 changes: 39 additions & 0 deletions tests/functional/venom/test_empty_db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from vyper.venom.parser import parse_venom


def test_empty_db_instruction():
"""Test that db x"" is accepted by the parser."""
venom_code = """
function test_data {
test_data:
db x""
}
"""

ctx = parse_venom(venom_code)

from vyper.venom.basicblock import IRLabel
assert IRLabel("test_data") in ctx.functions

fn = ctx.functions[IRLabel("test_data")]
bb = fn.get_basic_block("test_data")
assert len(bb.instructions) == 1
assert bb.instructions[0].opcode == "db"


def test_db_with_data():
venom_code = """
function test_data {
test_data:
db x"deadbeef"
}
"""

ctx = parse_venom(venom_code)

from vyper.venom.basicblock import IRLabel
assert IRLabel("test_data") in ctx.functions
fn = ctx.functions[IRLabel("test_data")]
bb = fn.get_basic_block("test_data")
assert len(bb.instructions) == 1
assert bb.instructions[0].opcode == "db"
65 changes: 65 additions & 0 deletions tests/functional/venom/test_runtime_deployment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import pytest

from vyper.evm.assembler import assembly_to_evm
from vyper.venom.parser import parse_venom
from vyper.venom.resolve_const import resolve_const_operands
from vyper.venom.venom_to_assembly import VenomCompiler


def test_runtime_size_storage_deployment(env):
"""This test demonstrates an InvalidJump error that occurs with certain Venom code structures.
"""
venom_code = """
const RUNTIME_SIZE = sub(@runtime_end, @runtime)

function __global {
__global:
invoke @constructor_StorageTest
%runtime_size = @RUNTIME_SIZE
%runtime_offset = @runtime
codecopy 0, %runtime_offset, %runtime_size
return 0, %runtime_size

revert: [pinned]
revert 0, 0
} ; close function __global

function constructor_StorageTest {
constructor_StorageTest:
%1 = param
sstore 0, 42
ret %1
} ; close function constructor_StorageTest

function runtime {
runtime: [pinned]
%1 = calldatasize
%2 = iszero %1
jnz %2, @1_then, @2_join

1_then:
%3 = sload 0
%value = %3
mstore 0, %value
return 0, 32

2_join:
revert 0, 0
} ; close function runtime

function runtime_end {
runtime_end: [pinned]
db x""
} ; close function runtime_end
"""

ctx = parse_venom(venom_code)

resolve_const_operands(ctx)

compiler = VenomCompiler(ctx)
assembly = compiler.generate_evm_assembly(no_optimize=True)

bytecode, _ = assembly_to_evm(assembly)

deployed_contract = env.deploy(abi=[], bytecode=bytecode)
Loading