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

Allow bison parsers to be generated as libraries #3259

Merged
merged 20 commits into from
Apr 13, 2023

Conversation

Baltoli
Copy link
Contributor

@Baltoli Baltoli commented Mar 20, 2023

Fixes #3258

This PR is related to my ongoing work towards documenting "K as a library" (i.e. using the LLVM backend to generate libraries users can use to build their own tools, rather than relying on the K scripts to run their programs. One missing link in the existing toolchain that I identified was generating KORE from a surface program; doing so currently would require the user to shell out to one of the bison-generated parsers. This PR makes a small improvement to that workflow by allowing the bison parsers to be generated as shared libraries rather than as executables; the parser libraries can then be shipped alongside the C bindings libraries for user definitions.

After this PR, users will be able to run something like:

$ kompile test.k -v             \
  --gen-glr-bison-parser        \
  --bison-parser-library        \
  --llvm-kompile-type c         \
  --llvm-kompile-output libfoo.so

to generate a pair of shared libraries (libfoo.so, libparse_KItem_TEST.so) that provide an LLVM backend runtime and GLR Bison parser, respectively. These can then be embedded into an application.

The changes in this PR are as follows:

  • Update the Bison wrapper code to use a similar "file or buffer" abstraction to the LLVM backend's writer type; this lets us output to a file directly as before for best performance, but also to keep the parsed KORE in memory if required.
  • Add some preprocessor definitions that create a function char *parse_SORT(...) as well as the existing bison main entrypoint.
  • Add frontend flags that generate the library following the syntax above.
  • Add a custom integration test that links a small application against a generated parser and calls it in library mode.

@rv-jenkins rv-jenkins changed the base branch from master to develop March 20, 2023 17:29
@Baltoli Baltoli force-pushed the bison-parser-library branch from 525bb35 to 588890f Compare March 21, 2023 09:36
@Baltoli Baltoli force-pushed the bison-parser-library branch from a944fd9 to 4fa4cbe Compare March 22, 2023 10:04
Baltoli and others added 12 commits March 22, 2023 10:06
* llvm-backend/src/main/native/llvm-backend: f137e48 - Run on ephemeral runner (#709)

* Sync flake inputs to submodules

* llvm-backend/src/main/native/llvm-backend: 39a9043 - Write initial documentation for "backend as a library" (#707)

* Sync flake inputs to submodules

* llvm-backend/src/main/native/llvm-backend: e29384e - Duplicate dependabot PR #687 (#706)

* Sync flake inputs to submodules

* Update Nix lock files

---------

Co-authored-by: rv-jenkins <devops@runtimeverification.com>
Co-authored-by: Bruce Collie <brucecollie82@gmail.com>
@Baltoli Baltoli force-pushed the bison-parser-library branch from 4fa4cbe to 305d03b Compare March 22, 2023 10:07
@Baltoli Baltoli marked this pull request as ready for review March 22, 2023 10:26
@dwightguth
Copy link
Collaborator

I'd like to review this, but I might not get to it until next week. Is this blocking anything currently?

@Baltoli
Copy link
Contributor Author

Baltoli commented Mar 22, 2023

I'd like to review this, but I might not get to it until next week. Is this blocking anything currently?

No, I'm only using it in the context of my own work on a blog post; I'm using kup overrides to point the project at branches so there's absolutely no rush at all to review. Enjoy your week!

Copy link
Contributor

@radumereuta radumereuta left a comment

Choose a reason for hiding this comment

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

A few questions.
Java part looks fine.
The C part I'm not that familiar with.

@Baltoli Baltoli requested a review from dwightguth April 11, 2023 13:48
Copy link
Collaborator

@theo25 theo25 left a comment

Choose a reason for hiding this comment

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

I went over the C code and the regression test and it all looks good to me.

@rv-jenkins rv-jenkins merged commit ce5d3ce into develop Apr 13, 2023
@rv-jenkins rv-jenkins deleted the bison-parser-library branch April 13, 2023 18:03
rv-jenkins pushed a commit to runtimeverification/pyk that referenced this pull request Apr 18, 2023
This PR threads the new options from
runtimeverification/k#3259 through `kbuild` and
`Kompile`.

---------

Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
@Baltoli Baltoli mentioned this pull request Dec 12, 2023
Baltoli added a commit that referenced this pull request Apr 9, 2024
This PR threads the new options from
#3259 through `kbuild` and
`Kompile`.

---------

Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
Baltoli added a commit that referenced this pull request Apr 9, 2024
This PR threads the new options from
#3259 through `kbuild` and
`Kompile`.

---------

Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
Baltoli added a commit that referenced this pull request Apr 9, 2024
This PR threads the new options from
#3259 through `kbuild` and
`Kompile`.

---------

Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
Baltoli added a commit that referenced this pull request Apr 10, 2024
This PR threads the new options from
#3259 through `kbuild` and
`Kompile`.

---------

Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
Baltoli added a commit that referenced this pull request Apr 10, 2024
This PR threads the new options from
#3259 through `kbuild` and
`Kompile`.

---------

Co-authored-by: devops <devops@runtimeverification.com>
Co-authored-by: Tamás Tóth <tothtamas28@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generate Bison parser libraries
5 participants