Skip to content

Autogenerate boilerplate code for expressions from a single tool #3264

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

Closed
wants to merge 82 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
d389a79
start somewhere
kripken Oct 15, 2020
14fb194
Revert "start somewhere"
kripken Oct 15, 2020
cce4360
start again
kripken Oct 15, 2020
fb0f2c4
work
kripken Oct 15, 2020
61f616a
start
kripken Oct 15, 2020
c918c5b
flake8
kripken Oct 15, 2020
1763960
more
kripken Oct 15, 2020
e8a2977
work
kripken Oct 15, 2020
3d38c15
work
kripken Oct 15, 2020
0e32bba
work
kripken Oct 15, 2020
1401e6a
work
kripken Oct 15, 2020
9664d82
work
kripken Oct 15, 2020
292da6f
work
kripken Oct 15, 2020
8d8ad96
work
kripken Oct 15, 2020
3bc9756
work
kripken Oct 15, 2020
367bb3a
work
kripken Oct 15, 2020
834ccd5
work
kripken Oct 15, 2020
ef59766
work
kripken Oct 16, 2020
4bc793d
work
kripken Oct 16, 2020
aefd373
work
kripken Oct 16, 2020
058958c
work
kripken Oct 16, 2020
2b3768b
work
kripken Oct 16, 2020
c33f8b7
work
kripken Oct 16, 2020
b0c30cc
work
kripken Oct 16, 2020
b46965f
work
kripken Oct 16, 2020
7ee2561
work
kripken Oct 16, 2020
3e2535b
work
kripken Oct 16, 2020
fd4ebb5
work
kripken Oct 16, 2020
1a40bbe
work
kripken Oct 16, 2020
652b184
work
kripken Oct 16, 2020
e0b63af
work
kripken Oct 16, 2020
b784418
work
kripken Oct 16, 2020
0438666
work
kripken Oct 16, 2020
a7a20f7
autoyear
kripken Oct 17, 2020
b23dde7
render only when needed
kripken Oct 17, 2020
f824c4b
fix return
kripken Oct 17, 2020
79ee0e1
fixes
kripken Oct 17, 2020
fd2b93c
format
kripken Oct 17, 2020
fd83d58
refactor
kripken Oct 17, 2020
352ea44
refactor
kripken Oct 17, 2020
cf98f2d
more
kripken Oct 17, 2020
ae3d510
fix
kripken Oct 17, 2020
f7342fb
work
kripken Oct 17, 2020
d766753
work
kripken Oct 17, 2020
2c72f72
refactor
kripken Oct 17, 2020
03fede8
refactor
kripken Oct 17, 2020
fe1249b
refactor
kripken Oct 17, 2020
3578e2b
work
kripken Oct 17, 2020
d3b9d3f
work
kripken Oct 17, 2020
c96d692
work
kripken Oct 17, 2020
8c98c56
work
kripken Oct 17, 2020
505fe7a
Merge remote-tracking branch 'origin/master' into gen
kripken Oct 17, 2020
d92bf85
start to compare expers
kripken Oct 17, 2020
d7ad65d
work
kripken Oct 17, 2020
bd0e527
fix
kripken Oct 18, 2020
75c8046
fix
kripken Oct 18, 2020
526e555
compiles
kripken Oct 18, 2020
41592f4
fix
kripken Oct 18, 2020
24e9dde
fixes
kripken Oct 18, 2020
d5ada9c
fix
kripken Oct 18, 2020
117a3a8
fix
kripken Oct 18, 2020
ba43591
fix
kripken Oct 18, 2020
f70c22a
Comment. speedup on code-folding is 1% time, 9% instrs
kripken Oct 18, 2020
1f6ed71
cmake?
kripken Oct 18, 2020
be2c2de
Revert "cmake?"
kripken Oct 18, 2020
f533ac2
more
kripken Oct 18, 2020
3cacc36
nicer
kripken Oct 18, 2020
5e99b49
nicer
kripken Oct 18, 2020
eb92572
nicer
kripken Oct 18, 2020
362cab0
clang format on the handwritten code...
kripken Oct 19, 2020
fe099f4
Simplify method declaractions - use a simple array of strings as sugg…
kripken Oct 19, 2020
73bc61d
verify on CI that gen-exprs was run
kripken Oct 19, 2020
1272905
fake change
kripken Oct 19, 2020
12e70a5
fix
kripken Oct 19, 2020
431de9d
cmake integration
kripken Oct 18, 2020
cc83ed7
fix
kripken Oct 22, 2020
e9ee12b
If clang-format is not present, skip it
kripken Oct 23, 2020
8de6c45
Merge remote-tracking branch 'origin/master' into gen2
kripken Oct 23, 2020
4ac589d
Add new SIMDLoadStoreLane
kripken Oct 23, 2020
4cb47e4
Merge remote-tracking branch 'origin/gen2' into gen2
kripken Oct 23, 2020
99360d5
Fix for the case where clang-format is missing
kripken Oct 23, 2020
8601f35
try to support windows
kripken Oct 23, 2020
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
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ jobs:
./scripts/clang-tidy-diff.sh
- name: gen-s-parser
run: ./scripts/gen-s-parser.py | diff src/gen-s-parser.inc -
- name: gen-exprs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If our CMake code is correct, it shouldn't be necessary to run these steps before CMake time, should it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I guess running the script is redundant here, I didn't realize that.

But thinking on it, I do still want to run it, just to avoid the risk of a future change in the other tests from affecting this. By running the script explicitly, we get a full self-contained test on one line here.

run: ./scripts/gen-exprs.py && git diff --exit-code src/

build:
name: build
Expand Down
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,13 @@ IF(BUILD_LLVM_DWARF)
SET(binaryen_objs ${binaryen_objs} $<TARGET_OBJECTS:llvm_dwarf>)
ENDIF()

# Code generation.

add_custom_target(gen_exprs ALL
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like you should just be able to use add_custom_command (using OUTPUT instead of BYPRODUCTS, and gen-exprs.py as the MAIN_DEPENDENCY), and then it wouldn't have to run everytime. Also the targets that depend on its output could just depend on whatever file they use, instead of this target. And you could remove the special no-change logic from the script itself.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that path earlier, but failed. The problem I ran into is that this tool emits .h files, and CMake doesn't track dependencies on them the way it does for other things. (Maybe related to that in CMake a C++ file doesn't write out which headers it depends on?)

I'm not an expert on how CMake works, but I spent a bunch of time on this and did quite a bit of searching for an example of how to do it (there are plenty of examples for generating a source file, but not a header), but came up empty.. 😞

COMMAND ${PROJECT_SOURCE_DIR}/scripts/gen-exprs
BYPRODUCTS src/wasm-expressions.generated.h src/ir/compare-expressions.generated.h
)

# Sources.

file(GLOB binaryen_HEADERS src/*.h)
Expand All @@ -310,6 +317,7 @@ install(TARGETS binaryen
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
add_dependencies(binaryen gen_exprs)

install(FILES src/binaryen-c.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

Expand All @@ -321,6 +329,7 @@ function(binaryen_add_executable name sources)
set_property(TARGET ${name} PROPERTY CXX_STANDARD_REQUIRED ON)
binaryen_setup_rpath(${name})
install(TARGETS ${name} DESTINATION ${CMAKE_INSTALL_BINDIR})
add_dependencies(${name} gen_exprs)
endfunction()

binaryen_add_executable(wasm-opt src/tools/wasm-opt.cpp)
Expand Down Expand Up @@ -363,6 +372,7 @@ if(EMSCRIPTEN)
set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD ${CXX_STANDARD})
set_property(TARGET binaryen_wasm PROPERTY CXX_STANDARD_REQUIRED ON)
install(TARGETS binaryen_wasm DESTINATION ${CMAKE_INSTALL_BINDIR})
add_dependencies(binaryen_wasm gen_exprs)

# binaryen.js JavaScript variant
add_executable(binaryen_js
Expand All @@ -388,4 +398,5 @@ if(EMSCRIPTEN)
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD ${CXX_STANDARD})
set_property(TARGET binaryen_js PROPERTY CXX_STANDARD_REQUIRED ON)
install(TARGETS binaryen_js DESTINATION ${CMAKE_INSTALL_BINDIR})
add_dependencies(binaryen_js gen_exprs)
endif()
35 changes: 35 additions & 0 deletions scripts/gen-exprs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
#
# Copyright 2020 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.
#
# Entry point for running gen-exprs.py, which requires python 3.
#

if [ -z "$PYTHON" ]; then
PYTHON=$(which python3 2> /dev/null)
fi

if [ -z "$PYTHON" ]; then
PYTHON=$(which python 2> /dev/null)
fi

if [ -z "$PYTHON" ]; then
echo 'unable to find python in $PATH'
exit 1
fi

DIR=`dirname "$0"`

exec "$PYTHON" "$DIR/gen-exprs.py"
8 changes: 8 additions & 0 deletions scripts/gen-exprs.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@echo off
:: Entry point for running gen-exprs.py on windows systems.

if "%PYTHON%"=="" (
set PYTHON=python
)

"%PYTHON%" "%~dp0\%~n0.py" %*
Loading