Skip to content

Commit 4486754

Browse files
Carl PetoCarl Peto
authored andcommitted
Simple AVR support
1 parent cdfeefc commit 4486754

File tree

6 files changed

+39
-7
lines changed

6 files changed

+39
-7
lines changed

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,15 @@ elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "WASI")
12181218
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
12191219
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
12201220

1221+
elseif("${SWIFT_HOST_VARIANT_SDK}" STREQUAL "EMBEDDED")
1222+
1223+
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING
1224+
"Deployment OS for Swift host tools (the compiler) [macosx, embedded].")
1225+
1226+
configure_sdk_unix("Embedded" "${SWIFT_HOST_VARIANT_ARCH}")
1227+
set(SWIFT_PRIMARY_VARIANT_SDK_default "${SWIFT_HOST_VARIANT_SDK}")
1228+
set(SWIFT_PRIMARY_VARIANT_ARCH_default "${SWIFT_HOST_VARIANT_ARCH}")
1229+
12211230
elseif("${SWIFT_HOST_VARIANT_SDK}" MATCHES "(OSX|IOS*|TVOS*|WATCHOS*|XROS*)")
12221231

12231232
set(SWIFT_HOST_VARIANT "macosx" CACHE STRING

cmake/modules/SwiftConfigureSDK.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,11 @@ macro(configure_sdk_unix name architectures)
455455
elseif("${prefix}" STREQUAL "LINUX_STATIC")
456456
set(SWIFT_SDK_LINUX_STATIC_ARCH_${arch}_TRIPLE "${arch}-swift-linux-musl")
457457
set(SWIFT_SDK_LINUX_STATIC_ARCH_${arch}_PATH "${SWIFT_MUSL_PATH}/${arch}")
458+
elseif("${prefix}" STREQUAL "EMBEDDED")
459+
if(NOT arch STREQUAL avr)
460+
message(FATAL_ERROR "unsupported arch for Embedded: ${arch}")
461+
endif()
462+
set(SWIFT_SDK_EMBEDDED_ARCH_AVR_TRIPLE "avr-unknown-unknown")
458463
else()
459464
message(FATAL_ERROR "unknown Unix OS: ${prefix}")
460465
endif()

cmake/modules/SwiftSetIfArchBitness.cmake

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function(set_if_arch_bitness var_name)
2222
"${SIA_ARCH}" STREQUAL "m68k" OR
2323
"${SIA_ARCH}" STREQUAL "riscv32" OR
2424
"${SIA_ARCH}" STREQUAL "wasm32" OR
25-
"${SIA_ARCH}" STREQUAL "powerpc")
25+
"${SIA_ARCH}" STREQUAL "powerpc" OR
26+
"${SIA_ARCH}" STREQUAL "avr") # this is incorrect, should be 16-bit pointer but will do for now...
2627
set("${var_name}" "${SIA_CASE_32_BIT}" PARENT_SCOPE)
2728
elseif("${SIA_ARCH}" STREQUAL "x86_64" OR
2829
"${SIA_ARCH}" STREQUAL "amd64" OR

lib/Basic/LangOptions.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationOSs[] = {
8787
"Haiku",
8888
"WASI",
8989
"none",
90+
"Embedded"
9091
};
9192

9293
static const SupportedConditionalValue SupportedConditionalCompilationArches[] = {
@@ -101,6 +102,7 @@ static const SupportedConditionalValue SupportedConditionalCompilationArches[] =
101102
"s390x",
102103
"wasm32",
103104
"riscv64",
105+
"avr"
104106
};
105107

106108
static const SupportedConditionalValue SupportedConditionalCompilationEndianness[] = {
@@ -540,6 +542,8 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
540542
break;
541543
case llvm::Triple::ArchType::riscv64:
542544
addPlatformConditionValue(PlatformConditionKind::Arch, "riscv64");
545+
case llvm::Triple::ArchType::avr:
546+
addPlatformConditionValue(PlatformConditionKind::Arch, "avr");
543547
break;
544548
default:
545549
UnsupportedArch = true;
@@ -564,10 +568,14 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
564568
}
565569

566570
// Set the "_pointerBitWidth" platform condition.
567-
if (Target.isArch32Bit()) {
568-
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_32");
569-
} else if (Target.isArch64Bit()) {
570-
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_64");
571+
if (Target.getArch()==llvm::Triple::ArchType::avr) {
572+
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_16");
573+
} else {
574+
if (Target.isArch32Bit()) {
575+
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_32");
576+
} else if (Target.isArch64Bit()) {
577+
addPlatformConditionValue(PlatformConditionKind::PointerBitWidth, "_64");
578+
}
571579
}
572580

573581
// Set the "runtime" platform condition.

utils/build-script-impl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ function verify_host_is_supported() {
463463
| openbsd-amd64 \
464464
| cygwin-x86_64 \
465465
| haiku-x86_64 \
466+
| embedded-avr \
466467
| linux-x86_64 \
467468
| linux-i686 \
468469
| linux-armv5 \
@@ -575,6 +576,11 @@ function set_build_options_for_host() {
575576
SWIFT_HOST_TRIPLE="armv7-unknown-linux-gnueabihf"
576577
llvm_target_arch="ARM"
577578
;;
579+
embedded-avr)
580+
SWIFT_HOST_VARIANT="macosx"
581+
SWIFT_HOST_VARIANT_SDK="EMBEDDED"
582+
SWIFT_HOST_VARIANT_ARCH="avr"
583+
;;
578584
macosx-* | \
579585
iphoneos-* | \
580586
iphonesimulator-* | \
@@ -1119,7 +1125,7 @@ function false_true() {
11191125
CROSS_COMPILE_HOSTS=($CROSS_COMPILE_HOSTS)
11201126
for t in "${CROSS_COMPILE_HOSTS[@]}"; do
11211127
case ${t} in
1122-
macosx* | iphone* | appletv* | watch* | linux-armv5 | linux-armv6 | linux-armv7 | android-* | openbsd-* | linux-static-* )
1128+
macosx* | iphone* | appletv* | watch* | linux-armv5 | linux-armv6 | linux-armv7 | android-* | openbsd-* | linux-static-* | embedded* )
11231129
;;
11241130
*)
11251131
echo "Unknown host to cross-compile for: ${t}"

utils/swift_build_support/swift_build_support/targets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ class StdlibDeploymentTarget(object):
292292
'x86_64',
293293
'aarch64'])
294294

295+
Embedded = Platform("embedded", archs=["avr"])
296+
295297
OpenBSD = OpenBSDPlatform("openbsd", archs=["amd64"])
296298

297299
Cygwin = Platform("cygwin", archs=["x86_64"])
@@ -320,7 +322,8 @@ class StdlibDeploymentTarget(object):
320322
Android,
321323
Windows,
322324
Haiku,
323-
WASI]
325+
WASI,
326+
Embedded]
324327

325328
# Cache of targets by name.
326329
_targets_by_name = dict((target.name, target)

0 commit comments

Comments
 (0)