]> git.lizzy.rs Git - rust.git/blob - src/librustc_trans/cabi_asmjs.rs
Fix checking for missing stability annotations
[rust.git] / src / librustc_trans / cabi_asmjs.rs
1 // Copyright 2012-2013 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, ArgAttribute, LayoutExt, Uniform};
12 use context::CrateContext;
13
14 // Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128
15
16 // See the https://github.com/kripken/emscripten-fastcomp-clang repository.
17 // The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions.
18
19 fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
20     if ret.layout.is_aggregate() {
21         if let Some(unit) = ret.layout.homogenous_aggregate(ccx) {
22             let size = ret.layout.size(ccx);
23             if unit.size == size {
24                 ret.cast_to(ccx, Uniform {
25                     unit,
26                     total: size
27                 });
28                 return;
29             }
30         }
31
32         ret.make_indirect(ccx);
33     }
34 }
35
36 fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
37     if arg.layout.is_aggregate() {
38         arg.make_indirect(ccx);
39         arg.attrs.set(ArgAttribute::ByVal);
40     }
41 }
42
43 pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
44     if !fty.ret.is_ignore() {
45         classify_ret_ty(ccx, &mut fty.ret);
46     }
47
48     for arg in &mut fty.args {
49         if arg.is_ignore() { continue; }
50         classify_arg_ty(ccx, arg);
51     }
52 }