|
65 | 65 |
|
66 | 66 | ## Global structure
|
67 | 67 |
|
68 |
| -* A module contains: |
69 |
| - * a header followed by |
70 |
| - * a table (sorted by offset) containing, for each section, its type and offset (within the module), followed by |
71 |
| - * a sequence of sections. |
| 68 | +* A module contains (in this order): |
| 69 | + - A header, containing: |
| 70 | + + The [magic number](https://en.wikipedia.org/wiki/Magic_number_%28programming%29) |
| 71 | + + Other data TBD |
| 72 | + - A table (sorted by offset) containing, for each section: |
| 73 | + + A string literal section type name |
| 74 | + + 64-bit offset within the module |
| 75 | + - A sequence of sections |
72 | 76 | * A section contains:
|
73 |
| - * a header followed by |
74 |
| - * the section contents (specific to the section type) |
75 |
| -* A code section contains: |
76 |
| - * the generic section header |
77 |
| - * a table containing, for each function, it's signature, offset (within the section), sorted by offset, followed by |
78 |
| - * a sequence of functions |
79 |
| -* A function contains: |
80 |
| - * a table containing, for each type, how many locals are indexed by the function body of that type |
81 |
| - * the serialized AST |
| 77 | + - A header followed by |
| 78 | + - The section contents (specific to the section type) |
| 79 | +* A `definitions` section contains (in this order): |
| 80 | + - The generic section header |
| 81 | + - A table (sorted by offset) containing, for each type which has opcodes: |
| 82 | + + A standardized string literal [type name](AstSemantics.md#local-and-memory-types). |
| 83 | + The index of a type name in this table is referred to as a type ID |
| 84 | + + 32-bit offset of its opcode table within the section |
| 85 | + - A sequence of opcode tables |
| 86 | + - An opcode table contains: |
| 87 | + + A sequence of standardized string literal [opcode names](AstSemantics.md), |
| 88 | + where order determines opcode index |
| 89 | +* A `code` section contains (in this order): |
| 90 | + - The generic section header |
| 91 | + - A table (sorted by offset) containing, for each function: |
| 92 | + + Signature |
| 93 | + + 64-bit offset within the section |
| 94 | + - A sequence of functions |
| 95 | + - A function contains: |
| 96 | + + A table containing, for each type ID that has [locals](AstSemantics.md#addressing-local-variables): |
| 97 | + * Type ID |
| 98 | + * Count of locals |
| 99 | + + The serialized AST |
| 100 | + |
| 101 | +All strings are encoded as null-terminated UTF8. |
82 | 102 |
|
83 | 103 | ## Serialized AST
|
84 | 104 |
|
|
0 commit comments