Skip to content

Commit 7988682

Browse files
committed
Merge branch '4598' into improve_remove
2 parents 0da2d8c + 483087c commit 7988682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+8482
-638
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ if(EMSCRIPTEN)
405405
target_link_libraries(binaryen_wasm "-s NODERAWFS=0")
406406
target_link_libraries(binaryen_wasm "-s EXPORT_NAME=Binaryen")
407407
target_link_libraries(binaryen_wasm "-s EXPORT_ES6=1")
408+
target_link_libraries(binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=allocate")
408409
target_link_libraries(binaryen_wasm "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
409410
target_link_libraries(binaryen_wasm "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-extern-pre.js")
410411
target_link_libraries(binaryen_wasm optimized "--closure 1")
@@ -439,6 +440,7 @@ if(EMSCRIPTEN)
439440
else()
440441
target_link_libraries(binaryen_js "-s EXPORT_ES6=1")
441442
endif()
443+
target_link_libraries(binaryen_js "-sEXPORTED_RUNTIME_METHODS=allocate")
442444
target_link_libraries(binaryen_js "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
443445
# js_of_ocaml needs a specified variable with special comment to provide the library to consumers
444446
if(JS_OF_OCAML)

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,10 @@ The `check.py` script supports some options:
561561
tool cannot be found, and you'll see a warning.
562562
* We have tests from upstream in `tests/spec`, in git submodules. Running
563563
`./check.py` should update those.
564+
565+
Note that we are trying to gradually port the legacy wasm-opt tests to use `lit` and `filecheck` as we modify them.
566+
For `passes` tests that output wast, this can be done automatically with `scripts/port_passes_tests_to_lit.py` and for non-`passes` tests that output wast, see
567+
https://github.com/WebAssembly/binaryen/pull/4779 for an example of how to do a simple manual port.
564568

565569
### Setting up dependencies
566570

scripts/fuzz_opt.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,18 @@ def is_git_repo():
263263
# not all relaxed SIMD instructions are implemented in the interpreter
264264
'relaxed-simd.wast',
265265
# TODO fuzzer and interpreter support for strings
266-
'strings.wast'
266+
'strings.wast',
267+
# ignore DWARF because it is incompatible with multivalue atm
268+
'zlib.wasm',
269+
'cubescript.wasm',
270+
'class_with_dwarf_noprint.wasm',
271+
'fib2_dwarf.wasm',
272+
'fib_nonzero-low-pc_dwarf.wasm',
273+
'inlined_to_start_dwarf.wasm',
274+
'fannkuch3_manyopts_dwarf.wasm',
275+
'fib2_emptylocspan_dwarf.wasm',
276+
'fannkuch3_dwarf.wasm',
277+
'multi_unit_abbrev_noprint.wasm',
267278
]
268279

269280

@@ -350,9 +361,6 @@ def pick_initial_contents():
350361
# )
351362
# )
352363
'--disable-multivalue',
353-
# DWARF is incompatible with multivalue atm; it's more important to
354-
# fuzz multivalue since we aren't actually fuzzing DWARF here
355-
'--strip-dwarf',
356364
]
357365

358366
# the given wasm may not work with the chosen feature opts. for example, if
@@ -823,8 +831,8 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
823831
b1 = open('b1.wasm', 'rb').read()
824832
b2 = open('b2.wasm', 'rb').read()
825833
if (b1 != b2):
826-
run([in_bin('wasm-dis'), 'b1.wasm', '-o', 'b1.wat', FEATURE_OPTS])
827-
run([in_bin('wasm-dis'), 'b2.wasm', '-o', 'b2.wat', FEATURE_OPTS])
834+
run([in_bin('wasm-dis'), 'b1.wasm', '-o', 'b1.wat'] + FEATURE_OPTS)
835+
run([in_bin('wasm-dis'), 'b2.wasm', '-o', 'b2.wat'] + FEATURE_OPTS)
828836
t1 = open('b1.wat', 'r').read()
829837
t2 = open('b2.wat', 'r').read()
830838
compare(t1, t2, 'Output must be deterministic.', verbose=False)

scripts/gen-s-parser.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,13 @@
617617
("string.new_wtf8", "makeStringNew(s, StringNewWTF8)"),
618618
("string.new_wtf16", "makeStringNew(s, StringNewWTF16)"),
619619
("string.const", "makeStringConst(s)"),
620+
("string.measure_wtf8", "makeStringMeasure(s, StringMeasureWTF8)"),
621+
("string.measure_wtf16", "makeStringMeasure(s, StringMeasureWTF16)"),
622+
("string.is_usv_sequence", "makeStringMeasure(s, StringMeasureIsUSV)"),
623+
("string.encode_wtf8", "makeStringEncode(s, StringEncodeWTF8)"),
624+
("string.encode_wtf16", "makeStringEncode(s, StringEncodeWTF16)"),
625+
("string.concat", "makeStringConcat(s)"),
626+
("string.eq", "makeStringEq(s)"),
620627
]
621628

622629

@@ -686,7 +693,7 @@ def insert(self, inst, expr):
686693
self.do_insert(inst, inst, expr)
687694

688695

689-
def instruction_parser():
696+
def instruction_parser(new_parser=False):
690697
"""Build a trie out of all the instructions, then emit it as C++ code."""
691698
trie = Node()
692699
inst_length = 0
@@ -696,12 +703,23 @@ def instruction_parser():
696703

697704
printer = CodePrinter()
698705

699-
printer.print_line("char op[{}] = {{'\\0'}};".format(inst_length + 1))
700-
printer.print_line("strncpy(op, s[0]->c_str(), {});".format(inst_length))
706+
if not new_parser:
707+
printer.print_line("char op[{}] = {{'\\0'}};".format(inst_length + 1))
708+
printer.print_line("strncpy(op, s[0]->c_str(), {});".format(inst_length))
701709

702710
def print_leaf(expr, inst):
703-
printer.print_line("if (strcmp(op, \"{inst}\") == 0) {{ return {expr}; }}"
704-
.format(inst=inst, expr=expr))
711+
if new_parser:
712+
expr = expr.replace("()", "(ctx)")
713+
expr = expr.replace("(s", "(ctx, in")
714+
printer.print_line("if (op == \"{inst}\"sv) {{".format(inst=inst))
715+
with printer.indent():
716+
printer.print_line("auto ret = {expr};".format(expr=expr))
717+
printer.print_line("CHECK_ERR(ret);")
718+
printer.print_line("return *ret;")
719+
printer.print_line("}")
720+
else:
721+
printer.print_line("if (strcmp(op, \"{inst}\") == 0) {{ return {expr}; }}"
722+
.format(inst=inst, expr=expr))
705723
printer.print_line("goto parse_error;")
706724

707725
def emit(node, idx=0):
@@ -730,7 +748,10 @@ def emit(node, idx=0):
730748
emit(trie)
731749
printer.print_line("parse_error:")
732750
with printer.indent():
733-
printer.print_line("throw ParseException(std::string(op), s.line, s.col);")
751+
if new_parser:
752+
printer.print_line("return in.err(\"unrecognized instruction\");")
753+
else:
754+
printer.print_line("throw ParseException(std::string(op), s.line, s.col);")
734755

735756

736757
def print_header():
@@ -756,6 +777,8 @@ def main():
756777
sys.exit(1)
757778
print_header()
758779
generate_with_guard(instruction_parser, "INSTRUCTION_PARSER")
780+
print()
781+
generate_with_guard(lambda: instruction_parser(True), "NEW_INSTRUCTION_PARSER")
759782
print_footer()
760783

761784

scripts/update_lit_checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
ALL_ITEMS = '|'.join(['type', 'import', 'global', 'memory', 'data', 'table',
4141
'elem', 'tag', 'export', 'start', 'func'])
4242
ITEM_NAME = r'\$?[^\s()]*|"[^\s()]*"'
43-
ITEM_RE = re.compile(r'(^\s*)\((' + ALL_ITEMS + r')\s+(' + ITEM_NAME + ').*$',
43+
ITEM_RE = re.compile(r'(?:^\s*\(rec\s*)?(^\s*)\((' + ALL_ITEMS + r')\s+(' + ITEM_NAME + ').*$',
4444
re.MULTILINE)
4545

4646
FUZZ_EXEC_FUNC = re.compile(r'^\[fuzz-exec\] calling (?P<name>\S*)$')

0 commit comments

Comments
 (0)