Add an encoding test for RISC-V.

Test that the generated encoding tables work as expected.

Change isa::Encoding into a struct with named fields so the recipe and bits can
be accessed.
This commit is contained in:
Jakob Stoklund Olesen
2016-08-30 10:44:33 -07:00
parent 1c51285845
commit 727510f97f
2 changed files with 77 additions and 2 deletions

View File

@@ -107,11 +107,28 @@ pub trait TargetIsa {
/// encoding *bits*. The recipe determines the native instruction format and the mapping of
/// operands to encoded bits. The encoding bits provide additional information to the recipe,
/// typically parts of the opcode.
pub struct Encoding(u16, u16);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Encoding {
recipe: u16,
bits: u16,
}
impl Encoding {
/// Create a new `Encoding` containing `(recipe, bits)`.
pub fn new(recipe: u16, bits: u16) -> Encoding {
Encoding(recipe, bits)
Encoding {
recipe: recipe,
bits: bits,
}
}
/// Get the recipe number in this encoding.
pub fn recipe(self) -> usize {
self.recipe as usize
}
/// Get the recipe-specific encoding bits.
pub fn bits(self) -> u16 {
self.bits
}
}