Skip to content

Instantly share code, notes, and snippets.

@sberan
Created December 7, 2015 17:00
Show Gist options
  • Save sberan/43bc5fbff78ea47658f0 to your computer and use it in GitHub Desktop.
Save sberan/43bc5fbff78ea47658f0 to your computer and use it in GitHub Desktop.
From 3a3785320d3c315ad71317a27d38c774748c8863 Mon Sep 17 00:00:00 2001
From: Sam Beran <sberan@gmail.com>
Date: Mon, 7 Dec 2015 10:59:12 -0600
Subject: [PATCH] add emscripten triple
---
include/llvm/ADT/Triple.h | 8 ++++++++
lib/Support/Triple.cpp | 12 ++++++++++++
2 files changed, 20 insertions(+)
diff --git a/include/llvm/ADT/Triple.h b/include/llvm/ADT/Triple.h
index ad9fe06..b71e573 100644
--- a/include/llvm/ADT/Triple.h
+++ b/include/llvm/ADT/Triple.h
@@ -78,6 +78,7 @@ public:
nvptx64, // NVPTX: 64-bit
le32, // le32: generic little-endian 32-bit CPU (PNaCl)
le64, // le64: generic little-endian 64-bit CPU (PNaCl)
+ asmjs, // asm.js JavaScript subset
amdil, // AMDIL
amdil64, // AMDIL with 64-bit pointers
hsail, // AMD HSAIL
@@ -148,6 +149,7 @@ public:
Haiku,
Minix,
RTEMS,
+ Emscripten, // Emscripten JavaScript runtime
NaCl, // Native Client
CNK, // BG/P Compute-Node Kernel
Bitrig,
@@ -505,6 +507,12 @@ public:
return getOS() == Triple::NaCl;
}
+ /// Tests whether the OS is Emscripten.
+ bool isOSEmscripten() const {
+ return getOS() == Triple::Emscripten;
+ }
+
+
/// \brief Tests whether the OS is Linux.
bool isOSLinux() const {
return getOS() == Triple::Linux;
diff --git a/lib/Support/Triple.cpp b/lib/Support/Triple.cpp
index 9d5f145..2f8f1c2 100644
--- a/lib/Support/Triple.cpp
+++ b/lib/Support/Triple.cpp
@@ -53,6 +53,7 @@ const char *Triple::getArchTypeName(ArchType Kind) {
case nvptx64: return "nvptx64";
case le32: return "le32";
case le64: return "le64";
+ case asmjs: return "asmjs";
case amdil: return "amdil";
case amdil64: return "amdil64";
case hsail: return "hsail";
@@ -117,6 +118,8 @@ const char *Triple::getArchTypePrefix(ArchType Kind) {
case le32: return "le32";
case le64: return "le64";
+ case asmjs: return "asmjs";
+
case amdil:
case amdil64: return "amdil";
@@ -173,6 +176,7 @@ const char *Triple::getOSTypeName(OSType Kind) {
case Haiku: return "haiku";
case Minix: return "minix";
case RTEMS: return "rtems";
+ case Emscripten: return "emscripten";
case NaCl: return "nacl";
case CNK: return "cnk";
case Bitrig: return "bitrig";
@@ -261,6 +265,7 @@ Triple::ArchType Triple::getArchTypeForLLVMName(StringRef Name) {
.Case("nvptx64", nvptx64)
.Case("le32", le32)
.Case("le64", le64)
+ .Case("asmjs", asmjs)
.Case("amdil", amdil)
.Case("amdil64", amdil64)
.Case("hsail", hsail)
@@ -369,6 +374,7 @@ static Triple::ArchType parseArch(StringRef ArchName) {
.Case("nvptx64", Triple::nvptx64)
.Case("le32", Triple::le32)
.Case("le64", Triple::le64)
+ .Case("asmjs", Triple::asmjs)
.Case("amdil", Triple::amdil)
.Case("amdil64", Triple::amdil64)
.Case("hsail", Triple::hsail)
@@ -430,6 +436,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("haiku", Triple::Haiku)
.StartsWith("minix", Triple::Minix)
.StartsWith("rtems", Triple::RTEMS)
+ .StartsWith("emscripten", Triple::Emscripten)
.StartsWith("nacl", Triple::NaCl)
.StartsWith("cnk", Triple::CNK)
.StartsWith("bitrig", Triple::Bitrig)
@@ -1079,6 +1086,7 @@ static unsigned getArchPointerBitWidth(llvm::Triple::ArchType Arch) {
case llvm::Triple::armeb:
case llvm::Triple::hexagon:
case llvm::Triple::le32:
+ case llvm::Triple::asmjs:
case llvm::Triple::mips:
case llvm::Triple::mipsel:
case llvm::Triple::nvptx:
@@ -1158,6 +1166,7 @@ Triple Triple::get32BitArchVariant() const {
case Triple::hexagon:
case Triple::kalimba:
case Triple::le32:
+ case Triple::asmjs:
case Triple::mips:
case Triple::mipsel:
case Triple::nvptx:
@@ -1205,6 +1214,7 @@ Triple Triple::get64BitArchVariant() const {
case Triple::thumb:
case Triple::thumbeb:
case Triple::xcore:
+ case Triple::asmjs:
case Triple::sparcel:
case Triple::shave:
T.setArch(UnknownArch);
@@ -1253,6 +1263,7 @@ Triple Triple::getBigEndianArchVariant() const {
case Triple::amdgcn:
case Triple::amdil64:
case Triple::amdil:
+ case Triple::asmjs:
case Triple::avr:
case Triple::hexagon:
case Triple::hsail64:
@@ -1326,6 +1337,7 @@ Triple Triple::getLittleEndianArchVariant() const {
case Triple::amdil64:
case Triple::amdil:
case Triple::arm:
+ case Triple::asmjs:
case Triple::avr:
case Triple::bpfel:
case Triple::hexagon:
--
2.3.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment