Implement conversion of signatures into clif signatures

This commit is contained in:
Brandon Fish 2019-05-23 20:04:55 -05:00
parent a713043360
commit 9f2e068ff4
2 changed files with 47 additions and 1 deletions

View File

@ -58,7 +58,7 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
let isa = get_isa();
CraneliftModuleCodeGenerator {
isa,
clif_signatures: Map::new(), // TODO FIX
clif_signatures: Map::new(),
functions: vec![],
function_signatures: None,
signatures: None,
@ -346,6 +346,9 @@ impl ModuleCodeGenerator<CraneliftFunctionCodeGenerator, Caller, CodegenError>
fn feed_signatures(&mut self, signatures: Map<SigIndex, FuncSig>) -> Result<(), CodegenError> {
self.signatures = Some(Arc::new(signatures));
for (_sig_idx, func_sig) in self.signatures.as_ref().unwrap().iter() {
self.clif_signatures.push(Converter(func_sig).into());
}
Ok(())
}

View File

@ -9,6 +9,7 @@ use std::sync::Arc;
use wasmer_runtime_core::cache::{Artifact, Error as CacheError};
use cranelift_codegen::isa::CallConv;
use wasmer_runtime_core::{
backend::{Backend, CompilerConfig},
error::CompileResult,
@ -168,6 +169,26 @@ impl From<Converter<ir::Signature>> for FuncSig {
}
}
impl From<Converter<&FuncSig>> for ir::Signature {
fn from(sig: Converter<&FuncSig>) -> Self {
ir::Signature {
params: sig
.0
.params()
.iter()
.map(|params| Converter(*params).into())
.collect::<Vec<_>>(),
returns: sig
.0
.returns()
.iter()
.map(|returns| Converter(*returns).into())
.collect::<Vec<_>>(),
call_conv: CallConv::SystemV, // TODO should come from isa
}
}
}
impl From<Converter<ir::Type>> for Type {
fn from(ty: Converter<ir::Type>) -> Self {
match ty.0 {
@ -179,3 +200,25 @@ impl From<Converter<ir::Type>> for Type {
}
}
}
impl From<Converter<Type>> for ir::Type {
fn from(ty: Converter<Type>) -> Self {
match ty.0 {
Type::I32 => ir::types::I32,
Type::I64 => ir::types::I64,
Type::F32 => ir::types::F32,
Type::F64 => ir::types::F64,
}
}
}
impl From<Converter<Type>> for ir::AbiParam {
fn from(ty: Converter<Type>) -> Self {
match ty.0 {
Type::I32 => ir::AbiParam::new(ir::types::I32),
Type::I64 => ir::AbiParam::new(ir::types::I64),
Type::F32 => ir::AbiParam::new(ir::types::F32),
Type::F64 => ir::AbiParam::new(ir::types::F64),
}
}
}