From 34d1bf415e9de5053f5f546c153438811e41fa2d Mon Sep 17 00:00:00 2001 From: Erin Date: Wed, 14 Feb 2024 01:25:44 +0100 Subject: [PATCH] Don't fail to compile on unsupported architectures --- hbvm/src/float/mod.rs | 26 ++++++++++++++++++++------ hbvm/src/float/unsupported.rs | 16 ++++++++++++++++ hbvm/src/lib.rs | 2 ++ hbxrt/src/main.rs | 11 +++++++++++ 4 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 hbvm/src/float/unsupported.rs diff --git a/hbvm/src/float/mod.rs b/hbvm/src/float/mod.rs index f8b3ea6..5206f70 100644 --- a/hbvm/src/float/mod.rs +++ b/hbvm/src/float/mod.rs @@ -1,13 +1,27 @@ macro_rules! arch_specific { { $({$($cfg:tt)*} : $mod:ident;)* - } => {$( - #[cfg($($cfg)*)] - mod $mod; + } => { + $( + #[cfg($($cfg)*)] + mod $mod; - #[cfg($($cfg)*)] - pub use $mod::*; - )*}; + #[cfg($($cfg)*)] + pub use $mod::*; + + #[cfg($($cfg)*)] + pub const FL_ARCH_SPECIFIC_SUPPORTED: bool = true; + )* + + #[cfg(not(any($($($cfg)*),*)))] + mod unsupported; + + #[cfg(not(any($($($cfg)*),*)))] + pub use unsupported::*; + + #[cfg(not(any($($($cfg)*),*)))] + pub const FL_ARCH_SPECIFIC_SUPPORTED: bool = false; + }; } arch_specific! { diff --git a/hbvm/src/float/unsupported.rs b/hbvm/src/float/unsupported.rs new file mode 100644 index 0000000..8befdd9 --- /dev/null +++ b/hbvm/src/float/unsupported.rs @@ -0,0 +1,16 @@ +use hbbytecode::RoundingMode; + +#[inline(always)] +pub fn conv64to32(_: f64, _: RoundingMode) -> f32 { + f32::NAN +} + +#[inline(always)] +pub fn f32toint(_: f32, _: RoundingMode) -> i64 { + i64::MAX +} + +#[inline(always)] +pub fn f64toint(_: f64, _: RoundingMode) -> i64 { + i64::MAX +} diff --git a/hbvm/src/lib.rs b/hbvm/src/lib.rs index e16c318..33a9fe2 100644 --- a/hbvm/src/lib.rs +++ b/hbvm/src/lib.rs @@ -25,6 +25,8 @@ mod float; mod utils; mod vmrun; +pub use float::FL_ARCH_SPECIFIC_SUPPORTED; + use { bmc::BlockCopier, mem::{Address, Memory}, diff --git a/hbxrt/src/main.rs b/hbxrt/src/main.rs index 93a037f..156cb25 100644 --- a/hbxrt/src/main.rs +++ b/hbxrt/src/main.rs @@ -14,6 +14,17 @@ fn main() -> Result<(), Box> { eprintln!("== HBĂ—RT (Holey Bytes Experimental Runtime) v0.1 =="); eprintln!("[W] Currently supporting only flat images"); + if !hbvm::FL_ARCH_SPECIFIC_SUPPORTED { + eprintln!( + "\ + [W] Architecture not fully supported!\n \ + FTI32, FTI64 will yield {:#x}\n \ + FC64T32 will yield NaN\ + ", + i64::MAX, + ) + } + let mut args = args().skip(1); let Some(image_path) = args.next() else { eprintln!("[E] Missing image path");