forked from runtimeverification/wasm-semantics
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e01a7a
commit fced21b
Showing
70 changed files
with
6,698 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
pykwasm/src/pykwasm/kdist/wasm-semantics/binary-parsing/block.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
Parsing [blocks](https://webassembly.github.io/spec/core/binary/instructions.html#control-instructions), | ||
i.e., a blocktype + instr list. | ||
|
||
```k | ||
module BINARY-PARSER-BLOCK-SYNTAX | ||
imports BINARY-PARSER-BASE-SYNTAX | ||
imports BINARY-PARSER-INSTR-LIST-SYNTAX | ||
imports WASM-COMMON-SYNTAX | ||
imports WASM-DATA-COMMON | ||
syntax BlockType ::= "epsilon" | ValType | Int | ||
syntax Block ::= block(BlockType, BinaryInstrs) | ||
syntax BinaryInstr ::= Block | ||
syntax BlockResult ::= blockResult(Block, endsWithElse: Bool, BytesWithIndex) | ParseError | ||
syntax BlockResult ::= parseBlock(BytesWithIndex) [function, total] | ||
syntax VecTypeOrError ::= VecType | ParseError | ||
syntax VecTypeOrError ::= blockTypeToVecType(BlockType, Defns) [function, total] | ||
endmodule | ||
module BINARY-PARSER-BLOCK [private] | ||
imports BINARY-PARSER-BLOCK-SYNTAX | ||
imports BINARY-PARSER-CONSTANT-SYNTAX | ||
imports BINARY-PARSER-INSTR-LIST-SYNTAX | ||
imports BINARY-PARSER-INT-SYNTAX | ||
imports BINARY-PARSER-TAGS | ||
imports BINARY-PARSER-VALTYPE-SYNTAX | ||
syntax BlockResult ::= #parseBlock1(BlockTypeResult) [function, total] | ||
| #parseBlock2(BlockType, InstrListResult) [function, total] | ||
rule parseBlock(BWI:BytesWithIndex) => #parseBlock1(parseBlockType(BWI)) | ||
rule #parseBlock1(blockTypeResult(BT:BlockType, BWI:BytesWithIndex)) | ||
=> #parseBlock2(BT, parseInstrList(BWI)) | ||
rule #parseBlock1(E:ParseError) => E | ||
rule #parseBlock2(BT:BlockType, instrListResult(Is:BinaryInstrs, EndsWithElse:Bool, BWI:BytesWithIndex)) | ||
=> blockResult(block(BT, Is), EndsWithElse, BWI) | ||
rule #parseBlock2(_:BlockType, E:ParseError) => E | ||
syntax BlockTypeResult ::= blockTypeResult(BlockType, BytesWithIndex) | ParseError | ||
syntax BlockTypeResult ::= parseBlockType(BytesWithIndex) [function, total] | ||
| #parseBlockType1(BytesWithIndex, BytesWithIndexOrError) [function, total] | ||
| #parseBlockType2(BytesWithIndex, ValTypeResult) [function, total] | ||
| #parseBlockType3(IntResult) [function, total] | ||
rule parseBlockType(BWI:BytesWithIndex) | ||
=> #parseBlockType1(BWI, parseConstant(BWI, TYPE_EMPTY)) | ||
rule #parseBlockType1(_:BytesWithIndex, BWI:BytesWithIndex) | ||
=> blockTypeResult(epsilon, BWI:BytesWithIndex) | ||
rule #parseBlockType1(BWI:BytesWithIndex, _:ParseError) | ||
=> #parseBlockType2(BWI, parseValType(BWI)) | ||
rule #parseBlockType2(_:BytesWithIndex, valTypeResult(VT:ValType, BWI:BytesWithIndex)) | ||
=> blockTypeResult(VT, BWI) | ||
rule #parseBlockType2(BWI:BytesWithIndex, _:ParseError) | ||
=> #parseBlockType3(parseLeb128SInt(BWI)) | ||
rule #parseBlockType3(intResult(Value:Int, BWI:BytesWithIndex)) | ||
=> blockTypeResult(Value, BWI) | ||
rule #parseBlockType3(E:ParseError) => E | ||
rule blockTypeToVecType(epsilon, _:Defns) => [ .ValTypes ] | ||
rule blockTypeToVecType(ValType, _:Defns) => [ ValType .ValTypes ] | ||
rule blockTypeToVecType(Index:Int, Ds::Defns) => parseError("blockTypeToVecType: unimplemented", ListItem(Index) ListItem(Ds)) | ||
// rule blockTypeToVecType(Index:Int, .Defns) => parseError("blockTypeToVecType: not found", ListItem(Index)) | ||
// rule blockTypeToVecType(0, #type(FT:FuncType, _:OptionalId) Ds:Defns) => [FT] | ||
// rule blockTypeToVecType(0, D:Defn Ds:Defns) => parseError("blockTypeToVecType", ListItem(D) ListItem(Ds)) | ||
// [owise] | ||
// rule blockTypeToVecType(Index:Int, D:Defn Ds:Defns) => blockTypeToVecType(Index -Int 1, Ds) | ||
// requires Index >Int 0 | ||
// rule blockTypeToVecType(Index:Int, Ds:Defns) => parseError("blockTypeToVecType", ListItem(I) ListItem(Ds)) | ||
// requires Index <Int 0 | ||
endmodule | ||
``` |
34 changes: 34 additions & 0 deletions
34
pykwasm/src/pykwasm/kdist/wasm-semantics/binary-parsing/bytes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
Extract a number of bytes from the buffer. | ||
|
||
```k | ||
module BINARY-PARSER-BYTES-SYNTAX | ||
imports BINARY-PARSER-BASE-SYNTAX | ||
syntax BytesResult ::= bytesResult(Bytes, BytesWithIndex) | ParseError | ||
syntax BytesResult ::= parseBytes(BytesWithIndex, Int) [function, total] | ||
syntax BytesWithIndexOrError ::= ignoreBytes(BytesWithIndex, Int) [function, total] | ||
endmodule | ||
module BINARY-PARSER-BYTES [private] | ||
imports BINARY-PARSER-BYTES-SYNTAX | ||
rule parseBytes(bwi(Buffer:Bytes, Index:Int), Count:Int) | ||
=> bytesResult | ||
( substrBytes(Buffer, Index, Index +Int Count) | ||
, bwi(Buffer, Index +Int Count) | ||
) | ||
requires Index +Int Count <=Int lengthBytes(Buffer) | ||
rule parseBytes(bwi(Buffer:Bytes, Index:Int), Count:Int) | ||
=> parseError("parseBytes", ListItem(lengthBytes(Buffer)) ListItem(Index) ListItem(Count) ListItem(Buffer)) | ||
[owise] | ||
rule ignoreBytes(BWI:BytesWithIndex, Count:Int) | ||
=> #ignoreBytes(parseBytes(BWI, Count)) | ||
syntax BytesWithIndexOrError ::= #ignoreBytes(BytesResult) [function, total] | ||
rule #ignoreBytes(bytesResult(_:Bytes, BWI:BytesWithIndex)) => BWI | ||
rule #ignoreBytes(E:ParseError) => E | ||
endmodule | ||
``` |
26 changes: 26 additions & 0 deletions
26
pykwasm/src/pykwasm/kdist/wasm-semantics/binary-parsing/code-section.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Parsing a [code section](https://webassembly.github.io/spec/core/binary/modules.html#code-section). | ||
|
||
```k | ||
module BINARY-PARSER-CODE-SECTION-SYNTAX | ||
imports BINARY-PARSER-BASE-SYNTAX | ||
syntax SectionResult ::= parseCodeSection(BytesWithIndex) [function, total] | ||
endmodule | ||
module BINARY-PARSER-CODE-SECTION [private] | ||
imports BINARY-PARSER-CODE-SECTION-SYNTAX | ||
imports BINARY-PARSER-CODE-SYNTAX | ||
imports BINARY-PARSER-INT-SYNTAX | ||
imports BINARY-PARSER-SECTION-SYNTAX | ||
syntax SectionResult ::= #parseCodeSection(IntResult) [function, total] | ||
rule parseCodeSection(BWI:BytesWithIndex) => #parseCodeSection(parseLeb128UInt(BWI)) | ||
rule #parseCodeSection(intResult(Count:Int, BWI:BytesWithIndex)) | ||
=> parseSectionVector(defnCode, Count, .BinaryDefns, BWI) | ||
rule #parseCodeSection(E:ParseError) => E | ||
syntax DefnKind ::= "defnCode" | ||
rule parseDefn(defnCode, BWI:BytesWithIndex) => parseDefnCode(BWI) | ||
endmodule | ||
``` |
43 changes: 43 additions & 0 deletions
43
pykwasm/src/pykwasm/kdist/wasm-semantics/binary-parsing/code.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Parsing a [code object](https://webassembly.github.io/spec/core/binary/modules.html#code-section). | ||
|
||
```k | ||
module BINARY-PARSER-CODE-SYNTAX | ||
imports BINARY-PARSER-BASE-SYNTAX | ||
imports BINARY-PARSER-INSTR-LIST-SYNTAX | ||
imports WASM | ||
syntax BinaryDefn ::= BinaryDefnFunctionBody | ||
syntax BinaryDefnFunctionBody ::= binaryDefnFunctionBody(VecType, BinaryInstrs) | ||
syntax BinaryDefnFunctionBodies ::= List{BinaryDefnFunctionBody, ""} | ||
syntax DefnResult ::= parseDefnCode(BytesWithIndex) [function, total] | ||
endmodule | ||
module BINARY-PARSER-CODE [private] | ||
imports BINARY-PARSER-CODE-SYNTAX | ||
imports BINARY-PARSER-INSTR-LIST-SYNTAX | ||
imports BINARY-PARSER-INT-SYNTAX | ||
imports BINARY-PARSER-LOCALS-SYNTAX | ||
imports BINARY-PARSER-SECTION-SYNTAX | ||
imports BINARY-PARSER-VALTYPE-SYNTAX | ||
imports BOOL | ||
syntax DefnResult ::= #parseDefnCode(sizeInBytes:IntResult) [function, total] | ||
| #parseDefnCode1(sizeInBytes:Int, LocalsVecResult) [function, total] | ||
| #parseDefnCode2(sizeInBytes:Int, ValTypes, InstrListResult) [function, total] | ||
rule parseDefnCode(BWI:BytesWithIndex) => #parseDefnCode(parseLeb128UInt(BWI)) | ||
rule #parseDefnCode(intResult(Size:Int, BWI:BytesWithIndex)) | ||
=> #parseDefnCode1(Size, parseLocalsVec(BWI)) | ||
rule #parseDefnCode(E:ParseError) => E | ||
rule #parseDefnCode1(Size:Int, localsVecResult(Locals:LocalsVec, BWI:BytesWithIndex)) | ||
=> #parseDefnCode2(Size, localsVecToValTypes(Locals), parseInstrList(BWI)) | ||
rule #parseDefnCode1(_, E:ParseError) => E | ||
rule #parseDefnCode2(_Size:Int, Locals:ValTypes, instrListResult(Is:BinaryInstrs, false, BWI:BytesWithIndex)) | ||
=> defnResult(binaryDefnFunctionBody([ Locals ], Is), BWI) | ||
rule #parseDefnCode2(_Size:Int, Locals:ValTypes, instrListResult(Is:BinaryInstrs, true, BWI:BytesWithIndex)) | ||
=> parseError("#parseDefnCode2", ListItem(Locals) ListItem(Is) ListItem(BWI)) | ||
rule #parseDefnCode2(_, _, E:ParseError) => E | ||
endmodule | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
pykwasm/src/pykwasm/kdist/wasm-semantics/binary-parsing/float.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Parsing a [float](https://webassembly.github.io/spec/core/binary/values.html#floating-point). | ||
|
||
```k | ||
module BINARY-PARSER-FLOAT-SYNTAX | ||
imports BINARY-PARSER-BASE-SYNTAX | ||
syntax FloatResult ::= floatResult(Float, BytesWithIndex) | ParseError | ||
syntax FloatResult ::= parseFloat64(BytesWithIndex) [function, total] | ||
syntax FloatResult ::= parseFloat32(BytesWithIndex) [function, total] | ||
endmodule | ||
module BINARY-PARSER-FLOAT [private] | ||
imports BINARY-PARSER-BYTES-SYNTAX | ||
imports BINARY-PARSER-FLOAT-SYNTAX | ||
syntax FloatResult ::= #parseFloat64(BytesResult) [function, total] | ||
rule parseFloat64(BWI:BytesWithIndex) => #parseFloat64(parseBytes(BWI, 8)) | ||
rule #parseFloat64(bytesResult(Bytes:Bytes, BWI:BytesWithIndex)) | ||
=> parseError("#parseFloat64: bytesToFloat is not implemented", ListItem(Bytes) ListItem(BWI)) // float(bytesToFloat(Bytes), BWI) | ||
rule #parseFloat64(E:ParseError) => E | ||
syntax FloatResult ::= #parseFloat32(BytesResult) [function, total] | ||
rule parseFloat32(BWI:BytesWithIndex) => #parseFloat32(parseBytes(BWI, 4)) | ||
rule #parseFloat32(bytesResult(Bytes:Bytes, BWI:BytesWithIndex)) | ||
=> parseError("#parseFloat32: bytesToFloat is not implemented", ListItem(Bytes) ListItem(BWI)) // float(bytesToFloat(Bytes), BWI) | ||
rule #parseFloat32(E:ParseError) => E | ||
// syntax Float ::= bytesToFloat(Bytes) [function, total] | ||
// TODO: implement. | ||
endmodule | ||
``` |
Oops, something went wrong.