|
| 1 | +// Copyright 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 llvm::*; |
| 12 | +use super::cabi::*; |
| 13 | +use super::common::*; |
| 14 | +use super::machine::*; |
| 15 | +use middle::trans::type_::Type; |
| 16 | + |
| 17 | +// Win64 ABI: http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx |
| 18 | + |
| 19 | +pub fn compute_abi_info(ccx: &CrateContext, |
| 20 | + atys: &[Type], |
| 21 | + rty: Type, |
| 22 | + ret_def: bool) -> FnType { |
| 23 | + let mut arg_tys = Vec::new(); |
| 24 | + |
| 25 | + let ret_ty; |
| 26 | + if !ret_def { |
| 27 | + ret_ty = ArgType::direct(Type::void(ccx), None, None, None); |
| 28 | + } else if rty.kind() == Struct { |
| 29 | + ret_ty = match llsize_of_alloc(ccx, rty) { |
| 30 | + 1 => ArgType::direct(rty, Some(Type::i8(ccx)), None, None), |
| 31 | + 2 => ArgType::direct(rty, Some(Type::i16(ccx)), None, None), |
| 32 | + 4 => ArgType::direct(rty, Some(Type::i32(ccx)), None, None), |
| 33 | + 8 => ArgType::direct(rty, Some(Type::i64(ccx)), None, None), |
| 34 | + _ => ArgType::indirect(rty, Some(StructRetAttribute)) |
| 35 | + }; |
| 36 | + } else { |
| 37 | + let attr = if rty == Type::i1(ccx) { Some(ZExtAttribute) } else { None }; |
| 38 | + ret_ty = ArgType::direct(rty, None, None, attr); |
| 39 | + } |
| 40 | + |
| 41 | + for &t in atys.iter() { |
| 42 | + let ty = match t.kind() { |
| 43 | + Struct => { |
| 44 | + match llsize_of_alloc(ccx, t) { |
| 45 | + 1 => ArgType::direct(rty, Some(Type::i8(ccx)), None, None), |
| 46 | + 2 => ArgType::direct(rty, Some(Type::i16(ccx)), None, None), |
| 47 | + 4 => ArgType::direct(rty, Some(Type::i32(ccx)), None, None), |
| 48 | + 8 => ArgType::direct(rty, Some(Type::i64(ccx)), None, None), |
| 49 | + _ => ArgType::indirect(t, Some(ByValAttribute)) |
| 50 | + } |
| 51 | + } |
| 52 | + _ => { |
| 53 | + let attr = if t == Type::i1(ccx) { Some(ZExtAttribute) } else { None }; |
| 54 | + ArgType::direct(t, None, None, attr) |
| 55 | + } |
| 56 | + }; |
| 57 | + arg_tys.push(ty); |
| 58 | + } |
| 59 | + |
| 60 | + return FnType { |
| 61 | + arg_tys: arg_tys, |
| 62 | + ret_ty: ret_ty, |
| 63 | + }; |
| 64 | +} |
0 commit comments