Files
botw/tools/viking/src/ui.rs
T
Léo Lam 6e30bbea32 tools: Add a new, optimized check tool
Reimplements tools/check.py in a faster language (picked Rust to learn
and play with the language and because installing dependencies is way
easier than with C++)

On my machine, a full run takes ~160ms with this new implementation
and 49s (!) with check.py.

The main performance improvements come from not having to use
pyelftools and the Python bindings of Capstone (which are both insanely
slow and perhaps less efficient than they could be). Function checking
is now also performed in parallel rather than sequentially for yet
another significant performance boost.

Other tweaks include editing Capstone and the bindings to avoid
computing expensive things that we don't actually need and avoiding
dynamic memory allocations in hot paths as much as possible.

check.py will be removed after the setup instructions are updated.
2021-07-30 23:52:55 +02:00

60 lines
1.3 KiB
Rust

use colored::*;
use std::io::StderrLock;
use std::io::Write;
use textwrap::indent;
use crate::functions;
pub fn print_note(msg: &str) {
eprintln!("{}{}{}", "note".bold().cyan(), ": ".bold(), msg.bold())
}
pub fn print_warning(msg: &str) {
eprintln!("{}{}{}", "warning".bold().yellow(), ": ".bold(), msg.bold())
}
pub fn print_error(msg: &str) {
let stderr = std::io::stderr();
let mut lock = stderr.lock();
print_error_ex(&mut lock, msg);
}
pub fn print_error_ex(lock: &mut StderrLock, msg: &str) {
writeln!(
lock,
"{}{}{}",
"error".bold().red(),
": ".bold(),
msg.bold()
)
.unwrap();
}
pub fn format_symbol_name(name: &str) -> String {
functions::demangle_str(name).map_or(name.blue().to_string(), |demangled| {
format!("{} ({})", demangled.blue(), name.blue().dimmed(),)
})
}
pub fn format_address(addr: u64) -> String {
format!("{:#x}", addr).green().to_string()
}
pub fn print_detail(msg: &str) {
let stderr = std::io::stderr();
let mut lock = stderr.lock();
print_detail_ex(&mut lock, msg);
}
pub fn print_detail_ex(lock: &mut StderrLock, msg: &str) {
writeln!(
lock,
"{}\n",
indent(
&msg.clear().to_string(),
&"".bold().dimmed().to_string()
)
)
.unwrap();
}