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 // Reference: RISC-V ELF psABI specification
12 // https://github.com/riscv/riscv-elf-psabi-doc
14 use abi::call::{ArgType, FnType};
16 fn classify_ret_ty<Ty>(arg: &mut ArgType<Ty>, xlen: u64) {
17 // "Scalars wider than 2✕XLEN are passed by reference and are replaced in
18 // the argument list with the address."
19 // "Aggregates larger than 2✕XLEN bits are passed by reference and are
20 // replaced in the argument list with the address, as are C++ aggregates
21 // with nontrivial copy constructors, destructors, or vtables."
22 if arg.layout.size.bits() > 2 * xlen {
26 // "When passed in registers, scalars narrower than XLEN bits are widened
27 // according to the sign of their type up to 32 bits, then sign-extended to
29 arg.extend_integer_width_to(xlen); // this method only affects integer scalars
32 fn classify_arg_ty<Ty>(arg: &mut ArgType<Ty>, xlen: u64) {
33 // "Scalars wider than 2✕XLEN are passed by reference and are replaced in
34 // the argument list with the address."
35 // "Aggregates larger than 2✕XLEN bits are passed by reference and are
36 // replaced in the argument list with the address, as are C++ aggregates
37 // with nontrivial copy constructors, destructors, or vtables."
38 if arg.layout.size.bits() > 2 * xlen {
42 // "When passed in registers, scalars narrower than XLEN bits are widened
43 // according to the sign of their type up to 32 bits, then sign-extended to
45 arg.extend_integer_width_to(xlen); // this method only affects integer scalars
48 pub fn compute_abi_info<Ty>(fty: &mut FnType<Ty>, xlen: u64) {
49 if !fty.ret.is_ignore() {
50 classify_ret_ty(&mut fty.ret, xlen);
53 for arg in &mut fty.args {
57 classify_arg_ty(arg, xlen);