Dumped code from the wasm2cretonne repo
This commit is contained in:
@@ -16,6 +16,7 @@ path = "src/cton-util.rs"
|
||||
cretonne = { path = "lib/cretonne" }
|
||||
cretonne-reader = { path = "lib/reader" }
|
||||
cretonne-frontend = { path = "lib/frontend" }
|
||||
wasm2cretonne-util = { path = "lib/wasm2cretonne-util" }
|
||||
filecheck = { path = "lib/filecheck" }
|
||||
docopt = "0.8.0"
|
||||
serde = "1.0.8"
|
||||
|
||||
22
lib/wasm2cretonne-util/Cargo.toml
Normal file
22
lib/wasm2cretonne-util/Cargo.toml
Normal file
@@ -0,0 +1,22 @@
|
||||
[package]
|
||||
name = "wasm2cretonne-util"
|
||||
version = "0.0.0"
|
||||
authors = ["The Cretonne Project Developers"]
|
||||
publish = false
|
||||
|
||||
[[bin]]
|
||||
name = "wasm2cretonne-util"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
wasm2cretonne = { path = "../wasm2cretonne" }
|
||||
wasmstandalone = { path = "../wasmstandalone" }
|
||||
wasmparser = "0.6.1"
|
||||
cretonne = { path = "../cretonne" }
|
||||
cretonne-frontend = { path = "../frontend" }
|
||||
wasmtext = { git = "https://github.com/yurydelendik/wasmtext" }
|
||||
docopt = "0.8.0"
|
||||
serde = "1.0.8"
|
||||
serde_derive = "1.0.8"
|
||||
term = "*"
|
||||
tempdir="*"
|
||||
62
lib/wasm2cretonne-util/README.md
Normal file
62
lib/wasm2cretonne-util/README.md
Normal file
@@ -0,0 +1,62 @@
|
||||
# wasm2cretonne
|
||||
|
||||
[Cretonne](https://github.com/stoklund/cretonne) frontend for WebAssembly. Reads wasm binary modules and translate the functions it contains into Cretonne IL functions.
|
||||
|
||||
The translation needs some info about the runtime in order to handle the wasm instructions `get_global`, `set_global`, and `call_indirect`. These informations are included in structs implementing the `WasmRuntime` trait like `DummyRuntime` or `StandaloneRuntime`.
|
||||
|
||||
|
||||
The `StandaloneRuntime` is a setup for in-memory execution of the module just after translation to Cretonne IL. It allocates memory for the wasm linear memories, the globals and the tables and embeds the addresses of these memories inside the generated Cretonne IL functions. Then it runs Cretonne's compilation, emits the code to memory and executes the `start` function of the module.
|
||||
|
||||
## API
|
||||
|
||||
Use the functions defined in the crates `wasm2cretonne` and `wasmruntime`.
|
||||
|
||||
### Example
|
||||
|
||||
```rust
|
||||
use wasm2cretonne::translate_module;
|
||||
use wasmruntime::{StandaloneRuntime, compile_module, execute};
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
let file = File::open(path)?;
|
||||
let mut buf_reader = BufReader::new(file);
|
||||
buf_reader.read_to_end(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
let path = Path::new("filetests/arith.wasm");
|
||||
let data = match read_wasm_file(path.to_path_buf()) {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
panic!("Error: {}", err);
|
||||
}
|
||||
};
|
||||
let mut runtime = StandaloneRuntime::new();
|
||||
let translation = match translate_module(&data, &mut runtime) {
|
||||
Ok(x) => x,
|
||||
Err(string) => {
|
||||
panic!(string);
|
||||
}
|
||||
};
|
||||
let exec = compile_module(&translation, "intel");
|
||||
execute(exec);
|
||||
println!("Memory after execution: {:?}", runtime.inspect_memory(0,0,4));
|
||||
```
|
||||
|
||||
## CLI tool
|
||||
|
||||
The binary created by the root crate of this repo is an utility to parse, translate, compile and execute wasm binaries using Cretonne. Usage:
|
||||
|
||||
```
|
||||
wasm2cretonne-util <files to translate>
|
||||
-v, --verbose displays info on the different steps
|
||||
-p, --print displays the module and translated functions
|
||||
-c, --check checks the corectness of the translated functions
|
||||
-o, --optimize runs optimization passes on the translated functions
|
||||
-e, --execute enable the standalone runtime and executes the start function of the module
|
||||
-m, --memory interactive memory inspector after execution
|
||||
```
|
||||
|
||||
The tool reads `.wasm` files but also `.wast` as long as the [WebAssembly binary toolkit](https://github.com/WebAssembly/wabt)'s `wast2wasm` executable is accessible in your `PATH`. For now, only the 64 bits Intel architecture is supported for execution.
|
||||
BIN
lib/wasm2cretonne-util/filetests/arith.wasm
Normal file
BIN
lib/wasm2cretonne-util/filetests/arith.wasm
Normal file
Binary file not shown.
13
lib/wasm2cretonne-util/filetests/arith.wast
Normal file
13
lib/wasm2cretonne-util/filetests/arith.wast
Normal file
@@ -0,0 +1,13 @@
|
||||
(module
|
||||
(memory 1)
|
||||
(func $main (local i32)
|
||||
(set_local 0 (i32.sub (i32.const 4) (i32.const 4)))
|
||||
(if
|
||||
(get_local 0)
|
||||
(then unreachable)
|
||||
(else (drop (i32.mul (i32.const 6) (get_local 0))))
|
||||
)
|
||||
)
|
||||
(start $main)
|
||||
(data (i32.const 0) "abcdefgh")
|
||||
)
|
||||
BIN
lib/wasm2cretonne-util/filetests/call.wasm
Normal file
BIN
lib/wasm2cretonne-util/filetests/call.wasm
Normal file
Binary file not shown.
10
lib/wasm2cretonne-util/filetests/call.wast
Normal file
10
lib/wasm2cretonne-util/filetests/call.wast
Normal file
@@ -0,0 +1,10 @@
|
||||
(module
|
||||
(func $main (local i32)
|
||||
(set_local 0 (i32.const 0))
|
||||
(drop (call $inc))
|
||||
)
|
||||
(func $inc (result i32)
|
||||
(i32.const 1)
|
||||
)
|
||||
(start $main)
|
||||
)
|
||||
BIN
lib/wasm2cretonne-util/filetests/globals.wasm
Normal file
BIN
lib/wasm2cretonne-util/filetests/globals.wasm
Normal file
Binary file not shown.
8
lib/wasm2cretonne-util/filetests/globals.wast
Normal file
8
lib/wasm2cretonne-util/filetests/globals.wast
Normal file
@@ -0,0 +1,8 @@
|
||||
(module
|
||||
(global $x (mut i32) (i32.const 4))
|
||||
(memory 1)
|
||||
(func $main (local i32)
|
||||
(i32.store (i32.const 0) (get_global $x))
|
||||
)
|
||||
(start $main)
|
||||
)
|
||||
BIN
lib/wasm2cretonne-util/filetests/memory.wasm
Normal file
BIN
lib/wasm2cretonne-util/filetests/memory.wasm
Normal file
Binary file not shown.
11
lib/wasm2cretonne-util/filetests/memory.wast
Normal file
11
lib/wasm2cretonne-util/filetests/memory.wast
Normal file
@@ -0,0 +1,11 @@
|
||||
(module
|
||||
(memory 1)
|
||||
(func $main (local i32)
|
||||
(i32.store (i32.const 0) (i32.const 0x0))
|
||||
(if (i32.load (i32.const 0))
|
||||
(then (i32.store (i32.const 0) (i32.const 0xa)))
|
||||
(else (i32.store (i32.const 0) (i32.const 0xb))))
|
||||
)
|
||||
(start $main)
|
||||
(data (i32.const 0) "0000")
|
||||
)
|
||||
BIN
lib/wasm2cretonne-util/filetests/sample.wasm
Normal file
BIN
lib/wasm2cretonne-util/filetests/sample.wasm
Normal file
Binary file not shown.
440
lib/wasm2cretonne-util/src/main.rs
Normal file
440
lib/wasm2cretonne-util/src/main.rs
Normal file
@@ -0,0 +1,440 @@
|
||||
//! CLI tool to use the functions provided by crates [wasm2cretonne](../wasm2cretonne/index.html)
|
||||
//! and [wasmstandalone](../wasmstandalone/index.html).
|
||||
//!
|
||||
//! Reads Wasm binary files (one Wasm module per file), translates the functions' code to Cretonne
|
||||
//! IL. Can also executes the `start` function of the module by laying out the memories, globals
|
||||
//! and tables, then emitting the translated code with hardcoded addresses to memory.
|
||||
|
||||
extern crate wasm2cretonne;
|
||||
extern crate wasmstandalone;
|
||||
extern crate wasmparser;
|
||||
extern crate cretonne;
|
||||
extern crate wasmtext;
|
||||
extern crate docopt;
|
||||
extern crate serde;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
extern crate term;
|
||||
extern crate tempdir;
|
||||
|
||||
use wasm2cretonne::{translate_module, TranslationResult, FunctionTranslation, DummyRuntime,
|
||||
WasmRuntime};
|
||||
use wasmstandalone::{StandaloneRuntime, compile_module, execute};
|
||||
use std::path::PathBuf;
|
||||
use wasmparser::{Parser, ParserState, WasmDecoder, SectionCode};
|
||||
use wasmtext::Writer;
|
||||
use cretonne::loop_analysis::LoopAnalysis;
|
||||
use cretonne::flowgraph::ControlFlowGraph;
|
||||
use cretonne::dominator_tree::DominatorTree;
|
||||
use cretonne::Context;
|
||||
use cretonne::result::CtonError;
|
||||
use cretonne::ir;
|
||||
use cretonne::ir::entities::AnyEntity;
|
||||
use cretonne::isa::TargetIsa;
|
||||
use cretonne::verifier;
|
||||
use std::fs::File;
|
||||
use std::error::Error;
|
||||
use std::io;
|
||||
use std::io::{BufReader, stdout};
|
||||
use std::io::prelude::*;
|
||||
use docopt::Docopt;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use tempdir::TempDir;
|
||||
|
||||
macro_rules! vprintln {
|
||||
($x: expr, $($tts:tt)*) => {
|
||||
if $x {
|
||||
println!($($tts)*);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! vprint {
|
||||
($x: expr, $($tts:tt)*) => {
|
||||
if $x {
|
||||
print!($($tts)*);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const USAGE: &str = "
|
||||
Wasm to Cretonne IL translation utility.
|
||||
Takes a binary WebAssembly module and returns its functions in Cretonne IL format.
|
||||
The translation is dependent on the runtime chosen.
|
||||
The default is a dummy runtime that produces placeholder values.
|
||||
|
||||
Usage:
|
||||
wasm2cretonne-util [-vcop] <file>...
|
||||
wasm2cretonne-util -e [-mvcop] <file>...
|
||||
wasm2cretonne-util --help | --version
|
||||
|
||||
Options:
|
||||
-v, --verbose displays info on the different steps
|
||||
-p, --print displays the module and translated functions
|
||||
-c, --check checks the corectness of the translated functions
|
||||
-o, --optimize runs optimization passes on the translated functions
|
||||
-e, --execute enable the standalone runtime and executes the start function of the module
|
||||
-m, --memory interactive memory inspector after execution
|
||||
-h, --help print this help message
|
||||
--version print the Cretonne version
|
||||
";
|
||||
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
struct Args {
|
||||
arg_file: Vec<String>,
|
||||
flag_verbose: bool,
|
||||
flag_execute: bool,
|
||||
flag_memory: bool,
|
||||
flag_check: bool,
|
||||
flag_optimize: bool,
|
||||
flag_print: bool,
|
||||
}
|
||||
|
||||
fn read_wasm_file(path: PathBuf) -> Result<Vec<u8>, io::Error> {
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
let file = File::open(path)?;
|
||||
let mut buf_reader = BufReader::new(file);
|
||||
buf_reader.read_to_end(&mut buf)?;
|
||||
Ok(buf)
|
||||
}
|
||||
|
||||
|
||||
fn main() {
|
||||
let args: Args = Docopt::new(USAGE)
|
||||
.and_then(|d| d.help(true).version(Some(format!("0.0.0"))).deserialize())
|
||||
.unwrap_or_else(|e| e.exit());
|
||||
let mut terminal = term::stdout().unwrap();
|
||||
for filename in args.arg_file.iter() {
|
||||
let path = Path::new(&filename);
|
||||
let name = String::from(path.as_os_str().to_string_lossy());
|
||||
match handle_module(&args, path.to_path_buf(), name) {
|
||||
Ok(()) => {}
|
||||
Err(message) => {
|
||||
terminal.fg(term::color::RED).unwrap();
|
||||
vprintln!(args.flag_verbose, "error");
|
||||
terminal.reset().unwrap();
|
||||
vprintln!(args.flag_verbose, "{}", message)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_module(args: &Args, path: PathBuf, name: String) -> Result<(), String> {
|
||||
let mut terminal = term::stdout().unwrap();
|
||||
terminal.fg(term::color::YELLOW).unwrap();
|
||||
vprint!(args.flag_verbose, "Handling: ");
|
||||
terminal.reset().unwrap();
|
||||
vprintln!(args.flag_verbose, "\"{}\"", name);
|
||||
terminal.fg(term::color::MAGENTA).unwrap();
|
||||
vprint!(args.flag_verbose, "Translating...");
|
||||
terminal.reset().unwrap();
|
||||
let data = match path.extension() {
|
||||
None => {
|
||||
return Err(String::from("the file extension is not wasm or wast"));
|
||||
}
|
||||
Some(ext) => {
|
||||
match ext.to_str() {
|
||||
Some("wasm") => {
|
||||
match read_wasm_file(path.clone()) {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
return Err(String::from(err.description()));
|
||||
}
|
||||
}
|
||||
}
|
||||
Some("wast") => {
|
||||
let tmp_dir = TempDir::new("wasm2cretonne").unwrap();
|
||||
let file_path = tmp_dir.path().join("module.wasm");
|
||||
File::create(file_path.clone()).unwrap();
|
||||
Command::new("wast2wasm")
|
||||
.arg(path.clone())
|
||||
.arg("-o")
|
||||
.arg(file_path.to_str().unwrap())
|
||||
.output()
|
||||
.or_else(|e| if let io::ErrorKind::NotFound = e.kind() {
|
||||
return Err(String::from("wast2wasm not found"));
|
||||
} else {
|
||||
return Err(String::from(e.description()));
|
||||
})
|
||||
.unwrap();
|
||||
match read_wasm_file(file_path) {
|
||||
Ok(data) => data,
|
||||
Err(err) => {
|
||||
return Err(String::from(err.description()));
|
||||
}
|
||||
}
|
||||
}
|
||||
None | Some(&_) => {
|
||||
return Err(String::from("the file extension is not wasm or wast"));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
let mut dummy_runtime = DummyRuntime::new();
|
||||
let mut standalone_runtime = StandaloneRuntime::new();
|
||||
let translation = {
|
||||
let mut runtime: &mut WasmRuntime = if args.flag_execute {
|
||||
&mut standalone_runtime
|
||||
} else {
|
||||
&mut dummy_runtime
|
||||
};
|
||||
match translate_module(&data, runtime) {
|
||||
Ok(x) => x,
|
||||
Err(string) => {
|
||||
return Err(string);
|
||||
}
|
||||
}
|
||||
};
|
||||
terminal.fg(term::color::GREEN).unwrap();
|
||||
vprintln!(args.flag_verbose, " ok");
|
||||
terminal.reset().unwrap();
|
||||
if args.flag_check {
|
||||
terminal.fg(term::color::MAGENTA).unwrap();
|
||||
vprint!(args.flag_verbose, "Checking... ");
|
||||
terminal.reset().unwrap();
|
||||
for func in translation.functions.iter() {
|
||||
let il = match func {
|
||||
&FunctionTranslation::Import() => continue,
|
||||
&FunctionTranslation::Code { ref il, .. } => il.clone(),
|
||||
};
|
||||
match verifier::verify_function(&il, None) {
|
||||
Ok(()) => (),
|
||||
Err(err) => return Err(pretty_verifier_error(&il, None, err)),
|
||||
}
|
||||
}
|
||||
terminal.fg(term::color::GREEN).unwrap();
|
||||
vprintln!(args.flag_verbose, " ok");
|
||||
terminal.reset().unwrap();
|
||||
}
|
||||
if args.flag_print {
|
||||
let mut writer1 = stdout();
|
||||
let mut writer2 = stdout();
|
||||
match pretty_print_translation(&name, &data, &translation, &mut writer1, &mut writer2) {
|
||||
Err(error) => return Err(String::from(error.description())),
|
||||
Ok(()) => (),
|
||||
}
|
||||
}
|
||||
if args.flag_optimize {
|
||||
terminal.fg(term::color::MAGENTA).unwrap();
|
||||
vprint!(args.flag_verbose, "Optimizing... ");
|
||||
terminal.reset().unwrap();
|
||||
for func in translation.functions.iter() {
|
||||
let mut il = match func {
|
||||
&FunctionTranslation::Import() => continue,
|
||||
&FunctionTranslation::Code { ref il, .. } => il.clone(),
|
||||
};
|
||||
let mut loop_analysis = LoopAnalysis::new();
|
||||
let mut cfg = ControlFlowGraph::new();
|
||||
cfg.compute(&il);
|
||||
let mut domtree = DominatorTree::new();
|
||||
domtree.compute(&mut il, &cfg);
|
||||
loop_analysis.compute(&mut il, &mut cfg, &mut domtree);
|
||||
let mut context = Context::new();
|
||||
context.func = il;
|
||||
context.cfg = cfg;
|
||||
context.domtree = domtree;
|
||||
context.loop_analysis = loop_analysis;
|
||||
match verifier::verify_context(&context.func, &context.cfg, &context.domtree, None) {
|
||||
Ok(()) => (),
|
||||
Err(err) => {
|
||||
return 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::ImplLimitExceeded |
|
||||
CtonError::CodeTooLarge => return Err(String::from(error.description())),
|
||||
}
|
||||
}
|
||||
};
|
||||
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();
|
||||
vprintln!(args.flag_verbose, " ok");
|
||||
terminal.reset().unwrap();
|
||||
}
|
||||
if args.flag_execute {
|
||||
terminal.fg(term::color::MAGENTA).unwrap();
|
||||
vprint!(args.flag_verbose, "Compiling... ");
|
||||
terminal.reset().unwrap();
|
||||
match compile_module(&translation) {
|
||||
Ok(exec) => {
|
||||
terminal.fg(term::color::GREEN).unwrap();
|
||||
vprintln!(args.flag_verbose, "ok");
|
||||
terminal.reset().unwrap();
|
||||
terminal.fg(term::color::MAGENTA).unwrap();
|
||||
vprint!(args.flag_verbose, "Executing... ");
|
||||
terminal.reset().unwrap();
|
||||
match execute(exec) {
|
||||
Ok(()) => {
|
||||
terminal.fg(term::color::GREEN).unwrap();
|
||||
vprintln!(args.flag_verbose, "ok");
|
||||
terminal.reset().unwrap();
|
||||
}
|
||||
Err(s) => {
|
||||
return Err(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(s) => {
|
||||
return Err(s);
|
||||
}
|
||||
};
|
||||
if args.flag_memory {
|
||||
let mut input = String::new();
|
||||
terminal.fg(term::color::YELLOW).unwrap();
|
||||
println!("Inspecting memory");
|
||||
terminal.fg(term::color::MAGENTA).unwrap();
|
||||
println!("Type 'quit' to exit.");
|
||||
terminal.reset().unwrap();
|
||||
loop {
|
||||
input.clear();
|
||||
terminal.fg(term::color::YELLOW).unwrap();
|
||||
print!("Memory index, offset, length (e.g. 0,0,4): ");
|
||||
terminal.reset().unwrap();
|
||||
let _ = stdout().flush();
|
||||
match io::stdin().read_line(&mut input) {
|
||||
Ok(_) => {
|
||||
input.pop();
|
||||
if input == "quit" {
|
||||
break;
|
||||
}
|
||||
let split: Vec<&str> = input.split(",").collect();
|
||||
if split.len() != 3 {
|
||||
break;
|
||||
}
|
||||
let memory = standalone_runtime
|
||||
.inspect_memory(str::parse(split[0]).unwrap(),
|
||||
str::parse(split[1]).unwrap(),
|
||||
str::parse(split[2]).unwrap());
|
||||
let mut s = memory
|
||||
.iter()
|
||||
.fold(String::from("#"), |mut acc, byte| {
|
||||
acc.push_str(format!("{:02x}_", byte).as_str());
|
||||
acc
|
||||
});
|
||||
s.pop();
|
||||
println!("{}", s);
|
||||
}
|
||||
Err(error) => return Err(String::from(error.description())),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// Prints out a Wasm module, and for each function the corresponding translation in Cretonne IL.
|
||||
fn pretty_print_translation(filename: &String,
|
||||
data: &Vec<u8>,
|
||||
translation: &TranslationResult,
|
||||
writer_wast: &mut Write,
|
||||
writer_cretonne: &mut Write)
|
||||
-> Result<(), io::Error> {
|
||||
let mut terminal = term::stdout().unwrap();
|
||||
let mut parser = Parser::new(data.as_slice());
|
||||
let mut parser_writer = Writer::new(writer_wast);
|
||||
let imports_count = translation
|
||||
.functions
|
||||
.iter()
|
||||
.fold(0, |acc, &ref f| match f {
|
||||
&FunctionTranslation::Import() => acc + 1,
|
||||
&FunctionTranslation::Code { .. } => acc,
|
||||
});
|
||||
match parser.read() {
|
||||
s @ &ParserState::BeginWasm { .. } => parser_writer.write(&s)?,
|
||||
_ => panic!("modules should begin properly"),
|
||||
}
|
||||
loop {
|
||||
match parser.read() {
|
||||
s @ &ParserState::BeginSection { code: SectionCode::Code, .. } => {
|
||||
// The code section begins
|
||||
parser_writer.write(&s)?;
|
||||
break;
|
||||
}
|
||||
&ParserState::EndWasm => return Ok(()),
|
||||
s @ _ => parser_writer.write(&s)?,
|
||||
}
|
||||
}
|
||||
let mut function_index = 0;
|
||||
loop {
|
||||
match parser.read() {
|
||||
s @ &ParserState::BeginFunctionBody { .. } => {
|
||||
terminal.fg(term::color::BLUE).unwrap();
|
||||
write!(writer_cretonne,
|
||||
"====== Function No. {} of module \"{}\" ======\n",
|
||||
function_index,
|
||||
filename)?;
|
||||
terminal.fg(term::color::CYAN).unwrap();
|
||||
write!(writer_cretonne, "Wast ---------->\n")?;
|
||||
terminal.reset().unwrap();
|
||||
parser_writer.write(&s)?;
|
||||
}
|
||||
s @ &ParserState::EndSection => {
|
||||
parser_writer.write(&s)?;
|
||||
break;
|
||||
}
|
||||
_ => panic!("wrong content in code section"),
|
||||
}
|
||||
{
|
||||
loop {
|
||||
match parser.read() {
|
||||
s @ &ParserState::EndFunctionBody => {
|
||||
parser_writer.write(&s)?;
|
||||
break;
|
||||
}
|
||||
s @ _ => {
|
||||
parser_writer.write(&s)?;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
let mut function_string =
|
||||
format!(" {}",
|
||||
match translation.functions[function_index + imports_count] {
|
||||
FunctionTranslation::Code { ref il, .. } => il,
|
||||
FunctionTranslation::Import() => panic!("should not happen"),
|
||||
}
|
||||
.display(None));
|
||||
function_string.pop();
|
||||
let function_str = str::replace(function_string.as_str(), "\n", "\n ");
|
||||
terminal.fg(term::color::CYAN).unwrap();
|
||||
write!(writer_cretonne, "Cretonne IL --->\n")?;
|
||||
terminal.reset().unwrap();
|
||||
write!(writer_cretonne, "{}\n", function_str)?;
|
||||
function_index += 1;
|
||||
}
|
||||
loop {
|
||||
match parser.read() {
|
||||
&ParserState::EndWasm => return Ok(()),
|
||||
s @ _ => parser_writer.write(&s)?,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Pretty-print a verifier error.
|
||||
pub fn pretty_verifier_error(func: &ir::Function,
|
||||
isa: Option<&TargetIsa>,
|
||||
err: verifier::Error)
|
||||
-> String {
|
||||
let msg = err.to_string();
|
||||
let str1 = match err.location {
|
||||
AnyEntity::Inst(inst) => {
|
||||
format!("{}\n{}: {}\n\n",
|
||||
msg,
|
||||
inst,
|
||||
func.dfg.display_inst(inst, isa))
|
||||
}
|
||||
_ => String::from(format!("{}\n", msg)),
|
||||
};
|
||||
format!("{}{}", str1, func.display(isa))
|
||||
}
|
||||
BIN
lib/wasm2cretonne-util/testsuite/address.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/address.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.1.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.1.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.2.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.2.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.3.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/binary.wast.3.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/block.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/block.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/br.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/br.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/br_if.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/br_if.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/br_table.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/br_table.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/break-drop.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/break-drop.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/call.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/call.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/call_indirect.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/call_indirect.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.1.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.1.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.2.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.2.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.3.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/comments.wast.3.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/conversions.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/conversions.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/custom_section.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/custom_section.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/custom_section.wast.1.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/custom_section.wast.1.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/custom_section.wast.2.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/custom_section.wast.2.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/endianness.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/endianness.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.1.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.1.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.10.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.10.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.11.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.11.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.18.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.18.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.19.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.19.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.2.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.2.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.20.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.20.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.21.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.21.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.22.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.22.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.23.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.23.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.24.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.24.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.25.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.25.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.26.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.26.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.27.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.27.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.28.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.28.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.29.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.29.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.3.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.3.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.36.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.36.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.37.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.37.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.38.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.38.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.39.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.39.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.4.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.4.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.40.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.40.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.41.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.41.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.42.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.42.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.43.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.43.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.44.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.44.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.45.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.45.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.46.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.46.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.47.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.47.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.48.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.48.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.49.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.49.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.5.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.5.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.55.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.55.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.56.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.56.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.57.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.57.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.58.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.58.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.59.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.59.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.6.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.6.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.60.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.60.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.61.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.61.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.62.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.62.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.63.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.63.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.64.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.64.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.65.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.65.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.66.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.66.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.67.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.67.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.68.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.68.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.7.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.7.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.8.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.8.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.9.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/exports.wast.9.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/f32.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/f32.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/f32_bitwise.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/f32_bitwise.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/f32_cmp.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/f32_cmp.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/f64.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/f64.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/f64_bitwise.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/f64_bitwise.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/f64_cmp.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/f64_cmp.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/fac.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/fac.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.0.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.0.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.1.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.1.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.10.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.10.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.11.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.11.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.12.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.12.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.13.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.13.wasm
Normal file
Binary file not shown.
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.14.wasm
Normal file
BIN
lib/wasm2cretonne-util/testsuite/float_exprs.wast.14.wasm
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user