|
8 | 8 | // option. This file may not be copied, modified, or distributed
|
9 | 9 | // except according to those terms.
|
10 | 10 |
|
11 |
| -use trans::cabi::FnType; |
12 |
| -use trans::cabi_arm; |
| 11 | +#![allow(non_upper_case_globals)] |
| 12 | + |
| 13 | +use llvm::{Struct, Array, Attribute}; |
| 14 | +use trans::cabi::{FnType, ArgType}; |
13 | 15 | use trans::context::CrateContext;
|
14 | 16 | use trans::type_::Type;
|
15 | 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 | + |
16 | 52 | pub fn compute_abi_info(ccx: &CrateContext,
|
17 | 53 | atys: &[Type],
|
18 | 54 | rty: Type,
|
19 | 55 | ret_def: bool) -> FnType {
|
20 |
| - cabi_arm::compute_abi_info(ccx, atys, rty, ret_def, |
21 |
| - cabi_arm::Flavor::General) |
| 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 | + }; |
22 | 72 | }
|
0 commit comments