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.
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.
11 use abi::{FnType, ArgType, ArgAttribute, LayoutExt, Uniform};
12 use context::CrateContext;
14 // Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128
16 // See the https://github.com/kripken/emscripten-fastcomp-clang repository.
17 // The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions.
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 {
32 ret.make_indirect(ccx);
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);
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);
48 for arg in &mut fty.args {
49 if arg.is_ignore() { continue; }
50 classify_arg_ty(ccx, arg);