-
Notifications
You must be signed in to change notification settings - Fork 859
[wasm2c] Add the very beginning of a wasm2c implementation and test harness #8763
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
Draft
lexi-nadia
wants to merge
16
commits into
WebAssembly:main
Choose a base branch
from
lexi-nadia:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
cd82e88
Import various wasm2c test and support files from wabt.
lexi-nadia 80912ea
import simde from https://github.com/simd-everywhere/simde
lexi-nadia bb0a426
Import picosha2
lexi-nadia 159e2e8
[wasm2c] Add the rules to build the prebuilt files from the associate…
lexi-nadia 45ea874
checkpoint
lexi-nadia f0c48b8
checkpoint 2
lexi-nadia 4c211be
checkpoint
lexi-nadia 3975f2e
Merge branch 'WebAssembly:main' into main
lexi-nadia 8975a7b
Merge branch 'WebAssembly:main' into main
lexi-nadia 98dde46
incorporate PR feedback from tlively
lexi-nadia 5020033
Merge branch 'main' of github.com:lexi-nadia/binaryen
lexi-nadia c5c3950
Move gen-wasm2c-templates.cmake to src/tools/wasm2c.
lexi-nadia f9ace05
remove examples
lexi-nadia de23e81
update header guards and include files
lexi-nadia 9237b84
remove an unused passOptions
lexi-nadia fcb31bc
don't run any spec tests yet
lexi-nadia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.