This is an archive of the discontinued LLVM Phabricator instance.

[WebAssembly] made assembler parse block_type
ClosedPublic

Authored by aardappel on Dec 26 2018, 2:26 PM.

Details

Summary

This was previously ignored and an incorrect value generated.

Also fixed Disassembler's handling of block_type.

Diff Detail

Repository
rL LLVM

Event Timeline

aardappel created this revision.Dec 26 2018, 2:26 PM

Note to reviewers: I can fix the FIXME in the disassembler by making it a proper SLEB, and change the WebAssembly::ExprType enum to have negative values as per the spec. I think that should have little impact as the backend treats these values as opaque, afaik.. though maybe I am missing something. Happy to put that in this CL or a next one.

aheejin added a comment.EditedJan 1 2019, 11:04 PM

Note to reviewers: I can fix the FIXME in the disassembler by making it a proper SLEB, and change the WebAssembly::ExprType enum to have negative values as per the spec. I think that should have little impact as the backend treats these values as opaque, afaik.. though maybe I am missing something. Happy to put that in this CL or a next one.

I think there's a discrepancy between what the github binary encoding doc says and what the official spec says. The official spec lists them explicitly as single byte values and not LEB, and I think we should follow the official spec. Actually, they had been listed as signed values but were changed to single byte values earlier this year by these CLs (D43921, D43922, and D43991).

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
303 ↗(On Diff #179526)

Nit: id should be Id or ID, according to the LLVM coding style

463 ↗(On Diff #179526)

When do we need this Parser.Lex() and when we don't? This exists only in if (ExpectBlockType) side, so I'm curious.

522 ↗(On Diff #179526)

It looks like we assume no signature as void, but all lines in the test case now have type signatures. Can we also have block/loop/try with no signatures?

lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
176 ↗(On Diff #179526)

This sentence sounds weird... perhaps a stray 'that'?

lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
350 ↗(On Diff #179526)

What is the difference between anyfunc and func?
Anyway, the current spec says [[ https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#block_type | block_type ]] should be either one of [[ https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#value_type | value_type ]] s or void, so I think that means anyfunc or func should not be allowed as a block type. [[ https://github.com/WebAssembly/exception-handling/blob/master/proposals/Exceptions.md#value_type | except_ref should be allowed ]] as a value type for the EH proposal though.

aardappel updated this revision to Diff 179912.Jan 2 2019, 12:08 PM
aardappel marked 9 inline comments as done.

Addressed code review.

@aheejin thanks for pointing out the spec discrepancy, I've now made the disassembler explicitly parse a byte instead of a SLEB for consistency.

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
463 ↗(On Diff #179526)

You call it whenever you consume a token (it advances to the next token). In the else branch parsePrimaryExpr calls it for us.

522 ↗(On Diff #179526)

I was originally going to require explicitly writing void, but the existing code (printWebAssemblySignatureOperand) wasn't printing it, so I decided to follow that.

lib/Target/WebAssembly/Disassembler/WebAssemblyDisassembler.cpp
176 ↗(On Diff #179526)

That comments is incorrect anyway, removed.

lib/Target/WebAssembly/MCTargetDesc/WebAssemblyMCTargetDesc.h
350 ↗(On Diff #179526)

Got that from https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#language-types

Ok, will disable them in the assembler block_type parsing. Will leave them in the enum, since they are part of the set of types we have, and if anyone refers to them it will likely be through this enum.

aardappel updated this revision to Diff 179940.Jan 2 2019, 1:57 PM

Ok, decided keeping func/anyfunc out of the enum was cleaner,
as we already have a lot of duplicate enums for subsets of types.

aheejin accepted this revision.Jan 2 2019, 3:17 PM

LGTM with a nit.

lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
522 ↗(On Diff #179526)

Yes I agree that we should be able to omit void. What I was suggesting was maybe we could add lines that omit void in the test case too.

This revision is now accepted and ready to land.Jan 2 2019, 3:17 PM
aardappel marked an inline comment as done.Jan 2 2019, 3:23 PM
aardappel added inline comments.
lib/Target/WebAssembly/AsmParser/WebAssemblyAsmParser.cpp
522 ↗(On Diff #179526)

There is such a case:
if # void

This revision was automatically updated to reflect the committed changes.