Skip to content

Commit 043550d

Browse files
shepmasterdylanmckay
authored andcommitted
[AVR] Add AVR platform support
1 parent d71ae5e commit 043550d

File tree

21 files changed

+191
-4
lines changed

21 files changed

+191
-4
lines changed

config.toml.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
# not built by default and the experimental Rust compilation targets that depend
6565
# on them will not work unless the user opts in to building them. By default the
6666
# `WebAssembly` and `RISCV` targets are enabled when compiling LLVM from scratch.
67-
#experimental-targets = "WebAssembly;RISCV"
67+
#experimental-targets = "AVR;WebAssembly;RISCV"
6868

6969
# Cap the number of parallel linker invocations when compiling LLVM.
7070
# This can be useful when building LLVM with debug info, which significantly

src/bootstrap/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ impl Config {
525525
set(&mut config.llvm_link_shared, llvm.link_shared);
526526
config.llvm_targets = llvm.targets.clone();
527527
config.llvm_experimental_targets = llvm.experimental_targets.clone()
528-
.unwrap_or_else(|| "WebAssembly;RISCV".to_string());
528+
.unwrap_or_else(|| "AVR;WebAssembly;RISCV".to_string());
529529
config.llvm_link_jobs = llvm.link_jobs;
530530
config.llvm_version_suffix = llvm.version_suffix.clone();
531531
config.llvm_clang_cl = llvm.clang_cl.clone();

src/librustc/ich/impls_syntax.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ impl_stable_hash_for!(enum ::rustc_target::spec::abi::Abi {
106106
Msp430Interrupt,
107107
X86Interrupt,
108108
AmdGpuKernel,
109+
AvrInterrupt,
110+
AvrNonBlockingInterrupt,
109111
Rust,
110112
C,
111113
System,

src/librustc/ty/layout.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2389,6 +2389,8 @@ where
23892389
Msp430Interrupt => Conv::Msp430Intr,
23902390
X86Interrupt => Conv::X86Intr,
23912391
AmdGpuKernel => Conv::AmdGpuKernel,
2392+
AvrInterrupt => Conv::AvrInterrupt,
2393+
AvrNonBlockingInterrupt => Conv::AvrNonBlockingInterrupt,
23922394

23932395
// These API constants ought to be more specific...
23942396
Cdecl => Conv::C,

src/librustc_codegen_llvm/abi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,8 @@ impl<'tcx> FnTypeLlvmExt<'tcx> for FnType<'tcx, Ty<'tcx>> {
371371
match self.conv {
372372
Conv::C => llvm::CCallConv,
373373
Conv::AmdGpuKernel => llvm::AmdGpuKernel,
374+
Conv::AvrInterrupt => llvm::AvrInterrupt,
375+
Conv::AvrNonBlockingInterrupt => llvm::AvrNonBlockingInterrupt,
374376
Conv::ArmAapcs => llvm::ArmAapcsCallConv,
375377
Conv::Msp430Intr => llvm::Msp430Intr,
376378
Conv::PtxKernel => llvm::PtxKernel,

src/librustc_codegen_llvm/llvm/ffi.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub enum CallConv {
4343
X86_64_Win64 = 79,
4444
X86_VectorCall = 80,
4545
X86_Intr = 83,
46+
AvrNonBlockingInterrupt = 84,
47+
AvrInterrupt = 85,
4648
AmdGpuKernel = 91,
4749
}
4850

src/librustc_llvm/build.rs

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

7272
let mut optional_components =
73-
vec!["x86", "arm", "aarch64", "amdgpu", "mips", "powerpc",
73+
vec!["x86", "arm", "aarch64", "amdgpu", "avr", "mips", "powerpc",
7474
"systemz", "jsbackend", "webassembly", "msp430", "sparc", "nvptx"];
7575

7676
let mut version_cmd = Command::new(&llvm_config);

src/librustc_llvm/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ pub fn initialize_available_targets() {
4141
LLVMInitializeARMTargetMC,
4242
LLVMInitializeARMAsmPrinter,
4343
LLVMInitializeARMAsmParser);
44+
init_target!(llvm_component = "avr",
45+
LLVMInitializeAVRTargetInfo,
46+
LLVMInitializeAVRTarget,
47+
LLVMInitializeAVRTargetMC,
48+
LLVMInitializeAVRAsmPrinter,
49+
LLVMInitializeAVRAsmParser);
4450
init_target!(llvm_component = "aarch64",
4551
LLVMInitializeAArch64TargetInfo,
4652
LLVMInitializeAArch64Target,

src/librustc_target/abi/call/avr.rs

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

src/librustc_target/abi/call/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ mod aarch64;
66
mod amdgpu;
77
mod arm;
88
mod asmjs;
9+
mod avr;
910
mod hexagon;
1011
mod mips;
1112
mod mips64;
@@ -516,6 +517,8 @@ pub enum Conv {
516517
X86_64Win64,
517518

518519
AmdGpuKernel,
520+
AvrInterrupt,
521+
AvrNonBlockingInterrupt,
519522
}
520523

521524
/// Metadata describing how the arguments to a native function
@@ -573,6 +576,7 @@ impl<'a, Ty> FnType<'a, Ty> {
573576
wasm32::compute_abi_info(self)
574577
}
575578
}
579+
"avr" => avr::compute_abi_info(self),
576580
"msp430" => msp430::compute_abi_info(self),
577581
"sparc" => sparc::compute_abi_info(cx, self),
578582
"sparc64" => sparc64::compute_abi_info(cx, self),

0 commit comments

Comments
 (0)