Skip to content
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

Output structured data format based on wasm-delegations.def #6460

Open
phated opened this issue Apr 1, 2024 · 1 comment · May be fixed by #6469
Open

Output structured data format based on wasm-delegations.def #6460

phated opened this issue Apr 1, 2024 · 1 comment · May be fixed by #6469

Comments

@phated
Copy link
Contributor

phated commented Apr 1, 2024

Based on #6225 (reply in thread)

Currently, many Wasm instructions are defined in src/wasm-delegations*.def, which is a C header that Binaryen and tools within Binaryen can use.

This file could also be processed and output as structured data (JSON, YAML, etc) in the build artifacts, which would allow other tools and bindings to consume it for automation.

I'm particular to JSON, but we should see what others would want to consume.

kripken added a commit that referenced this issue Apr 3, 2024
This removes the hard-coded generation of a switch and cases, and allows the user
to define the boilerplate at the start and end of the main output, and of what is
generated for each expression. By default we still emit a switch and cases.

Also standardize the output by never emitting ; unnecessarily, which we were
inconsistent about.

This serves two goals: First, it will make using embind on Binaryen simpler as
embind needs to generate C++ template logic for each expression, and not a
switch (and we cannot have extra ; in embind notation). Second, this makes
the format much simple to parse, which is a stepping stone for #6460, e.g.
before we had

  case Expression::Id::LoopId: {
    DELEGATE_START(Loop);
    DELEGATE_FIELD_CHILD(Loop, body);
    DELEGATE_FIELD_SCOPE_NAME_DEF(Loop, name);
    DELEGATE_END(Loop);
    break;
  }

and now we have

DELEGATE_FIELD_CASE_START(Loop)
DELEGATE_FIELD_CHILD(Loop, body)
DELEGATE_FIELD_SCOPE_NAME_DEF(Loop, name)
DELEGATE_FIELD_CASE_END(Loop)

The main part of this diff was autogenerated by this python:

for l in x.splitlines():
  if l.startswith('  case'):
    id = l.split(':')[4][:-2]
    print(f'DELEGATE_FIELD_CASE_START({id})')
  if l.startswith('    DELEGATE_FIELD'):
    print(l)
  if l.startswith('    DELEGATE_END'):
    id = l[17:-2]
    print(f'DELEGATE_FIELD_CASE_END({id})')
    print()
@kripken
Copy link
Member

kripken commented Apr 3, 2024

I opened #6469 for this, let me know what you think there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants