-
Notifications
You must be signed in to change notification settings - Fork 870
[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
Changes from all commits
cd82e88
80912ea
bb0a426
159e2e8
45ea874
f0c48b8
4c211be
3975f2e
8975a7b
98dde46
5020033
c5c3950
f9ace05
de23e81
9237b84
fcb31bc
8cc4d19
d1ec005
981ddfd
5f5a222
8d3d7a3
d637cd5
922981b
c51b74c
da0e3ff
36b7a0f
9bc016b
4887576
ef97bde
f53fdd6
8a006ce
377043e
714aaea
69769c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would hope these are not needed, and we don't try to use the same compile flags for building binaryen itself as the generated C source code. i.e. those two sets of flags should probably not be related.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These flags aren't used for building the generated C source code, but they are used for building the wasm-rt C runtime library. I added this because I couldn't find any other way to get the clang-tidy pass to treat this as C code rather than C++ code (the file extension notwithstanding). If you have a better idea, I'm happy to change this!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. i'm kind of tempted to say that the wasm-rt C runtime library should also be built with the same flags that the generated code (i.e. not these flags), but whatever works best I guess |
||
|
|
||
| if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") | ||
| # Google style requires this, so make sure we compile cleanly with it. | ||
|
|
||
| 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(): | ||
|
lexi-nadia marked this conversation as resolved.
|
||
| 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() | ||
|
lexi-nadia marked this conversation as resolved.
|
| 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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This this file was not actually added in this PR it seem to include this here.
BTW, the
*.cmakeline above seems odd.. does the in-tree build really make files with the.cmakeextension?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this file, and the generation step, in favor of just checking in the "prebuilt" files. I forgot to remove this from .gitignore, though. :( I'll remove it in my next PR (or I can send a one-line PR to remove it, if you'd prefer?).