Use the WasmRuntime's signature list rather than keeping a separate list.
This way, if the runtime modifies the signature, such as to add special arguments, they are reflected in the resulting function defintions.
This commit is contained in:
@@ -39,7 +39,6 @@ pub fn translate_module(
|
|||||||
}
|
}
|
||||||
ref s => panic!("modules should begin properly: {:?}", s),
|
ref s => panic!("modules should begin properly: {:?}", s),
|
||||||
}
|
}
|
||||||
let mut signatures = None;
|
|
||||||
let mut functions: Option<Vec<SignatureIndex>> = None;
|
let mut functions: Option<Vec<SignatureIndex>> = None;
|
||||||
let mut globals = Vec::new();
|
let mut globals = Vec::new();
|
||||||
let mut exports: Option<HashMap<FunctionIndex, String>> = None;
|
let mut exports: Option<HashMap<FunctionIndex, String>> = None;
|
||||||
@@ -50,7 +49,7 @@ pub fn translate_module(
|
|||||||
match *parser.read_with_input(next_input) {
|
match *parser.read_with_input(next_input) {
|
||||||
ParserState::BeginSection { code: SectionCode::Type, .. } => {
|
ParserState::BeginSection { code: SectionCode::Type, .. } => {
|
||||||
match parse_function_signatures(&mut parser, runtime) {
|
match parse_function_signatures(&mut parser, runtime) {
|
||||||
Ok(sigs) => signatures = Some(sigs),
|
Ok(()) => (),
|
||||||
Err(SectionParsingError::WrongSectionContent(s)) => {
|
Err(SectionParsingError::WrongSectionContent(s)) => {
|
||||||
return Err(format!("wrong content in the type section: {}", s))
|
return Err(format!("wrong content in the type section: {}", s))
|
||||||
}
|
}
|
||||||
@@ -192,7 +191,6 @@ pub fn translate_module(
|
|||||||
}
|
}
|
||||||
// At this point we've entered the code section
|
// At this point we've entered the code section
|
||||||
// First we check that we have all that is necessary to translate a function.
|
// First we check that we have all that is necessary to translate a function.
|
||||||
let signatures = signatures.unwrap_or_default();
|
|
||||||
let functions = match functions {
|
let functions = match functions {
|
||||||
None => return Err(String::from("missing a function section")),
|
None => return Err(String::from("missing a function section")),
|
||||||
Some(functions) => functions,
|
Some(functions) => functions,
|
||||||
@@ -209,7 +207,7 @@ pub fn translate_module(
|
|||||||
runtime.next_function();
|
runtime.next_function();
|
||||||
// First we build the Function object with its name and signature
|
// First we build the Function object with its name and signature
|
||||||
let mut func = Function::new();
|
let mut func = Function::new();
|
||||||
func.signature = signatures[functions[function_index]].clone();
|
func.signature = runtime.get_signature(functions[function_index]).clone();
|
||||||
if let Some(ref exports) = exports {
|
if let Some(ref exports) = exports {
|
||||||
if let Some(name) = exports.get(&function_index) {
|
if let Some(name) = exports.get(&function_index) {
|
||||||
func.name = FunctionName::new(name.clone());
|
func.name = FunctionName::new(name.clone());
|
||||||
|
|||||||
@@ -123,6 +123,10 @@ impl WasmRuntime for DummyRuntime {
|
|||||||
self.signatures.push(sig.clone());
|
self.signatures.push(sig.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_signature(&self, sig_index: SignatureIndex) -> &ir::Signature {
|
||||||
|
&self.signatures[sig_index]
|
||||||
|
}
|
||||||
|
|
||||||
fn declare_func_import(&mut self, sig_index: SignatureIndex, module: &[u8], field: &[u8]) {
|
fn declare_func_import(&mut self, sig_index: SignatureIndex, module: &[u8], field: &[u8]) {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
self.func_types.len(),
|
self.func_types.len(),
|
||||||
|
|||||||
@@ -153,6 +153,9 @@ pub trait WasmRuntime: FuncEnvironment {
|
|||||||
/// Declares a function signature to the runtime.
|
/// Declares a function signature to the runtime.
|
||||||
fn declare_signature(&mut self, sig: &ir::Signature);
|
fn declare_signature(&mut self, sig: &ir::Signature);
|
||||||
|
|
||||||
|
/// Return the signature with the given index.
|
||||||
|
fn get_signature(&self, sig_index: SignatureIndex) -> &ir::Signature;
|
||||||
|
|
||||||
/// Declares a function import to the runtime.
|
/// Declares a function import to the runtime.
|
||||||
fn declare_func_import(&mut self, sig_index: SignatureIndex, module: &[u8], field: &[u8]);
|
fn declare_func_import(&mut self, sig_index: SignatureIndex, module: &[u8], field: &[u8]);
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ pub enum SectionParsingError {
|
|||||||
pub fn parse_function_signatures(
|
pub fn parse_function_signatures(
|
||||||
parser: &mut Parser,
|
parser: &mut Parser,
|
||||||
runtime: &mut WasmRuntime,
|
runtime: &mut WasmRuntime,
|
||||||
) -> Result<Vec<Signature>, SectionParsingError> {
|
) -> Result<(), SectionParsingError> {
|
||||||
let mut signatures: Vec<Signature> = Vec::new();
|
|
||||||
loop {
|
loop {
|
||||||
match *parser.read() {
|
match *parser.read() {
|
||||||
ParserState::EndSection => break,
|
ParserState::EndSection => break,
|
||||||
@@ -51,12 +50,11 @@ pub fn parse_function_signatures(
|
|||||||
ArgumentType::new(cret_arg)
|
ArgumentType::new(cret_arg)
|
||||||
}));
|
}));
|
||||||
runtime.declare_signature(&sig);
|
runtime.declare_signature(&sig);
|
||||||
signatures.push(sig);
|
|
||||||
}
|
}
|
||||||
ref s => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
ref s => return Err(SectionParsingError::WrongSectionContent(format!("{:?}", s))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(signatures)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves the imports from the imports section of the binary.
|
/// Retrieves the imports from the imports section of the binary.
|
||||||
|
|||||||
Reference in New Issue
Block a user