rahulchaphalkar opened PR #10918 from rahulchaphalkar:custom-print to bytecodealliance:main:
This PR implements custom print logic for
lockinstruction, and reworks the existing logic forcustom_visitto be more in the form of.custom(Visit | Display). Thecustom_visitlogic was originally implemented in https://github.com/bytecodealliance/wasmtime/pull/10887 and the changes are made based on some of these comments https://github.com/bytecodealliance/wasmtime/pull/10887#discussion_r2121785272The
Displaylogic will be used for compare instructions as well.
@abrown
rahulchaphalkar requested fitzgen for a review on PR #10918.
rahulchaphalkar requested wasmtime-compiler-reviewers for a review on PR #10918.
abrown requested abrown for a review on PR #10918.
abrown submitted PR review:
I think the important bits are mostly here, most of the comments below are smaller Rust issues. The one real issue here is _where_ we put the logic... see below.
abrown created PR review comment:
Encode,We don't need
Nonehere becauseCustomcan be empty.
abrown created PR review comment:
pub struct Custom(Vec<CustomOperation>);No need for this to be
pubif you haveiterbelow.
abrown created PR review comment:
/// Indicate this instruction as needing custom processing.
abrown created PR review comment:
if !custom.is_empty() { write!(f, " custom({custom})")?; }Since we already have
Displayimplemented forCustom.
abrown created PR review comment:
custom: Custom::default(),We could
#[derive(Default)]to create the empty set or we could create aCustom::empty() -> Selffunction if we want to be more clear.
abrown created PR review comment:
mod custom;No need to publicize this; we re-publish the types we want to be public in the
pub use custom::...below.
abrown created PR review comment:
These might not be needed ever, but probably aren't used now (?). Can we remove them?
abrown created PR review comment:
As mentioned above, this should move to
cranelift_assembler_x64::custom::display. And, just likevisit, we will (1) want to have a function for each instruction that needs the custom display logic and (2) pass through the whole instruction, in case we need more information in the future:pub mod display { pub fn lock_addb(inst: &lock_addb) -> String { ... } pub fn lock_addw(inst: &lock_addw) -> String { ... } ... pub fn lock_subb(inst: &lock_subb) -> String { ... } pub fn lock_subw(inst: &lock_subw) -> String { ... } ... }Two thoughts about this:
- this could be quite repetitive so we might want to use a macro
- eventually we probably want the signature(&<inst>) -> Stringto be a bit more expansive, i.e., to return the entire display string and not just the altered mnemonic, but this is probably OK for now.
abrown created PR review comment:
/// Whether or not this instruction uses custom, external functions /// instead of Rust code generated by this crate.
abrown created PR review comment:
mod custom;?
abrown created PR review comment:
We don't want any implementation of the actual custom functions to live in this crate; we want them to live in the parent crate,
cranelift-assembler-x64, in thecustommodule. So thatcustommodule, which you modified to contain avisitsub-module, should also contain adisplaysub-module and eventually anencodemodule, once we need it.
abrown created PR review comment:
This should look more like the logic with
visitabove: if we have a customdisplayfunction, then we emit something like:fmtln!(f, "let inst_name = crate::custom::display::{}(self)", self.name());And then, in this case, we would use
inst_namelater in the generated code instead of the already-knowninst_namewe have here.
abrown created PR review comment:
use crate::{Fixed, Gpr, GprMem, RegisterVisitor, Registers, gpr};
rahulchaphalkar updated PR #10918.
rahulchaphalkar commented on PR #10918:
Ready for review, addressed feedback
abrown submitted PR review:
Thanks! This looks good. I'll put this in the merge queue but if @alexcrichton has any further suggestions we could follow this up in the
comparePR.
alexcrichton submitted PR review.
abrown merged PR #10918.
Last updated: Dec 06 2025 at 07:03 UTC