Clippy cleanups.
This commit is contained in:
@@ -6,7 +6,7 @@ use cretonne::verifier;
|
|||||||
use cretonne::settings::Configurable;
|
use cretonne::settings::Configurable;
|
||||||
use cretonne::result::CtonError;
|
use cretonne::result::CtonError;
|
||||||
use cretonne::ir::entities::AnyEntity;
|
use cretonne::ir::entities::AnyEntity;
|
||||||
use cretonne::ir::{self, Ebb, FuncRef, JumpTable, Function};
|
use cretonne::ir::{Ebb, FuncRef, JumpTable, Function};
|
||||||
use cretonne::binemit::{RelocSink, Reloc, CodeOffset};
|
use cretonne::binemit::{RelocSink, Reloc, CodeOffset};
|
||||||
use cton_wasm::{TranslationResult, FunctionTranslation, ImportMappings, FunctionIndex};
|
use cton_wasm::{TranslationResult, FunctionTranslation, ImportMappings, FunctionIndex};
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
@@ -140,7 +140,7 @@ pub fn compile_module(trans_result: &TranslationResult) -> Result<ExecutableCode
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Jumps to the code region of memory and execute the start function of the module.
|
/// Jumps to the code region of memory and execute the start function of the module.
|
||||||
pub fn execute(exec: ExecutableCode) -> Result<(), String> {
|
pub fn execute(exec: &ExecutableCode) -> Result<(), String> {
|
||||||
let code_buf = &exec.functions_code[exec.start_index];
|
let code_buf = &exec.functions_code[exec.start_index];
|
||||||
unsafe {
|
unsafe {
|
||||||
match protect(
|
match protect(
|
||||||
@@ -192,17 +192,17 @@ pub fn execute(exec: ExecutableCode) -> Result<(), String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Performs the relocations inside the function bytecode, provided the necessary metadata
|
/// Performs the relocations inside the function bytecode, provided the necessary metadata
|
||||||
fn relocate(functions_metatada: &Vec<FunctionMetaData>, functions_code: &mut Vec<Vec<u8>>) {
|
fn relocate(functions_metatada: &[FunctionMetaData], functions_code: &mut Vec<Vec<u8>>) {
|
||||||
// The relocations are relative to the relocation's address plus four bytes
|
// The relocations are relative to the relocation's address plus four bytes
|
||||||
for (func_index, function_in_memory) in functions_metatada.iter().enumerate() {
|
for (func_index, function_in_memory) in functions_metatada.iter().enumerate() {
|
||||||
match function_in_memory {
|
match *function_in_memory {
|
||||||
&FunctionMetaData::Import() => continue,
|
FunctionMetaData::Import() => continue,
|
||||||
&FunctionMetaData::Local {
|
FunctionMetaData::Local {
|
||||||
ref relocs,
|
ref relocs,
|
||||||
ref imports,
|
ref imports,
|
||||||
ref il_func,
|
ref il_func,
|
||||||
} => {
|
} => {
|
||||||
for (_, &(func_ref, offset)) in relocs.funcs.iter() {
|
for &(func_ref, offset) in relocs.funcs.values() {
|
||||||
let target_func_index = imports.functions[&func_ref];
|
let target_func_index = imports.functions[&func_ref];
|
||||||
let target_func_address: isize = functions_code[target_func_index].as_ptr() as
|
let target_func_address: isize = functions_code[target_func_index].as_ptr() as
|
||||||
isize;
|
isize;
|
||||||
@@ -215,7 +215,7 @@ fn relocate(functions_metatada: &Vec<FunctionMetaData>, functions_code: &mut Vec
|
|||||||
write_unaligned(reloc_address as *mut i32, reloc_delta_i32);
|
write_unaligned(reloc_address as *mut i32, reloc_delta_i32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (_, &(ebb, offset)) in relocs.ebbs.iter() {
|
for &(ebb, offset) in relocs.ebbs.values() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let reloc_address: isize = functions_code[func_index]
|
let reloc_address: isize = functions_code[func_index]
|
||||||
.as_mut_ptr()
|
.as_mut_ptr()
|
||||||
@@ -240,7 +240,7 @@ fn relocate(functions_metatada: &Vec<FunctionMetaData>, functions_code: &mut Vec
|
|||||||
pub fn pretty_verifier_error(
|
pub fn pretty_verifier_error(
|
||||||
func: &Function,
|
func: &Function,
|
||||||
isa: Option<&TargetIsa>,
|
isa: Option<&TargetIsa>,
|
||||||
err: verifier::Error,
|
err: &verifier::Error,
|
||||||
) -> String {
|
) -> String {
|
||||||
let mut msg = err.to_string();
|
let mut msg = err.to_string();
|
||||||
match err.location {
|
match err.location {
|
||||||
@@ -256,7 +256,7 @@ pub fn pretty_verifier_error(
|
|||||||
/// Pretty-print a Cretonne error.
|
/// Pretty-print a Cretonne error.
|
||||||
pub fn pretty_error(func: &Function, isa: Option<&TargetIsa>, err: CtonError) -> String {
|
pub fn pretty_error(func: &Function, isa: Option<&TargetIsa>, err: CtonError) -> String {
|
||||||
if let CtonError::Verifier(e) = err {
|
if let CtonError::Verifier(e) = err {
|
||||||
pretty_verifier_error(func, isa, e)
|
pretty_verifier_error(func, isa, &e)
|
||||||
} else {
|
} else {
|
||||||
err.to_string()
|
err.to_string()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,12 +210,12 @@ impl WasmRuntime for StandaloneRuntime {
|
|||||||
// At instantiation, we allocate memory for the globals, the memories and the tables
|
// At instantiation, we allocate memory for the globals, the memories and the tables
|
||||||
// First the globals
|
// First the globals
|
||||||
let mut globals_data_size = 0;
|
let mut globals_data_size = 0;
|
||||||
for globalinfo in self.globals.info.iter_mut() {
|
for globalinfo in &mut self.globals.info {
|
||||||
globalinfo.offset = globals_data_size;
|
globalinfo.offset = globals_data_size;
|
||||||
globals_data_size += globalinfo.global.ty.bytes() as usize;
|
globals_data_size += globalinfo.global.ty.bytes() as usize;
|
||||||
}
|
}
|
||||||
self.globals.data.resize(globals_data_size, 0);
|
self.globals.data.resize(globals_data_size, 0);
|
||||||
for globalinfo in self.globals.info.iter() {
|
for globalinfo in &self.globals.info {
|
||||||
match globalinfo.global.initializer {
|
match globalinfo.global.initializer {
|
||||||
GlobalInit::I32Const(val) => unsafe {
|
GlobalInit::I32Const(val) => unsafe {
|
||||||
write(
|
write(
|
||||||
|
|||||||
68
src/main.rs
68
src/main.rs
@@ -106,10 +106,10 @@ fn main() {
|
|||||||
})
|
})
|
||||||
.unwrap_or_else(|e| e.exit());
|
.unwrap_or_else(|e| e.exit());
|
||||||
let mut terminal = term::stdout().unwrap();
|
let mut terminal = term::stdout().unwrap();
|
||||||
for filename in args.arg_file.iter() {
|
for filename in &args.arg_file {
|
||||||
let path = Path::new(&filename);
|
let path = Path::new(&filename);
|
||||||
let name = String::from(path.as_os_str().to_string_lossy());
|
let name = path.as_os_str().to_string_lossy();
|
||||||
match handle_module(&args, path.to_path_buf(), name) {
|
match handle_module(&args, path.to_path_buf(), &name) {
|
||||||
Ok(()) => {}
|
Ok(()) => {}
|
||||||
Err(message) => {
|
Err(message) => {
|
||||||
terminal.fg(term::color::RED).unwrap();
|
terminal.fg(term::color::RED).unwrap();
|
||||||
@@ -121,7 +121,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String> {
|
fn handle_module(args: &Args, path: PathBuf, name: &str) -> Result<(), String> {
|
||||||
let mut terminal = term::stdout().unwrap();
|
let mut terminal = term::stdout().unwrap();
|
||||||
terminal.fg(term::color::YELLOW).unwrap();
|
terminal.fg(term::color::YELLOW).unwrap();
|
||||||
vprint!(args.flag_verbose, "Handling: ");
|
vprint!(args.flag_verbose, "Handling: ");
|
||||||
@@ -194,14 +194,14 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
terminal.fg(term::color::MAGENTA).unwrap();
|
terminal.fg(term::color::MAGENTA).unwrap();
|
||||||
vprint!(args.flag_verbose, "Checking... ");
|
vprint!(args.flag_verbose, "Checking... ");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
for func in translation.functions.iter() {
|
for func in &translation.functions {
|
||||||
let il = match func {
|
let il = match *func {
|
||||||
&FunctionTranslation::Import() => continue,
|
FunctionTranslation::Import() => continue,
|
||||||
&FunctionTranslation::Code { ref il, .. } => il.clone(),
|
FunctionTranslation::Code { ref il, .. } => il.clone(),
|
||||||
};
|
};
|
||||||
match verifier::verify_function(&il, None) {
|
match verifier::verify_function(&il, None) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) => return Err(pretty_verifier_error(&il, None, err)),
|
Err(ref err) => return Err(pretty_verifier_error(&il, None, err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
@@ -220,17 +220,17 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
terminal.fg(term::color::MAGENTA).unwrap();
|
terminal.fg(term::color::MAGENTA).unwrap();
|
||||||
vprint!(args.flag_verbose, "Optimizing... ");
|
vprint!(args.flag_verbose, "Optimizing... ");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
for func in translation.functions.iter() {
|
for func in &translation.functions {
|
||||||
let mut il = match func {
|
let il = match *func {
|
||||||
&FunctionTranslation::Import() => continue,
|
FunctionTranslation::Import() => continue,
|
||||||
&FunctionTranslation::Code { ref il, .. } => il.clone(),
|
FunctionTranslation::Code { ref il, .. } => il.clone(),
|
||||||
};
|
};
|
||||||
let mut loop_analysis = LoopAnalysis::new();
|
let mut loop_analysis = LoopAnalysis::new();
|
||||||
let mut cfg = ControlFlowGraph::new();
|
let mut cfg = ControlFlowGraph::new();
|
||||||
cfg.compute(&il);
|
cfg.compute(&il);
|
||||||
let mut domtree = DominatorTree::new();
|
let mut domtree = DominatorTree::new();
|
||||||
domtree.compute(&mut il, &cfg);
|
domtree.compute(&il, &cfg);
|
||||||
loop_analysis.compute(&mut il, &mut cfg, &mut domtree);
|
loop_analysis.compute(&il, &cfg, &domtree);
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
context.func = il;
|
context.func = il;
|
||||||
context.cfg = cfg;
|
context.cfg = cfg;
|
||||||
@@ -238,7 +238,7 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
context.loop_analysis = loop_analysis;
|
context.loop_analysis = loop_analysis;
|
||||||
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) => {
|
Err(ref err) => {
|
||||||
return Err(pretty_verifier_error(&context.func, None, err));
|
return Err(pretty_verifier_error(&context.func, None, err));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -246,7 +246,7 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
Ok(())=> (),
|
Ok(())=> (),
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
match error {
|
match error {
|
||||||
CtonError::Verifier(err) => {
|
CtonError::Verifier(ref err) => {
|
||||||
return Err(pretty_verifier_error(&context.func, None, err));
|
return Err(pretty_verifier_error(&context.func, None, err));
|
||||||
}
|
}
|
||||||
CtonError::InvalidInput |
|
CtonError::InvalidInput |
|
||||||
@@ -257,7 +257,7 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
};
|
};
|
||||||
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
||||||
Ok(()) => (),
|
Ok(()) => (),
|
||||||
Err(err) => return Err(pretty_verifier_error(&context.func, None, err)),
|
Err(ref err) => return Err(pretty_verifier_error(&context.func, None, err)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
@@ -269,7 +269,7 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
vprint!(args.flag_verbose, "Compiling... ");
|
vprint!(args.flag_verbose, "Compiling... ");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
match compile_module(&translation) {
|
match compile_module(&translation) {
|
||||||
Ok(exec) => {
|
Ok(ref exec) => {
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(args.flag_verbose, "ok");
|
vprintln!(args.flag_verbose, "ok");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
@@ -310,7 +310,7 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
if input == "quit" {
|
if input == "quit" {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let split: Vec<&str> = input.split(",").collect();
|
let split: Vec<&str> = input.split(',').collect();
|
||||||
if split.len() != 3 {
|
if split.len() != 3 {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -336,32 +336,32 @@ fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String>
|
|||||||
|
|
||||||
// Prints out a Wasm module, and for each function the corresponding translation in Cretonne IL.
|
// Prints out a Wasm module, and for each function the corresponding translation in Cretonne IL.
|
||||||
fn pretty_print_translation(
|
fn pretty_print_translation(
|
||||||
filename: &String,
|
filename: &str,
|
||||||
data: &Vec<u8>,
|
data: &[u8],
|
||||||
translation: &TranslationResult,
|
translation: &TranslationResult,
|
||||||
writer_wast: &mut Write,
|
writer_wast: &mut Write,
|
||||||
writer_cretonne: &mut Write,
|
writer_cretonne: &mut Write,
|
||||||
) -> Result<(), io::Error> {
|
) -> Result<(), io::Error> {
|
||||||
let mut terminal = term::stdout().unwrap();
|
let mut terminal = term::stdout().unwrap();
|
||||||
let mut parser = Parser::new(data.as_slice());
|
let mut parser = Parser::new(data);
|
||||||
let mut parser_writer = Writer::new(writer_wast);
|
let mut parser_writer = Writer::new(writer_wast);
|
||||||
let imports_count = translation.functions.iter().fold(0, |acc, &ref f| match f {
|
let imports_count = translation.functions.iter().fold(0, |acc, f| match f {
|
||||||
&FunctionTranslation::Import() => acc + 1,
|
&FunctionTranslation::Import() => acc + 1,
|
||||||
&FunctionTranslation::Code { .. } => acc,
|
&FunctionTranslation::Code { .. } => acc,
|
||||||
});
|
});
|
||||||
match parser.read() {
|
match parser.read() {
|
||||||
s @ &ParserState::BeginWasm { .. } => parser_writer.write(&s)?,
|
s @ &ParserState::BeginWasm { .. } => parser_writer.write(s)?,
|
||||||
_ => panic!("modules should begin properly"),
|
_ => panic!("modules should begin properly"),
|
||||||
}
|
}
|
||||||
loop {
|
loop {
|
||||||
match parser.read() {
|
match parser.read() {
|
||||||
s @ &ParserState::BeginSection { code: SectionCode::Code, .. } => {
|
s @ &ParserState::BeginSection { code: SectionCode::Code, .. } => {
|
||||||
// The code section begins
|
// The code section begins
|
||||||
parser_writer.write(&s)?;
|
parser_writer.write(s)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
&ParserState::EndWasm => return Ok(()),
|
&ParserState::EndWasm => return Ok(()),
|
||||||
s @ _ => parser_writer.write(&s)?,
|
s => parser_writer.write(s)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let mut function_index = 0;
|
let mut function_index = 0;
|
||||||
@@ -378,10 +378,10 @@ fn pretty_print_translation(
|
|||||||
terminal.fg(term::color::CYAN).unwrap();
|
terminal.fg(term::color::CYAN).unwrap();
|
||||||
write!(writer_cretonne, "Wast ---------->\n")?;
|
write!(writer_cretonne, "Wast ---------->\n")?;
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
parser_writer.write(&s)?;
|
parser_writer.write(s)?;
|
||||||
}
|
}
|
||||||
s @ &ParserState::EndSection => {
|
s @ &ParserState::EndSection => {
|
||||||
parser_writer.write(&s)?;
|
parser_writer.write(s)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
_ => panic!("wrong content in code section"),
|
_ => panic!("wrong content in code section"),
|
||||||
@@ -390,11 +390,11 @@ fn pretty_print_translation(
|
|||||||
loop {
|
loop {
|
||||||
match parser.read() {
|
match parser.read() {
|
||||||
s @ &ParserState::EndFunctionBody => {
|
s @ &ParserState::EndFunctionBody => {
|
||||||
parser_writer.write(&s)?;
|
parser_writer.write(s)?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s @ _ => {
|
s => {
|
||||||
parser_writer.write(&s)?;
|
parser_writer.write(s)?;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -417,7 +417,7 @@ fn pretty_print_translation(
|
|||||||
loop {
|
loop {
|
||||||
match parser.read() {
|
match parser.read() {
|
||||||
&ParserState::EndWasm => return Ok(()),
|
&ParserState::EndWasm => return Ok(()),
|
||||||
s @ _ => parser_writer.write(&s)?,
|
s => parser_writer.write(s)?,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,7 +426,7 @@ fn pretty_print_translation(
|
|||||||
pub fn pretty_verifier_error(
|
pub fn pretty_verifier_error(
|
||||||
func: &ir::Function,
|
func: &ir::Function,
|
||||||
isa: Option<&TargetIsa>,
|
isa: Option<&TargetIsa>,
|
||||||
err: verifier::Error,
|
err: &verifier::Error,
|
||||||
) -> String {
|
) -> String {
|
||||||
let msg = err.to_string();
|
let msg = err.to_string();
|
||||||
let str1 = match err.location {
|
let str1 = match err.location {
|
||||||
|
|||||||
Reference in New Issue
Block a user