Skip to content

Commit

Permalink
wasm: add support for wasm32-unknown-wasi
Browse files Browse the repository at this point in the history
This adds the initial conditional compilation support for the WASM32
"architecture" assuming that WASI is used as the "OS".  Support for
baremetal targets in Swift needs more work still, but this gives enough
infrastructure to start playing with WASM.
  • Loading branch information
compnerd committed Dec 5, 2019
1 parent 245aac3 commit 15869ac
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Basic/LangOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
"PS4",
"Cygwin",
"Haiku",
"WASI",
};

static const StringRef SupportedConditionalCompilationArches[] = {
Expand All @@ -48,7 +49,8 @@ static const StringRef SupportedConditionalCompilationArches[] = {
"x86_64",
"powerpc64",
"powerpc64le",
"s390x"
"s390x",
"wasm32",
};

static const StringRef SupportedConditionalCompilationEndianness[] = {
Expand Down Expand Up @@ -246,6 +248,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
case llvm::Triple::Haiku:
addPlatformConditionValue(PlatformConditionKind::OS, "Haiku");
break;
case llvm::Triple::WASI:
addPlatformConditionValue(PlatformConditionKind::OS, "WASI");
break;
default:
UnsupportedOS = true;
break;
Expand Down Expand Up @@ -277,6 +282,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
case llvm::Triple::ArchType::systemz:
addPlatformConditionValue(PlatformConditionKind::Arch, "s390x");
break;
case llvm::Triple::ArchType::wasm32:
addPlatformConditionValue(PlatformConditionKind::Arch, "wasm32");
break;
default:
UnsupportedArch = true;
}
Expand All @@ -291,6 +299,7 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
case llvm::Triple::ArchType::thumb:
case llvm::Triple::ArchType::aarch64:
case llvm::Triple::ArchType::ppc64le:
case llvm::Triple::ArchType::wasm32:
case llvm::Triple::ArchType::x86:
case llvm::Triple::ArchType::x86_64:
addPlatformConditionValue(PlatformConditionKind::Endianness, "little");
Expand Down
8 changes: 8 additions & 0 deletions test/Parse/ConditionalCompilation/wasm32Target.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %swift -typecheck %s -verify -target wasm32-unknown-wasi -disable-objc-interop -parse-stdlib
// RUN: %swift-ide-test -test-input-complete -source-filename %s -target wasm32-unknown-wasi

#if arch(wasm32) && os(WASI) && _runtime(_Native) && _endian(little)
class C {}
var x = C()
#endif
var y = x

0 comments on commit 15869ac

Please sign in to comment.