Skip to content

Commit 1db0bbf

Browse files
committed
[AVR] Add AVR platform support
1 parent 6f0aafb commit 1db0bbf

File tree

16 files changed

+161
-3
lines changed

16 files changed

+161
-3
lines changed

src/bootstrap/native.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ pub fn llvm(build: &Build, target: &str) {
9292
.profile(profile)
9393
.define("LLVM_ENABLE_ASSERTIONS", assertions)
9494
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
95+
.define("LLVM_EXPERIMENTAL_TARGETS_TO_BUILD", "AVR")
9596
.define("LLVM_INCLUDE_EXAMPLES", "OFF")
9697
.define("LLVM_INCLUDE_TESTS", "OFF")
9798
.define("LLVM_INCLUDE_DOCS", "OFF")

src/librustc/ich/impls_syntax.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ impl_stable_hash_for!(enum ::syntax::abi::Abi {
6767
PtxKernel,
6868
Msp430Interrupt,
6969
X86Interrupt,
70+
AvrInterrupt,
71+
AvrNonBlockingInterrupt,
7072
Rust,
7173
C,
7274
System,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2015 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+
use LinkerFlavor;
12+
use target::{Target, TargetOptions, TargetResult};
13+
14+
pub fn target() -> TargetResult {
15+
Ok(Target {
16+
llvm_target: "avr-atmel-none".to_string(),
17+
target_endian: "little".to_string(),
18+
target_pointer_width: "16".to_string(),
19+
data_layout: "e-p:16:16:16-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-n8".to_string(),
20+
arch: "avr".to_string(),
21+
linker_flavor: LinkerFlavor::Gcc,
22+
target_os: "none".to_string(),
23+
target_env: "gnu".to_string(),
24+
target_vendor: "unknown".to_string(),
25+
options: TargetOptions {
26+
// jemalloc is not supported on 16-bit targets.
27+
exe_allocation_crate: "alloc_system".to_string(),
28+
lib_allocation_crate: "alloc_system".to_string(),
29+
.. super::none_base::opts()
30+
},
31+
})
32+
}

src/librustc_back/target/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ mod emscripten_base;
6262
mod freebsd_base;
6363
mod haiku_base;
6464
mod linux_base;
65+
mod none_base;
6566
mod linux_musl_base;
6667
mod openbsd_base;
6768
mod netbsd_base;
@@ -201,6 +202,8 @@ supported_targets! {
201202
("armv7-apple-ios", armv7_apple_ios),
202203
("armv7s-apple-ios", armv7s_apple_ios),
203204

205+
("avr-atmel-none", avr_atmel_none),
206+
204207
("x86_64-sun-solaris", x86_64_sun_solaris),
205208
("sparcv9-sun-solaris", sparcv9_sun_solaris),
206209

@@ -239,7 +242,7 @@ pub struct Target {
239242
/// Vendor name to use for conditional compilation.
240243
pub target_vendor: String,
241244
/// Architecture to use for ABI considerations. Valid options: "x86",
242-
/// "x86_64", "arm", "aarch64", "mips", "powerpc", and "powerpc64".
245+
/// "x86_64", "arm", "avr", "aarch64", "mips", "powerpc", and "powerpc64".
243246
pub arch: String,
244247
/// [Data layout](http://llvm.org/docs/LangRef.html#data-layout) to pass to LLVM.
245248
pub data_layout: String,

src/librustc_back/target/none_base.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2014 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+
use LinkerFlavor;
12+
use std::default::Default;
13+
use target::{LinkArgs, TargetOptions};
14+
15+
pub fn opts() -> TargetOptions {
16+
let mut args = LinkArgs::new();
17+
18+
args.insert(LinkerFlavor::Gcc, vec![
19+
// We want to be able to strip as much executable code as possible
20+
// from the linker command line, and this flag indicates to the
21+
// linker that it can avoid linking in dynamic libraries that don't
22+
// actually satisfy any symbols up to that point (as with many other
23+
// resolutions the linker does). This option only applies to all
24+
// following libraries so we're sure to pass it as one of the first
25+
// arguments.
26+
"-Wl,--as-needed".to_string(),
27+
]);
28+
29+
TargetOptions {
30+
dynamic_linking: false,
31+
executables: true,
32+
linker_is_gnu: true,
33+
has_rpath: false,
34+
pre_link_args: args,
35+
position_independent_executables: true,
36+
.. Default::default()
37+
}
38+
}

src/librustc_llvm/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ fn main() {
9393
let is_crossed = target != host;
9494

9595
let optional_components =
96-
["x86", "arm", "aarch64", "mips", "powerpc", "pnacl", "systemz", "jsbackend", "msp430",
96+
["x86", "arm", "aarch64", "avr", "mips", "powerpc", "pnacl", "systemz", "jsbackend", "msp430",
9797
"sparc", "nvptx"];
9898

9999
// FIXME: surely we don't need all these components, right? Stuff like mcjit

src/librustc_llvm/ffi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum CallConv {
5454
X86_64_Win64 = 79,
5555
X86_VectorCall = 80,
5656
X86_Intr = 83,
57+
AvrNonBlockingInterrupt = 84,
58+
AvrInterrupt = 85,
5759
}
5860

5961
/// LLVMRustLinkage

src/librustc_llvm/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,12 @@ pub fn initialize_available_targets() {
334334
LLVMInitializeARMTargetMC,
335335
LLVMInitializeARMAsmPrinter,
336336
LLVMInitializeARMAsmParser);
337+
init_target!(llvm_component = "avr",
338+
LLVMInitializeAVRTargetInfo,
339+
LLVMInitializeAVRTarget,
340+
LLVMInitializeAVRTargetMC,
341+
LLVMInitializeAVRAsmPrinter,
342+
LLVMInitializeAVRAsmParser);
337343
init_target!(llvm_component = "aarch64",
338344
LLVMInitializeAArch64TargetInfo,
339345
LLVMInitializeAArch64Target,

src/librustc_trans/abi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use cabi_x86_64;
1818
use cabi_x86_win64;
1919
use cabi_arm;
2020
use cabi_aarch64;
21+
use cabi_avr;
2122
use cabi_powerpc;
2223
use cabi_powerpc64;
2324
use cabi_s390x;
@@ -649,6 +650,8 @@ impl<'a, 'tcx> FnType<'tcx> {
649650
PtxKernel => llvm::PtxKernel,
650651
Msp430Interrupt => llvm::Msp430Intr,
651652
X86Interrupt => llvm::X86_Intr,
653+
AvrInterrupt => llvm::AvrInterrupt,
654+
AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
652655

653656
// These API constants ought to be more specific...
654657
Cdecl => llvm::CCallConv,
@@ -883,6 +886,7 @@ impl<'a, 'tcx> FnType<'tcx> {
883886
cabi_x86_64::compute_abi_info(ccx, self);
884887
},
885888
"aarch64" => cabi_aarch64::compute_abi_info(ccx, self),
889+
"avr" => cabi_avr::compute_abi_info(ccx, self),
886890
"arm" => cabi_arm::compute_abi_info(ccx, self),
887891
"mips" => cabi_mips::compute_abi_info(ccx, self),
888892
"mips64" => cabi_mips64::compute_abi_info(ccx, self),

src/librustc_trans/cabi_avr.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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 abi::{FnType, ArgType, LayoutExt};
14+
use context::CrateContext;
15+
16+
fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ret: &mut ArgType<'tcx>) {
17+
if ret.layout.is_aggregate() {
18+
ret.extend_integer_width_to(8); // Is 8 correct?
19+
} else {
20+
ret.make_indirect(ccx);
21+
}
22+
}
23+
24+
fn classify_arg_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, arg: &mut ArgType<'tcx>) {
25+
if arg.layout.is_aggregate() {
26+
arg.extend_integer_width_to(8);
27+
} else {
28+
arg.make_indirect(ccx);
29+
}
30+
}
31+
32+
pub fn compute_abi_info<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fty: &mut FnType<'tcx>) {
33+
if !fty.ret.is_ignore() {
34+
classify_ret_ty(ccx, &mut fty.ret);
35+
}
36+
37+
for arg in &mut fty.args {
38+
if arg.is_ignore() {
39+
continue;
40+
}
41+
42+
classify_arg_ty(ccx, arg);
43+
}
44+
}

src/librustc_trans/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ mod base;
9696
mod builder;
9797
mod cabi_aarch64;
9898
mod cabi_arm;
99+
mod cabi_avr;
99100
mod cabi_asmjs;
100101
mod cabi_mips;
101102
mod cabi_mips64;

src/libstd/env.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ pub mod consts {
733733
/// - x86_64
734734
/// - arm
735735
/// - aarch64
736+
/// - avr
736737
/// - mips
737738
/// - mips64
738739
/// - powerpc
@@ -845,6 +846,11 @@ mod arch {
845846
pub const ARCH: &'static str = "aarch64";
846847
}
847848

849+
#[cfg(target_arch = "avr")]
850+
mod arch {
851+
pub const ARCH: &'static str = "avr";
852+
}
853+
848854
#[cfg(target_arch = "mips")]
849855
mod arch {
850856
pub const ARCH: &'static str = "mips";

src/libsyntax/abi.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ pub enum Abi {
2626
PtxKernel,
2727
Msp430Interrupt,
2828
X86Interrupt,
29+
AvrInterrupt,
30+
AvrNonBlockingInterrupt,
2931

3032
// Multiplatform / generic ABIs
3133
Rust,
@@ -61,6 +63,8 @@ const AbiDatas: &'static [AbiData] = &[
6163
AbiData {abi: Abi::PtxKernel, name: "ptx-kernel", generic: false },
6264
AbiData {abi: Abi::Msp430Interrupt, name: "msp430-interrupt", generic: false },
6365
AbiData {abi: Abi::X86Interrupt, name: "x86-interrupt", generic: false },
66+
AbiData {abi: Abi::AvrInterrupt, name: "avr-interrupt", generic: false },
67+
AbiData {abi: Abi::AvrNonBlockingInterrupt, name: "avr-non-blocking-interrupt", generic: false },
6468

6569
// Cross-platform ABIs
6670
AbiData {abi: Abi::Rust, name: "Rust", generic: true },

src/libsyntax/feature_gate.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,6 @@ declare_features! (
334334
// `extern "x86-interrupt" fn()`
335335
(active, abi_x86_interrupt, "1.17.0", Some(40180)),
336336

337-
338337
// Allows the `catch {...}` expression
339338
(active, catch_expr, "1.17.0", Some(31436)),
340339

@@ -355,6 +354,9 @@ declare_features! (
355354

356355
// Allows use of the :vis macro fragment specifier
357356
(active, macro_vis_matcher, "1.18.0", Some(41022)),
357+
358+
// `extern "avr-interrupt" fn()`
359+
(active, abi_avr_interrupt, "1.18.0", Some(000)),
358360
);
359361

360362
declare_features! (
@@ -1075,6 +1077,10 @@ impl<'a> PostExpansionVisitor<'a> {
10751077
Abi::X86Interrupt => {
10761078
gate_feature_post!(&self, abi_x86_interrupt, span,
10771079
"x86-interrupt ABI is experimental and subject to change");
1080+
}
1081+
Abi::AvrInterrupt | Abi::AvrNonBlockingInterrupt => {
1082+
gate_feature_post!(&self, abi_avr_interrupt, span,
1083+
"avr-interrupt and avr-non-blocking-interrupt ABIs are experimental and subject to change");
10781084
},
10791085
// Stable
10801086
Abi::Cdecl |

src/rustllvm/PassWrapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,12 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
117117
#define SUBTARGET_AARCH64
118118
#endif
119119

120+
#ifdef LLVM_COMPONENT_AVR
121+
#define SUBTARGET_AVR SUBTARGET(AVR)
122+
#else
123+
#define SUBTARGET_AVR
124+
#endif
125+
120126
#ifdef LLVM_COMPONENT_MIPS
121127
#define SUBTARGET_MIPS SUBTARGET(Mips)
122128
#else
@@ -151,6 +157,7 @@ extern "C" void LLVMRustAddPass(LLVMPassManagerRef PMR, LLVMPassRef RustPass) {
151157
SUBTARGET_X86 \
152158
SUBTARGET_ARM \
153159
SUBTARGET_AARCH64 \
160+
SUBTARGET_AVR \
154161
SUBTARGET_MIPS \
155162
SUBTARGET_PPC \
156163
SUBTARGET_SYSTEMZ \

src/tools/compiletest/src/util.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const OS_TABLE: &'static [(&'static str, &'static str)] = &[
2323
("linux", "linux"),
2424
("mingw32", "windows"),
2525
("netbsd", "netbsd"),
26+
("none", "none"),
2627
("openbsd", "openbsd"),
2728
("win32", "windows"),
2829
("windows", "windows"),
@@ -35,6 +36,7 @@ const ARCH_TABLE: &'static [(&'static str, &'static str)] = &[
3536
("amd64", "x86_64"),
3637
("arm", "arm"),
3738
("arm64", "aarch64"),
39+
("avr", "avr"),
3840
("hexagon", "hexagon"),
3941
("i386", "x86"),
4042
("i586", "x86"),

0 commit comments

Comments
 (0)