From f1ed8e5ed73d4d8bb3498d15e456a7efe9fd9669 Mon Sep 17 00:00:00 2001 From: Johan Engelen Date: Sun, 26 May 2024 00:41:09 +0200 Subject: [PATCH] Add support for triple wasm32-unknown-emscripten (#4672) --- ldc/driver/main.cpp | 3 +++ ldc/tests/codegen/wasm_emscripten.d | 11 +++++++++++ 2 files changed, 14 insertions(+) create mode 100644 ldc/tests/codegen/wasm_emscripten.d diff --git a/ldc/driver/main.cpp b/ldc/driver/main.cpp index af8254fc553..22980575f70 100644 --- a/ldc/driver/main.cpp +++ b/ldc/driver/main.cpp @@ -922,6 +922,9 @@ void registerPredefinedTargetVersions() { VersionCondition::addPredefinedGlobalIdent("WASI"); VersionCondition::addPredefinedGlobalIdent("CRuntime_WASI"); break; + case llvm::Triple::Emscripten: + VersionCondition::addPredefinedGlobalIdent("Emscripten"); + break; default: if (triple.getEnvironment() == llvm::Triple::Android) { VersionCondition::addPredefinedGlobalIdent("Android"); diff --git a/ldc/tests/codegen/wasm_emscripten.d b/ldc/tests/codegen/wasm_emscripten.d new file mode 100644 index 00000000000..8b00a4ee9d1 --- /dev/null +++ b/ldc/tests/codegen/wasm_emscripten.d @@ -0,0 +1,11 @@ +// REQUIRES: target_WebAssembly + +// RUN: %ldc -mtriple=wasm32-unknown-emscripten -w -output-ll -of=%t.ll %s +// RUN: FileCheck %s < %t.ll + +// test predefined versions: +version (Emscripten) {} else static assert(0); + +void foo() {} + +// CHECK: target datalayout = "e-m:e-p:32:32-p10:8:8-p20:8:8-i64:64-f128:64-n32:64-S128-ni:1:10:20"