committed by
Jakob Stoklund Olesen
parent
c8be39fa9d
commit
7459fee71a
@@ -171,13 +171,13 @@ def gen_display(sgrp, fmt):
|
||||
with fmt.indented(
|
||||
'fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {',
|
||||
'}'):
|
||||
fmt.line('try!(writeln!(f, "[{}]"));'.format(sgrp.name))
|
||||
fmt.line('writeln!(f, "[{}]")?;'.format(sgrp.name))
|
||||
with fmt.indented('for d in &DESCRIPTORS {', '}'):
|
||||
fmt.line('try!(write!(f, "{} = ", d.name));')
|
||||
fmt.line('write!(f, "{} = ", d.name)?;')
|
||||
fmt.line(
|
||||
'try!(TEMPLATE.format_toml_value(d.detail,' +
|
||||
'self.bytes[d.offset as usize], f));')
|
||||
fmt.line('try!(writeln!(f, ""));')
|
||||
'TEMPLATE.format_toml_value(d.detail,' +
|
||||
'self.bytes[d.offset as usize], f)?;')
|
||||
fmt.line('writeln!(f, "")?;')
|
||||
fmt.line('Ok(())')
|
||||
|
||||
|
||||
|
||||
@@ -42,9 +42,9 @@ fn needs_quotes(name: &str) -> bool {
|
||||
impl fmt::Display for FunctionName {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if needs_quotes(&self.0) {
|
||||
try!(f.write_char('"'));
|
||||
f.write_char('"')?;
|
||||
for c in self.0.chars().flat_map(char::escape_default) {
|
||||
try!(f.write_char(c));
|
||||
f.write_char(c)?;
|
||||
}
|
||||
f.write_char('"')
|
||||
} else {
|
||||
|
||||
@@ -49,10 +49,10 @@ impl Display for Imm64 {
|
||||
// 0xffff_ffff_fff8_4400
|
||||
//
|
||||
let mut pos = (64 - x.leading_zeros() - 1) & 0xf0;
|
||||
try!(write!(f, "0x{:04x}", (x >> pos) & 0xffff));
|
||||
write!(f, "0x{:04x}", (x >> pos) & 0xffff)?;
|
||||
while pos > 0 {
|
||||
pos -= 16;
|
||||
try!(write!(f, "_{:04x}", (x >> pos) & 0xffff));
|
||||
write!(f, "_{:04x}", (x >> pos) & 0xffff)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -178,7 +178,7 @@ fn format_float(bits: u64, w: u8, t: u8, f: &mut Formatter) -> fmt::Result {
|
||||
|
||||
// All formats share the leading sign.
|
||||
if sign_bit != 0 {
|
||||
try!(write!(f, "-"));
|
||||
write!(f, "-")?;
|
||||
}
|
||||
|
||||
if e_bits == 0 {
|
||||
|
||||
@@ -265,9 +265,9 @@ impl Display for VariableArgs {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
for (i, val) in self.0.iter().enumerate() {
|
||||
if i == 0 {
|
||||
try!(write!(fmt, "{}", val));
|
||||
write!(fmt, "{}", val)?;
|
||||
} else {
|
||||
try!(write!(fmt, ", {}", val));
|
||||
write!(fmt, ", {}", val)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -289,9 +289,9 @@ pub struct UnaryImmVectorData {
|
||||
|
||||
impl Display for UnaryImmVectorData {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
try!(write!(f, "#"));
|
||||
write!(f, "#")?;
|
||||
for b in &self.imm {
|
||||
try!(write!(f, "{:02x}", b));
|
||||
write!(f, "{:02x}", b)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -356,9 +356,9 @@ impl BranchData {
|
||||
|
||||
impl Display for BranchData {
|
||||
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
|
||||
try!(write!(f, "{}, {}", self.arg, self.destination));
|
||||
write!(f, "{}, {}", self.arg, self.destination)?;
|
||||
if !self.varargs.is_empty() {
|
||||
try!(write!(f, "({})", self.varargs));
|
||||
write!(f, "({})", self.varargs)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -97,14 +97,14 @@ impl<'a> Iterator for Entries<'a> {
|
||||
impl Display for JumpTableData {
|
||||
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
|
||||
match self.table.first().and_then(|e| e.expand()) {
|
||||
None => try!(write!(fmt, "jump_table 0")),
|
||||
Some(first) => try!(write!(fmt, "jump_table {}", first)),
|
||||
None => write!(fmt, "jump_table 0")?,
|
||||
Some(first) => write!(fmt, "jump_table {}", first)?,
|
||||
}
|
||||
|
||||
for dest in self.table.iter().skip(1).map(|e| e.expand()) {
|
||||
match dest {
|
||||
None => try!(write!(fmt, ", 0")),
|
||||
Some(ebb) => try!(write!(fmt, ", {}", ebb)),
|
||||
None => write!(fmt, ", 0")?,
|
||||
Some(ebb) => write!(fmt, ", {}", ebb)?,
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -103,7 +103,7 @@ fn parse_enum_value(value: &str, choices: &[&str]) -> Result<u8> {
|
||||
impl Configurable for Builder {
|
||||
fn set_bool(&mut self, name: &str, value: bool) -> Result<()> {
|
||||
use self::detail::Detail;
|
||||
let (offset, detail) = try!(self.lookup(name));
|
||||
let (offset, detail) = self.lookup(name)?;
|
||||
if let Detail::Bool { bit } = detail {
|
||||
self.set_bit(offset, bit, value);
|
||||
Ok(())
|
||||
@@ -114,17 +114,17 @@ impl Configurable for Builder {
|
||||
|
||||
fn set(&mut self, name: &str, value: &str) -> Result<()> {
|
||||
use self::detail::Detail;
|
||||
let (offset, detail) = try!(self.lookup(name));
|
||||
let (offset, detail) = self.lookup(name)?;
|
||||
match detail {
|
||||
Detail::Bool { bit } => {
|
||||
self.set_bit(offset, bit, try!(parse_bool_value(value)));
|
||||
self.set_bit(offset, bit, parse_bool_value(value))?;
|
||||
}
|
||||
Detail::Num => {
|
||||
self.bytes[offset] = try!(value.parse().map_err(|_| Error::BadValue));
|
||||
self.bytes[offset] = value.parse().map_err(|_| Error::BadValue)?;
|
||||
}
|
||||
Detail::Enum { last, enumerators } => {
|
||||
self.bytes[offset] = try!(parse_enum_value(value,
|
||||
self.template.enums(last, enumerators)));
|
||||
self.bytes[offset] = parse_enum_value(value,
|
||||
self.template.enums(last, enumerators))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -159,8 +159,8 @@ impl<'a> Verifier<'a> {
|
||||
pub fn run(&self) -> Result<()> {
|
||||
for ebb in self.func.layout.ebbs() {
|
||||
for inst in self.func.layout.ebb_insts(ebb) {
|
||||
try!(self.ebb_integrity(ebb, inst));
|
||||
try!(self.instruction_integrity(inst));
|
||||
self.ebb_integrity(ebb, inst)?;
|
||||
self.instruction_integrity(inst)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
||||
@@ -12,14 +12,14 @@ use std::result;
|
||||
/// Write `func` to `w` as equivalent text.
|
||||
/// Use `isa` to emit ISA-dependent annotations.
|
||||
pub fn write_function(w: &mut Write, func: &Function, isa: Option<&TargetIsa>) -> Result {
|
||||
try!(write_spec(w, func));
|
||||
try!(writeln!(w, " {{"));
|
||||
let mut any = try!(write_preamble(w, func));
|
||||
write_spec(w, func)?;
|
||||
writeln!(w, " {{")?;
|
||||
let mut any = write_preamble(w, func)?;
|
||||
for ebb in &func.layout {
|
||||
if any {
|
||||
try!(writeln!(w, ""));
|
||||
writeln!(w, "")?;
|
||||
}
|
||||
try!(write_ebb(w, func, isa, ebb));
|
||||
write_ebb(w, func, isa, ebb)?;
|
||||
any = true;
|
||||
}
|
||||
writeln!(w, "}}")
|
||||
@@ -40,24 +40,24 @@ fn write_preamble(w: &mut Write, func: &Function) -> result::Result<bool, Error>
|
||||
|
||||
for ss in func.stack_slots.keys() {
|
||||
any = true;
|
||||
try!(writeln!(w, " {} = {}", ss, func.stack_slots[ss]));
|
||||
writeln!(w, " {} = {}", ss, func.stack_slots[ss])?;
|
||||
}
|
||||
|
||||
// Write out all signatures before functions since function declarations can refer to
|
||||
// signatures.
|
||||
for sig in func.dfg.signatures.keys() {
|
||||
any = true;
|
||||
try!(writeln!(w, " {} = signature{}", sig, func.dfg.signatures[sig]));
|
||||
writeln!(w, " {} = signature{}", sig, func.dfg.signatures[sig])?;
|
||||
}
|
||||
|
||||
for fnref in func.dfg.ext_funcs.keys() {
|
||||
any = true;
|
||||
try!(writeln!(w, " {} = {}", fnref, func.dfg.ext_funcs[fnref]));
|
||||
writeln!(w, " {} = {}", fnref, func.dfg.ext_funcs[fnref])?;
|
||||
}
|
||||
|
||||
for jt in func.jump_tables.keys() {
|
||||
any = true;
|
||||
try!(writeln!(w, " {} = {}", jt, func.jump_tables[jt]));
|
||||
writeln!(w, " {} = {}", jt, func.jump_tables[jt])?;
|
||||
}
|
||||
|
||||
Ok(any)
|
||||
@@ -83,29 +83,29 @@ pub fn write_ebb_header(w: &mut Write, func: &Function, ebb: Ebb) -> Result {
|
||||
|
||||
// If we're writing encoding annotations, shift by 20.
|
||||
if !func.encodings.is_empty() {
|
||||
try!(write!(w, " "));
|
||||
write!(w, " ")?;
|
||||
}
|
||||
|
||||
let mut args = func.dfg.ebb_args(ebb);
|
||||
match args.next() {
|
||||
None => return writeln!(w, "{}:", ebb),
|
||||
Some(arg) => {
|
||||
try!(write!(w, "{}(", ebb));
|
||||
try!(write_arg(w, func, arg));
|
||||
write!(w, "{}(", ebb)?;
|
||||
write_arg(w, func, arg)?;
|
||||
}
|
||||
}
|
||||
// Remaining arguments.
|
||||
for arg in args {
|
||||
try!(write!(w, ", "));
|
||||
try!(write_arg(w, func, arg));
|
||||
write!(w, ", ")?;
|
||||
write_arg(w, func, arg)?;
|
||||
}
|
||||
writeln!(w, "):")
|
||||
}
|
||||
|
||||
pub fn write_ebb(w: &mut Write, func: &Function, isa: Option<&TargetIsa>, ebb: Ebb) -> Result {
|
||||
try!(write_ebb_header(w, func, ebb));
|
||||
write_ebb_header(w, func, ebb)?;
|
||||
for inst in func.layout.ebb_insts(ebb) {
|
||||
try!(write_instruction(w, func, isa, inst));
|
||||
write_instruction(w, func, isa, inst)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -151,7 +151,7 @@ fn write_value_aliases(w: &mut Write, func: &Function, inst: Inst, indent: usize
|
||||
for &arg in func.dfg[inst].arguments().iter().flat_map(|x| x.iter()) {
|
||||
let resolved = func.dfg.resolve_aliases(arg);
|
||||
if resolved != arg {
|
||||
try!(writeln!(w, "{1:0$}{2} -> {3}", indent, "", arg, resolved));
|
||||
writeln!(w, "{1:0$}{2} -> {3}", indent, "", arg, resolved)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
@@ -166,13 +166,13 @@ fn write_instruction(w: &mut Write,
|
||||
let indent = if func.encodings.is_empty() { 4 } else { 24 };
|
||||
|
||||
// Value aliases come out on lines before the instruction using them.
|
||||
try!(write_value_aliases(w, func, inst, indent));
|
||||
write_value_aliases(w, func, inst, indent)?;
|
||||
|
||||
// Write out encoding info.
|
||||
if let Some(enc) = func.encodings.get(inst).cloned() {
|
||||
let mut s = String::with_capacity(16);
|
||||
if let Some(isa) = isa {
|
||||
try!(write!(s, "[{}", isa.display_enc(enc)));
|
||||
write!(s, "[{}", isa.display_enc(enc))?;
|
||||
// Write value locations, if we have them.
|
||||
if !func.locations.is_empty() {
|
||||
let regs = isa.register_info();
|
||||
@@ -184,15 +184,15 @@ fn write_instruction(w: &mut Write,
|
||||
}
|
||||
}
|
||||
}
|
||||
try!(write!(s, "]"));
|
||||
write!(s, "]")?;
|
||||
} else {
|
||||
try!(write!(s, "[{}]", enc));
|
||||
write!(s, "[{}]", enc)?;
|
||||
}
|
||||
// Align instruction following ISA annotation to col 24.
|
||||
try!(write!(w, "{:23} ", s));
|
||||
write!(w, "{:23} ", s)?;
|
||||
} else {
|
||||
// No annotations, simply indent.
|
||||
try!(write!(w, "{1:0$}", indent, ""));
|
||||
write!(w, "{1:0$}", indent, "")?;
|
||||
}
|
||||
|
||||
// Write out the result values, if any.
|
||||
@@ -200,21 +200,21 @@ fn write_instruction(w: &mut Write,
|
||||
for r in func.dfg.inst_results(inst) {
|
||||
if !has_results {
|
||||
has_results = true;
|
||||
try!(write!(w, "{}", r));
|
||||
write!(w, "{}", r)?;
|
||||
} else {
|
||||
try!(write!(w, ", {}", r));
|
||||
write!(w, ", {}", r)?;
|
||||
}
|
||||
}
|
||||
if has_results {
|
||||
try!(write!(w, " = "));
|
||||
write!(w, " = ")?;
|
||||
}
|
||||
|
||||
// Then the opcode, possibly with a '.type' suffix.
|
||||
let opcode = func.dfg[inst].opcode();
|
||||
|
||||
match type_suffix(func, inst) {
|
||||
Some(suf) => try!(write!(w, "{}.{}", opcode, suf)),
|
||||
None => try!(write!(w, "{}", opcode)),
|
||||
Some(suf) => write!(w, "{}.{}", opcode, suf)?,
|
||||
None => write!(w, "{}", opcode)?,
|
||||
}
|
||||
|
||||
// Then the operands, depending on format.
|
||||
|
||||
Reference in New Issue
Block a user