Skip to content

Support IBI variation in Ocaml offline backend - #149

Merged
katrinafyi merged 10 commits into
partial_evalfrom
ocamlibi
May 28, 2026
Merged

Support IBI variation in Ocaml offline backend#149
katrinafyi merged 10 commits into
partial_evalfrom
ocamlibi

Conversation

@katrinafyi

Copy link
Copy Markdown
Member

Uses first-class modules in all the instruction class lifting functions. The generated files now look something like this:

(* AUTO-GENERATED LIFTER FILE *)

open Instruction_building_interface

let f_aarch64_integer_arithmetic_add_sub_carry (type bitvector) (module I : IBI with type bitvector = bitvector) (v_enc : bitvector) : unit = 
  if I.f_eq_bits (I.bigint_of_string "32") (I.f_and_bits (I.bigint_of_string "32") (v_enc) (I.from_bitsLit "10000000000000000000000000000000")) (I.from_bitsLit "10000000000000000000000000000000") then begin

This allows for parametrisation without module functors, as described in https://ocaml.org/manual/5.4/firstclassmodules.html#p:fst-mod-advexamples

The implementation is what you'd expect, with a bunch of work to define the IBI and distinguish IBI functions from instruction class functions. This is because we have to use I.f_functionname when calling IBI functions and we have to propagate the (module I) when calling instruction class functions (though, maybe this could be avoided with an open....)

In doing so, we are able to make ASLp an optional dependency of the offline lifter package - it's only needed if you want to use the ASL IBI, otherwise you can BYO.

@agle agle left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

very cool, a completely normal and expectable set of changes. lmk if you want me to handle pushing the opam package when you're done

Comment thread libASL/ocaml_backend.ml

let write_epilogue use_pc fid st =
let conv_pc = "let pc = (mkBits (Z.of_int 64) (Z.of_int pc)) in" in
let conv_pc = "let pc = (I.mkBits (I.bigint_of_int 64) (I.bigint_of_int pc)) in" in

@agle agle May 28, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This is the only reason to for constraining Asl_ibi.bitvector = Primops.bitvector right? Could just shove the conversion in the IBI too, or take a bv and make the caller do it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I changed it so this function is only generated in the ASL instantiation of the IBI. I can rename it to make it more obvious.

extract ibi names dynamically
fix offline_coverage reference and make asli optional dependency
use offlineASL_runner module directly
add stateful reset_ir and get_ir functions
@katrinafyi
katrinafyi enabled auto-merge (squash) May 28, 2026 03:33
@katrinafyi
katrinafyi merged commit fcbf7ac into partial_eval May 28, 2026
5 checks passed
@katrinafyi katrinafyi linked an issue May 28, 2026 that may be closed by this pull request
@katrinafyi

Copy link
Copy Markdown
Member Author

Oh yeah if you can do the opam stuff that would be really good, thanks

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.

offline lifter ocaml IBI interface

2 participants