Add a utility read_to_string() function.

This commit is contained in:
Jakob Stoklund Olesen
2016-09-14 13:14:43 -07:00
parent 4521afd474
commit 480054a094
5 changed files with 22 additions and 20 deletions

View File

@@ -2,10 +2,10 @@
//!
//! Read a series of Cretonne IL files and print their control flow graphs
//! in graphviz format.
use std::fs::File;
use std::io::{Read, Write, stdout};
use std::io::{Write, stdout};
use CommandResult;
use utils::read_to_string;
use cretonne::ir::Function;
use cretonne::cfg::ControlFlowGraph;
use cretonne::ir::instructions::InstructionData;
@@ -156,10 +156,7 @@ impl<T: Write> CFGPrinter<T> {
}
fn print_cfg(filename: String) -> CommandResult {
let mut file = try!(File::open(&filename).map_err(|e| format!("{}: {}", filename, e)));
let mut buffer = String::new();
try!(file.read_to_string(&mut buffer)
.map_err(|e| format!("Couldn't read {}: {}", filename, e)));
let buffer = try!(read_to_string(&filename).map_err(|e| format!("{}: {}", filename, e)));
let items = try!(parse_functions(&buffer).map_err(|e| format!("{}: {}", filename, e)));
let mut cfg_printer = CFGPrinter::new(stdout());