Add meta definition for bitcast.

This instruction uses two type variables: input and output. Make sure that our
parser can handle it. The output type variable annotation is mandatory.

Add a ValueTypeSet::example() method which is used to provide better diagnostics
for a missing type variable.
This commit is contained in:
Jakob Stoklund Olesen
2016-07-07 13:40:16 -07:00
parent 2bfb4ca5b7
commit 4a929f5e41
6 changed files with 113 additions and 9 deletions

View File

@@ -432,6 +432,30 @@ impl ValueTypeSet {
};
allowed && self.is_base_type(typ.lane_type())
}
/// Get an example member of this type set.
///
/// This is used for error messages to avoid suggesting invalid types.
pub fn example(&self) -> Type {
if self.base != types::VOID {
return self.base;
}
let t = if self.all_ints {
types::I32
} else if self.all_floats {
types::F32
} else if self.allow_scalars {
types::B1
} else {
types::B32
};
if self.allow_scalars {
t
} else {
t.by(4).unwrap()
}
}
}
/// Operand constraints. This describes the value type constraints on a single `Value` operand.
@@ -506,4 +530,49 @@ mod tests {
// that?
assert_eq!(mem::size_of::<InstructionData>(), 16);
}
#[test]
fn value_set() {
use types::*;
let vts = ValueTypeSet {
allow_scalars: true,
allow_simd: true,
base: VOID,
all_ints: true,
all_floats: false,
all_bools: true,
};
assert_eq!(vts.example().to_string(), "i32");
let vts = ValueTypeSet {
allow_scalars: true,
allow_simd: true,
base: VOID,
all_ints: false,
all_floats: true,
all_bools: true,
};
assert_eq!(vts.example().to_string(), "f32");
let vts = ValueTypeSet {
allow_scalars: false,
allow_simd: true,
base: VOID,
all_ints: false,
all_floats: true,
all_bools: true,
};
assert_eq!(vts.example().to_string(), "f32x4");
let vts = ValueTypeSet {
allow_scalars: false,
allow_simd: true,
base: VOID,
all_ints: false,
all_floats: false,
all_bools: true,
};
assert_eq!(vts.example().to_string(), "b32x4");
}
}

View File

@@ -651,7 +651,10 @@ impl<'a> Parser<'a> {
} else if constraints.is_polymorphic() {
// This opcode does not support type inference, so the explicit type variable
// is required.
return err!(self.loc, "type variable required for polymorphic opcode");
return err!(self.loc,
"type variable required for polymorphic opcode, e.g. '{}.{}'",
opcode,
constraints.ctrl_typeset().unwrap().example());
} else {
// This is a non-polymorphic opcode. No typevar needed.
VOID