Skip to content

Commit

Permalink
Merge pull request #6 from dhil/wasmfx
Browse files Browse the repository at this point in the history
Merge with WebAssembly/spec
  • Loading branch information
dhil authored Sep 19, 2023
2 parents 74a3ed3 + 0cfa5a5 commit 42228fb
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 59 deletions.
2 changes: 1 addition & 1 deletion document/core/syntax/instructions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ It is guaranteed that no sequence of nested calls using only these instructions
Expressions
~~~~~~~~~~~

:ref:`Function <syntax-func>` bodies, initialization values for :ref:`globals <syntax-global>`, and offsets of :ref:`element <syntax-elem>` or :ref:`data <syntax-data>` segments are given as expressions, which are sequences of :ref:`instructions <syntax-instr>` terminated by an |END| marker.
:ref:`Function <syntax-func>` bodies, initialization values for :ref:`globals <syntax-global>`, elements and offsets of :ref:`element <syntax-elem>` segments, and offsets of :ref:`data <syntax-data>` segments are given as expressions, which are sequences of :ref:`instructions <syntax-instr>` terminated by an |END| marker.

.. math::
\begin{array}{llll}
Expand Down
113 changes: 62 additions & 51 deletions interpreter/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This Makefile uses dune but does not rely on ocamlfind or the Opam
# package manager to build. However, Opam package management is available
# optionally through the check/install/uninstall targets.
# optionally through the install target.
#
# The $(JSLIB).js target requires Js_of_ocaml (using ocamlfind).
#
Expand All @@ -9,80 +9,90 @@

# Configuration

NAME = wasm
OPT = $(NAME).exe
ZIP = $(NAME).zip
NAME = wasm
LIB = $(NAME)
JSLIB = wast.js
ZIP = $(NAME).zip

BUILDDIR = _build/default
BUILDDIR = _build/default

JS = # set to JS shell command to run JS tests, empty to skip


# Main targets

.PHONY: default opt jslib all zip smallint
.PHONY: default all ci jslib zip

default: $(NAME)
all: default partest
ci: all jslib zip

default: $(OPT)
jslib: $(JSLIB)
all: $(OPT) test
zip: $(ZIP)
smallint: smallint.exe
ci: all jslib

# Building executable
.PHONY: $(NAME).exe
$(NAME).exe:
rm -f $(NAME)
dune build $@
cp $(BUILDDIR)/$(OPT) $(NAME)

.PHONY: smallint.exe
smallint.exe:
dune build $@
# Building

$(NAME):
rm -f $@
dune build $@.exe
ln $(BUILDDIR)/$@.exe $@

$(JSLIB):
rm -f $@
dune build $(@:%.js=%.bc.js)
ln $(BUILDDIR)/$(@:%.js=%.bc.js) $@


# Unit tests

UNITTESTDIR = unittest
UNITTESTFILES = $(shell cd $(UNITTESTDIR); ls *.ml)
UNITTESTS = $(UNITTESTFILES:%.ml=%)

# Building JavaScript library
.PHONY: unittest

$(JSLIB): $(BUILDDIR)/$(JSLIB)
cp $< $@
unittest: $(UNITTESTS:%=unittest/%)

$(BUILDDIR)/$(JSLIB):
dune build $(JSLIB)
unittest/%:
dune build $(@F).exe
dune exec ./$(@F).exe

# Executing test suite

# Test suite

TESTDIR = ../test/core
# Skip _output directory, since that's a tmp directory, and list all other wast files.
TESTFILES = $(shell cd $(TESTDIR); ls *.wast; ls [a-z]*/*.wast)
TESTS = $(TESTFILES:%.wast=%)

.PHONY: test partest dune-test
.PHONY: test partest quiettest

test: $(NAME) unittest
$(TESTDIR)/run.py --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',)

test: $(OPT) smallint
$(TESTDIR)/run.py --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',)
dune exec ./smallint.exe
test/%: $(NAME)
$(TESTDIR)/run.py --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast

test/%: $(OPT)
$(TESTDIR)/run.py --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast
run/%: $(NAME)
./$(NAME) $(TESTDIR)/$*.wast

run/%: $(OPT)
./$(OPT) $(TESTDIR)/$*.wast
partest: $(NAME)
make -j10 quiettest

partest: $(TESTS:%=quiettest/%)
@echo All tests passed.
quiettest: $(TESTS:%=quiettest/%)
@echo All tests passed.

quiettest/%: $(OPT)
@ ( \
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(BUILDDIR)/$(OPT) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
rm $(@F).out \
) || \
cat $(@F).out || rm $(@F).out || exit 1
quiettest/%: $(NAME)
@ ( \
$(TESTDIR)/run.py 2>$(@F).out --wasm `pwd`/$(NAME) $(if $(JS),--js '$(JS)',) $(TESTDIR)/$*.wast && \
rm $(@F).out \
) || \
(cat $(@F).out && rm $(@F).out && exit 1)

smallinttest: smallint
dune exec ./smallint.exe

dunetest:
dune test
# Packaging

.PHONY: install

install:
dune build -p $(NAME) @install
Expand All @@ -101,15 +111,16 @@ opam-release/%:
rm opam-$*.zip
@echo Created file ./opam, submit to github opam-repository/packages/wasm/wasm.$*/opam

# Miscellaneous targets

.PHONY: clean

$(ZIP):
git archive --format=zip --prefix=$(NAME)/ -o $@ HEAD


# Cleanup

.PHONY: clean distclean

clean:
dune clean

distclean: clean
rm -f $(NAME) $(JSLIB)
rm -f $(NAME) $(JSLIB) $(ZIP)
5 changes: 0 additions & 5 deletions interpreter/dune
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,6 @@
(deps main/main.ml)
(action (copy main/main.ml wasm.ml)))

(rule
(targets wast.js)
(deps wast.bc.js)
(action (copy wast.bc.js wast.js)))

(subdir
text
(rule
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions test/core/unreachable.wast
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
(func $dummy3 (param i32 i32 i32))

(func (export "type-i32") (result i32) (unreachable))
(func (export "type-i64") (result i32) (unreachable))
(func (export "type-f32") (result f64) (unreachable))
(func (export "type-i64") (result i64) (unreachable))
(func (export "type-f32") (result f32) (unreachable))
(func (export "type-f64") (result f64) (unreachable))

(func (export "as-func-first") (result i32)
Expand Down

0 comments on commit 42228fb

Please sign in to comment.