Skip to content

Commit 9a79137

Browse files
committed
Auto merge of #31653 - tomaka:emscripten-abi, r=eddyb
Needs a correct review because I'm not too confident with how this works. All tests related to the C ABI are now passing. References: - https://github.com/kripken/emscripten-fastcomp-clang/blob/dbe68fecd03d6f646bd075963c3cc0e7130e5767/lib/CodeGen/TargetInfo.cpp#L479-L489 - https://github.com/kripken/emscripten-fastcomp-clang/blob/dbe68fecd03d6f646bd075963c3cc0e7130e5767/lib/CodeGen/TargetInfo.cpp#L466-L477 The `classifyArgumentType` function has two different paths depending on `RAA == CGCXXABI::RAA_DirectInMemory`, but I don't really know what's the corresponding option in Rust. cc @brson @eddyb
2 parents 5ba9402 + 5b224ec commit 9a79137

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

src/librustc_trans/trans/cabi_asmjs.rs

+54-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,65 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use trans::cabi::FnType;
12-
use trans::cabi_arm;
11+
#![allow(non_upper_case_globals)]
12+
13+
use llvm::{Struct, Array, Attribute};
14+
use trans::cabi::{FnType, ArgType};
1315
use trans::context::CrateContext;
1416
use trans::type_::Type;
1517

18+
// Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128
19+
20+
// See the https://github.com/kripken/emscripten-fastcomp-clang repository.
21+
// The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions.
22+
23+
fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
24+
match ty.kind() {
25+
Struct => {
26+
let field_types = ty.field_types();
27+
if field_types.len() == 1 {
28+
ArgType::direct(ty, Some(field_types[0]), None, None)
29+
} else {
30+
ArgType::indirect(ty, Some(Attribute::StructRet))
31+
}
32+
},
33+
Array => {
34+
ArgType::indirect(ty, Some(Attribute::StructRet))
35+
},
36+
_ => {
37+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
38+
ArgType::direct(ty, None, None, attr)
39+
}
40+
}
41+
}
42+
43+
fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType {
44+
if ty.is_aggregate() {
45+
ArgType::indirect(ty, Some(Attribute::ByVal))
46+
} else {
47+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
48+
ArgType::direct(ty, None, None, attr)
49+
}
50+
}
51+
1652
pub fn compute_abi_info(ccx: &CrateContext,
1753
atys: &[Type],
1854
rty: Type,
1955
ret_def: bool) -> FnType {
20-
cabi_arm::compute_abi_info(ccx, atys, rty, ret_def,
21-
cabi_arm::Flavor::General)
56+
let mut arg_tys = Vec::new();
57+
for &aty in atys {
58+
let ty = classify_arg_ty(ccx, aty);
59+
arg_tys.push(ty);
60+
}
61+
62+
let ret_ty = if ret_def {
63+
classify_ret_ty(ccx, rty)
64+
} else {
65+
ArgType::direct(Type::void(ccx), None, None, None)
66+
};
67+
68+
return FnType {
69+
arg_tys: arg_tys,
70+
ret_ty: ret_ty,
71+
};
2272
}

0 commit comments

Comments
 (0)