Skip to content

Commit

Permalink
Merge branch '4598' into improve_remove
Browse files Browse the repository at this point in the history
  • Loading branch information
aheejin committed Jul 12, 2022
2 parents 0da2d8c + 483087c commit 7988682
Show file tree
Hide file tree
Showing 43 changed files with 8,482 additions and 638 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -405,6 +405,7 @@ if(EMSCRIPTEN)
target_link_libraries(binaryen_wasm "-s NODERAWFS=0")
target_link_libraries(binaryen_wasm "-s EXPORT_NAME=Binaryen")
target_link_libraries(binaryen_wasm "-s EXPORT_ES6=1")
target_link_libraries(binaryen_wasm "-sEXPORTED_RUNTIME_METHODS=allocate")
target_link_libraries(binaryen_wasm "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
target_link_libraries(binaryen_wasm "--extern-pre-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-extern-pre.js")
target_link_libraries(binaryen_wasm optimized "--closure 1")
Expand Down Expand Up @@ -439,6 +440,7 @@ if(EMSCRIPTEN)
else()
target_link_libraries(binaryen_js "-s EXPORT_ES6=1")
endif()
target_link_libraries(binaryen_js "-sEXPORTED_RUNTIME_METHODS=allocate")
target_link_libraries(binaryen_js "--post-js ${CMAKE_CURRENT_SOURCE_DIR}/src/js/binaryen.js-post.js")
# js_of_ocaml needs a specified variable with special comment to provide the library to consumers
if(JS_OF_OCAML)
Expand Down
4 changes: 4 additions & 0 deletions README.md
Expand Up @@ -561,6 +561,10 @@ The `check.py` script supports some options:
tool cannot be found, and you'll see a warning.
* We have tests from upstream in `tests/spec`, in git submodules. Running
`./check.py` should update those.

Note that we are trying to gradually port the legacy wasm-opt tests to use `lit` and `filecheck` as we modify them.
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
https://github.com/WebAssembly/binaryen/pull/4779 for an example of how to do a simple manual port.

### Setting up dependencies

Expand Down
20 changes: 14 additions & 6 deletions scripts/fuzz_opt.py
Expand Up @@ -263,7 +263,18 @@ def is_git_repo():
# not all relaxed SIMD instructions are implemented in the interpreter
'relaxed-simd.wast',
# TODO fuzzer and interpreter support for strings
'strings.wast'
'strings.wast',
# ignore DWARF because it is incompatible with multivalue atm
'zlib.wasm',
'cubescript.wasm',
'class_with_dwarf_noprint.wasm',
'fib2_dwarf.wasm',
'fib_nonzero-low-pc_dwarf.wasm',
'inlined_to_start_dwarf.wasm',
'fannkuch3_manyopts_dwarf.wasm',
'fib2_emptylocspan_dwarf.wasm',
'fannkuch3_dwarf.wasm',
'multi_unit_abbrev_noprint.wasm',
]


Expand Down Expand Up @@ -350,9 +361,6 @@ def pick_initial_contents():
# )
# )
'--disable-multivalue',
# DWARF is incompatible with multivalue atm; it's more important to
# fuzz multivalue since we aren't actually fuzzing DWARF here
'--strip-dwarf',
]

# the given wasm may not work with the chosen feature opts. for example, if
Expand Down Expand Up @@ -823,8 +831,8 @@ def handle_pair(self, input, before_wasm, after_wasm, opts):
b1 = open('b1.wasm', 'rb').read()
b2 = open('b2.wasm', 'rb').read()
if (b1 != b2):
run([in_bin('wasm-dis'), 'b1.wasm', '-o', 'b1.wat', FEATURE_OPTS])
run([in_bin('wasm-dis'), 'b2.wasm', '-o', 'b2.wat', FEATURE_OPTS])
run([in_bin('wasm-dis'), 'b1.wasm', '-o', 'b1.wat'] + FEATURE_OPTS)
run([in_bin('wasm-dis'), 'b2.wasm', '-o', 'b2.wat'] + FEATURE_OPTS)
t1 = open('b1.wat', 'r').read()
t2 = open('b2.wat', 'r').read()
compare(t1, t2, 'Output must be deterministic.', verbose=False)
Expand Down
35 changes: 29 additions & 6 deletions scripts/gen-s-parser.py
Expand Up @@ -617,6 +617,13 @@
("string.new_wtf8", "makeStringNew(s, StringNewWTF8)"),
("string.new_wtf16", "makeStringNew(s, StringNewWTF16)"),
("string.const", "makeStringConst(s)"),
("string.measure_wtf8", "makeStringMeasure(s, StringMeasureWTF8)"),
("string.measure_wtf16", "makeStringMeasure(s, StringMeasureWTF16)"),
("string.is_usv_sequence", "makeStringMeasure(s, StringMeasureIsUSV)"),
("string.encode_wtf8", "makeStringEncode(s, StringEncodeWTF8)"),
("string.encode_wtf16", "makeStringEncode(s, StringEncodeWTF16)"),
("string.concat", "makeStringConcat(s)"),
("string.eq", "makeStringEq(s)"),
]


Expand Down Expand Up @@ -686,7 +693,7 @@ def insert(self, inst, expr):
self.do_insert(inst, inst, expr)


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

printer = CodePrinter()

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

def print_leaf(expr, inst):
printer.print_line("if (strcmp(op, \"{inst}\") == 0) {{ return {expr}; }}"
.format(inst=inst, expr=expr))
if new_parser:
expr = expr.replace("()", "(ctx)")
expr = expr.replace("(s", "(ctx, in")
printer.print_line("if (op == \"{inst}\"sv) {{".format(inst=inst))
with printer.indent():
printer.print_line("auto ret = {expr};".format(expr=expr))
printer.print_line("CHECK_ERR(ret);")
printer.print_line("return *ret;")
printer.print_line("}")
else:
printer.print_line("if (strcmp(op, \"{inst}\") == 0) {{ return {expr}; }}"
.format(inst=inst, expr=expr))
printer.print_line("goto parse_error;")

def emit(node, idx=0):
Expand Down Expand Up @@ -730,7 +748,10 @@ def emit(node, idx=0):
emit(trie)
printer.print_line("parse_error:")
with printer.indent():
printer.print_line("throw ParseException(std::string(op), s.line, s.col);")
if new_parser:
printer.print_line("return in.err(\"unrecognized instruction\");")
else:
printer.print_line("throw ParseException(std::string(op), s.line, s.col);")


def print_header():
Expand All @@ -756,6 +777,8 @@ def main():
sys.exit(1)
print_header()
generate_with_guard(instruction_parser, "INSTRUCTION_PARSER")
print()
generate_with_guard(lambda: instruction_parser(True), "NEW_INSTRUCTION_PARSER")
print_footer()


Expand Down
2 changes: 1 addition & 1 deletion scripts/update_lit_checks.py
Expand Up @@ -40,7 +40,7 @@
ALL_ITEMS = '|'.join(['type', 'import', 'global', 'memory', 'data', 'table',
'elem', 'tag', 'export', 'start', 'func'])
ITEM_NAME = r'\$?[^\s()]*|"[^\s()]*"'
ITEM_RE = re.compile(r'(^\s*)\((' + ALL_ITEMS + r')\s+(' + ITEM_NAME + ').*$',
ITEM_RE = re.compile(r'(?:^\s*\(rec\s*)?(^\s*)\((' + ALL_ITEMS + r')\s+(' + ITEM_NAME + ').*$',
re.MULTILINE)

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

0 comments on commit 7988682

Please sign in to comment.