Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
cd82e88
Import various wasm2c test and support files from wabt.
lexi-nadia May 14, 2026
80912ea
import simde from https://github.com/simd-everywhere/simde
lexi-nadia May 15, 2026
bb0a426
Import picosha2
lexi-nadia May 19, 2026
159e2e8
[wasm2c] Add the rules to build the prebuilt files from the associate…
lexi-nadia May 21, 2026
45ea874
checkpoint
lexi-nadia May 21, 2026
f0c48b8
checkpoint 2
lexi-nadia May 22, 2026
4c211be
checkpoint
lexi-nadia May 22, 2026
3975f2e
Merge branch 'WebAssembly:main' into main
lexi-nadia May 22, 2026
8975a7b
Merge branch 'WebAssembly:main' into main
lexi-nadia May 26, 2026
98dde46
incorporate PR feedback from tlively
lexi-nadia May 26, 2026
5020033
Merge branch 'main' of github.com:lexi-nadia/binaryen
lexi-nadia May 26, 2026
c5c3950
Move gen-wasm2c-templates.cmake to src/tools/wasm2c.
lexi-nadia May 26, 2026
f9ace05
remove examples
lexi-nadia May 26, 2026
de23e81
update header guards and include files
lexi-nadia May 26, 2026
9237b84
remove an unused passOptions
lexi-nadia May 26, 2026
fcb31bc
don't run any spec tests yet
lexi-nadia May 26, 2026
8cc4d19
don't use CHECK-NEXT as the first line of a lit test
lexi-nadia May 27, 2026
d1ec005
remove an unneeded file
lexi-nadia Jun 23, 2026
981ddfd
Merge branch 'WebAssembly:main' into main
lexi-nadia Jun 23, 2026
5f5a222
update flags to support an older version of filecheck
lexi-nadia Jun 23, 2026
8d3d7a3
Merge branch 'main' of github.com:lexi-nadia/binaryen
lexi-nadia Jun 23, 2026
d637cd5
Merge branch 'WebAssembly:main' into main
lexi-nadia Jul 23, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ options-pinned.h
# files related to building in-tree
CMakeFiles
*.cmake
!src/tools/wasm2c/gen-wasm2c-templates.cmake
/CMakeCache.txt
/Makefile
/*.ninja
Expand Down
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
[submodule "third_party/mimalloc"]
path = third_party/mimalloc
url = https://github.com/microsoft/mimalloc.git
[submodule "third_party/simde"]
path = third_party/simde
url = https://github.com/simd-everywhere/simde
[submodule "third_party/picosha2"]
path = third_party/picosha2
url = https://github.com/okdshin/PicoSHA2
3 changes: 2 additions & 1 deletion check.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from multiprocessing.pool import ThreadPool
from pathlib import Path

from scripts.test import binaryenjs, finalize, shared, support, wasm2js, wasm_opt
from scripts.test import binaryenjs, finalize, shared, support, wasm2js, wasm2c, wasm_opt
from scripts.test.shared import print_heading

assert sys.version_info >= (3, 10), 'requires Python 3.10'
Expand Down Expand Up @@ -442,6 +442,7 @@ def wrapper(*args, **kwargs):
'spec': run_spec_tests,
'finalize': finalize.test_wasm_emscripten_finalize,
'wasm2js': wasm2js.test_wasm2js,
'wasm2c-spec': wasm2c.test_wasm2c_spec,
'validator': run_validator_tests,
'example': run_example_tests,
'unit': run_unittest,
Expand Down
1 change: 1 addition & 0 deletions scripts/test/shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ def is_exe(fpath):
WASM_AS = [os.path.join(options.binaryen_bin, 'wasm-as')]
WASM_DIS = [os.path.join(options.binaryen_bin, 'wasm-dis')]
WASM2JS = [os.path.join(options.binaryen_bin, 'wasm2js')]
WASM2C = [os.path.join(options.binaryen_bin, 'wasm2c')]
WASM_CTOR_EVAL = [os.path.join(options.binaryen_bin, 'wasm-ctor-eval')]
WASM_SHELL = [os.path.join(options.binaryen_bin, 'wasm-shell')]
WASM_REDUCE = [os.path.join(options.binaryen_bin, 'wasm-reduce')]
Expand Down
67 changes: 67 additions & 0 deletions scripts/test/wasm2c.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2026 WebAssembly Community Group participants
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import pathlib
import subprocess
import tempfile

from . import shared, support
from .shared import print_heading

spec_tests = [
]

def test_wasm2c_spec_output():
for t in shared.options.spec_tests:
test_path = pathlib.Path(t)
if test_path.name not in spec_tests:
continue

print('..', test_path.name)

is_fail_test = '.fail' in test_path.name

test_subdir = f'wasm2c_spec_{test_path.stem}'
test_subdir_path = pathlib.Path(test_subdir)
test_subdir_path.mkdir(exist_ok=True)

wasm2c_cmd = [shared.WASM2C[0], t, '-o', f'{test_subdir}/{test_path.stem}.c', '--allow-asserts']
support.run_command(wasm2c_cmd, expected_status = (1 if is_fail_test else 0))

c_sources = sorted(test_subdir_path.glob('*.c'))

wasm_rt_dir = pathlib.Path(shared.options.binaryen_root) / 'src' / 'tools' / 'wasm2c' / 'wasm-rt'
c_sources.append(wasm_rt_dir / 'wasm-rt-impl.c')
c_sources.append(wasm_rt_dir / 'wasm-rt-mem-impl.c')
c_sources.append(wasm_rt_dir / 'wasm-rt-exceptions-impl.c')

compile_cmd = [shared.NATIVECC, '-O2', '-std=c11', '-D_GNU_SOURCE', '-D_DEFAULT_SOURCE', '-I.', f"-I{wasm_rt_dir}"] + [str(s) for s in c_sources] + ['-o', f'{test_subdir}/spec_test_runner']

compile_cmd += ['-fno-optimize-sibling-calls', '-frounding-math']
if 'gcc' in shared.NATIVECC.lower():
compile_cmd.append('-fsignaling-nans')

compile_cmd.append('-lm')
compile_cmd.append('-lpthread')

support.run_command(compile_cmd)

# Run spec test runner binary and assert success
support.run_command([f'{test_subdir}/spec_test_runner'])

def test_wasm2c_spec():
print_heading('checking wasm2c spec testcases...')
if shared.skip_if_on_windows('wasm2c-spec'):
return
test_wasm2c_spec_output()
1 change: 1 addition & 0 deletions src/tools/CMakeLists.txt
Comment thread
lexi-nadia marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ set(fuzzing_SOURCES
binaryen_add_executable(wasm-opt "${fuzzing_SOURCES};wasm-opt.cpp")
binaryen_add_executable(wasm-metadce wasm-metadce.cpp)
binaryen_add_executable(wasm2js wasm2js.cpp)
add_subdirectory(wasm2c)
binaryen_add_executable(wasm-emscripten-finalize wasm-emscripten-finalize.cpp)
binaryen_add_executable(wasm-as wasm-as.cpp)
binaryen_add_executable(wasm-dis wasm-dis.cpp)
Expand Down
43 changes: 43 additions & 0 deletions src/tools/wasm2c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
set(TEMPLATE_CMAKE ${CMAKE_CURRENT_SOURCE_DIR}/gen-wasm2c-templates.cmake)
set(TEMPLATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/templates)
set(PREBUILT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/prebuilt)

add_custom_command(
OUTPUT ${PREBUILT_DIR}/wasm2c_header_top.cpp
${PREBUILT_DIR}/wasm2c_header_bottom.cpp
${PREBUILT_DIR}/wasm2c_source_includes.cpp
${PREBUILT_DIR}/wasm2c_source_declarations.cpp
${PREBUILT_DIR}/wasm2c_simd_source_declarations.cpp
${PREBUILT_DIR}/wasm2c_atomicops_source_declarations.cpp
${PREBUILT_DIR}/wasm2c_spec_top.cpp

COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_header_top.cpp" -D in="${TEMPLATE_DIR}/wasm2c.top.h" -D symbol="HeaderTop" -P ${TEMPLATE_CMAKE}
COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_header_bottom.cpp" -D in="${TEMPLATE_DIR}/wasm2c.bottom.h" -D symbol="HeaderBottom" -P ${TEMPLATE_CMAKE}
COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_source_includes.cpp" -D in="${TEMPLATE_DIR}/wasm2c.includes.c" -D symbol="SourceIncludes" -P ${TEMPLATE_CMAKE}
COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_source_declarations.cpp" -D in="${TEMPLATE_DIR}/wasm2c.declarations.c" -D symbol="SourceDeclarations" -P ${TEMPLATE_CMAKE}
COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_simd_source_declarations.cpp" -D in="${TEMPLATE_DIR}/wasm2c_simd.declarations.c" -D symbol="SimdSourceDeclarations" -P ${TEMPLATE_CMAKE}
COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_atomicops_source_declarations.cpp" -D in="${TEMPLATE_DIR}/wasm2c_atomicops.declarations.c" -D symbol="AtomicsOpsSourceDeclarations" -P ${TEMPLATE_CMAKE}
COMMAND ${CMAKE_COMMAND} -D out="${PREBUILT_DIR}/wasm2c_spec_top.cpp" -D in="${TEMPLATE_DIR}/wasm2c_spec.top.c" -D symbol="SpecTop" -P ${TEMPLATE_CMAKE}

DEPENDS ${TEMPLATE_DIR}/wasm2c.top.h
${TEMPLATE_DIR}/wasm2c.bottom.h
${TEMPLATE_DIR}/wasm2c.includes.c
${TEMPLATE_DIR}/wasm2c.declarations.c
${TEMPLATE_DIR}/wasm2c_simd.declarations.c
${TEMPLATE_DIR}/wasm2c_atomicops.declarations.c
${TEMPLATE_DIR}/wasm2c_spec.top.c
)

set(WASM2C_GENERATED_SOURCES
${PREBUILT_DIR}/wasm2c_header_top.cpp
${PREBUILT_DIR}/wasm2c_header_bottom.cpp
${PREBUILT_DIR}/wasm2c_source_includes.cpp
${PREBUILT_DIR}/wasm2c_source_declarations.cpp
${PREBUILT_DIR}/wasm2c_simd_source_declarations.cpp
${PREBUILT_DIR}/wasm2c_atomicops_source_declarations.cpp
${PREBUILT_DIR}/wasm2c_spec_top.cpp
)

binaryen_add_executable(wasm2c "wasm2c-builder.cpp;assertion-emitter.cpp;wasm2c.cpp;${WASM2C_GENERATED_SOURCES}")
# TODO: https://github.com/WebAssembly/binaryen/issues/8775 - stop using picosha2
target_include_directories(wasm2c PRIVATE ${PROJECT_SOURCE_DIR}/third_party/picosha2 ${PROJECT_SOURCE_DIR}/src/tools/wasm2c)
Loading