From e64eb79aaf7627fd32e7b1cfd1dfea29d0b945ed Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Sat, 23 Sep 2017 15:37:48 -0700 Subject: [PATCH] Fix dependency paths. wasmstandalone no longer depends on out-of-tree patches. --- Cargo.toml | 10 +++++----- lib/wasm2obj/Cargo.toml | 7 ++++--- lib/wasm2obj/src/emit_module.rs | 4 +++- lib/wasm2obj/src/lib.rs | 1 + lib/wasmstandalone/Cargo.toml | 6 +++--- lib/wasmstandalone/src/execution.rs | 12 +++--------- lib/wasmstandalone/src/standalone.rs | 15 ++++++++------- src/main.rs | 13 +++++++++++-- src/wasm2obj.rs | 2 +- 9 files changed, 39 insertions(+), 31 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 47045d1b67..d8278d9ccc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,11 @@ name = "wasm2obj" path = "src/wasm2obj.rs" [dependencies] -cretonne = { path = "/home/sunfish/rust/cretonne/lib/cretonne" } -cretonne-frontend = { path = "/home/sunfish/rust/cretonne/lib/frontend" } -cretonne-reader = { path = "/home/sunfish/rust/cretonne/lib/reader" } -cretonne-wasm = { path = "/home/sunfish/rust/cretonne/lib/wasm" } -cretonne-native = { path = "/home/sunfish/rust/cretonne/lib/native" } +cretonne = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-frontend = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-reader = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-native = { git = "https://github.com/stoklund/cretonne.git" } wasmstandalone = { path = "lib/wasmstandalone" } wasm2obj = { path = "lib/wasm2obj" } wasmparser = "0.8.2" diff --git a/lib/wasm2obj/Cargo.toml b/lib/wasm2obj/Cargo.toml index d00ad37f45..3b61e7f84c 100644 --- a/lib/wasm2obj/Cargo.toml +++ b/lib/wasm2obj/Cargo.toml @@ -5,7 +5,8 @@ authors = ["The Cretonne Project Developers"] publish = false [dependencies] -cretonne = { path = "/home/sunfish/rust/cretonne/lib/cretonne" } -cretonne-frontend = { path = "/home/sunfish/rust/cretonne/lib/frontend" } -cretonne-wasm = { path = "/home/sunfish/rust/cretonne/lib/wasm" } +cretonne = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-frontend = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } +wasmstandalone = { path = "../wasmstandalone" } faerie = { git = "https://github.com/m4b/faerie" } diff --git a/lib/wasm2obj/src/emit_module.rs b/lib/wasm2obj/src/emit_module.rs index 79c8a9b0f3..63a12b90ee 100644 --- a/lib/wasm2obj/src/emit_module.rs +++ b/lib/wasm2obj/src/emit_module.rs @@ -12,6 +12,7 @@ use cton_wasm::TranslationResult; use std::collections::HashMap; use std::fmt::Write; use faerie::Artifact; +use wasmstandalone::StandaloneRuntime; type RelocRef = u16; @@ -50,10 +51,11 @@ pub fn emit_module( trans_result: &TranslationResult, obj: &mut Artifact, isa: &TargetIsa, + runtime: &StandaloneRuntime, ) -> Result<(), String> { debug_assert!( trans_result.start_index.is_none() || - trans_result.start_index.unwrap() >= trans_result.function_imports_count, + trans_result.start_index.unwrap() >= runtime.imported_funcs.len(), "imported start functions not supported yet" ); diff --git a/lib/wasm2obj/src/lib.rs b/lib/wasm2obj/src/lib.rs index d79f851abf..1157eb17ce 100644 --- a/lib/wasm2obj/src/lib.rs +++ b/lib/wasm2obj/src/lib.rs @@ -1,6 +1,7 @@ extern crate cretonne; extern crate cton_wasm; extern crate faerie; +extern crate wasmstandalone; mod emit_module; diff --git a/lib/wasmstandalone/Cargo.toml b/lib/wasmstandalone/Cargo.toml index 5d3c4ed339..d7f8fa1b6f 100644 --- a/lib/wasmstandalone/Cargo.toml +++ b/lib/wasmstandalone/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/stoklund/cretonne" license = "Apache-2.0" [dependencies] -cretonne = { path = "/home/sunfish/rust/cretonne/lib/cretonne" } -cretonne-frontend = { path = "/home/sunfish/rust/cretonne/lib/frontend" } -cretonne-wasm = { path = "/home/sunfish/rust/cretonne/lib/wasm" } +cretonne = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-frontend = { git = "https://github.com/stoklund/cretonne.git" } +cretonne-wasm = { git = "https://github.com/stoklund/cretonne.git" } region = "0.0.8" diff --git a/lib/wasmstandalone/src/execution.rs b/lib/wasmstandalone/src/execution.rs index 1baa6f1518..400a7b4901 100644 --- a/lib/wasmstandalone/src/execution.rs +++ b/lib/wasmstandalone/src/execution.rs @@ -68,7 +68,7 @@ pub fn compile_module( ) -> Result { debug_assert!( trans_result.start_index.is_none() || - trans_result.start_index.unwrap() >= trans_result.function_imports_count, + trans_result.start_index.unwrap() >= runtime.imported_funcs.len(), "imported start functions not supported yet" ); @@ -101,12 +101,7 @@ pub fn compile_module( }); functions_code.push(code_buf); } - relocate( - trans_result.function_imports_count, - &functions_metatada, - &mut functions_code, - runtime, - ); + relocate(&functions_metatada, &mut functions_code, runtime); // After having emmitted the code to memory, we deal with relocations match trans_result.start_index { None => Err(String::from( @@ -152,7 +147,6 @@ pub fn execute(exec: &ExecutableCode) -> Result<(), String> { /// Performs the relocations inside the function bytecode, provided the necessary metadata fn relocate( - function_imports_count: usize, functions_metatada: &[FunctionMetaData], functions_code: &mut Vec>, runtime: &StandaloneRuntime, @@ -164,7 +158,7 @@ fn relocate( ref il_func, } = *function_in_memory; for &(func_ref, offset) in relocs.funcs.values() { - let target_func_index = runtime.func_indices[func_ref] - function_imports_count; + let target_func_index = runtime.func_indices[func_ref] - runtime.imported_funcs.len(); let target_func_address: isize = functions_code[target_func_index].as_ptr() as isize; unsafe { let reloc_address: isize = functions_code[func_index].as_mut_ptr().offset( diff --git a/lib/wasmstandalone/src/standalone.rs b/lib/wasmstandalone/src/standalone.rs index 13ef9a3a32..793d60840a 100644 --- a/lib/wasmstandalone/src/standalone.rs +++ b/lib/wasmstandalone/src/standalone.rs @@ -23,7 +23,7 @@ struct GlobalInfo { offset: usize, } -struct GlobalsData { +pub struct GlobalsData { data: Vec, info: Vec, } @@ -51,17 +51,18 @@ const PAGE_SIZE: usize = 65536; /// Object containing the standalone runtime information. To be passed after creation as argument /// to `cton_wasm::translatemodule`. pub struct StandaloneRuntime { - // Compilation setting flags. + /// Compilation setting flags. flags: settings::Flags, - // Unprocessed signatures exactly as provided by `declare_signature()`. + /// Unprocessed signatures exactly as provided by `declare_signature()`. signatures: Vec, - // Types of functions, imported and local. + /// Types of functions, imported and local. func_types: Vec, - // Names of imported functions. - imported_funcs: Vec, + /// Names of imported functions. + pub imported_funcs: Vec, - globals: GlobalsData, + /// WebAssembly global variables. + pub globals: GlobalsData, /// WebAssembly tables. pub tables: Vec, /// WebAssembly linear memories. diff --git a/src/main.rs b/src/main.rs index 86c9be958e..e0d3728124 100644 --- a/src/main.rs +++ b/src/main.rs @@ -207,7 +207,15 @@ fn handle_module(args: &Args, path: PathBuf, name: &str, isa: &TargetIsa) -> Res if args.flag_print { let mut writer1 = stdout(); let mut writer2 = stdout(); - match pretty_print_translation(name, &data, &translation, &mut writer1, &mut writer2, isa) { + match pretty_print_translation( + name, + &data, + &translation, + &mut writer1, + &mut writer2, + isa, + &runtime, + ) { Err(error) => return Err(String::from(error.description())), Ok(()) => (), } @@ -334,11 +342,12 @@ fn pretty_print_translation( writer_wat: &mut Write, writer_cretonne: &mut Write, isa: &TargetIsa, + runtime: &StandaloneRuntime, ) -> Result<(), io::Error> { let mut terminal = term::stdout().unwrap(); let mut parser = Parser::new(data); let mut parser_writer = Writer::new(writer_wat); - let imports_count = translation.function_imports_count; + let imports_count = runtime.imported_funcs.len(); match parser.read() { s @ &ParserState::BeginWasm { .. } => parser_writer.write(s)?, _ => panic!("modules should begin properly"), diff --git a/src/wasm2obj.rs b/src/wasm2obj.rs index 5b4c6d00aa..3912d974b1 100644 --- a/src/wasm2obj.rs +++ b/src/wasm2obj.rs @@ -106,7 +106,7 @@ fn handle_module(path: PathBuf, output: &str) -> Result<(), String> { // FIXME: Make the output filename a parameter. let mut obj = Artifact::new(Target::X86_64, Some(String::from(output))); - emit_module(&translation, &mut obj, &*isa)?; + emit_module(&translation, &mut obj, &*isa, &runtime)?; if !runtime.tables.is_empty() { if runtime.tables.len() > 1 {