Auto-generate boilerplate for 'impl InstructionData'.

Accessors for shared fields and multiple results can be generated automatically.

Add a 'boxed_storage' flag to the instruction format definitions to enable
generated code to access 'data'.
This commit is contained in:
Jakob Stoklund Olesen
2016-05-19 10:16:40 -07:00
parent ebe224a912
commit 2ce5f05bed
4 changed files with 93 additions and 82 deletions

View File

@@ -251,85 +251,6 @@ impl InstructionData {
}),
}
}
/// Get the opcode of this instruction.
pub fn opcode(&self) -> Opcode {
use self::InstructionData::*;
match *self {
Nullary { opcode, .. } => opcode,
Unary { opcode, .. } => opcode,
UnaryImm { opcode, .. } => opcode,
UnaryIeee32 { opcode, .. } => opcode,
UnaryIeee64 { opcode, .. } => opcode,
UnaryImmVector { opcode, .. } => opcode,
Binary { opcode, .. } => opcode,
BinaryImm { opcode, .. } => opcode,
BinaryImmRev { opcode, .. } => opcode,
Jump { opcode, .. } => opcode,
Branch { opcode, .. } => opcode,
BranchTable { opcode, .. } => opcode,
Call { opcode, .. } => opcode,
}
}
/// Type of the first result.
pub fn first_type(&self) -> Type {
use self::InstructionData::*;
match *self {
Nullary { ty, .. } => ty,
Unary { ty, .. } => ty,
UnaryImm { ty, .. } => ty,
UnaryIeee32 { ty, .. } => ty,
UnaryIeee64 { ty, .. } => ty,
UnaryImmVector { ty, .. } => ty,
Binary { ty, .. } => ty,
BinaryImm { ty, .. } => ty,
BinaryImmRev { ty, .. } => ty,
Jump { ty, .. } => ty,
Branch { ty, .. } => ty,
BranchTable { ty, .. } => ty,
Call { ty, .. } => ty,
}
}
/// Second result value, if any.
pub fn second_result(&self) -> Option<Value> {
use self::InstructionData::*;
match *self {
Nullary { .. } => None,
Unary { .. } => None,
UnaryImm { .. } => None,
UnaryIeee32 { .. } => None,
UnaryIeee64 { .. } => None,
UnaryImmVector { .. } => None,
Binary { .. } => None,
BinaryImm { .. } => None,
BinaryImmRev { .. } => None,
Jump { .. } => None,
Branch { .. } => None,
BranchTable { .. } => None,
Call { ref data, .. } => Some(data.second_result),
}
}
pub fn second_result_mut<'a>(&'a mut self) -> Option<&'a mut Value> {
use self::InstructionData::*;
match *self {
Nullary { .. } => None,
Unary { .. } => None,
UnaryImm { .. } => None,
UnaryIeee32 { .. } => None,
UnaryIeee64 { .. } => None,
UnaryImmVector { .. } => None,
Binary { .. } => None,
BinaryImm { .. } => None,
BinaryImmRev { .. } => None,
Jump { .. } => None,
Branch { .. } => None,
BranchTable { .. } => None,
Call { ref mut data, .. } => Some(&mut data.second_result),
}
}
}
#[cfg(test)]