Improve error handling, and start refactoring Instance.
Introduce proper error handling in several places, and perform a first pass at refactoring Instance to make it easier to use.
This commit is contained in:
@@ -38,7 +38,7 @@ use cranelift_codegen::settings;
|
||||
use cranelift_codegen::settings::Configurable;
|
||||
use docopt::Docopt;
|
||||
use std::path::Path;
|
||||
use wasmtime_wast::wast_file;
|
||||
use wasmtime_wast::WastContext;
|
||||
|
||||
static LOG_FILENAME_PREFIX: &str = "cranelift.dbg.";
|
||||
|
||||
@@ -94,9 +94,10 @@ fn main() {
|
||||
}
|
||||
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
let mut wast_context = WastContext::new();
|
||||
for filename in &args.arg_file {
|
||||
let path = Path::new(&filename);
|
||||
wast_file(path, &*isa)
|
||||
.unwrap_or_else(|e| panic!("error reading file {}: {}", path.display(), e));
|
||||
wast_context
|
||||
.run_file(&*isa, Path::new(&filename))
|
||||
.unwrap_or_else(|e| panic!("{}", e));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -146,7 +146,12 @@ fn handle_module(path: PathBuf, target: &Option<String>, output: &str) -> Result
|
||||
.map_err(|err| format!("{}", err))?;
|
||||
}
|
||||
|
||||
let (compilation, relocations) = compile_module(&translation, &*isa)?;
|
||||
let (compilation, relocations) = compile_module(
|
||||
&translation.module,
|
||||
&translation.lazy.function_body_inputs,
|
||||
&*isa,
|
||||
)
|
||||
.map_err(|e| e.to_string())?;
|
||||
|
||||
emit_module(&mut obj, &translation.module, &compilation, &relocations)?;
|
||||
|
||||
|
||||
@@ -105,6 +105,13 @@ fn main() {
|
||||
.deserialize()
|
||||
})
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
|
||||
if args.flag_debug {
|
||||
pretty_env_logger::init();
|
||||
} else {
|
||||
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
|
||||
}
|
||||
|
||||
let isa_builder = cranelift_native::builder().unwrap_or_else(|_| {
|
||||
panic!("host machine is not a supported target");
|
||||
});
|
||||
@@ -115,18 +122,13 @@ fn main() {
|
||||
flag_builder.enable("enable_verifier").unwrap();
|
||||
}
|
||||
|
||||
if args.flag_debug {
|
||||
pretty_env_logger::init();
|
||||
} else {
|
||||
file_per_thread_logger::initialize(LOG_FILENAME_PREFIX);
|
||||
}
|
||||
|
||||
// Enable optimization if requested.
|
||||
if args.flag_optimize {
|
||||
flag_builder.set("opt_level", "best").unwrap();
|
||||
}
|
||||
|
||||
let isa = isa_builder.finish(settings::Flags::new(flag_builder));
|
||||
|
||||
for filename in &args.arg_file {
|
||||
let path = Path::new(&filename);
|
||||
match handle_module(&args, path, &*isa) {
|
||||
@@ -149,10 +151,14 @@ fn handle_module(args: &Args, path: &Path, isa: &TargetIsa) -> Result<(), String
|
||||
}
|
||||
let mut resolver = NullResolver {};
|
||||
let mut code = Code::new();
|
||||
let mut world = InstanceWorld::new(&mut code, isa, &data, &mut resolver)?;
|
||||
let mut world =
|
||||
InstanceWorld::new(&mut code, isa, &data, &mut resolver).map_err(|e| e.to_string())?;
|
||||
|
||||
if let Some(ref f) = args.flag_invoke {
|
||||
match world.invoke(&mut code, isa, &f, &[])? {
|
||||
match world
|
||||
.invoke(&mut code, isa, &f, &[])
|
||||
.map_err(|e| e.to_string())?
|
||||
{
|
||||
ActionOutcome::Returned { .. } => {}
|
||||
ActionOutcome::Trapped { message } => {
|
||||
return Err(format!("Trap from within function {}: {}", f, message));
|
||||
|
||||
Reference in New Issue
Block a user