Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sdk] Add wasm interpreter support. #5924

Merged
merged 9 commits into from
Nov 7, 2017
16 changes: 15 additions & 1 deletion mono/mini/exceptions-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,18 @@ mono_arch_get_throw_corlib_exception (MonoTrampInfo **info, gboolean aot)
{
g_error ("mono_arch_get_throw_corlib_exception");
return NULL;
}
}

gpointer
mono_arch_get_rethrow_exception (MonoTrampInfo **info, gboolean aot)
{
g_error ("mono_arch_get_rethrow_exception");
return NULL;
}

gpointer
mono_arch_get_throw_exception (MonoTrampInfo **info, gboolean aot)
{
g_error ("mono_arch_get_rethrow_exception");
return NULL;
}
7 changes: 7 additions & 0 deletions mono/mini/mini-wasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,13 @@ int pthread_getschedparam (pthread_t thread, int *policy, struct sched_param *pa
return 0;
}

int
pthread_setschedparam(pthread_t thread, int policy, const struct sched_param *param)
{
return 0;
}


int
pthread_attr_getstacksize (const pthread_attr_t *restrict attr, size_t *restrict stacksize)
{
Expand Down
6 changes: 3 additions & 3 deletions mono/sgen/sgen-gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -1138,11 +1138,11 @@ gboolean nursery_canaries_enabled (void);
static inline void
sgen_dummy_use (gpointer v)
{
#if defined(__GNUC__)
__asm__ volatile ("" : "=r"(v) : "r"(v));
#elif defined(_MSC_VER)
#if defined(_MSC_VER) || defined(HOST_WASM)
static volatile gpointer ptr;
ptr = v;
#elif defined(__GNUC__)
__asm__ volatile ("" : "=r"(v) : "r"(v));
#else
#error "Implement sgen_dummy_use for your compiler"
#endif
Expand Down
4 changes: 4 additions & 0 deletions runtime/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ if INSTALL_UNREAL
build_profiles += unreal
endif

if INSTALL_WASM
build_profiles += wasm
endif

test_profiles = $(filter-out binary_reference_assemblies monodroid_tools,$(build_profiles))

if BUILD_MCS
Expand Down
9 changes: 8 additions & 1 deletion sdks/builds/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ $(TOP)/configure: $(TOP)/configure.ac $(TOP)/autogen.sh
cd $(TOP) && PATH=$(EXTRA_PATH):$$PATH NOCONFIGURE=1 ./autogen.sh

TARGETS=
#Targets with custom build rules should append themselves here and we won't generate a generic target
CUSTOM_BUILD_TARGETS=


## BCL targets
ifndef DISABLE_BCL
Expand All @@ -29,6 +32,10 @@ ifndef DISABLE_IOS
include ios.mk
endif

## WASM targets
ifndef DISABLE_WASM
include wasm.mk
endif

## Generic targets
.PHONY: $(foreach target,$(TARGETS),toolchain-$(target))
Expand All @@ -38,7 +45,7 @@ $(foreach target,$(TARGETS),toolchain-$(target)): toolchain-%: .stamp-%-toolchai
$(foreach target,$(TARGETS),configure-$(target)): configure-%: .stamp-%-configure

.PHONY: $(foreach target,$(TARGETS),build-$(target))
$(foreach target,$(TARGETS),build-$(target)): build-%: .stamp-%-configure
$(filter-out $(CUSTOM_BUILD_TARGETS), $(foreach target,$(TARGETS),build-$(target))): build-%: .stamp-%-configure
$(MAKE) -C $*

.PHONY: $(foreach target,$(TARGETS),setup-$(target))
Expand Down
2 changes: 1 addition & 1 deletion sdks/builds/android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ _android_$(1)_CONFIGURE_FLAGS= \
$$(NDK_DIR)/build/tools/make-standalone-toolchain.sh --platform=$(2) --arch=$(1) --install-dir=$$(TOP)/sdks/builds/toolchains/android-$(1) --toolchain=$(4)
touch $$@

android-toolchain:: .stamp-android-$(1)-toolchain
android-toolchain: .stamp-android-$(1)-toolchain

.stamp-android-$(1)-configure: $$(TOP)/configure .stamp-android-$(1)-toolchain
mkdir -p $$(TOP)/sdks/builds/android-$(1)
Expand Down
5 changes: 3 additions & 2 deletions sdks/builds/bcl.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
cd $(TOP)/sdks/builds/bcl && $(TOP)/configure --with-monodroid=yes --with-monotouch=yes --with-profile4_x=no --with-wasm=yes --with-mcs-docs=no --disable-btls --disable-nls --disable-boehm
touch $@

$(TOP)/sdks/out/bcl/monodroid $(TOP)/sdks/out/bcl/monotouch:
$(TOP)/sdks/out/bcl/monodroid $(TOP)/sdks/out/bcl/monotouch $(TOP)/sdks/out/bcl/wasm:
mkdir -p $@

.PHONY: package-bcl
package-bcl: $(TOP)/sdks/out/bcl/monodroid $(TOP)/sdks/out/bcl/monotouch
package-bcl: $(TOP)/sdks/out/bcl/monodroid $(TOP)/sdks/out/bcl/monotouch $(TOP)/sdks/out/bcl/wasm
cp -R $(TOP)/mcs/class/lib/monodroid/* $(TOP)/sdks/out/bcl/monodroid
cp -R $(TOP)/mcs/class/lib/monotouch/* $(TOP)/sdks/out/bcl/monotouch
cp -R $(TOP)/mcs/class/lib/wasm/* $(TOP)/sdks/out/bcl/wasm

.PHONY: clean-bcl
clean-bcl::
Expand Down
54 changes: 54 additions & 0 deletions sdks/builds/wasm.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@

WASM_INTERP_CONFIGURE_FLAGS = \
--cache-file=$(TOP)/sdks/builds/wasm-interp.config.cache \
--prefix=$(TOP)/sdks/out/wasm-interp \
--enable-wasm \
--enable-interpreter \
--disable-mcs-build \
--disable-nls \
--disable-boehm \
--disable-btls \
--with-lazy-gc-thread-creation=yes \
--with-libgc=none \
--disable-executables \
--disable-support-build \
--disable-visibility-hidden \
--enable-minimal=ssa,com,jit,reflection_emit_save,reflection_emit,portability,assembly_remapping,attach,verifier,full_messages,appdomains,security,sgen_remset,sgen_marksweep_par,sgen_marksweep_fixed,sgen_marksweep_fixed_par,sgen_copying,logging,remoting,shared_perfcounters \
--host=i386-apple-darwin10

#toolchain code
.stamp-wasm-toolchain:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have a wasm while all other targets are wasm-interp?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cuz the other wasm targets require their own toolchains.

git clone https://github.com/juj/emsdk.git $(TOP)/sdks/builds/toolchains/emsdk
cd $(TOP)/sdks/builds/toolchains/emsdk && ./emsdk install latest && ./emsdk activate --embedded latest
touch $@

.stamp-wasm-interp-toolchain: .stamp-wasm-toolchain
touch $@

#configure step
.stamp-wasm-interp-configure: $(TOP)/configure .stamp-wasm-interp-toolchain
mkdir -p $(TOP)/sdks/builds/wasm-interp
cd $(TOP)/sdks/builds/wasm-interp && source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && CFLAGS="-Os -g" emconfigure $(TOP)/configure $(WASM_INTERP_CONFIGURE_FLAGS)
touch $@

package-wasm-interp:
$(MAKE) -C $(TOP)/sdks/builds/wasm-interp/mono install


#custom build rule
CUSTOM_BUILD_TARGETS += build-wasm-interp
build-wasm-interp: .stamp-wasm-interp-configure
source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && make -C wasm-interp



.PHONY: clean-wasm-interp clean-wasm
clean-wasm::
rm -rf .stamp-wasm-toolchain
clean-wasm-interp:: clean-wasm
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please unify both wasm-interp and wasm targets as there is no apparent reason to have wasm

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a reason for this.
There are 4 more runtime configs coming down the line: mini aot/runtime, llvm aot/runtime.

This is the only one ready for merging and I feel like keeping the bits for the others made sense.

rm -rf .stamp-wasm-configure $(TOP)/sdks/builds/toolchains/emcc $(TOP)/sdks/builds/wasm $$(TOP)/sdks/builds/wasm.config.cache

TARGETS += wasm-interp



91 changes: 91 additions & 0 deletions sdks/wasm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
TOP=$(realpath $(CURDIR)/../..)
include $(TOP)/sdks/paths.mk

EMCC=source $(TOP)/sdks/builds/toolchains/emsdk/emsdk_env.sh && emcc
D8=$(TOP)/sdks/wasm/v8/out.gn/x64.release/d8
WASM_BCL_DIR=$(TOP)/sdks/out/bcl/wasm
MANAGED_DEPLOY_DIR=$(TOP)/sdks/wasm/managed
MINI_PATH=$(TOP)/mono/mini

BCL_ASSEMBLIES= \
mscorlib.dll \
System.dll \
System.Core.dll

DEPS_ASSEMBLIES= \
nunitlite.dll

MINI_TEST_FILES= \
TestDriver.cs \
aot-tests.cs \
arrays.cs \
basic-calls.cs \
basic-float.cs \
basic-long.cs \
basic-math.cs \
basic.cs \
exceptions.cs \
generics.cs \
gshared.cs \
objects.cs \
builtin-types.cs \
devirtualization.cs \
mixed.cs \
gc-test.cs


BCL_INPUT_ASM = $(patsubst %,$(WASM_BCL_DIR)/%,$(BCL_ASSEMBLIES))
BCL_OUTPUT_ASM = $(patsubst %,$(MANAGED_DEPLOY_DIR)/%,$(BCL_ASSEMBLIES))
DEPS_FILES = $(patsubst %,$(MANAGED_DEPLOY_DIR)/%,$(DEPS_ASSEMBLIES))

MINI_TEST_SOURCES= $(patsubst %,$(MINI_PATH)/%,$(MINI_TEST_FILES))
MINI_TEST_DEPS= $(patsubst %,-r:%,$(BCL_OUTPUT_ASM) $(DEPS_FILES))

.stamp-depot-tools:
git clone https://chromium.googlesource.com/chromium/tools/depot_tools.git depot_tools
touch $@

.stamp-v8: .stamp-depot-tools
PATH=$(TOP)/sdks/wasm/depot_tools:$$PATH fetch v8
cd v8 && tools/dev/v8gen.py x64.release
cd v8 && $(TOP)/sdks/wasm/depot_tools/ninja -C out.gn/x64.release
touch $@

.PHONY: toolchain
toolchain: .stamp-v8

driver.o: driver.c
$(EMCC) -g -Os -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s TOTAL_MEMORY=134217728 -s ALIASING_FUNCTION_POINTERS=0 driver.c -c -o driver.o

mono.js: driver.o library_mono.js $(TOP)/sdks/out/wasm-interp/lib/libmonosgen-2.0.a
$(EMCC) -g4 -Os -s WASM=1 -s ALLOW_MEMORY_GROWTH=1 -s BINARYEN=1 -s "BINARYEN_TRAP_MODE='clamp'" -s TOTAL_MEMORY=134217728 -s ALIASING_FUNCTION_POINTERS=0 --js-library library_mono.js driver.o $(TOP)/sdks/out/wasm-interp/lib/libmonosgen-2.0.a -o mono.js

build-native: mono.js

#FIXME some Make magic here would be appreciated
.stamp-copy-bcl: $(TOP)/sdks/wasm/managed $(BCL_INPUT_ASM)
mkdir -p managed/
cp $(BCL_INPUT_ASM) managed/
touch $@

managed/main.exe: main.cs .stamp-copy-bcl managed/nunitlite.dll
mcs /nostdlib /unsafe main.cs -r:managed/nunitlite.dll $(MINI_TEST_DEPS) -out:managed/main.exe

managed/mini_tests.dll: $(MINI_TEST_SOURCES) mini-test-runner.cs .stamp-copy-bcl managed/nunitlite.dll
mcs /nostdlib /unsafe -target:library -out:managed/mini_tests.dll -define:__MOBILE__,ARCH_32 $(MINI_TEST_DEPS) $(MINI_TEST_SOURCES) mini-test-runner.cs

managed/nunitlite.dll: $(TOP)/mcs/class/lib/wasm/nunitlite.dll
cd $(TOP)/mcs/tools/nunit-lite && make PROFILE=wasm
cp $< $@

build-managed: .stamp-copy-bcl managed/nunitlite.dll managed/mini_tests.dll managed/main.exe

build: build-native build-managed


run: toolchain build
$(D8) --expose_wasm test.js

clean:

package:
Loading