Brian Anderson | d6c0d85 | 2015-11-26 19:05:10 | [diff] [blame] | 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 | |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 11 | #![allow(non_upper_case_globals)] |
| 12 | |
| 13 | use llvm::{Struct, Array, Attribute}; |
Eduard Burtescu | 035a645 | 2016-03-22 17:23:36 | [diff] [blame] | 14 | use abi::{FnType, ArgType}; |
| 15 | use context::CrateContext; |
Brian Anderson | d6c0d85 | 2015-11-26 19:05:10 | [diff] [blame] | 16 | |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 17 | // Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128 |
| 18 | |
| 19 | // See the https://github.com/kripken/emscripten-fastcomp-clang repository. |
| 20 | // The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions. |
| 21 | |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 22 | fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { |
Eduard Burtescu | ac60318 | 2016-02-25 08:49:58 | [diff] [blame] | 23 | match ret.ty.kind() { |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 24 | Struct => { |
Eduard Burtescu | ac60318 | 2016-02-25 08:49:58 | [diff] [blame] | 25 | let field_types = ret.ty.field_types(); |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 26 | if field_types.len() == 1 { |
Eduard Burtescu | ac60318 | 2016-02-25 08:49:58 | [diff] [blame] | 27 | ret.cast = Some(field_types[0]); |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 28 | } else { |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 29 | ret.make_indirect(ccx); |
Eduard Burtescu | ac60318 | 2016-02-25 08:49:58 | [diff] [blame] | 30 | } |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 31 | } |
Eduard Burtescu | d492d09 | 2016-02-25 10:11:02 | [diff] [blame] | 32 | Array => { |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 33 | ret.make_indirect(ccx); |
Eduard Burtescu | d492d09 | 2016-02-25 10:11:02 | [diff] [blame] | 34 | } |
| 35 | _ => {} |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 36 | } |
| 37 | } |
| 38 | |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 39 | fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) { |
Eduard Burtescu | ac60318 | 2016-02-25 08:49:58 | [diff] [blame] | 40 | if arg.ty.is_aggregate() { |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 41 | arg.make_indirect(ccx); |
| 42 | arg.attrs.set(Attribute::ByVal); |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 43 | } |
| 44 | } |
| 45 | |
Eduard Burtescu | c6d214b | 2016-02-23 19:55:19 | [diff] [blame] | 46 | pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { |
Eduard Burtescu | 80d939f | 2016-03-06 10:36:39 | [diff] [blame] | 47 | if !fty.ret.is_ignore() { |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 48 | classify_ret_ty(ccx, &mut fty.ret); |
Pierre Krieger | 5b224ec | 2016-02-14 16:07:44 | [diff] [blame] | 49 | } |
| 50 | |
Eduard Burtescu | c6d214b | 2016-02-23 19:55:19 | [diff] [blame] | 51 | for arg in &mut fty.args { |
Eduard Burtescu | 80d939f | 2016-03-06 10:36:39 | [diff] [blame] | 52 | if arg.is_ignore() { continue; } |
Eduard Burtescu | de5f824 | 2016-02-25 17:35:40 | [diff] [blame] | 53 | classify_arg_ty(ccx, arg); |
Eduard Burtescu | c6d214b | 2016-02-23 19:55:19 | [diff] [blame] | 54 | } |
Brian Anderson | d6c0d85 | 2015-11-26 19:05:10 | [diff] [blame] | 55 | } |