Stream: cranelift

Topic: ISA-specific flags


view this post on Zulip Andrew Brown (May 20 2020 at 23:02):

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.

view this post on Zulip bjorn3 (May 21 2020 at 12:44):

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

view this post on Zulip Andrew Brown (May 21 2020 at 15:45):

Good find; I guess I'll have to do some casting or something...

view this post on Zulip Andrew Brown (May 21 2020 at 17:41):

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

view this post on Zulip Andrew Brown (May 21 2020 at 17:42):

I get: casting &dyn isa::TargetIsa as *const isa::x86::Isa is invalid

view this post on Zulip Alex Crichton (May 21 2020 at 18:37):

@Andrew Brown in general that's not a safe thing to do in Rust

view this post on Zulip Alex Crichton (May 21 2020 at 18:37):

you can get away with it though by doing &*(ptr as *const dyn A as *const B)

view this post on Zulip Andrew Brown (May 21 2020 at 18:37):

:+1: I figured

view this post on Zulip Alex Crichton (May 21 2020 at 18:37):

the other "trick" is to add fn as_any(&self) -> &dyn Any; to the trait

view this post on Zulip Andrew Brown (May 21 2020 at 18:37):

What is the better way?

view this post on Zulip Alex Crichton (May 21 2020 at 18:37):

and then you'd call ptr.as_any().downcast_ref::<B>().unwrap()

view this post on Zulip Alex Crichton (May 21 2020 at 18:38):

which would be a safe assertion of the type

view this post on Zulip Andrew Brown (May 21 2020 at 18:38):

Yeah, I was looking into Any::downcast_ref... is this a preferable way to do things?

view this post on Zulip Alex Crichton (May 21 2020 at 18:39):

yeah for dynamic type downcasting it's through Any

view this post on Zulip Andrew Brown (May 21 2020 at 18:39):

Ok, I'll do that then; thanks!


Last updated: Dec 23 2024 at 12:05 UTC