From b258644d07bee06dd58f2038349fbd2250ca8550 Mon Sep 17 00:00:00 2001 From: Jakob Stoklund Olesen Date: Wed, 12 Oct 2016 10:07:00 -0700 Subject: [PATCH] Use 'varargs' consistently for VariableArgs members. The meta code generators need to be able to infer these too. --- meta/cretonne/__init__.py | 13 ++++++------- src/libcretonne/ir/instructions.rs | 24 ++++++++++++------------ src/libcretonne/test_utils/make_inst.rs | 6 +++--- src/libcretonne/write.rs | 4 ++-- src/libreader/parser.rs | 14 +++++++------- 5 files changed, 30 insertions(+), 31 deletions(-) diff --git a/meta/cretonne/__init__.py b/meta/cretonne/__init__.py index 825b30a8dc..05366b0720 100644 --- a/meta/cretonne/__init__.py +++ b/meta/cretonne/__init__.py @@ -290,10 +290,10 @@ class OperandKind(object): instruction. """ - def __init__(self, name, doc): + def __init__(self, name, doc, default_member=None): self.name = name self.__doc__ = doc - self.default_member = None + self.default_member = default_member # The camel-cased name of an operand kind is also the Rust type used to # represent it. self.camel_name = camel_case(name) @@ -334,7 +334,8 @@ variable_args = OperandKind( Use this to represent arguemtns passed to a function call, arguments passed to an extended basic block, or a variable number of results returned from an instruction. - """) + """, + default_member='varargs') # Instances of immediate operand types are provided in the @@ -348,8 +349,7 @@ class ImmediateKind(OperandKind): """ def __init__(self, name, doc, default_member='imm'): - super(ImmediateKind, self).__init__(name, doc) - self.default_member = default_member + super(ImmediateKind, self).__init__(name, doc, default_member) def __repr__(self): return 'ImmediateKind({})'.format(self.name) @@ -363,8 +363,7 @@ class EntityRefKind(OperandKind): """ def __init__(self, name, doc, default_member=None): - super(EntityRefKind, self).__init__(name, doc) - self.default_member = default_member or name + super(EntityRefKind, self).__init__(name, doc, default_member or name) def __repr__(self): return 'EntityRefKind({})'.format(self.name) diff --git a/src/libcretonne/ir/instructions.rs b/src/libcretonne/ir/instructions.rs index fd7fd5f25b..6b3e0e5ffe 100644 --- a/src/libcretonne/ir/instructions.rs +++ b/src/libcretonne/ir/instructions.rs @@ -283,15 +283,15 @@ impl Display for TernaryOverflowData { #[derive(Clone, Debug)] pub struct JumpData { pub destination: Ebb, - pub arguments: VariableArgs, + pub varargs: VariableArgs, } impl Display for JumpData { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - if self.arguments.is_empty() { + if self.varargs.is_empty() { write!(f, "{}", self.destination) } else { - write!(f, "{}({})", self.destination, self.arguments) + write!(f, "{}({})", self.destination, self.varargs) } } } @@ -302,14 +302,14 @@ impl Display for JumpData { pub struct BranchData { pub arg: Value, pub destination: Ebb, - pub arguments: VariableArgs, + pub varargs: VariableArgs, } impl Display for BranchData { fn fmt(&self, f: &mut Formatter) -> fmt::Result { try!(write!(f, "{}, {}", self.arg, self.destination)); - if !self.arguments.is_empty() { - try!(write!(f, "({})", self.arguments)); + if !self.varargs.is_empty() { + try!(write!(f, "({})", self.varargs)); } Ok(()) } @@ -322,12 +322,12 @@ pub struct CallData { second_result: Value, // Dynamically sized array containing call argument values. - pub args: VariableArgs, + pub varargs: VariableArgs, } impl Display for CallData { fn fmt(&self, f: &mut Formatter) -> fmt::Result { - write!(f, "TBD({})", self.args) + write!(f, "TBD({})", self.varargs) } } @@ -335,7 +335,7 @@ impl Display for CallData { #[derive(Clone, Debug)] pub struct ReturnData { // Dynamically sized array containing return values. - pub args: VariableArgs, + pub varargs: VariableArgs, } impl InstructionData { @@ -346,7 +346,7 @@ impl InstructionData { ty: return_type, data: Box::new(CallData { second_result: NO_VALUE, - args: VariableArgs::new(), + varargs: VariableArgs::new(), }), } } @@ -364,10 +364,10 @@ impl InstructionData { pub fn analyze_branch<'a>(&'a self) -> BranchInfo<'a> { match self { &InstructionData::Jump { ref data, .. } => { - BranchInfo::SingleDest(data.destination, &data.arguments) + BranchInfo::SingleDest(data.destination, &data.varargs) } &InstructionData::Branch { ref data, .. } => { - BranchInfo::SingleDest(data.destination, &data.arguments) + BranchInfo::SingleDest(data.destination, &data.varargs) } &InstructionData::BranchTable { table, .. } => BranchInfo::Table(table), _ => BranchInfo::NotABranch, diff --git a/src/libcretonne/test_utils/make_inst.rs b/src/libcretonne/test_utils/make_inst.rs index a072b8ba8f..9ab4429b76 100644 --- a/src/libcretonne/test_utils/make_inst.rs +++ b/src/libcretonne/test_utils/make_inst.rs @@ -11,7 +11,7 @@ pub fn jump(func: &mut Function, dest: Ebb) -> Inst { ty: types::VOID, data: Box::new(JumpData { destination: dest, - arguments: VariableArgs::new(), + varargs: VariableArgs::new(), }), }) } @@ -23,7 +23,7 @@ pub fn branch(func: &mut Function, dest: Ebb) -> Inst { data: Box::new(BranchData { arg: NO_VALUE, destination: dest, - arguments: VariableArgs::new(), + varargs: VariableArgs::new(), }), }) } @@ -32,6 +32,6 @@ pub fn ret(func: &mut Function) -> Inst { func.dfg.make_inst(InstructionData::Return { opcode: Opcode::Return, ty: types::VOID, - data: Box::new(ReturnData { args: VariableArgs::new() }), + data: Box::new(ReturnData { varargs: VariableArgs::new() }), }) } diff --git a/src/libcretonne/write.rs b/src/libcretonne/write.rs index 8f7acde772..e49c8382bf 100644 --- a/src/libcretonne/write.rs +++ b/src/libcretonne/write.rs @@ -201,10 +201,10 @@ fn write_instruction(w: &mut Write, BranchTable { arg, table, .. } => writeln!(w, " {}, {}", arg, table), Call { ref data, .. } => writeln!(w, " {}", data), Return { ref data, .. } => { - if data.args.is_empty() { + if data.varargs.is_empty() { writeln!(w, "") } else { - writeln!(w, " {}", data.args) + writeln!(w, " {}", data.varargs) } } } diff --git a/src/libreader/parser.rs b/src/libreader/parser.rs index 258f920b81..eb8c78de38 100644 --- a/src/libreader/parser.rs +++ b/src/libreader/parser.rs @@ -145,21 +145,21 @@ impl Context { InstructionData::Jump { ref mut data, .. } => { try!(self.map.rewrite_ebb(&mut data.destination, loc)); - try!(self.map.rewrite_values(&mut data.arguments, loc)); + try!(self.map.rewrite_values(&mut data.varargs, loc)); } InstructionData::Branch { ref mut data, .. } => { try!(self.map.rewrite_value(&mut data.arg, loc)); try!(self.map.rewrite_ebb(&mut data.destination, loc)); - try!(self.map.rewrite_values(&mut data.arguments, loc)); + try!(self.map.rewrite_values(&mut data.varargs, loc)); } InstructionData::Call { ref mut data, .. } => { - try!(self.map.rewrite_values(&mut data.args, loc)); + try!(self.map.rewrite_values(&mut data.varargs, loc)); } InstructionData::Return { ref mut data, .. } => { - try!(self.map.rewrite_values(&mut data.args, loc)); + try!(self.map.rewrite_values(&mut data.varargs, loc)); } } } @@ -1104,7 +1104,7 @@ impl<'a> Parser<'a> { ty: VOID, data: Box::new(JumpData { destination: ebb_num, - arguments: args, + varargs: args, }), } } @@ -1119,7 +1119,7 @@ impl<'a> Parser<'a> { data: Box::new(BranchData { arg: ctrl_arg, destination: ebb_num, - arguments: args, + varargs: args, }), } } @@ -1178,7 +1178,7 @@ impl<'a> Parser<'a> { InstructionData::Return { opcode: opcode, ty: VOID, - data: Box::new(ReturnData { args: args }), + data: Box::new(ReturnData { varargs: args }), } } InstructionFormat::BranchTable => {