-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #37672 - japaric:msp430, r=alexcrichton
enable the MSP430 LLVM backend to let people experiment with this target out of tree. The MSP430 architecture is used in 16-bit microcontrollers commonly used in Digital Signal Processing applications. --- How this was tested: Declaring a custom target with the following specification: ``` json { "arch": "msp430", "data-layout": "e-m:e-p:16:16-i32:16:32-a:16-n8:16", "executables": true, "linker": "msp430-gcc", "llvm-target": "msp430", "max-atomic-width": 0, "no-integrated-as": true, "os": "none", "panic-strategy": "abort", "relocation-model": "static", "target-endian": "little", "target-pointer-width": "16" } ``` And this minimal file: ``` rust pub fn start() -> ! { loop {} } trait Copy {} trait Sized {} ``` Produces the following object files: ``` $ rustc --target=msp430 --emit=obj foo.rs $ msp430-objdump -Cd foo.o foo.o: file format elf32-msp430 Disassembly of section .text.start: 00000000 <start>: 0: 21 83 decd r1 2: 00 3c jmp $+2 ;abs 0x4 4: 00 3c jmp $+2 ;abs 0x6 6: ff 3f jmp $+0 ;abs 0x6 $ rustc --target=msp430 --emit=obj foo.rs -O $ msp430-objdump -Cd foo.o foo.o: file format elf32-msp430 Disassembly of section .text.start: 00000000 <start>: 0: ff 3f jmp $+0 ;abs 0x0 ``` --- r? @alexcrichton ~~TODO get this working with Makefiles so nightly releases include this backend~~ ~~TODO measure the increase in binary size~~ +187KiB (+0.47%) ~~FIXME --emit=obj produces empty object files~~
- Loading branch information
Showing
12 changed files
with
106 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Reference: MSP430 Embedded Application Binary Interface | ||
// http://www.ti.com/lit/an/slaa534/slaa534.pdf | ||
|
||
#![allow(non_upper_case_globals)] | ||
|
||
use llvm::Struct; | ||
|
||
use abi::{self, ArgType, FnType}; | ||
use context::CrateContext; | ||
use type_::Type; | ||
|
||
fn ty_size(ty: Type) -> usize { | ||
abi::ty_size(ty, 2) | ||
} | ||
|
||
// 3.5 Structures or Unions Passed and Returned by Reference | ||
// | ||
// "Structures (including classes) and unions larger than 32 bits are passed and | ||
// returned by reference. To pass a structure or union by reference, the caller | ||
// places its address in the appropriate location: either in a register or on | ||
// the stack, according to its position in the argument list. (..)" | ||
fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) { | ||
if ret.ty.kind() == Struct && ty_size(ret.ty) > 32 { | ||
ret.make_indirect(ccx); | ||
} else { | ||
ret.extend_integer_width_to(16); | ||
} | ||
} | ||
|
||
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) { | ||
if arg.ty.kind() == Struct && ty_size(arg.ty) > 32 { | ||
arg.make_indirect(ccx); | ||
} else { | ||
arg.extend_integer_width_to(16); | ||
} | ||
} | ||
|
||
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) { | ||
if !fty.ret.is_ignore() { | ||
classify_ret_ty(ccx, &mut fty.ret); | ||
} | ||
|
||
for arg in &mut fty.args { | ||
if arg.is_ignore() { | ||
continue; | ||
} | ||
classify_arg_ty(ccx, arg); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters