Browse Source

Fix dependency paths. wasmstandalone no longer depends on out-of-tree patches.

pull/3/head
Dan Gohman 7 years ago
parent
commit
e64eb79aaf
  1. 10
      Cargo.toml
  2. 7
      lib/wasm2obj/Cargo.toml
  3. 4
      lib/wasm2obj/src/emit_module.rs
  4. 1
      lib/wasm2obj/src/lib.rs
  5. 6
      lib/wasmstandalone/Cargo.toml
  6. 12
      lib/wasmstandalone/src/execution.rs
  7. 15
      lib/wasmstandalone/src/standalone.rs
  8. 13
      src/main.rs
  9. 2
      src/wasm2obj.rs

10
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"

7
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" }

4
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"
);

1
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;

6
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"

12
lib/wasmstandalone/src/execution.rs

@ -68,7 +68,7 @@ pub fn compile_module(
) -> Result<ExecutableCode, 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"
);
@ -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<Vec<u8>>,
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(

15
lib/wasmstandalone/src/standalone.rs

@ -23,7 +23,7 @@ struct GlobalInfo {
offset: usize,
}
struct GlobalsData {
pub struct GlobalsData {
data: Vec<u8>,
info: Vec<GlobalInfo>,
}
@ -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<ir::Signature>,
// Types of functions, imported and local.
/// Types of functions, imported and local.
func_types: Vec<SignatureIndex>,
// Names of imported functions.
imported_funcs: Vec<ir::FunctionName>,
/// Names of imported functions.
pub imported_funcs: Vec<ir::FunctionName>,
globals: GlobalsData,
/// WebAssembly global variables.
pub globals: GlobalsData,
/// WebAssembly tables.
pub tables: Vec<TableData>,
/// WebAssembly linear memories.

13
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"),

2
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 {

Loading…
Cancel
Save