Skip to content

Commit

Permalink
Initial WebAssembly support.
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Feb 24, 2023
1 parent e179634 commit 3b96413
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
13 changes: 13 additions & 0 deletions code/mps.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,19 @@
#include "spw3i6.c" /* Windows on x86-64 stack probe */
#include "mpsiw3.c" /* Windows interface layer extras */

/* Emscripten */

#elif defined(MPS_PF_EMJ3LL) || defined(MPS_PF_EMJ6LL)

#include "lockan.c" /* generic locks */
#include "than.c" /* generic threads manager */
#include "vman.c" /* malloc-based pseudo memory mapping */
#include "protan.c" /* generic memory protection */
#include "prmcan.c" /* generic operating system mutator context */
#include "prmcanan.c" /* generic architecture mutator context */
#include "span.c" /* generic stack probe */


#else

#error "Unknown platform -- can't determine platform specific parts."
Expand Down
32 changes: 32 additions & 0 deletions code/mpstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,38 @@
#define MPS_PF_ALIGN 8


#elif defined(__EMSCRIPTEN__) && defined(__wasm32__)
#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_EMJ3LL)
#error "specified CONFIG_PF_... inconsistent with detected emj3ll"
#endif
#define MPS_PF_EMJ3LL
#define MPS_PF_STRING "emj3ll"
#define MPS_OS_EM
#define MPS_ARCH_J3
#define MPS_BUILD_LL
#define MPS_T_WORD unsigned long
#define MPS_T_ULONGEST unsigned long
#define MPS_WORD_WIDTH 32
#define MPS_WORD_SHIFT 5
#define MPS_PF_ALIGN 4


#elif defined(__EMSCRIPTEN__) && defined(__wasm64__)
#if defined(CONFIG_PF_STRING) && ! defined(CONFIG_PF_EMJ6LL)
#error "specified CONFIG_PF_... inconsistent with detected emj6ll"
#endif
#define MPS_PF_EMJ6LL
#define MPS_PF_STRING "emj6ll"
#define MPS_OS_EM
#define MPS_ARCH_J6
#define MPS_BUILD_LL
#define MPS_T_WORD unsigned long
#define MPS_T_ULONGEST unsigned long
#define MPS_WORD_WIDTH 64
#define MPS_WORD_SHIFT 6
#define MPS_PF_ALIGN 8


#else
#error "The MPS Kit does not have a configuration for this platform out of the box; see manual/build.txt"
#endif
Expand Down
37 changes: 37 additions & 0 deletions manual/source/topic/platform.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ six-character code breaks down into three pairs of characters:
====== ================ ====================
``OS`` Operating system Constant
====== ================ ====================
``em`` Emscripten :c:macro:`MPS_OS_EM`
``fr`` FreeBSD :c:macro:`MPS_OS_FR`
``li`` Linux :c:macro:`MPS_OS_LI`
``w3`` Windows :c:macro:`MPS_OS_W3`
Expand All @@ -31,6 +32,8 @@ The second pair of characters names the processor architecture:
``a6`` ARM64 :c:macro:`MPS_ARCH_A6`
``i3`` Intel/AMD IA-32 :c:macro:`MPS_ARCH_I3`
``i6`` Intel/AMD x86-64 :c:macro:`MPS_ARCH_I6`
``j3`` WebAssembly (32 bit) :c:macro:`MPS_ARCH_WA`
``j6`` WebAssembly (64 bit) :c:macro:`MPS_ARCH_WA`
====== ====================== ======================

The third pair of characters names the compiler toolchain:
Expand Down Expand Up @@ -92,6 +95,20 @@ Platform interface
The MPS is not supported on IA-64 (Itanium).


.. c:macro:: MPS_ARCH_J3
A :term:`C` preprocessor macro that indicates, if defined, that
the target processor architecture of the compilation is 32-bit
WebAssembly.


.. c:macro:: MPS_ARCH_J6
A :term:`C` preprocessor macro that indicates, if defined, that
the target processor architecture of the compilation is 64-bit
WebAssembly.


.. c:macro:: MPS_BUILD_GC
A :term:`C` preprocessor macro that indicates, if defined, that
Expand All @@ -113,6 +130,12 @@ Platform interface
Studio.


.. c:macro:: MPS_OS_EM
A :term:`C` preprocessor macro that indicates, if defined, that
the MPS was compiled for Emscripten.


.. c:macro:: MPS_OS_FR
A :term:`C` preprocessor macro that indicates, if defined, that
Expand Down Expand Up @@ -143,6 +166,20 @@ Platform interface
the :term:`natural alignment` of the :term:`platform`.


.. c:macro:: MPS_PF_EMJ3LL
A :term:`C` preprocessor macro that indicates, if defined, that
the :term:`platform` consists of the Emscripten operating environemtn,
the 32-bit WebAssembly target architecture, and the Clang/LLVM compiler.


.. c:macro:: MPS_PF_EMJ6LL
A :term:`C` preprocessor macro that indicates, if defined, that
the :term:`platform` consists of the Emscripten operating environemtn,
the 64-bit WebAssembly target architecture, and the Clang/LLVM compiler.


.. c:macro:: MPS_PF_FRI3GC
A :term:`C` preprocessor macro that indicates, if defined, that
Expand Down

0 comments on commit 3b96413

Please sign in to comment.