Skip to content

feat(kframework_ffi): Marshaller for moving rust kore types to the llvm-backend#10

Merged
gtrepta merged 13 commits into
masterfrom
ffi_additions
May 4, 2026
Merged

feat(kframework_ffi): Marshaller for moving rust kore types to the llvm-backend#10
gtrepta merged 13 commits into
masterfrom
ffi_additions

Conversation

@gtrepta
Copy link
Copy Markdown
Contributor

@gtrepta gtrepta commented May 1, 2026

This PR extends the kframework_ffi crate to offer a Marshaller utility that allows converting the rust library's kore representation to the llvm-backend's kore AST.

Changes/Additions

  • Now uses bindgen to generate the llvm-backend's API bindings from its C header file
  • Adds kframework_ffi::kllvm::{Sort, Symbol}, which hold pointers to the llvm-backend's respective representations.
    • A Symbol consists of a symbol name and sort arguments for creating production terms
  • Adds kframework_ffi::kllvm::{Marshaller, MarshalError, VarHandler} (See section below)
  • Changes the fuzzing example in examples/fuzzer to use the Marshaller
  • Makes a few cargo clippy formatting changes

Marshaller


VarHandler trait

The VarHandler can be implemented by the user to provide the marshaller with a way to substitute any variables it encounters in the kore term during its marshalling.

MarshalError

An enum of errors that can happen during marshalling

  • Unsupported: A kore tree node that the llvm-backend's execution engine doesn't support was encountered (ie. an Axiom, or an Exists)
  • UnknownVar: A variable that the marshaller wasn't able to substitute with a term, either because it doesn't have a VarHandler or because the one it has doesn't handle it.
  • Cstring: There was an error when creating a C-string from a rust String. The constructors for the rust types should normally protect against this.

Marshaller

The marshaller can be constructed with an optional VarHandler. You can then call marshal with a kore::Pattern to get a kllvm::Pattern.

It has a set_handler method to change out the variable handler to make repeated calls with different variable substitutions on the term.

It will cache any variable-free subtrees in the term to speed up repeated calls with different handlers. See the doc-strings for more details.

@gtrepta gtrepta marked this pull request as ready for review May 1, 2026 15:07
@gtrepta gtrepta requested a review from tothtamas28 May 1, 2026 15:07
@gtrepta gtrepta merged commit 1e7ee3a into master May 4, 2026
2 checks passed
@gtrepta gtrepta deleted the ffi_additions branch May 4, 2026 15:16
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 this pull request may close these issues.

2 participants