Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 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
922981b
Disable --strict-whitespace
lexi-nadia Jul 28, 2026
c51b74c
Merge branch 'main' of github.com:lexi-nadia/binaryen
lexi-nadia Jul 28, 2026
da0e3ff
Use filecheck without -D, since the filecheck that binaryen uses does…
lexi-nadia Jul 29, 2026
36b7a0f
Fix lint errors
lexi-nadia Jul 29, 2026
9bc016b
Stop generating the source files - just use raw string literals
lexi-nadia Jul 29, 2026
4887576
Update formatting
lexi-nadia Jul 29, 2026
ef97bde
Use braces around an if-statement body
lexi-nadia Jul 29, 2026
f53fdd6
Try really hard to get clang-tidy to treat the wasm-rt files as C, no…
lexi-nadia Jul 29, 2026
8a006ce
Remove two unintended line breaks in templates
lexi-nadia Jul 29, 2026
377043e
Set two warning flags as C++-only
lexi-nadia Jul 29, 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
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ else() # MSVC
add_compile_flag("-Wno-unknown-warning-option")
add_compile_flag("-Wswitch") # we explicitly expect this in the code
add_compile_flag("-Wimplicit-fallthrough")
add_compile_flag("-Wnon-virtual-dtor")
add_compile_flag("-Wsuggest-override")
add_compile_flag("-Wnon-virtual-dtor" "CXX_ONLY")
add_compile_flag("-Wsuggest-override" "CXX_ONLY")

if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Google style requires this, so make sure we compile cleanly with it.
Expand Down
11 changes: 10 additions & 1 deletion check.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@
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,
wasm2c,
wasm2js,
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 +450,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

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
40 changes: 40 additions & 0 deletions src/tools/wasm2c/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
set(PREBUILT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/prebuilt)
set(WASM_RT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/wasm-rt)

set(WASM2C_TEMPLATE_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_TEMPLATE_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)

set(WASM_RT_SOURCES
${WASM_RT_DIR}/wasm-rt-exceptions-impl.c
${WASM_RT_DIR}/wasm-rt-impl.c
${WASM_RT_DIR}/wasm-rt-mem-impl.c
)

set(WASM_RT_INCLUDES
${WASM_RT_DIR}/wasm-rt-exceptions.h
${WASM_RT_DIR}/wasm-rt.h
${WASM_RT_DIR}/wasm-rt-impl.h
${WASM_RT_DIR}/wasm-rt-impl-tableops.inc
${WASM_RT_DIR}/wasm-rt-mem-impl-helper.inc
)

set_source_files_properties(${WASM_RT_SOURCES}
PROPERTIES LANGUAGE C
)

set_source_files_properties(${WASM_RT_INCLUDES}
PROPERTIES LANGUAGE C
)

add_library(wasm-rt ${WASM_RT_SOURCES})
Loading
Loading