Skip to content

Commit e7cae41

Browse files
author
Jorge Aparicio
committed
add cabi_msp430
1 parent a6a2477 commit e7cae41

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/librustc_trans/abi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use cabi_s390x;
2424
use cabi_mips;
2525
use cabi_mips64;
2626
use cabi_asmjs;
27+
use cabi_msp430;
2728
use machine::{llalign_of_min, llsize_of, llsize_of_alloc};
2829
use type_::Type;
2930
use type_of;
@@ -520,6 +521,7 @@ impl FnType {
520521
"s390x" => cabi_s390x::compute_abi_info(ccx, self),
521522
"asmjs" => cabi_asmjs::compute_abi_info(ccx, self),
522523
"wasm32" => cabi_asmjs::compute_abi_info(ccx, self),
524+
"msp430" => cabi_msp430::compute_abi_info(ccx, self),
523525
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))
524526
}
525527

src/librustc_trans/cabi_msp430.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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+
// Reference: MSP430 Embedded Application Binary Interface
12+
// http://www.ti.com/lit/an/slaa534/slaa534.pdf
13+
14+
#![allow(non_upper_case_globals)]
15+
16+
use llvm::Struct;
17+
18+
use abi::{self, ArgType, FnType};
19+
use context::CrateContext;
20+
use type_::Type;
21+
22+
fn ty_size(ty: Type) -> usize {
23+
abi::ty_size(ty, 2)
24+
}
25+
26+
// 3.5 Structures or Unions Passed and Returned by Reference
27+
//
28+
// "Structures (including classes) and unions larger than 32 bits are passed and
29+
// returned by reference. To pass a structure or union by reference, the caller
30+
// places its address in the appropriate location: either in a register or on
31+
// the stack, according to its position in the argument list. (..)"
32+
fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
33+
if ret.ty.kind() == Struct && ty_size(ret.ty) > 32 {
34+
ret.make_indirect(ccx);
35+
} else {
36+
ret.extend_integer_width_to(16);
37+
}
38+
}
39+
40+
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
41+
if arg.ty.kind() == Struct && ty_size(arg.ty) > 32 {
42+
arg.make_indirect(ccx);
43+
} else {
44+
arg.extend_integer_width_to(16);
45+
}
46+
}
47+
48+
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
49+
if !fty.ret.is_ignore() {
50+
classify_ret_ty(ccx, &mut fty.ret);
51+
}
52+
53+
for arg in &mut fty.args {
54+
if arg.is_ignore() {
55+
continue;
56+
}
57+
classify_arg_ty(ccx, arg);
58+
}
59+
}

src/librustc_trans/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ mod cabi_arm;
101101
mod cabi_asmjs;
102102
mod cabi_mips;
103103
mod cabi_mips64;
104+
mod cabi_msp430;
104105
mod cabi_powerpc;
105106
mod cabi_powerpc64;
106107
mod cabi_s390x;

0 commit comments

Comments
 (0)