]> git.lizzy.rs Git - rust.git/blob - src/librustc_target/abi/call/asmjs.rs
Auto merge of #57770 - Zoxc:no-hash-query, r=michaelwoerister
[rust.git] / src / librustc_target / abi / call / asmjs.rs
1 use crate::abi::call::{FnType, ArgType, Uniform};
2 use crate::abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods};
3
4 // Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128
5
6 // See the https://github.com/kripken/emscripten-fastcomp-clang repository.
7 // The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions.
8
9 fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>)
10     where Ty: TyLayoutMethods<'a, C> + Copy,
11           C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
12 {
13     if ret.layout.is_aggregate() {
14         if let Some(unit) = ret.layout.homogeneous_aggregate(cx).unit() {
15             let size = ret.layout.size;
16             if unit.size == size {
17                 ret.cast_to(Uniform {
18                     unit,
19                     total: size
20                 });
21                 return;
22             }
23         }
24
25         ret.make_indirect();
26     }
27 }
28
29 fn classify_arg_ty<Ty>(arg: &mut ArgType<'_, Ty>) {
30     if arg.layout.is_aggregate() {
31         arg.make_indirect_byval();
32     }
33 }
34
35 pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>)
36     where Ty: TyLayoutMethods<'a, C> + Copy,
37           C: LayoutOf<Ty = Ty, TyLayout = TyLayout<'a, Ty>> + HasDataLayout
38 {
39     if !fty.ret.is_ignore() {
40         classify_ret_ty(cx, &mut fty.ret);
41     }
42
43     for arg in &mut fty.args {
44         if arg.is_ignore() { continue; }
45         classify_arg_ty(arg);
46     }
47 }