]>
Commit | Line | Data |
---|---|---|
7453a54e SL |
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 | #![allow(non_upper_case_globals)] | |
12 | ||
13 | use llvm::{Struct, Array, Attribute}; | |
14 | use trans::cabi::{FnType, ArgType}; | |
15 | use trans::context::CrateContext; | |
16 | use trans::type_::Type; | |
17 | ||
18 | // Data layout: e-p:32:32-i64:64-v128:32:128-n32-S128 | |
19 | ||
20 | // See the https://github.com/kripken/emscripten-fastcomp-clang repository. | |
21 | // The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions. | |
22 | ||
23 | fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType { | |
24 | match ty.kind() { | |
25 | Struct => { | |
26 | let field_types = ty.field_types(); | |
27 | if field_types.len() == 1 { | |
28 | ArgType::direct(ty, Some(field_types[0]), None, None) | |
29 | } else { | |
30 | ArgType::indirect(ty, Some(Attribute::StructRet)) | |
31 | } | |
32 | }, | |
33 | Array => { | |
34 | ArgType::indirect(ty, Some(Attribute::StructRet)) | |
35 | }, | |
36 | _ => { | |
37 | let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None }; | |
38 | ArgType::direct(ty, None, None, attr) | |
39 | } | |
40 | } | |
41 | } | |
42 | ||
43 | fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType { | |
44 | if ty.is_aggregate() { | |
45 | ArgType::indirect(ty, Some(Attribute::ByVal)) | |
46 | } else { | |
47 | let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None }; | |
48 | ArgType::direct(ty, None, None, attr) | |
49 | } | |
50 | } | |
51 | ||
52 | pub fn compute_abi_info(ccx: &CrateContext, | |
53 | atys: &[Type], | |
54 | rty: Type, | |
55 | ret_def: bool) -> FnType { | |
56 | let mut arg_tys = Vec::new(); | |
57 | for &aty in atys { | |
58 | let ty = classify_arg_ty(ccx, aty); | |
59 | arg_tys.push(ty); | |
60 | } | |
61 | ||
62 | let ret_ty = if ret_def { | |
63 | classify_ret_ty(ccx, rty) | |
64 | } else { | |
65 | ArgType::direct(Type::void(ccx), None, None, None) | |
66 | }; | |
67 | ||
68 | return FnType { | |
69 | arg_tys: arg_tys, | |
70 | ret_ty: ret_ty, | |
71 | }; | |
72 | } |