Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ wasmtime-runtime = { path = "lib/runtime" }
wasmtime-jit = { path = "lib/jit" }
wasmtime-obj = { path = "lib/obj" }
wasmtime-wast = { path = "lib/wast" }
docopt = "1.0.1"
serde = "1.0.75"
serde_derive = "1.0.75"
structopt = "0.2.15"
faerie = "0.7.1"
target-lexicon = { version = "0.2.0", default-features = false }
pretty_env_logger = "0.3.0"
Expand Down
56 changes: 22 additions & 34 deletions src/wasm2obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,9 @@
)
)]

#[macro_use]
extern crate serde_derive;

use cranelift_codegen::isa;
use cranelift_codegen::settings;
use cranelift_native;
use docopt::Docopt;
use faerie::Artifact;
use std::error::Error;
use std::fmt::format;
Expand All @@ -47,34 +43,33 @@ use std::path::PathBuf;
use std::process;
use std::str;
use std::str::FromStr;
use structopt::StructOpt;
use target_lexicon::Triple;
use wasmtime_debug::{emit_debugsections, read_debuginfo};
use wasmtime_environ::{cranelift, ModuleEnvironment, Tunables};
use wasmtime_obj::emit_module;

const USAGE: &str = "
Wasm to native object translation utility.
Takes a binary WebAssembly module into a native object file.
The translation is dependent on the environment chosen.
The default is a dummy environment that produces placeholder values.

Usage:
wasm2obj [--target TARGET] [-g] <file> -o <output>
wasm2obj --help | --version

Options:
-v, --verbose displays the module and translated functions
-h, --help print this help message
--target <TARGET> build for the target triple; default is the host machine
-g generate debug information
--version print the Cranelift version
";

#[derive(Deserialize, Debug, Clone)]
/// Wasm to native object translation utility.
///
/// Takes a binary WebAssembly module into a native object file.
/// The translation is dependent on the environment chosen.
/// The default is a dummy environment that produces placeholder values.
#[derive(StructOpt, Debug, Clone)]
#[structopt(name = "wasm2obj")]
struct Args {
arg_file: String,
#[structopt(name = "FILE", parse(from_os_str))]
arg_file: PathBuf,

/// output file
#[structopt(short = "o")]
arg_output: String,

/// build for the target triple; default is the host machine
#[structopt(long = "target")]
arg_target: Option<String>,

/// generate debug information
#[structopt(short = "g")]
flag_g: bool,
}

Expand All @@ -86,17 +81,10 @@ fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
}

fn main() {
let args: Args = Docopt::new(USAGE)
.and_then(|d| {
d.help(true)
.version(Some(String::from("0.0.0")))
.deserialize()
})
.unwrap_or_else(|e| e.exit());

let path = Path::new(&args.arg_file);
let args = Args::from_args();

match handle_module(
path.to_path_buf(),
args.arg_file,
&args.arg_target,
&args.arg_output,
args.flag_g,
Expand Down
64 changes: 26 additions & 38 deletions src/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,9 @@
)
)]

#[macro_use]
extern crate serde_derive;

use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_native;
use docopt::Docopt;
use file_per_thread_logger;
use pretty_env_logger;
use std::error::Error;
Expand All @@ -45,39 +41,38 @@ use std::io;
use std::io::prelude::*;
use std::path::{Path, PathBuf};
use std::process::exit;
use structopt::StructOpt;
use wabt;
use wasmtime_jit::{ActionOutcome, Context};
use wasmtime_wast::instantiate_spectest;

static LOG_FILENAME_PREFIX: &str = "wasmtime.dbg.";

const USAGE: &str = "
Wasm runner.

Takes a binary (wasm) or text (wat) WebAssembly module and instantiates it,
including calling the start function if one is present. Additional functions
given with --invoke are then called.

Usage:
wasmtime [-odg] <file>...
wasmtime [-odg] <file>... --invoke=<fn>
wasmtime --help | --version

Options:
--invoke=<fn> name of function to run
-o, --optimize runs optimization passes on the translated functions
-g generate debug information
-d, --debug enable debug output on stderr/stdout
-h, --help print this help message
--version print the Cranelift version
";

#[derive(Deserialize, Debug, Clone)]
/// Wasm runner.
///
/// Takes a binary (wasm) or text (wat) WebAssembly module and instantiates it,
/// including calling the start function if one is present. Additional functions
/// given with --invoke are then called.
#[derive(StructOpt, Debug, Clone)]
#[structopt(name = "wasmtime")]
struct Args {
arg_file: Vec<String>,
#[structopt(name = "FILE", parse(from_os_str))]
arg_file: Vec<PathBuf>,

/// runs optimization passes on the translated functions
#[structopt(short = "o", long = "optimize")]
flag_optimize: bool,

/// enable debug output on stderr/stdout
#[structopt(short = "d", long = "debug")]
flag_debug: bool,

/// generate debug information
#[structopt(short = "g")]
flag_g: bool,

/// name of function to run
#[structopt(long = "invoke")]
flag_invoke: Option<String>,
}

Expand All @@ -101,13 +96,7 @@ fn read_wasm(path: PathBuf) -> Result<Vec<u8>, String> {
}

fn main() {
let args: Args = Docopt::new(USAGE)
.and_then(|d| {
d.help(true)
.version(Some(String::from("0.0.0")))
.deserialize()
})
.unwrap_or_else(|e| e.exit());
let args = Args::from_args();

if args.flag_debug {
pretty_env_logger::init();
Expand Down Expand Up @@ -142,12 +131,11 @@ fn main() {
// Enable/disable producing of debug info.
context.set_debug_info(args.flag_g);

for filename in &args.arg_file {
let path = Path::new(&filename);
match handle_module(&mut context, &args, path) {
for path in &args.arg_file {
match handle_module(&mut context, &args, &path) {
Ok(()) => {}
Err(message) => {
let name = path.as_os_str().to_string_lossy();
let name = path.to_string_lossy();
println!("error while processing {}: {}", name, message);
exit(1);
}
Expand Down
54 changes: 20 additions & 34 deletions src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,40 @@
)
)]

#[macro_use]
extern crate serde_derive;

use cranelift_codegen::settings;
use cranelift_codegen::settings::Configurable;
use cranelift_native;
use docopt::Docopt;
use file_per_thread_logger;
use pretty_env_logger;
use std::path::Path;
use std::path::PathBuf;
use std::process;
use structopt::StructOpt;
use wasmtime_jit::Compiler;
use wasmtime_wast::WastContext;

static LOG_FILENAME_PREFIX: &str = "cranelift.dbg.";

const USAGE: &str = "
Wast test runner.

Usage:
run_wast [-do] <file>...
run_wast --help | --version

Options:
-h, --help print this help message
--version print the Cranelift version
-o, --optimize runs optimization passes on the translated functions
-d, --debug enable debug output on stderr/stdout
";

#[derive(Deserialize, Debug, Clone)]
/// Wast test runner.
#[derive(StructOpt, Debug, Clone)]
#[structopt(name = "wast")]
struct Args {
arg_file: Vec<String>,
#[structopt(name = "FILE", parse(from_os_str))]
arg_file: Vec<PathBuf>,

/// enable debug output on stderr/stdout
#[structopt(short = "d", long = "debug")]
flag_debug: bool,

#[structopt(long = "function")]
flag_function: Option<String>,

/// runs optimization passes on the translated functions
#[structopt(short = "o", long = "optimize")]
flag_optimize: bool,
}

fn main() {
let args: Args = Docopt::new(USAGE)
.and_then(|d| {
d.help(true)
.version(Some(String::from("0.0.0")))
.deserialize()
})
.unwrap_or_else(|e| e.exit());
let args = Args::from_args();

if args.flag_debug {
pretty_env_logger::init();
Expand Down Expand Up @@ -102,11 +90,9 @@ fn main() {
.expect("error instantiating \"spectest\"");

for filename in &args.arg_file {
wast_context
.run_file(Path::new(&filename))
.unwrap_or_else(|e| {
eprintln!("{}", e);
process::exit(1)
});
wast_context.run_file(&filename).unwrap_or_else(|e| {
eprintln!("{}", e);
process::exit(1)
});
}
}