Does anyone by chance remember how to get an instance of cranelift_codegen::isa::x86::settings::Flags
and not cranelift_codegen::settings::Flags
? I want to use the ISA-specific one that's already configured by CLIF flags, e.g., without building a new instance of it.
It seems to be stored in cranelift_codegen::isa::x86::Isa.isa_flags
:
https://docs.rs/cranelift-codegen/0.63.0/src/cranelift_codegen/isa/x86/mod.rs.html#33
Good find; I guess I'll have to do some casting or something...
I guess it's going to be unsafe but what is the "right" way to do this? I tried let x86_isa = &*(isa as *const isa::x86::Isa)
but that doesn't work because isa
is &dyn TargetIsa
I get: casting &dyn isa::TargetIsa
as *const isa::x86::Isa
is invalid
@Andrew Brown in general that's not a safe thing to do in Rust
you can get away with it though by doing &*(ptr as *const dyn A as *const B)
:+1: I figured
the other "trick" is to add fn as_any(&self) -> &dyn Any;
to the trait
What is the better way?
and then you'd call ptr.as_any().downcast_ref::<B>().unwrap()
which would be a safe assertion of the type
Yeah, I was looking into Any::downcast_ref
... is this a preferable way to do things?
yeah for dynamic type downcasting it's through Any
Ok, I'll do that then; thanks!
Last updated: Nov 22 2024 at 16:03 UTC