Add C ABI for wasm-bindgen compat

This commit is contained in:
Thomas Lively 2019-10-03 15:00:03 -07:00
parent 63955bbdf9
commit 43c4b81be7
2 changed files with 30 additions and 0 deletions

View File

@ -21,6 +21,7 @@ mod x86;
mod x86_64;
mod x86_win64;
mod wasm32;
mod wasm32_bindgen_compat;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum PassMode {
@ -564,6 +565,8 @@ impl<'a, Ty> FnType<'a, Ty> {
"hexagon" => hexagon::compute_abi_info(self),
"riscv32" => riscv::compute_abi_info(self, 32),
"riscv64" => riscv::compute_abi_info(self, 64),
"wasm32" if cx.target_spec().target_os != "emscripten"
=> wasm32_bindgen_compat::compute_abi_info(self),
"wasm32" | "asmjs" => wasm32::compute_abi_info(cx, self),
a => return Err(format!("unrecognized arch \"{}\" in target specification", a))
}

View File

@ -0,0 +1,27 @@
// This is not and has never been a correct C ABI for WebAssembly, but
// for a long time this was the C ABI that Rust used. wasm-bindgen
// depends on ABI details for this ABI and is incompatible with the
// correct C ABI, so this ABI is being kept around until wasm-bindgen
// can be fixed to work with the correct ABI. See #63649 for further
// discussion.
use crate::abi::call::{FnType, ArgType};
fn classify_ret_ty<Ty>(ret: &mut ArgType<'_, Ty>) {
ret.extend_integer_width_to(32);
}
fn classify_arg_ty<Ty>(arg: &mut ArgType<'_, Ty>) {
arg.extend_integer_width_to(32);
}
pub fn compute_abi_info<Ty>(fty: &mut FnType<'_, Ty>) {
if !fty.ret.is_ignore() {
classify_ret_ty(&mut fty.ret);
}
for arg in &mut fty.args {
if arg.is_ignore() { continue; }
classify_arg_ty(arg);
}
}