Never use the first vararg as typevar operand
If an instruction only takes varargs as values, it may have no arguments at all.
This commit is contained in:
@@ -133,7 +133,7 @@ impl InstructionFormatBuilder {
|
||||
|
||||
pub fn typevar_operand(mut self, operand_index: usize) -> Self {
|
||||
assert!(self.typevar_operand.is_none());
|
||||
assert!(self.has_value_list || operand_index < self.num_value_operands);
|
||||
assert!(operand_index < self.num_value_operands);
|
||||
self.typevar_operand = Some(operand_index);
|
||||
self
|
||||
}
|
||||
@@ -141,7 +141,7 @@ impl InstructionFormatBuilder {
|
||||
pub fn build(self) -> Rc<InstructionFormat> {
|
||||
let typevar_operand = if self.typevar_operand.is_some() {
|
||||
self.typevar_operand
|
||||
} else if self.has_value_list || self.num_value_operands > 0 {
|
||||
} else if self.num_value_operands > 0 {
|
||||
// Default to the first value operand, if there's one.
|
||||
Some(0)
|
||||
} else {
|
||||
|
||||
@@ -75,15 +75,13 @@ fn gen_instruction_data(formats: &[&InstructionFormat], fmt: &mut Formatter) {
|
||||
fmtln!(fmt, "{} {{", format.name);
|
||||
fmt.indent(|fmt| {
|
||||
fmt.line("opcode: Opcode,");
|
||||
if format.typevar_operand.is_some() {
|
||||
if format.has_value_list {
|
||||
fmt.line("args: ValueList,");
|
||||
} else if format.num_value_operands == 1 {
|
||||
fmt.line("arg: Value,");
|
||||
} else {
|
||||
} else if format.num_value_operands > 0 {
|
||||
fmtln!(fmt, "args: [Value; {}],", format.num_value_operands);
|
||||
}
|
||||
}
|
||||
for field in &format.imm_fields {
|
||||
fmtln!(fmt, "{}: {},", field.member, field.kind.rust_type);
|
||||
}
|
||||
@@ -287,17 +285,17 @@ fn gen_instruction_data_impl(formats: &[&InstructionFormat], fmt: &mut Formatter
|
||||
let name = format!("&Self::{}", format.name);
|
||||
let mut members = vec!["opcode"];
|
||||
|
||||
let args_eq = if format.typevar_operand.is_none() {
|
||||
None
|
||||
} else if format.has_value_list {
|
||||
let args_eq = if format.has_value_list {
|
||||
members.push("args");
|
||||
Some("args1.as_slice(pool) == args2.as_slice(pool)")
|
||||
} else if format.num_value_operands == 1 {
|
||||
members.push("arg");
|
||||
Some("arg1 == arg2")
|
||||
} else {
|
||||
} else if format.num_value_operands > 0 {
|
||||
members.push("args");
|
||||
Some("args1 == args2")
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
for field in &format.imm_fields {
|
||||
@@ -339,17 +337,17 @@ fn gen_instruction_data_impl(formats: &[&InstructionFormat], fmt: &mut Formatter
|
||||
let name = format!("Self::{}", format.name);
|
||||
let mut members = vec!["opcode"];
|
||||
|
||||
let args = if format.typevar_operand.is_none() {
|
||||
"&()"
|
||||
} else if format.has_value_list {
|
||||
let args = if format.has_value_list {
|
||||
members.push("ref args");
|
||||
"args.as_slice(pool)"
|
||||
} else if format.num_value_operands == 1 {
|
||||
members.push("ref arg");
|
||||
"arg"
|
||||
} else {
|
||||
} else if format.num_value_operands > 0{
|
||||
members.push("ref args");
|
||||
"args"
|
||||
} else {
|
||||
"&()"
|
||||
};
|
||||
|
||||
for field in &format.imm_fields {
|
||||
|
||||
Reference in New Issue
Block a user