Use the more-asserts crate in more places.
This provides assert_le, assert_lt, and so on, which can print the values of the operands.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#![allow(clippy::float_cmp)]
|
||||
|
||||
use self::registers::*;
|
||||
use crate::error::Error;
|
||||
use crate::microwasm::{BrTarget, Ieee32, Ieee64, SignlessType, Type, Value, F32, F64, I32, I64};
|
||||
use crate::module::ModuleContext;
|
||||
@@ -8,6 +9,7 @@ use dynasm::dynasm;
|
||||
use dynasmrt::x64::Assembler;
|
||||
use dynasmrt::{AssemblyOffset, DynamicLabel, DynasmApi, DynasmLabelApi, ExecutableBuffer};
|
||||
use either::Either;
|
||||
use more_asserts::assert_le;
|
||||
use std::{
|
||||
any::{Any, TypeId},
|
||||
collections::HashMap,
|
||||
@@ -18,8 +20,6 @@ use std::{
|
||||
ops::RangeInclusive,
|
||||
};
|
||||
|
||||
use self::registers::*;
|
||||
|
||||
// TODO: Get rid of this! It's a total hack.
|
||||
mod magic {
|
||||
use cranelift_codegen::ir;
|
||||
@@ -1954,7 +1954,7 @@ macro_rules! store {
|
||||
ctx.block_state.regs.release(src);
|
||||
}
|
||||
|
||||
assert!(offset <= i32::max_value() as u32);
|
||||
assert_le!(offset, i32::max_value() as u32);
|
||||
|
||||
let mut src = self.pop();
|
||||
let base = self.pop();
|
||||
|
||||
@@ -9,6 +9,7 @@ use core::{fmt, mem};
|
||||
use cranelift_codegen::binemit;
|
||||
use dynasmrt::DynasmApi;
|
||||
use either::{Either, Left, Right};
|
||||
use more_asserts::assert_ge;
|
||||
use multi_mut::HashMapMultiMut;
|
||||
use std::{collections::HashMap, hash::Hash};
|
||||
|
||||
@@ -152,26 +153,6 @@ where
|
||||
block.is_next = true;
|
||||
}
|
||||
|
||||
macro_rules! assert_ge {
|
||||
($left:expr, $right:expr) => ({
|
||||
match (&$left, &$right) {
|
||||
(left_val, right_val) => {
|
||||
if !(*left_val >= *right_val) {
|
||||
// The reborrows below are intentional. Without them, the stack slot for the
|
||||
// borrow is initialized even before the values are compared, leading to a
|
||||
// noticeable slow down.
|
||||
panic!(r#"assertion failed: `(left >= right)`
|
||||
left: `{:?}`,
|
||||
right: `{:?}`"#, &*left_val, &*right_val)
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
($left:expr, $right:expr,) => ({
|
||||
assert_ge!($left, $right)
|
||||
});
|
||||
}
|
||||
|
||||
// `cfg` on blocks doesn't work in the compiler right now, so we have to write a dummy macro
|
||||
#[cfg(debug_assertions)]
|
||||
macro_rules! assertions {
|
||||
|
||||
@@ -7,6 +7,7 @@ use cranelift_codegen::{
|
||||
ir::{self, AbiParam, Signature as CraneliftSignature},
|
||||
isa,
|
||||
};
|
||||
use more_asserts::assert_le;
|
||||
use wasmparser::{FuncType, MemoryType, ModuleReader, SectionCode, Type};
|
||||
|
||||
pub trait AsValueType {
|
||||
@@ -554,8 +555,9 @@ pub fn translate_only(data: &[u8]) -> Result<TranslatedModule, Error> {
|
||||
let memories = section.get_memory_section_reader()?;
|
||||
let mem = translate_sections::memory(memories)?;
|
||||
|
||||
assert!(
|
||||
mem.len() <= 1,
|
||||
assert_le!(
|
||||
mem.len(),
|
||||
1,
|
||||
"Multiple memory sections not yet unimplemented"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user