Skip to content

Commit 74f5dd0

Browse files
committed
rustc: Start a custom cabi module for wasm32
It actually was already using the `cabi_asmjs` module but that was by accident, so route the new `wasm32-unknown-unknown` target to a new `cabi_wasm32` module. The first entries in this module are to use `signext` and `zeroext` for types that are under 32 bytes in size Closes rust-lang-nursery/rust-wasm#88
1 parent 222b0eb commit 74f5dd0

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

src/librustc_trans/abi.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ use cabi_sparc64;
3030
use cabi_nvptx;
3131
use cabi_nvptx64;
3232
use cabi_hexagon;
33+
use cabi_wasm32;
3334
use mir::place::PlaceRef;
3435
use mir::operand::OperandValue;
3536
use type_::Type;
@@ -948,7 +949,13 @@ impl<'a, 'tcx> FnType<'tcx> {
948949
"powerpc64" => cabi_powerpc64::compute_abi_info(cx, self),
949950
"s390x" => cabi_s390x::compute_abi_info(cx, self),
950951
"asmjs" => cabi_asmjs::compute_abi_info(cx, self),
951-
"wasm32" => cabi_asmjs::compute_abi_info(cx, self),
952+
"wasm32" => {
953+
if cx.sess().opts.target_triple.contains("emscripten") {
954+
cabi_asmjs::compute_abi_info(cx, self)
955+
} else {
956+
cabi_wasm32::compute_abi_info(cx, self)
957+
}
958+
}
952959
"msp430" => cabi_msp430::compute_abi_info(self),
953960
"sparc" => cabi_sparc::compute_abi_info(cx, self),
954961
"sparc64" => cabi_sparc64::compute_abi_info(cx, self),

src/librustc_trans/cabi_wasm32.rs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use abi::{FnType, ArgType};
12+
use context::CodegenCx;
13+
14+
fn classify_ret_ty<'a, 'tcx>(_cx: &CodegenCx<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
15+
ret.extend_integer_width_to(32);
16+
}
17+
18+
fn classify_arg_ty(arg: &mut ArgType) {
19+
arg.extend_integer_width_to(32);
20+
}
21+
22+
pub fn compute_abi_info<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, fty: &mut FnType<'tcx>) {
23+
if !fty.ret.is_ignore() {
24+
classify_ret_ty(cx, &mut fty.ret);
25+
}
26+
27+
for arg in &mut fty.args {
28+
if arg.is_ignore() { continue; }
29+
classify_arg_ty(arg);
30+
}
31+
}

src/librustc_trans/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ mod cabi_sparc64;
123123
mod cabi_x86;
124124
mod cabi_x86_64;
125125
mod cabi_x86_win64;
126+
mod cabi_wasm32;
126127
mod callee;
127128
mod common;
128129
mod consts;

0 commit comments

Comments
 (0)