From 15869aceaa965f1e4fcdd831fcf5f408a7b653c6 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Sun, 24 Nov 2019 16:59:57 -0800 Subject: [PATCH] wasm: add support for `wasm32-unknown-wasi` 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. --- lib/Basic/LangOptions.cpp | 11 ++++++++++- test/Parse/ConditionalCompilation/wasm32Target.swift | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test/Parse/ConditionalCompilation/wasm32Target.swift diff --git a/lib/Basic/LangOptions.cpp b/lib/Basic/LangOptions.cpp index 12b4a9b5b064e..95c937cbd2f43 100644 --- a/lib/Basic/LangOptions.cpp +++ b/lib/Basic/LangOptions.cpp @@ -39,6 +39,7 @@ static const StringRef SupportedConditionalCompilationOSs[] = { "PS4", "Cygwin", "Haiku", + "WASI", }; static const StringRef SupportedConditionalCompilationArches[] = { @@ -48,7 +49,8 @@ static const StringRef SupportedConditionalCompilationArches[] = { "x86_64", "powerpc64", "powerpc64le", - "s390x" + "s390x", + "wasm32", }; static const StringRef SupportedConditionalCompilationEndianness[] = { @@ -246,6 +248,9 @@ std::pair 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; @@ -277,6 +282,9 @@ std::pair 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; } @@ -291,6 +299,7 @@ std::pair 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"); diff --git a/test/Parse/ConditionalCompilation/wasm32Target.swift b/test/Parse/ConditionalCompilation/wasm32Target.swift new file mode 100644 index 0000000000000..96e173ee4259f --- /dev/null +++ b/test/Parse/ConditionalCompilation/wasm32Target.swift @@ -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