Skip to content

Commit

Permalink
Tests and fixes for the memory instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
virgil-serbanuta committed Jan 27, 2025
1 parent 3afcc0e commit fe6d323
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 11 deletions.
14 changes: 12 additions & 2 deletions pykwasm/src/pykwasm/kdist/wasm-semantics/binary-parsing/instr.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,19 @@ module BINARY-PARSER-INSTR
rule #parseInstrx62s1(memArgResult(MemArg2:MemArg, BWI:BytesWithIndex)) => instrResult(#store(i64, store32, getMemArgOffset(MemArg2)), BWI)
rule #parseInstrx62s1(E:ParseError) => E
syntax InstrResult ::= parseInstrx63(BytesWithIndex) [function, total]
rule parseInstrx63(BWI:BytesWithIndex) => instrResult(memory.size, BWI)
syntax InstrResult ::= #parseInstrx63s1
( BytesWithIndexOrError
) [function, total]
rule parseInstrx63(BWI) => #parseInstrx63s1(parseConstant(BWI, b"\x00"))
rule #parseInstrx63s1(BWI:BytesWithIndex) => instrResult(memory.size, BWI)
rule #parseInstrx63s1(E:ParseError) => E
syntax InstrResult ::= parseInstrx64(BytesWithIndex) [function, total]
rule parseInstrx64(BWI:BytesWithIndex) => instrResult(memory.grow, BWI)
syntax InstrResult ::= #parseInstrx64s1
( BytesWithIndexOrError
) [function, total]
rule parseInstrx64(BWI) => #parseInstrx64s1(parseConstant(BWI, b"\x00"))
rule #parseInstrx64s1(BWI:BytesWithIndex) => instrResult(memory.grow, BWI)
rule #parseInstrx64s1(E:ParseError) => E
syntax InstrResult ::= parseInstrx65(BytesWithIndex) [function, total]
syntax InstrResult ::= #parseInstrx65s1
( IntResult
Expand Down
4 changes: 2 additions & 2 deletions pykwasm/src/pykwasm/scripts/binary-parser-gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,8 +404,8 @@ def with_prefix(self, p: bytes) -> 'InstrConfig':
InstrConfig('I64_STORE_8', b'\x3C', [constructor_arg('i64'), constructor_arg('store8'), 'MemArg', ], '#store'),
InstrConfig('I64_STORE_16', b'\x3D', [constructor_arg('i64'), constructor_arg('store16'), 'MemArg', ], '#store'),
InstrConfig('I64_STORE_32', b'\x3E', [constructor_arg('i64'), constructor_arg('store32'), 'MemArg', ], '#store'),
InstrConfig('MEM_SIZE', b'\x3F', [], 'memory.size'),
InstrConfig('MEM_GROW', b'\x40', [], 'memory.grow'),
InstrConfig('MEM_SIZE', b'\x3F', [parse_constant(b'\x00')], 'memory.size'),
InstrConfig('MEM_GROW', b'\x40', [parse_constant(b'\x00')], 'memory.grow'),
InstrConfig('MEM_INIT', b'\xFC\x08', ['UnsignedInt', parse_constant(b'\x00'), ], not_implemented()),
InstrConfig('DATA_DROP', b'\xFC\x09', ['UnsignedInt', ], not_implemented()),
InstrConfig('MEM_COPY', b'\xFC\x0A', [parse_constant(b'\x00'), parse_constant(b'\x00'), ], 'memory.copy'),
Expand Down
14 changes: 14 additions & 0 deletions tests/binary-parsing/code-memory-mem-init-data-drop.wast
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(module $mymodule
(func (param i32) (result i32)

i32.const 0
i32.const 0
i32.const 0
memory.init 0

data.drop 0
(return (i32.const 1))
)
(memory (;0;) 17)
(data (i32.const 1048576) ";askdfja;skdjf")
)
6 changes: 0 additions & 6 deletions tests/binary-parsing/code-memory.wast
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,6 @@
i32.const 0
memory.copy

i32.const 0
i32.const 0
i32.const 0
memory.init 0

data.drop 0
(return (i32.const 1))
)
(memory (;0;) 17)
Expand Down
65 changes: 65 additions & 0 deletions tests/binary-parsing/code-memory.wast.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<generatedTop>
<k>
#module (... types: #type (... type: [ i32 .ValTypes ] -> [ i32 .ValTypes ] , metadata: ) .EmptyStmts , funcs: #func (... type: 0 , locals: [ .ValTypes ] , body: i32 . const 0 #load ( i32 , load , 0 ) drop i32 . const 0 #load ( i32 , load , 8 ) drop i32 . const 0 #load ( i32 , load , 0 ) drop i32 . const 0 #load ( i32 , load , 8 ) drop i32 . const 0 #load ( i64 , load , 8 ) drop i32 . const 0 #load ( f32 , load , 8 ) drop i32 . const 0 #load ( f64 , load , 8 ) drop i32 . const 0 #load ( i32 , load8_s , 8 ) drop i32 . const 0 #load ( i32 , load8_u , 8 ) drop i32 . const 0 #load ( i32 , load16_s , 8 ) drop i32 . const 0 #load ( i32 , load16_u , 8 ) drop i32 . const 0 #load ( i64 , load8_s , 8 ) drop i32 . const 0 #load ( i64 , load8_u , 8 ) drop i32 . const 0 #load ( i64 , load16_s , 8 ) drop i32 . const 0 #load ( i64 , load16_u , 8 ) drop i32 . const 0 #load ( i64 , load32_s , 8 ) drop i32 . const 0 #load ( i64 , load32_u , 8 ) drop i32 . const 0 i32 . const 0 #store ( i32 , store , 8 ) i32 . const 0 i32 . const 0 #store ( i32 , store8 , 8 ) i32 . const 0 i32 . const 0 #store ( i32 , store16 , 8 ) i32 . const 0 i64 . const 0 #store ( i64 , store , 8 ) i32 . const 0 i64 . const 0 #store ( i64 , store8 , 8 ) i32 . const 0 i64 . const 0 #store ( i64 , store16 , 8 ) i32 . const 0 i64 . const 0 #store ( i64 , store32 , 8 ) i32 . const 0 i32 . const 0 #load ( f32 , load , 8 ) #store ( f32 , store , 8 ) i32 . const 0 i32 . const 0 #load ( f64 , load , 8 ) #store ( f64 , store , 8 ) memory.size drop i32 . const 0 memory.grow drop i32 . const 0 i32 . const 0 i32 . const 0 memory.fill i32 . const 0 i32 . const 0 i32 . const 0 memory.copy i32 . const 1 return .EmptyStmts , metadata: #meta (... id: , localIds: .Map ) ) .EmptyStmts , tables: .EmptyStmts , mems: #memory (... limits: #limitsMin ( 17 ) , metadata: ) .EmptyStmts , globals: #global (... type: var i32 , init: i32 . const 1048576 .EmptyStmts , metadata: ) .EmptyStmts , elem: .EmptyStmts , data: #data (... index: 0 , offset: i32 . const 1048576 .EmptyStmts , data: b";askdfja;skdjf" ) .EmptyStmts , start: .EmptyStmts , importDefns: .EmptyStmts , exports: .EmptyStmts , metadata: #meta (... id: , funcIds: .Map , filename: .String ) ) ~> .K
</k>
<wasm>
<instrs>
.K
</instrs>
<valstack>
.ValStack
</valstack>
<curFrame>
<locals>
.List
</locals>
<curModIdx>
.Int
</curModIdx>
</curFrame>
<moduleRegistry>
.Map
</moduleRegistry>
<moduleIds>
.Map
</moduleIds>
<moduleInstances>
.ModuleInstCellMap
</moduleInstances>
<nextModuleIdx>
0
</nextModuleIdx>
<mainStore>
<funcs>
.FuncDefCellMap
</funcs>
<nextFuncAddr>
0
</nextFuncAddr>
<tabs>
.TabInstCellMap
</tabs>
<nextTabAddr>
0
</nextTabAddr>
<mems>
.List
</mems>
<globals>
.GlobalInstCellMap
</globals>
<nextGlobAddr>
0
</nextGlobAddr>
<elems>
.ElemInstCellMap
</elems>
<nextElemAddr>
0
</nextElemAddr>
</mainStore>
<deterministicMemoryGrowth>
true
</deterministicMemoryGrowth>
</wasm>
</generatedTop>
2 changes: 1 addition & 1 deletion tests/binary-parsing/failing
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
tests/binary-parsing/type-param-v128.wast
tests/binary-parsing/code-call-indirect.wast
tests/binary-parsing/code-variable-global.wast
tests/binary-parsing/code-memory.wast
tests/binary-parsing/code-memory-mem-init-data-drop.wast
tests/binary-parsing/code-numeric-float-parsing.md
tests/binary-parsing/code-numeric-convert-reinterpret.wast

0 comments on commit fe6d323

Please sign in to comment.