Skip to main content

dada_codegen/cx/
wasm_fn_type.rs

1use wasm_encoder::ValType;
2
3use super::Cx;
4
5pub(crate) struct FnTypeIndex(u32);
6
7impl From<FnTypeIndex> for u32 {
8    fn from(value: FnTypeIndex) -> Self {
9        value.0
10    }
11}
12
13impl Cx<'_> {
14    /// Declares an instantiation of a function with a given set of arguments and returns its index.
15    /// If the function is already declared, nothing happens.
16    /// If the function is not already declared, it is enqueued for code-generation.
17    pub(crate) fn declare_fn_type(
18        &mut self,
19        inputs: Vec<ValType>,
20        outputs: Vec<ValType>,
21    ) -> FnTypeIndex {
22        let index = self.type_section.len();
23        self.type_section.ty().function(inputs, outputs);
24        FnTypeIndex(index)
25    }
26}