Skip to content

Commit 15869ac

Browse files
committed
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.
1 parent 245aac3 commit 15869ac

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Basic/LangOptions.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static const StringRef SupportedConditionalCompilationOSs[] = {
3939
"PS4",
4040
"Cygwin",
4141
"Haiku",
42+
"WASI",
4243
};
4344

4445
static const StringRef SupportedConditionalCompilationArches[] = {
@@ -48,7 +49,8 @@ static const StringRef SupportedConditionalCompilationArches[] = {
4849
"x86_64",
4950
"powerpc64",
5051
"powerpc64le",
51-
"s390x"
52+
"s390x",
53+
"wasm32",
5254
};
5355

5456
static const StringRef SupportedConditionalCompilationEndianness[] = {
@@ -246,6 +248,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
246248
case llvm::Triple::Haiku:
247249
addPlatformConditionValue(PlatformConditionKind::OS, "Haiku");
248250
break;
251+
case llvm::Triple::WASI:
252+
addPlatformConditionValue(PlatformConditionKind::OS, "WASI");
253+
break;
249254
default:
250255
UnsupportedOS = true;
251256
break;
@@ -277,6 +282,9 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
277282
case llvm::Triple::ArchType::systemz:
278283
addPlatformConditionValue(PlatformConditionKind::Arch, "s390x");
279284
break;
285+
case llvm::Triple::ArchType::wasm32:
286+
addPlatformConditionValue(PlatformConditionKind::Arch, "wasm32");
287+
break;
280288
default:
281289
UnsupportedArch = true;
282290
}
@@ -291,6 +299,7 @@ std::pair<bool, bool> LangOptions::setTarget(llvm::Triple triple) {
291299
case llvm::Triple::ArchType::thumb:
292300
case llvm::Triple::ArchType::aarch64:
293301
case llvm::Triple::ArchType::ppc64le:
302+
case llvm::Triple::ArchType::wasm32:
294303
case llvm::Triple::ArchType::x86:
295304
case llvm::Triple::ArchType::x86_64:
296305
addPlatformConditionValue(PlatformConditionKind::Endianness, "little");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %swift -typecheck %s -verify -target wasm32-unknown-wasi -disable-objc-interop -parse-stdlib
2+
// RUN: %swift-ide-test -test-input-complete -source-filename %s -target wasm32-unknown-wasi
3+
4+
#if arch(wasm32) && os(WASI) && _runtime(_Native) && _endian(little)
5+
class C {}
6+
var x = C()
7+
#endif
8+
var y = x

0 commit comments

Comments
 (0)