1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
|
# ``WasmParser``
A WebAssembly binary parser library.
## Overview
WasmParser is a library for parsing WebAssembly binary format. It provides a parser for [WebAssembly binary format](https://webassembly.github.io/spec/core/binary/index.html).
## Quick start
To parse a WebAssembly binary file, you can use the `Parser` struct and its `parseNext()` method to incrementally parse the binary.
```swift
import WasmParser
var parser = Parser(bytes: [
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x06, 0x01, 0x60,
0x01, 0x7e, 0x01, 0x7e, 0x03, 0x02, 0x01, 0x00, 0x07, 0x07, 0x01, 0x03,
0x66, 0x61, 0x63, 0x00, 0x00, 0x0a, 0x17, 0x01, 0x15, 0x00, 0x20, 0x00,
0x50, 0x04, 0x7e, 0x42, 0x01, 0x05, 0x20, 0x00, 0x20, 0x00, 0x42, 0x01,
0x7d, 0x10, 0x00, 0x7e, 0x0b, 0x0b
])
while let payload = try parser.parseNext() {
switch payload {
case .header(let version): print("Version: \(version)")
case .customSection(let customSection): print("Custom section: \(customSection)")
case .typeSection(let types): print("Type section: \(types)")
case .importSection(let importSection): print("Import section: \(importSection)")
case .functionSection(let types): print("Function section: \(types)")
case .tableSection(let tableSection): print("Table section: \(tableSection)")
case .memorySection(let memorySection): print("Memory section: \(memorySection)")
case .globalSection(let globalSection): print("Global section: \(globalSection)")
case .exportSection(let exportSection): print("Export section: \(exportSection)")
case .startSection(let functionIndex): print("Start section: \(functionIndex)")
case .elementSection(let elementSection): print("Element section: \(elementSection)")
case .codeSection(let codeSection): print("Code section: \(codeSection)")
case .dataSection(let dataSection): print("Data section: \(dataSection)")
case .dataCount(let count): print("Data count: \(count)")
}
}
```
## Topics
### Parsing
- ``Parser``
- ``Parser/parseNext()``
- ``NameSectionParser``
### Visitor
- ``InstructionVisitor``
- ``AnyInstructionVisitor``
### Core Module Elements
- ``Import``
- ``ImportDescriptor``
- ``Export``
- ``ExportDescriptor``
- ``Table``
- ``TableType``
- ``Global``
- ``GlobalType``
- ``Memory``
- ``MemoryType``
- ``Mutability``
- ``Limits``
- ``DataSegment``
- ``ElementSegment``
- ``Code``
- ``CustomSection``
### Instruction Types
- ``Instruction``
- ``BrTable``
- ``BlockType``
- ``MemArg``
### Index Types
- ``TypeIndex``
- ``FunctionIndex``
- ``TableIndex``
- ``GlobalIndex``
- ``MemoryIndex``
- ``ElementIndex``
- ``DataIndex``
|