Use 'varargs' consistently for VariableArgs members.

The meta code generators need to be able to infer these too.
This commit is contained in:
Jakob Stoklund Olesen
2016-10-12 10:07:00 -07:00
parent 2372486ec5
commit b258644d07
5 changed files with 30 additions and 31 deletions

View File

@@ -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)

View File

@@ -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,

View File

@@ -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() }),
})
}

View File

@@ -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)
}
}
}

View File

@@ -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 => {