Fixes #244: Prints the generated code size and wasm bytecode size in wasm command;
This commit is contained in:
committed by
Jakob Stoklund Olesen
parent
c7655c4928
commit
f02c8fd1ff
@@ -32,7 +32,7 @@ Usage:
|
|||||||
cton-util filecheck [-v] <file>
|
cton-util filecheck [-v] <file>
|
||||||
cton-util print-cfg <file>...
|
cton-util print-cfg <file>...
|
||||||
cton-util compile [-vpT] [--set <set>]... [--isa <isa>] <file>...
|
cton-util compile [-vpT] [--set <set>]... [--isa <isa>] <file>...
|
||||||
cton-util wasm [-ctvpT] [--set <set>]... [--isa <isa>] <file>...
|
cton-util wasm [-ctvpTs] [--set <set>]... [--isa <isa>] <file>...
|
||||||
cton-util --help | --version
|
cton-util --help | --version
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
@@ -41,6 +41,8 @@ Options:
|
|||||||
print pass timing report
|
print pass timing report
|
||||||
-t, --just-decode
|
-t, --just-decode
|
||||||
just decode WebAssembly to Cretonne IL
|
just decode WebAssembly to Cretonne IL
|
||||||
|
-s, --print-size
|
||||||
|
prints generated code size
|
||||||
-c, --check-translation
|
-c, --check-translation
|
||||||
just checks the correctness of Cretonne IL translated from WebAssembly
|
just checks the correctness of Cretonne IL translated from WebAssembly
|
||||||
-p, --print print the resulting Cretonne IL
|
-p, --print print the resulting Cretonne IL
|
||||||
@@ -67,6 +69,7 @@ struct Args {
|
|||||||
flag_set: Vec<String>,
|
flag_set: Vec<String>,
|
||||||
flag_isa: String,
|
flag_isa: String,
|
||||||
flag_time_passes: bool,
|
flag_time_passes: bool,
|
||||||
|
flag_print_size: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A command either succeeds or fails with an error message.
|
/// A command either succeeds or fails with an error message.
|
||||||
@@ -103,6 +106,7 @@ fn cton_util() -> CommandResult {
|
|||||||
args.flag_print,
|
args.flag_print,
|
||||||
args.flag_set,
|
args.flag_set,
|
||||||
args.flag_isa,
|
args.flag_isa,
|
||||||
|
args.flag_print_size,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
// Debugging / shouldn't happen with proper command line handling above.
|
// Debugging / shouldn't happen with proper command line handling above.
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ pub fn run(
|
|||||||
flag_print: bool,
|
flag_print: bool,
|
||||||
flag_set: Vec<String>,
|
flag_set: Vec<String>,
|
||||||
flag_isa: String,
|
flag_isa: String,
|
||||||
|
flag_print_size: bool,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let parsed = parse_sets_and_isa(flag_set, flag_isa)?;
|
let parsed = parse_sets_and_isa(flag_set, flag_isa)?;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ pub fn run(
|
|||||||
flag_just_decode,
|
flag_just_decode,
|
||||||
flag_check_translation,
|
flag_check_translation,
|
||||||
flag_print,
|
flag_print,
|
||||||
|
flag_print_size,
|
||||||
path.to_path_buf(),
|
path.to_path_buf(),
|
||||||
name,
|
name,
|
||||||
parsed.as_fisa(),
|
parsed.as_fisa(),
|
||||||
@@ -63,6 +65,7 @@ fn handle_module(
|
|||||||
flag_just_decode: bool,
|
flag_just_decode: bool,
|
||||||
flag_check_translation: bool,
|
flag_check_translation: bool,
|
||||||
flag_print: bool,
|
flag_print: bool,
|
||||||
|
flag_print_size: bool,
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
name: String,
|
name: String,
|
||||||
fisa: FlagsOrIsa,
|
fisa: FlagsOrIsa,
|
||||||
@@ -75,6 +78,7 @@ fn handle_module(
|
|||||||
terminal.fg(term::color::MAGENTA).unwrap();
|
terminal.fg(term::color::MAGENTA).unwrap();
|
||||||
vprint!(flag_verbose, "Translating... ");
|
vprint!(flag_verbose, "Translating... ");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
|
|
||||||
let mut data = read_to_end(path.clone()).map_err(|err| {
|
let mut data = read_to_end(path.clone()).map_err(|err| {
|
||||||
String::from(err.description())
|
String::from(err.description())
|
||||||
})?;
|
})?;
|
||||||
@@ -96,11 +100,14 @@ fn handle_module(
|
|||||||
|err| String::from(err.description()),
|
|err| String::from(err.description()),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dummy_environ = DummyEnvironment::with_flags(fisa.flags.clone());
|
let mut dummy_environ = DummyEnvironment::with_flags(fisa.flags.clone());
|
||||||
translate_module(&data, &mut dummy_environ)?;
|
translate_module(&data, &mut dummy_environ)?;
|
||||||
|
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, "ok");
|
vprintln!(flag_verbose, "ok");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
|
|
||||||
if flag_just_decode {
|
if flag_just_decode {
|
||||||
if flag_print {
|
if flag_print {
|
||||||
let num_func_imports = dummy_environ.get_num_func_imports();
|
let num_func_imports = dummy_environ.get_num_func_imports();
|
||||||
@@ -124,6 +131,7 @@ fn handle_module(
|
|||||||
}
|
}
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
terminal.fg(term::color::MAGENTA).unwrap();
|
terminal.fg(term::color::MAGENTA).unwrap();
|
||||||
if flag_check_translation {
|
if flag_check_translation {
|
||||||
vprint!(flag_verbose, "Checking... ");
|
vprint!(flag_verbose, "Checking... ");
|
||||||
@@ -131,7 +139,13 @@ fn handle_module(
|
|||||||
vprint!(flag_verbose, "Compiling... ");
|
vprint!(flag_verbose, "Compiling... ");
|
||||||
}
|
}
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
|
|
||||||
|
if flag_print_size {
|
||||||
|
vprintln!(flag_verbose, "");
|
||||||
|
}
|
||||||
|
|
||||||
let num_func_imports = dummy_environ.get_num_func_imports();
|
let num_func_imports = dummy_environ.get_num_func_imports();
|
||||||
|
let mut total_module_code_size = 0;
|
||||||
for (def_index, func) in dummy_environ.info.function_bodies.iter().enumerate() {
|
for (def_index, func) in dummy_environ.info.function_bodies.iter().enumerate() {
|
||||||
let func_index = num_func_imports + def_index;
|
let func_index = num_func_imports + def_index;
|
||||||
let mut context = Context::new();
|
let mut context = Context::new();
|
||||||
@@ -142,9 +156,22 @@ fn handle_module(
|
|||||||
})?;
|
})?;
|
||||||
} else {
|
} else {
|
||||||
if let Some(isa) = fisa.isa {
|
if let Some(isa) = fisa.isa {
|
||||||
context.compile(isa).map_err(|err| {
|
let compiled_size = context.compile(isa).map_err(|err| {
|
||||||
pretty_error(&context.func, fisa.isa, err)
|
pretty_error(&context.func, fisa.isa, err)
|
||||||
})?;
|
})?;
|
||||||
|
if flag_print_size {
|
||||||
|
println!(
|
||||||
|
"Function #{} code size: {} bytes",
|
||||||
|
func_index,
|
||||||
|
compiled_size
|
||||||
|
);
|
||||||
|
total_module_code_size += compiled_size;
|
||||||
|
println!(
|
||||||
|
"Function #{} bytecode size: {} bytes",
|
||||||
|
func_index,
|
||||||
|
dummy_environ.func_bytecode_sizes[func_index]
|
||||||
|
);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(String::from("compilation requires a target isa"));
|
return Err(String::from("compilation requires a target isa"));
|
||||||
}
|
}
|
||||||
@@ -163,6 +190,16 @@ fn handle_module(
|
|||||||
vprintln!(flag_verbose, "");
|
vprintln!(flag_verbose, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !flag_check_translation && flag_print_size {
|
||||||
|
println!("Total module code size: {} bytes", total_module_code_size);
|
||||||
|
let total_bytecode_size = dummy_environ.func_bytecode_sizes.iter().fold(
|
||||||
|
0,
|
||||||
|
|sum, x| sum + x,
|
||||||
|
);
|
||||||
|
println!("Total module bytecode size: {} bytes", total_bytecode_size);
|
||||||
|
}
|
||||||
|
|
||||||
terminal.fg(term::color::GREEN).unwrap();
|
terminal.fg(term::color::GREEN).unwrap();
|
||||||
vprintln!(flag_verbose, "ok");
|
vprintln!(flag_verbose, "ok");
|
||||||
terminal.reset().unwrap();
|
terminal.reset().unwrap();
|
||||||
|
|||||||
@@ -92,6 +92,9 @@ pub struct DummyEnvironment {
|
|||||||
|
|
||||||
/// Function translation.
|
/// Function translation.
|
||||||
trans: FuncTranslator,
|
trans: FuncTranslator,
|
||||||
|
|
||||||
|
/// Vector of wasm bytecode size for each function.
|
||||||
|
pub func_bytecode_sizes: Vec<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DummyEnvironment {
|
impl DummyEnvironment {
|
||||||
@@ -105,6 +108,7 @@ impl DummyEnvironment {
|
|||||||
Self {
|
Self {
|
||||||
info: DummyModuleInfo::with_flags(flags),
|
info: DummyModuleInfo::with_flags(flags),
|
||||||
trans: FuncTranslator::new(),
|
trans: FuncTranslator::new(),
|
||||||
|
func_bytecode_sizes: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -384,6 +388,7 @@ impl<'data> ModuleEnvironment<'data> for DummyEnvironment {
|
|||||||
.map_err(|e| String::from(e.description()))?;
|
.map_err(|e| String::from(e.description()))?;
|
||||||
func
|
func
|
||||||
};
|
};
|
||||||
|
self.func_bytecode_sizes.push(body_bytes.len());
|
||||||
self.info.function_bodies.push(func);
|
self.info.function_bodies.push(func);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user