Simplify using map_err and expect.
This commit is contained in:
@@ -67,17 +67,14 @@ pub fn run(
|
|||||||
for filename in files {
|
for filename in files {
|
||||||
let path = Path::new(&filename);
|
let path = Path::new(&filename);
|
||||||
let name = String::from(path.as_os_str().to_string_lossy());
|
let name = String::from(path.as_os_str().to_string_lossy());
|
||||||
match handle_module(
|
handle_module(
|
||||||
flag_verbose,
|
flag_verbose,
|
||||||
flag_optimize,
|
flag_optimize,
|
||||||
flag_check,
|
flag_check,
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
name,
|
name,
|
||||||
&flags,
|
&flags,
|
||||||
) {
|
)?;
|
||||||
Ok(()) => {}
|
|
||||||
Err(message) => return Err(message),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -105,12 +102,9 @@ fn handle_module(
|
|||||||
Some(ext) => {
|
Some(ext) => {
|
||||||
match ext.to_str() {
|
match ext.to_str() {
|
||||||
Some("wasm") => {
|
Some("wasm") => {
|
||||||
match read_wasm_file(path.clone()) {
|
read_wasm_file(path.clone()).map_err(|err| {
|
||||||
Ok(data) => data,
|
String::from(err.description())
|
||||||
Err(err) => {
|
})?
|
||||||
return Err(String::from(err.description()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Some("wat") => {
|
Some("wat") => {
|
||||||
let tmp_dir = TempDir::new("cretonne-wasm").unwrap();
|
let tmp_dir = TempDir::new("cretonne-wasm").unwrap();
|
||||||
@@ -127,12 +121,9 @@ fn handle_module(
|
|||||||
return Err(String::from(e.description()));
|
return Err(String::from(e.description()));
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
match read_wasm_file(file_path) {
|
read_wasm_file(file_path).map_err(|err| {
|
||||||
Ok(data) => data,
|
String::from(err.description())
|
||||||
Err(err) => {
|
})?
|
||||||
return Err(String::from(err.description()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None | Some(&_) => {
|
None | Some(&_) => {
|
||||||
return Err(String::from("the file extension is not wasm or wat"));
|
return Err(String::from("the file extension is not wasm or wat"));
|
||||||
@@ -143,12 +134,7 @@ fn handle_module(
|
|||||||
let mut dummy_runtime = DummyRuntime::with_flags(flags.clone());
|
let mut dummy_runtime = DummyRuntime::with_flags(flags.clone());
|
||||||
let translation = {
|
let translation = {
|
||||||
let runtime: &mut WasmRuntime = &mut dummy_runtime;
|
let runtime: &mut WasmRuntime = &mut dummy_runtime;
|
||||||
match translate_module(&data, runtime) {
|
translate_module(&data, runtime)?
|
||||||
Ok(x) => x,
|
|
||||||
Err(string) => {
|
|
||||||
return Err(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, " ok");
|
vprintln!(flag_verbose, " ok");
|
||||||
@@ -158,10 +144,9 @@ fn handle_module(
|
|||||||
vprint!(flag_verbose, "Checking... ");
|
vprint!(flag_verbose, "Checking... ");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
for func in &translation.functions {
|
for func in &translation.functions {
|
||||||
match verifier::verify_function(func, None) {
|
verifier::verify_function(func, None).map_err(|err| {
|
||||||
Ok(()) => (),
|
pretty_verifier_error(func, None, err)
|
||||||
Err(err) => return Err(pretty_verifier_error(func, None, err)),
|
})?;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, " ok");
|
vprintln!(flag_verbose, " ok");
|
||||||
@@ -184,42 +169,22 @@ fn handle_module(
|
|||||||
context.cfg = cfg;
|
context.cfg = cfg;
|
||||||
context.domtree = domtree;
|
context.domtree = domtree;
|
||||||
context.loop_analysis = loop_analysis;
|
context.loop_analysis = loop_analysis;
|
||||||
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
verifier::verify_context(&context.func, &context.cfg, &context.domtree, None)
|
||||||
Ok(()) => (),
|
.map_err(|err| pretty_verifier_error(&context.func, None, err))?;
|
||||||
Err(err) => {
|
context.licm().map_err(|error| match error {
|
||||||
return Err(pretty_verifier_error(&context.func, None, err));
|
CtonError::Verifier(err) => pretty_verifier_error(&context.func, None, err),
|
||||||
}
|
|
||||||
};
|
|
||||||
match context.licm() {
|
|
||||||
Ok(())=> (),
|
|
||||||
Err(error) => {
|
|
||||||
match error {
|
|
||||||
CtonError::Verifier(err) => {
|
|
||||||
return Err(pretty_verifier_error(&context.func, None, err));
|
|
||||||
}
|
|
||||||
CtonError::InvalidInput |
|
CtonError::InvalidInput |
|
||||||
CtonError::ImplLimitExceeded |
|
CtonError::ImplLimitExceeded |
|
||||||
CtonError::CodeTooLarge => return Err(String::from(error.description())),
|
CtonError::CodeTooLarge => String::from(error.description()),
|
||||||
}
|
})?;
|
||||||
}
|
context.simple_gvn().map_err(|error| match error {
|
||||||
};
|
CtonError::Verifier(err) => pretty_verifier_error(&context.func, None, err),
|
||||||
match context.simple_gvn() {
|
|
||||||
Ok(())=> (),
|
|
||||||
Err(error) => {
|
|
||||||
match error {
|
|
||||||
CtonError::Verifier(err) => {
|
|
||||||
return Err(pretty_verifier_error(&context.func, None, err));
|
|
||||||
}
|
|
||||||
CtonError::InvalidInput |
|
CtonError::InvalidInput |
|
||||||
CtonError::ImplLimitExceeded |
|
CtonError::ImplLimitExceeded |
|
||||||
CtonError::CodeTooLarge => return Err(String::from(error.description())),
|
CtonError::CodeTooLarge => String::from(error.description()),
|
||||||
}
|
})?;
|
||||||
}
|
verifier::verify_context(&context.func, &context.cfg, &context.domtree, None)
|
||||||
};
|
.map_err(|err| pretty_verifier_error(&context.func, None, err))?;
|
||||||
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
|
||||||
Ok(()) => (),
|
|
||||||
Err(err) => return Err(pretty_verifier_error(&context.func, None, err)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, " ok");
|
vprintln!(flag_verbose, " ok");
|
||||||
|
|||||||
@@ -39,19 +39,15 @@ pub fn parse_function_signatures(
|
|||||||
}) => {
|
}) => {
|
||||||
let mut sig = Signature::new(CallConv::Native);
|
let mut sig = Signature::new(CallConv::Native);
|
||||||
sig.argument_types.extend(params.iter().map(|ty| {
|
sig.argument_types.extend(params.iter().map(|ty| {
|
||||||
let cret_arg: cretonne::ir::Type = match type_to_type(ty) {
|
let cret_arg: cretonne::ir::Type = type_to_type(ty).expect(
|
||||||
Ok(ty) => ty,
|
"only numeric types are supported in function signatures",
|
||||||
Err(()) => panic!("only numeric types are supported in\
|
);
|
||||||
function signatures"),
|
|
||||||
};
|
|
||||||
ArgumentType::new(cret_arg)
|
ArgumentType::new(cret_arg)
|
||||||
}));
|
}));
|
||||||
sig.return_types.extend(returns.iter().map(|ty| {
|
sig.return_types.extend(returns.iter().map(|ty| {
|
||||||
let cret_arg: cretonne::ir::Type = match type_to_type(ty) {
|
let cret_arg: cretonne::ir::Type = type_to_type(ty).expect(
|
||||||
Ok(ty) => ty,
|
"only numeric types are supported in function signatures",
|
||||||
Err(()) => panic!("only numeric types are supported in\
|
);
|
||||||
function signatures"),
|
|
||||||
};
|
|
||||||
ArgumentType::new(cret_arg)
|
ArgumentType::new(cret_arg)
|
||||||
}));
|
}));
|
||||||
runtime.declare_signature(&sig);
|
runtime.declare_signature(&sig);
|
||||||
|
|||||||
@@ -67,12 +67,7 @@ fn handle_module(path: PathBuf, isa: Option<&TargetIsa>) {
|
|||||||
}
|
}
|
||||||
Some(ext) => {
|
Some(ext) => {
|
||||||
match ext.to_str() {
|
match ext.to_str() {
|
||||||
Some("wasm") => {
|
Some("wasm") => read_wasm_file(path.clone()).expect("error reading wasm file"),
|
||||||
match read_wasm_file(path.clone()) {
|
|
||||||
Ok(data) => data,
|
|
||||||
Err(err) => panic!("error reading wasm file: {}", err.description()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Some("wat") => {
|
Some("wat") => {
|
||||||
let tmp_dir = TempDir::new("cretonne-wasm").unwrap();
|
let tmp_dir = TempDir::new("cretonne-wasm").unwrap();
|
||||||
let file_path = tmp_dir.path().join("module.wasm");
|
let file_path = tmp_dir.path().join("module.wasm");
|
||||||
@@ -104,12 +99,7 @@ fn handle_module(path: PathBuf, isa: Option<&TargetIsa>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match read_wasm_file(file_path) {
|
read_wasm_file(file_path).expect("error reading converted wasm file")
|
||||||
Ok(data) => data,
|
|
||||||
Err(err) => {
|
|
||||||
panic!("error reading converted wasm file: {}", err.description());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None | Some(&_) => panic!("the file extension is not wasm or wat"),
|
None | Some(&_) => panic!("the file extension is not wasm or wat"),
|
||||||
}
|
}
|
||||||
@@ -121,18 +111,12 @@ fn handle_module(path: PathBuf, isa: Option<&TargetIsa>) {
|
|||||||
};
|
};
|
||||||
let translation = {
|
let translation = {
|
||||||
let runtime: &mut WasmRuntime = &mut dummy_runtime;
|
let runtime: &mut WasmRuntime = &mut dummy_runtime;
|
||||||
match translate_module(&data, runtime) {
|
translate_module(&data, runtime).unwrap()
|
||||||
Ok(x) => x,
|
|
||||||
Err(string) => {
|
|
||||||
panic!(string);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
for func in &translation.functions {
|
for func in &translation.functions {
|
||||||
match verifier::verify_function(func, isa) {
|
verifier::verify_function(func, isa)
|
||||||
Ok(()) => (),
|
.map_err(|err| panic!(pretty_verifier_error(func, isa, err)))
|
||||||
Err(err) => panic!(pretty_verifier_error(func, isa, err)),
|
.unwrap();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user