MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / parse_function_decl

Method parse_function_decl

cranelift/reader/src/parser.rs:1745–1799  ·  view source on GitHub ↗

Parse a function decl. Two variants: function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] name function-decl-sig function-decl-sig ::= SigRef(sig) | signature The first variant allocates a new signature reference. The second references an existing signature which must be declared first.

(&mut self, ctx: &mut Context)

Source from the content-addressed store, hash-verified

1743 // signature which must be declared first.
1744 //
1745 fn parse_function_decl(&mut self, ctx: &mut Context) -> ParseResult<(FuncRef, ExtFuncData)> {
1746 let fn_ = self.match_fn("expected function number: fn«n»")?;
1747 self.match_token(Token::Equal, "expected '=' in function decl")?;
1748
1749 let loc = self.loc;
1750
1751 // function-decl ::= FuncRef(fnref) "=" * ["colocated"] ["patchable"] name function-decl-sig
1752 let colocated = self.optional(Token::Identifier("colocated"));
1753 // function-decl ::= FuncRef(fnref) "=" ["colocated"] * ["patchable"] name function-decl-sig
1754 let patchable = self.optional(Token::Identifier("patchable"));
1755
1756 // function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] * name function-decl-sig
1757 let name = self.parse_external_name()?;
1758
1759 // function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] name * function-decl-sig
1760 let data = match self.token() {
1761 Some(Token::LPar) => {
1762 // function-decl ::= FuncRef(fnref) "=" ["colocated"] ["patchable"] name * signature
1763 let sig = self.parse_signature()?;
1764 let sigref = ctx.function.import_signature(sig);
1765 ctx.map
1766 .def_entity(sigref.into(), loc)
1767 .expect("duplicate SigRef entities created");
1768 ExtFuncData {
1769 name,
1770 signature: sigref,
1771 colocated,
1772 patchable,
1773 }
1774 }
1775 Some(Token::SigRef(sig_src)) => {
1776 let sig = match SigRef::with_number(sig_src) {
1777 None => {
1778 return err!(self.loc, "attempted to use invalid signature ss{}", sig_src);
1779 }
1780 Some(sig) => sig,
1781 };
1782 ctx.check_sig(sig, self.loc)?;
1783 self.consume();
1784 ExtFuncData {
1785 name,
1786 signature: sig,
1787 colocated,
1788 patchable,
1789 }
1790 }
1791 _ => return err!(self.loc, "expected 'function' or sig«n» in function decl"),
1792 };
1793
1794 // Collect any trailing comments.
1795 self.token();
1796 self.claim_gathered_comments(fn_);
1797
1798 Ok((fn_, data))
1799 }
1800
1801 // Parse a jump table literal.
1802 //

Callers 1

parse_preambleMethod · 0.80

Calls 13

OkFunction · 0.85
match_fnMethod · 0.80
match_tokenMethod · 0.80
optionalMethod · 0.80
parse_external_nameMethod · 0.80
tokenMethod · 0.80
def_entityMethod · 0.80
check_sigMethod · 0.80
parse_signatureMethod · 0.45
import_signatureMethod · 0.45
expectMethod · 0.45

Tested by

no test coverage detected