vihaco_syntax/types.rs
1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4//! Parsed-syntax data shapes. See module docs in [`super`].
5
6pub use vihaco_module::module::Symbol;
7
8/// One parsed SST section: its header and its flat `.text` stream.
9///
10/// `I` is the consumer's instruction syntax type and `H` its section-header
11/// type. `.text` is not structured: it is one instruction stream in which
12/// `@name:` lines bind symbols to addresses without occupying a slot. What a
13/// symbol *is* (for example a function's signature) lives in the header.
14#[derive(Debug, Clone, PartialEq)]
15pub struct ParsedModule<I, H> {
16 pub header: H,
17 /// Instructions in address order.
18 pub code: Vec<I>,
19 /// Symbol definitions in source order. Each address is the index of the
20 /// next instruction in [`code`](Self::code), possibly `code.len()`.
21 pub symbols: Vec<Symbol>,
22}
23
24impl<I, H> ParsedModule<I, H> {
25 /// Check function declarations and the symbol table against supplied
26 /// metadata without changing either.
27 pub fn validate_metadata<V, Ty: Clone, Info>(
28 &self,
29 metadata: &vihaco_module::module::ProgramMetadata<V, Ty, Info>,
30 ) -> eyre::Result<()> {
31 metadata.validate(&self.symbols, self.code.len())
32 }
33}