mirror of
https://github.com/encounter/objdiff.git
synced 2025-12-15 08:06:25 +00:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7b58f9a269 | |||
| d9e7dacb6d | |||
| 04b4fdcd21 | |||
| 803eaafee6 | |||
| e1dc84698f | |||
| e68629c339 | |||
| bb9ff4b928 | |||
| 57392daaeb | |||
| 2dd3dd60a8 | |||
| f4757b8d92 | |||
| 52f8c5d4f9 |
867
Cargo.lock
generated
867
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
61
Cargo.toml
61
Cargo.toml
@@ -1,8 +1,8 @@
|
||||
[package]
|
||||
name = "objdiff"
|
||||
version = "0.4.3"
|
||||
version = "0.5.2"
|
||||
edition = "2021"
|
||||
rust-version = "1.65"
|
||||
rust-version = "1.70"
|
||||
authors = ["Luke Street <luke@street.dev>"]
|
||||
license = "MIT OR Apache-2.0"
|
||||
repository = "https://github.com/encounter/objdiff"
|
||||
@@ -22,46 +22,47 @@ default = []
|
||||
wgpu = ["eframe/wgpu"]
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0.71"
|
||||
byteorder = "1.4.3"
|
||||
bytes = "1.4.0"
|
||||
anyhow = "1.0.75"
|
||||
byteorder = "1.5.0"
|
||||
bytes = "1.5.0"
|
||||
cfg-if = "1.0.0"
|
||||
const_format = "0.2.31"
|
||||
cwdemangle = "0.1.6"
|
||||
dirs = "5.0.1"
|
||||
eframe = { version = "0.22.0", features = ["persistence"] }
|
||||
egui = "0.22.0"
|
||||
egui_extras = "0.22.0"
|
||||
flagset = "0.4.3"
|
||||
eframe = { version = "0.23.0", features = ["persistence"] }
|
||||
egui = "0.23.0"
|
||||
egui_extras = "0.23.0"
|
||||
filetime = "0.2.22"
|
||||
flagset = "0.4.4"
|
||||
globset = { version = "0.4.13", features = ["serde1"] }
|
||||
log = "0.4.19"
|
||||
memmap2 = "0.7.1"
|
||||
notify = "6.0.1"
|
||||
object = { version = "0.31.1", features = ["read_core", "std", "elf"], default-features = false }
|
||||
png = "0.17.9"
|
||||
ppc750cl = { git = "https://github.com/terorie/ppc750cl", rev = "9ae36eef34aa6d74e00972c7671f547a2acfd0aa" }
|
||||
rabbitizer = "1.7.4"
|
||||
rfd = { version = "0.11.4" } #, default-features = false, features = ['xdg-portal']
|
||||
ron = "0.8.0"
|
||||
semver = "1.0.17"
|
||||
log = "0.4.20"
|
||||
memmap2 = "0.9.0"
|
||||
notify = "6.1.1"
|
||||
object = { version = "0.32.1", features = ["read_core", "std", "elf"], default-features = false }
|
||||
png = "0.17.10"
|
||||
ppc750cl = { git = "https://github.com/encounter/ppc750cl", rev = "4a2bbbc6f84dcb76255ab6f3595a8d4a0ce96618" }
|
||||
rabbitizer = "1.7.10"
|
||||
rfd = { version = "0.12.0" } #, default-features = false, features = ['xdg-portal']
|
||||
ron = "0.8.1"
|
||||
semver = "1.0.19"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1.0.104"
|
||||
serde_json = "1.0.107"
|
||||
serde_yaml = "0.9.25"
|
||||
tempfile = "3.6.0"
|
||||
thiserror = "1.0.41"
|
||||
time = { version = "0.3.22", features = ["formatting", "local-offset"] }
|
||||
toml = "0.7.6"
|
||||
tempfile = "3.8.0"
|
||||
thiserror = "1.0.49"
|
||||
time = { version = "0.3.29", features = ["formatting", "local-offset"] }
|
||||
toml = "0.8.2"
|
||||
twox-hash = "1.6.3"
|
||||
|
||||
# For Linux static binaries, use rustls
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
reqwest = { version = "0.11.18", default-features = false, features = ["blocking", "json", "rustls"] }
|
||||
self_update = { version = "0.37.0", default-features = false, features = ["rustls"] }
|
||||
reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "json", "rustls"] }
|
||||
self_update = { version = "0.38.0", default-features = false, features = ["rustls"] }
|
||||
|
||||
# For all other platforms, use native TLS
|
||||
[target.'cfg(not(target_os = "linux"))'.dependencies]
|
||||
reqwest = "0.11.18"
|
||||
self_update = "0.37.0"
|
||||
reqwest = "0.11.22"
|
||||
self_update = "0.38.0"
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
path-slash = "0.2.1"
|
||||
@@ -83,5 +84,5 @@ console_error_panic_hook = "0.1.7"
|
||||
tracing-wasm = "0.2"
|
||||
|
||||
[build-dependencies]
|
||||
anyhow = "1.0.71"
|
||||
vergen = { version = "8.2.4", features = ["build", "cargo", "git", "gitcl"] }
|
||||
anyhow = "1.0.75"
|
||||
vergen = { version = "8.2.5", features = ["build", "cargo", "git", "gitcl"] }
|
||||
|
||||
170
src/app.rs
170
src/app.rs
@@ -1,5 +1,6 @@
|
||||
use std::{
|
||||
default::Default,
|
||||
fs,
|
||||
path::{Path, PathBuf},
|
||||
rc::Rc,
|
||||
sync::{
|
||||
@@ -9,16 +10,18 @@ use std::{
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
use filetime::FileTime;
|
||||
use globset::{Glob, GlobSet};
|
||||
use notify::{RecursiveMode, Watcher};
|
||||
use time::UtcOffset;
|
||||
|
||||
use crate::{
|
||||
app_config::{deserialize_config, AppConfigVersion},
|
||||
config::{
|
||||
build_globset, load_project_config, ProjectObject, ProjectObjectNode, CONFIG_FILENAMES,
|
||||
config::{build_globset, load_project_config, ProjectObject, ProjectObjectNode},
|
||||
jobs::{
|
||||
objdiff::{start_build, ObjDiffConfig},
|
||||
Job, JobQueue, JobResult, JobStatus,
|
||||
},
|
||||
jobs::{objdiff::start_build, Job, JobQueue, JobResult, JobStatus},
|
||||
views::{
|
||||
appearance::{appearance_window, Appearance},
|
||||
config::{config_ui, project_window, ConfigViewState, DEFAULT_WATCH_PATTERNS},
|
||||
@@ -51,26 +54,50 @@ pub struct ObjectConfig {
|
||||
pub complete: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Eq, PartialEq)]
|
||||
pub struct ProjectConfigInfo {
|
||||
pub path: PathBuf,
|
||||
pub timestamp: FileTime,
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn bool_true() -> bool { true }
|
||||
|
||||
#[inline]
|
||||
fn default_watch_patterns() -> Vec<Glob> {
|
||||
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||
}
|
||||
|
||||
#[derive(Clone, serde::Deserialize, serde::Serialize)]
|
||||
pub struct AppConfig {
|
||||
// TODO: https://github.com/ron-rs/ron/pull/455
|
||||
// #[serde(flatten)]
|
||||
// pub version: AppConfigVersion,
|
||||
pub version: u32,
|
||||
#[serde(default)]
|
||||
pub custom_make: Option<String>,
|
||||
#[serde(default)]
|
||||
pub selected_wsl_distro: Option<String>,
|
||||
#[serde(default)]
|
||||
pub project_dir: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub target_obj_dir: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub base_obj_dir: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub selected_obj: Option<ObjectConfig>,
|
||||
#[serde(default = "bool_true")]
|
||||
pub build_base: bool,
|
||||
#[serde(default)]
|
||||
pub build_target: bool,
|
||||
#[serde(default = "bool_true")]
|
||||
pub rebuild_on_changes: bool,
|
||||
#[serde(default)]
|
||||
pub auto_update_check: bool,
|
||||
#[serde(default = "default_watch_patterns")]
|
||||
pub watch_patterns: Vec<Glob>,
|
||||
#[serde(default)]
|
||||
pub recent_projects: Vec<PathBuf>,
|
||||
|
||||
#[serde(skip)]
|
||||
pub objects: Vec<ProjectObject>,
|
||||
@@ -85,7 +112,9 @@ pub struct AppConfig {
|
||||
#[serde(skip)]
|
||||
pub queue_build: bool,
|
||||
#[serde(skip)]
|
||||
pub project_config_loaded: bool,
|
||||
pub queue_reload: bool,
|
||||
#[serde(skip)]
|
||||
pub project_config_info: Option<ProjectConfigInfo>,
|
||||
}
|
||||
|
||||
impl Default for AppConfig {
|
||||
@@ -98,23 +127,31 @@ impl Default for AppConfig {
|
||||
target_obj_dir: None,
|
||||
base_obj_dir: None,
|
||||
selected_obj: None,
|
||||
build_base: true,
|
||||
build_target: false,
|
||||
rebuild_on_changes: true,
|
||||
auto_update_check: true,
|
||||
watch_patterns: DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect(),
|
||||
recent_projects: vec![],
|
||||
objects: vec![],
|
||||
object_nodes: vec![],
|
||||
watcher_change: false,
|
||||
config_change: false,
|
||||
obj_change: false,
|
||||
queue_build: false,
|
||||
project_config_loaded: false,
|
||||
queue_reload: false,
|
||||
project_config_info: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppConfig {
|
||||
pub fn set_project_dir(&mut self, path: PathBuf) {
|
||||
self.recent_projects.retain(|p| p != &path);
|
||||
if self.recent_projects.len() > 9 {
|
||||
self.recent_projects.truncate(9);
|
||||
}
|
||||
self.recent_projects.insert(0, path.clone());
|
||||
self.project_dir = Some(path);
|
||||
self.target_obj_dir = None;
|
||||
self.base_obj_dir = None;
|
||||
@@ -126,7 +163,7 @@ impl AppConfig {
|
||||
self.config_change = true;
|
||||
self.obj_change = true;
|
||||
self.queue_build = false;
|
||||
self.project_config_loaded = false;
|
||||
self.project_config_info = None;
|
||||
}
|
||||
|
||||
pub fn set_target_obj_dir(&mut self, path: PathBuf) {
|
||||
@@ -158,7 +195,6 @@ pub struct App {
|
||||
view_state: ViewState,
|
||||
config: AppConfigRef,
|
||||
modified: Arc<AtomicBool>,
|
||||
config_modified: Arc<AtomicBool>,
|
||||
watcher: Option<notify::RecommendedWatcher>,
|
||||
relaunch_path: Rc<Mutex<Option<PathBuf>>>,
|
||||
should_relaunch: bool,
|
||||
@@ -264,8 +300,10 @@ impl App {
|
||||
};
|
||||
let config = &mut *config;
|
||||
|
||||
if self.config_modified.swap(false, Ordering::Relaxed) {
|
||||
config.config_change = true;
|
||||
if let Some(info) = &config.project_config_info {
|
||||
if file_modified(&info.path, info.timestamp) {
|
||||
config.config_change = true;
|
||||
}
|
||||
}
|
||||
|
||||
if config.config_change {
|
||||
@@ -283,21 +321,14 @@ impl App {
|
||||
drop(self.watcher.take());
|
||||
|
||||
if let Some(project_dir) = &config.project_dir {
|
||||
if !config.watch_patterns.is_empty() {
|
||||
match build_globset(&config.watch_patterns)
|
||||
.map_err(anyhow::Error::new)
|
||||
.and_then(|globset| {
|
||||
create_watcher(
|
||||
self.modified.clone(),
|
||||
self.config_modified.clone(),
|
||||
project_dir,
|
||||
globset,
|
||||
)
|
||||
match build_globset(&config.watch_patterns).map_err(anyhow::Error::new).and_then(
|
||||
|globset| {
|
||||
create_watcher(self.modified.clone(), project_dir, globset)
|
||||
.map_err(anyhow::Error::new)
|
||||
}) {
|
||||
Ok(watcher) => self.watcher = Some(watcher),
|
||||
Err(e) => log::error!("Failed to create watcher: {e}"),
|
||||
}
|
||||
},
|
||||
) {
|
||||
Ok(watcher) => self.watcher = Some(watcher),
|
||||
Err(e) => log::error!("Failed to create watcher: {e}"),
|
||||
}
|
||||
config.watcher_change = false;
|
||||
}
|
||||
@@ -315,11 +346,32 @@ impl App {
|
||||
config.queue_build = true;
|
||||
}
|
||||
|
||||
if let Some(result) = &diff_state.build {
|
||||
if let Some(obj) = &result.first_obj {
|
||||
if file_modified(&obj.path, obj.timestamp) {
|
||||
config.queue_reload = true;
|
||||
}
|
||||
}
|
||||
if let Some(obj) = &result.second_obj {
|
||||
if file_modified(&obj.path, obj.timestamp) {
|
||||
config.queue_reload = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Don't clear `queue_build` if a build is running. A file may have been modified during
|
||||
// the build, so we'll start another build after the current one finishes.
|
||||
if config.queue_build && config.selected_obj.is_some() && !jobs.is_running(Job::ObjDiff) {
|
||||
jobs.push(start_build(self.config.clone()));
|
||||
jobs.push(start_build(ObjDiffConfig::from_config(config)));
|
||||
config.queue_build = false;
|
||||
config.queue_reload = false;
|
||||
} else if config.queue_reload && !jobs.is_running(Job::ObjDiff) {
|
||||
let mut diff_config = ObjDiffConfig::from_config(config);
|
||||
// Don't build, just reload the current files
|
||||
diff_config.build_base = false;
|
||||
diff_config.build_target = false;
|
||||
jobs.push(start_build(diff_config));
|
||||
config.queue_reload = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -351,6 +403,31 @@ impl eframe::App for App {
|
||||
egui::TopBottomPanel::top("top_panel").show(ctx, |ui| {
|
||||
egui::menu::bar(ui, |ui| {
|
||||
ui.menu_button("File", |ui| {
|
||||
if ui.button("Project…").clicked() {
|
||||
*show_project_config = !*show_project_config;
|
||||
ui.close_menu();
|
||||
}
|
||||
let recent_projects = if let Ok(guard) = config.read() {
|
||||
guard.recent_projects.clone()
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
if recent_projects.is_empty() {
|
||||
ui.add_enabled(false, egui::Button::new("Recent projects…"));
|
||||
} else {
|
||||
ui.menu_button("Recent Projects…", |ui| {
|
||||
if ui.button("Clear").clicked() {
|
||||
config.write().unwrap().recent_projects.clear();
|
||||
};
|
||||
ui.separator();
|
||||
for path in recent_projects {
|
||||
if ui.button(format!("{}", path.display())).clicked() {
|
||||
config.write().unwrap().set_project_dir(path);
|
||||
ui.close_menu();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
if ui.button("Appearance…").clicked() {
|
||||
*show_appearance_config = !*show_appearance_config;
|
||||
ui.close_menu();
|
||||
@@ -365,6 +442,29 @@ impl eframe::App for App {
|
||||
ui.close_menu();
|
||||
}
|
||||
});
|
||||
ui.menu_button("Diff Options", |ui| {
|
||||
let mut config = config.write().unwrap();
|
||||
let response = ui
|
||||
.checkbox(&mut config.rebuild_on_changes, "Rebuild on changes")
|
||||
.on_hover_text("Automatically re-run the build & diff when files change.");
|
||||
if response.changed() {
|
||||
config.watcher_change = true;
|
||||
};
|
||||
ui.add_enabled(
|
||||
!diff_state.symbol_state.disable_reverse_fn_order,
|
||||
egui::Checkbox::new(
|
||||
&mut diff_state.symbol_state.reverse_fn_order,
|
||||
"Reverse function order (-inline deferred)",
|
||||
),
|
||||
)
|
||||
.on_disabled_hover_text(
|
||||
"Option disabled because it's set by the project configuration file.",
|
||||
);
|
||||
ui.checkbox(
|
||||
&mut diff_state.symbol_state.show_hidden_symbols,
|
||||
"Show hidden symbols",
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -416,16 +516,9 @@ impl eframe::App for App {
|
||||
|
||||
fn create_watcher(
|
||||
modified: Arc<AtomicBool>,
|
||||
config_modified: Arc<AtomicBool>,
|
||||
project_dir: &Path,
|
||||
patterns: GlobSet,
|
||||
) -> notify::Result<notify::RecommendedWatcher> {
|
||||
let mut config_patterns = GlobSetBuilder::new();
|
||||
for filename in CONFIG_FILENAMES {
|
||||
config_patterns.add(Glob::new(filename).unwrap());
|
||||
}
|
||||
let config_patterns = config_patterns.build().unwrap();
|
||||
|
||||
let base_dir = project_dir.to_owned();
|
||||
let mut watcher =
|
||||
notify::recommended_watcher(move |res: notify::Result<notify::Event>| match res {
|
||||
@@ -440,9 +533,7 @@ fn create_watcher(
|
||||
let Ok(path) = path.strip_prefix(&base_dir) else {
|
||||
continue;
|
||||
};
|
||||
if config_patterns.is_match(path) {
|
||||
config_modified.store(true, Ordering::Relaxed);
|
||||
} else if patterns.is_match(path) {
|
||||
if patterns.is_match(path) {
|
||||
modified.store(true, Ordering::Relaxed);
|
||||
}
|
||||
}
|
||||
@@ -453,3 +544,12 @@ fn create_watcher(
|
||||
watcher.watch(project_dir, RecursiveMode::Recursive)?;
|
||||
Ok(watcher)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn file_modified(path: &Path, last_ts: FileTime) -> bool {
|
||||
if let Ok(metadata) = fs::metadata(path) {
|
||||
FileTime::from_last_modification_time(&metadata) != last_ts
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,54 @@
|
||||
use std::{
|
||||
fs::File,
|
||||
io::Read,
|
||||
path::{Component, Path, PathBuf},
|
||||
};
|
||||
|
||||
use anyhow::{bail, Context, Result};
|
||||
use anyhow::{bail, Result};
|
||||
use filetime::FileTime;
|
||||
use globset::{Glob, GlobSet, GlobSetBuilder};
|
||||
|
||||
use crate::{app::AppConfig, views::config::DEFAULT_WATCH_PATTERNS};
|
||||
use crate::{
|
||||
app::{AppConfig, ProjectConfigInfo},
|
||||
views::config::DEFAULT_WATCH_PATTERNS,
|
||||
};
|
||||
|
||||
#[inline]
|
||||
fn bool_true() -> bool { true }
|
||||
|
||||
#[derive(Default, Clone, serde::Deserialize)]
|
||||
#[serde(default)]
|
||||
pub struct ProjectConfig {
|
||||
#[serde(default)]
|
||||
pub min_version: Option<String>,
|
||||
#[serde(default)]
|
||||
pub custom_make: Option<String>,
|
||||
#[serde(default)]
|
||||
pub target_dir: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub base_dir: Option<PathBuf>,
|
||||
#[serde(default = "bool_true")]
|
||||
pub build_base: bool,
|
||||
#[serde(default)]
|
||||
pub build_target: bool,
|
||||
#[serde(default)]
|
||||
pub watch_patterns: Option<Vec<Glob>>,
|
||||
#[serde(alias = "units")]
|
||||
#[serde(default, alias = "units")]
|
||||
pub objects: Vec<ProjectObject>,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, serde::Deserialize)]
|
||||
pub struct ProjectObject {
|
||||
#[serde(default)]
|
||||
pub name: Option<String>,
|
||||
#[serde(default)]
|
||||
pub path: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub target_path: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub base_path: Option<PathBuf>,
|
||||
#[serde(default)]
|
||||
pub reverse_fn_order: Option<bool>,
|
||||
#[serde(default)]
|
||||
pub complete: Option<bool>,
|
||||
}
|
||||
|
||||
@@ -120,7 +141,7 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
||||
let Some(project_dir) = &config.project_dir else {
|
||||
return Ok(());
|
||||
};
|
||||
if let Some(result) = try_project_config(project_dir) {
|
||||
if let Some((result, info)) = try_project_config(project_dir) {
|
||||
let project_config = result?;
|
||||
if let Some(min_version) = &project_config.min_version {
|
||||
let version_str = env!("CARGO_PKG_VERSION");
|
||||
@@ -133,6 +154,7 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
||||
config.custom_make = project_config.custom_make;
|
||||
config.target_obj_dir = project_config.target_dir.map(|p| project_dir.join(p));
|
||||
config.base_obj_dir = project_config.base_dir.map(|p| project_dir.join(p));
|
||||
config.build_base = project_config.build_base;
|
||||
config.build_target = project_config.build_target;
|
||||
config.watch_patterns = project_config.watch_patterns.unwrap_or_else(|| {
|
||||
DEFAULT_WATCH_PATTERNS.iter().map(|s| Glob::new(s).unwrap()).collect()
|
||||
@@ -141,34 +163,39 @@ pub fn load_project_config(config: &mut AppConfig) -> Result<()> {
|
||||
config.objects = project_config.objects;
|
||||
config.object_nodes =
|
||||
build_nodes(&config.objects, project_dir, &config.target_obj_dir, &config.base_obj_dir);
|
||||
config.project_config_loaded = true;
|
||||
config.project_config_info = Some(info);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn try_project_config(dir: &Path) -> Option<Result<ProjectConfig>> {
|
||||
fn try_project_config(dir: &Path) -> Option<(Result<ProjectConfig>, ProjectConfigInfo)> {
|
||||
for filename in CONFIG_FILENAMES.iter() {
|
||||
let config_path = dir.join(filename);
|
||||
if config_path.is_file() {
|
||||
return match filename.contains("json") {
|
||||
true => Some(read_json_config(&config_path)),
|
||||
false => Some(read_yml_config(&config_path)),
|
||||
let Ok(mut file) = File::open(&config_path) else {
|
||||
continue;
|
||||
};
|
||||
let metadata = file.metadata();
|
||||
if let Ok(metadata) = metadata {
|
||||
if !metadata.is_file() {
|
||||
continue;
|
||||
}
|
||||
let ts = FileTime::from_last_modification_time(&metadata);
|
||||
let config = match filename.contains("json") {
|
||||
true => read_json_config(&mut file),
|
||||
false => read_yml_config(&mut file),
|
||||
};
|
||||
return Some((config, ProjectConfigInfo { path: config_path, timestamp: ts }));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn read_yml_config(config_path: &Path) -> Result<ProjectConfig> {
|
||||
let mut reader = File::open(config_path)
|
||||
.with_context(|| format!("Failed to open config file '{}'", config_path.display()))?;
|
||||
Ok(serde_yaml::from_reader(&mut reader)?)
|
||||
fn read_yml_config<R: Read>(reader: &mut R) -> Result<ProjectConfig> {
|
||||
Ok(serde_yaml::from_reader(reader)?)
|
||||
}
|
||||
|
||||
fn read_json_config(config_path: &Path) -> Result<ProjectConfig> {
|
||||
let mut reader = File::open(config_path)
|
||||
.with_context(|| format!("Failed to open config file '{}'", config_path.display()))?;
|
||||
Ok(serde_json::from_reader(&mut reader)?)
|
||||
fn read_json_config<R: Read>(reader: &mut R) -> Result<ProjectConfig> {
|
||||
Ok(serde_json::from_reader(reader)?)
|
||||
}
|
||||
|
||||
pub fn build_globset(vec: &[Glob]) -> std::result::Result<GlobSet, globset::Error> {
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
use std::{path::Path, process::Command, str::from_utf8, sync::mpsc::Receiver};
|
||||
use std::{
|
||||
path::{Path, PathBuf},
|
||||
process::Command,
|
||||
str::from_utf8,
|
||||
sync::mpsc::Receiver,
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Context, Error, Result};
|
||||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{
|
||||
app::{AppConfig, AppConfigRef},
|
||||
app::{AppConfig, ObjectConfig},
|
||||
diff::diff_objs,
|
||||
jobs::{start_job, update_status, Job, JobResult, JobState, JobStatusRef},
|
||||
obj::{elf, ObjInfo},
|
||||
@@ -15,6 +20,28 @@ pub struct BuildStatus {
|
||||
pub log: String,
|
||||
}
|
||||
|
||||
pub struct ObjDiffConfig {
|
||||
pub build_base: bool,
|
||||
pub build_target: bool,
|
||||
pub custom_make: Option<String>,
|
||||
pub project_dir: Option<PathBuf>,
|
||||
pub selected_obj: Option<ObjectConfig>,
|
||||
pub selected_wsl_distro: Option<String>,
|
||||
}
|
||||
|
||||
impl ObjDiffConfig {
|
||||
pub(crate) fn from_config(config: &AppConfig) -> Self {
|
||||
ObjDiffConfig {
|
||||
build_base: config.build_base,
|
||||
build_target: config.build_target,
|
||||
custom_make: config.custom_make.clone(),
|
||||
project_dir: config.project_dir.clone(),
|
||||
selected_obj: config.selected_obj.clone(),
|
||||
selected_wsl_distro: config.selected_wsl_distro.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ObjDiffResult {
|
||||
pub first_status: BuildStatus,
|
||||
pub second_status: BuildStatus,
|
||||
@@ -23,7 +50,7 @@ pub struct ObjDiffResult {
|
||||
pub time: OffsetDateTime,
|
||||
}
|
||||
|
||||
fn run_make(cwd: &Path, arg: &Path, config: &AppConfig) -> BuildStatus {
|
||||
fn run_make(cwd: &Path, arg: &Path, config: &ObjDiffConfig) -> BuildStatus {
|
||||
match (|| -> Result<BuildStatus> {
|
||||
let make = config.custom_make.as_deref().unwrap_or("make");
|
||||
#[cfg(not(windows))]
|
||||
@@ -73,9 +100,8 @@ fn run_make(cwd: &Path, arg: &Path, config: &AppConfig) -> BuildStatus {
|
||||
fn run_build(
|
||||
status: &JobStatusRef,
|
||||
cancel: Receiver<()>,
|
||||
config: AppConfigRef,
|
||||
config: ObjDiffConfig,
|
||||
) -> Result<Box<ObjDiffResult>> {
|
||||
let config = config.read().map_err(|_| Error::msg("Failed to lock app config"))?.clone();
|
||||
let obj_config = config.selected_obj.as_ref().ok_or_else(|| Error::msg("Missing obj path"))?;
|
||||
let project_dir =
|
||||
config.project_dir.as_ref().ok_or_else(|| Error::msg("Missing project dir"))?;
|
||||
@@ -106,7 +132,7 @@ fn run_build(
|
||||
if config.build_target && target_path_rel.is_some() {
|
||||
total += 1;
|
||||
}
|
||||
if base_path_rel.is_some() {
|
||||
if config.build_base && base_path_rel.is_some() {
|
||||
total += 1;
|
||||
}
|
||||
let first_status = match target_path_rel {
|
||||
@@ -123,17 +149,18 @@ fn run_build(
|
||||
_ => BuildStatus { success: true, log: String::new() },
|
||||
};
|
||||
|
||||
let second_status = if let Some(base_path_rel) = base_path_rel {
|
||||
update_status(
|
||||
status,
|
||||
format!("Building base {}", base_path_rel.display()),
|
||||
1,
|
||||
total,
|
||||
&cancel,
|
||||
)?;
|
||||
run_make(project_dir, base_path_rel, &config)
|
||||
} else {
|
||||
BuildStatus { success: true, log: String::new() }
|
||||
let second_status = match base_path_rel {
|
||||
Some(base_path_rel) if config.build_base => {
|
||||
update_status(
|
||||
status,
|
||||
format!("Building base {}", base_path_rel.display()),
|
||||
0,
|
||||
total,
|
||||
&cancel,
|
||||
)?;
|
||||
run_make(project_dir, base_path_rel, &config)
|
||||
}
|
||||
_ => BuildStatus { success: true, log: String::new() },
|
||||
};
|
||||
|
||||
let time = OffsetDateTime::now_utc();
|
||||
@@ -179,7 +206,7 @@ fn run_build(
|
||||
Ok(Box::new(ObjDiffResult { first_status, second_status, first_obj, second_obj, time }))
|
||||
}
|
||||
|
||||
pub fn start_build(config: AppConfigRef) -> JobState {
|
||||
pub fn start_build(config: ObjDiffConfig) -> JobState {
|
||||
start_job("Object diff", Job::ObjDiff, move |status, cancel| {
|
||||
run_build(status, cancel, config).map(|result| JobResult::ObjDiff(Some(result)))
|
||||
})
|
||||
|
||||
@@ -3,10 +3,11 @@ use std::{collections::BTreeMap, fs, io::Cursor, path::Path};
|
||||
use anyhow::{anyhow, bail, Context, Result};
|
||||
use byteorder::{BigEndian, ReadBytesExt};
|
||||
use cwdemangle::demangle;
|
||||
use filetime::FileTime;
|
||||
use flagset::Flags;
|
||||
use object::{
|
||||
elf, Architecture, File, Object, ObjectSection, ObjectSymbol, RelocationKind, RelocationTarget,
|
||||
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolSection,
|
||||
SectionIndex, SectionKind, Symbol, SymbolKind, SymbolScope, SymbolSection,
|
||||
};
|
||||
|
||||
use crate::obj::{
|
||||
@@ -42,6 +43,9 @@ fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> R
|
||||
if symbol.is_weak() {
|
||||
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Weak);
|
||||
}
|
||||
if symbol.scope() == SymbolScope::Linkage {
|
||||
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Hidden);
|
||||
}
|
||||
let section_address = if let Some(section) =
|
||||
symbol.section_index().and_then(|idx| obj_file.section_by_index(idx).ok())
|
||||
{
|
||||
@@ -301,9 +305,10 @@ fn line_info(obj_file: &File<'_>) -> Result<Option<BTreeMap<u32, u32>>> {
|
||||
}
|
||||
|
||||
pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
||||
let data = {
|
||||
let (data, timestamp) = {
|
||||
let file = fs::File::open(obj_path)?;
|
||||
unsafe { memmap2::Mmap::map(&file) }?
|
||||
let timestamp = FileTime::from_last_modification_time(&file.metadata()?);
|
||||
(unsafe { memmap2::Mmap::map(&file) }?, timestamp)
|
||||
};
|
||||
let obj_file = File::parse(&*data)?;
|
||||
let architecture = match obj_file.architecture() {
|
||||
@@ -319,6 +324,7 @@ pub fn read(obj_path: &Path) -> Result<ObjInfo> {
|
||||
let mut result = ObjInfo {
|
||||
architecture,
|
||||
path: obj_path.to_owned(),
|
||||
timestamp,
|
||||
sections: filter_sections(&obj_file)?,
|
||||
common: common_symbols(&obj_file)?,
|
||||
line_info: line_info(&obj_file)?,
|
||||
|
||||
@@ -91,6 +91,7 @@ pub fn process_code(
|
||||
reloc: reloc.cloned(),
|
||||
branch_dest,
|
||||
line,
|
||||
orig: None,
|
||||
});
|
||||
cur_addr += 4;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ pub mod ppc;
|
||||
|
||||
use std::{collections::BTreeMap, path::PathBuf};
|
||||
|
||||
use filetime::FileTime;
|
||||
use flagset::{flags, FlagSet};
|
||||
|
||||
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
|
||||
@@ -18,6 +19,7 @@ flags! {
|
||||
Local,
|
||||
Weak,
|
||||
Common,
|
||||
Hidden,
|
||||
}
|
||||
}
|
||||
#[derive(Debug, Copy, Clone, Default)]
|
||||
@@ -37,7 +39,8 @@ pub struct ObjSection {
|
||||
pub data_diff: Vec<ObjDataDiff>,
|
||||
pub match_percent: f32,
|
||||
}
|
||||
#[derive(Debug, Clone)]
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum ObjInsArg {
|
||||
PpcArg(ppc750cl::Argument),
|
||||
MipsArg(String),
|
||||
@@ -46,6 +49,7 @@ pub enum ObjInsArg {
|
||||
RelocWithBase,
|
||||
BranchOffset(i32),
|
||||
}
|
||||
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct ObjInsArgDiff {
|
||||
/// Incrementing index for coloring
|
||||
@@ -86,6 +90,8 @@ pub struct ObjIns {
|
||||
pub branch_dest: Option<u32>,
|
||||
/// Line info
|
||||
pub line: Option<u32>,
|
||||
/// Original (unsimplified) instruction
|
||||
pub orig: Option<String>,
|
||||
}
|
||||
#[derive(Debug, Clone, Default)]
|
||||
pub struct ObjInsDiff {
|
||||
@@ -139,6 +145,7 @@ pub enum ObjArchitecture {
|
||||
pub struct ObjInfo {
|
||||
pub architecture: ObjArchitecture,
|
||||
pub path: PathBuf,
|
||||
pub timestamp: FileTime,
|
||||
pub sections: Vec<ObjSection>,
|
||||
pub common: Vec<ObjSymbol>,
|
||||
pub line_info: Option<BTreeMap<u32, u32>>,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use anyhow::Result;
|
||||
use ppc750cl::{disasm_iter, Argument};
|
||||
use ppc750cl::{disasm_iter, Argument, SimplifiedIns};
|
||||
|
||||
use crate::obj::{ObjIns, ObjInsArg, ObjReloc, ObjRelocKind};
|
||||
|
||||
@@ -40,7 +40,7 @@ pub fn process_code(
|
||||
_ => ins.code,
|
||||
};
|
||||
}
|
||||
let simplified = ins.simplified();
|
||||
let simplified = ins.clone().simplified();
|
||||
let mut args: Vec<ObjInsArg> = simplified
|
||||
.args
|
||||
.iter()
|
||||
@@ -86,9 +86,10 @@ pub fn process_code(
|
||||
mnemonic: format!("{}{}", simplified.mnemonic, simplified.suffix),
|
||||
args,
|
||||
reloc: reloc.cloned(),
|
||||
op: 0,
|
||||
op: ins.op as u8,
|
||||
branch_dest: None,
|
||||
line,
|
||||
orig: Some(format!("{}", SimplifiedIns::basic_form(ins))),
|
||||
});
|
||||
}
|
||||
Ok((ops, insts))
|
||||
|
||||
@@ -438,7 +438,8 @@ fn filter_node(
|
||||
match node {
|
||||
ProjectObjectNode::File(name, object) => {
|
||||
if (search.is_empty() || name.to_ascii_lowercase().contains(search))
|
||||
&& (!filter_diffable || object.base_path.is_some())
|
||||
&& (!filter_diffable
|
||||
|| (object.base_path.is_some() && object.target_path.is_some()))
|
||||
{
|
||||
Some(node.clone())
|
||||
} else {
|
||||
@@ -616,7 +617,7 @@ fn split_obj_config_ui(
|
||||
ui.label(job);
|
||||
},
|
||||
appearance,
|
||||
!config.project_config_loaded,
|
||||
config.project_config_info.is_none(),
|
||||
);
|
||||
if response.clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder() {
|
||||
@@ -666,13 +667,36 @@ fn split_obj_config_ui(
|
||||
ui.label(job);
|
||||
},
|
||||
appearance,
|
||||
!config.project_config_loaded,
|
||||
config.project_config_info.is_none(),
|
||||
);
|
||||
if response.clicked() {
|
||||
if let Some(path) = rfd::FileDialog::new().set_directory(&project_dir).pick_folder() {
|
||||
config.set_base_obj_dir(path);
|
||||
}
|
||||
}
|
||||
ui.checkbox(&mut config.build_base, "Build base objects").on_hover_ui(|ui| {
|
||||
let mut job = LayoutJob::default();
|
||||
job.append(
|
||||
"Tells the build system to produce the base object.\n",
|
||||
0.0,
|
||||
text_format.clone(),
|
||||
);
|
||||
job.append("For example, this would call ", 0.0, text_format.clone());
|
||||
job.append("make path/to/base.o", 0.0, code_format.clone());
|
||||
job.append(".\n\n", 0.0, text_format.clone());
|
||||
job.append(
|
||||
"This can be disabled if you're running the build system\n",
|
||||
0.0,
|
||||
text_format.clone(),
|
||||
);
|
||||
job.append(
|
||||
"externally, and just want objdiff to reload the files\n",
|
||||
0.0,
|
||||
text_format.clone(),
|
||||
);
|
||||
job.append("when they change.", 0.0, text_format.clone());
|
||||
ui.label(job);
|
||||
});
|
||||
ui.separator();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
use std::{cmp::Ordering, default::Default};
|
||||
use std::{
|
||||
cmp::{max, Ordering},
|
||||
default::Default,
|
||||
};
|
||||
|
||||
use cwdemangle::demangle;
|
||||
use eframe::emath::Align;
|
||||
use egui::{text::LayoutJob, Color32, FontId, Label, Layout, Sense, Vec2};
|
||||
use egui_extras::{Column, TableBuilder};
|
||||
use egui::{text::LayoutJob, Color32, Label, Layout, RichText, Sense, TextFormat, Vec2};
|
||||
use egui_extras::{Column, TableBuilder, TableRow};
|
||||
use ppc750cl::Argument;
|
||||
use time::format_description;
|
||||
|
||||
@@ -19,21 +22,49 @@ use crate::{
|
||||
},
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub enum HighlightKind {
|
||||
#[default]
|
||||
None,
|
||||
Opcode(u8),
|
||||
Arg(ObjInsArg),
|
||||
Symbol(String),
|
||||
Address(u32),
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct FunctionViewState {
|
||||
pub highlight: HighlightKind,
|
||||
}
|
||||
|
||||
fn write_reloc_name(
|
||||
reloc: &ObjReloc,
|
||||
color: Color32,
|
||||
background_color: Color32,
|
||||
job: &mut LayoutJob,
|
||||
font_id: FontId,
|
||||
appearance: &Appearance,
|
||||
) {
|
||||
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
|
||||
write_text(name, appearance.emphasized_text_color, job, font_id.clone());
|
||||
job.append(name, 0.0, TextFormat {
|
||||
font_id: appearance.code_font.clone(),
|
||||
color: appearance.emphasized_text_color,
|
||||
background: background_color,
|
||||
..Default::default()
|
||||
});
|
||||
match reloc.target.addend.cmp(&0i64) {
|
||||
Ordering::Greater => {
|
||||
write_text(&format!("+{:#X}", reloc.target.addend), color, job, font_id)
|
||||
}
|
||||
Ordering::Greater => write_text(
|
||||
&format!("+{:#X}", reloc.target.addend),
|
||||
color,
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
),
|
||||
Ordering::Less => {
|
||||
write_text(&format!("-{:#X}", -reloc.target.addend), color, job, font_id);
|
||||
write_text(
|
||||
&format!("-{:#X}", -reloc.target.addend),
|
||||
color,
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -42,57 +73,57 @@ fn write_reloc_name(
|
||||
fn write_reloc(
|
||||
reloc: &ObjReloc,
|
||||
color: Color32,
|
||||
background_color: Color32,
|
||||
job: &mut LayoutJob,
|
||||
font_id: FontId,
|
||||
appearance: &Appearance,
|
||||
) {
|
||||
match reloc.kind {
|
||||
ObjRelocKind::PpcAddr16Lo => {
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text("@l", color, job, font_id);
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text("@l", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::PpcAddr16Hi => {
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text("@h", color, job, font_id);
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text("@h", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::PpcAddr16Ha => {
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text("@ha", color, job, font_id);
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text("@ha", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::PpcEmbSda21 => {
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text("@sda21", color, job, font_id);
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text("@sda21", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::MipsHi16 => {
|
||||
write_text("%hi(", color, job, font_id.clone());
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text(")", color, job, font_id);
|
||||
write_text("%hi(", color, job, appearance.code_font.clone());
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text(")", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::MipsLo16 => {
|
||||
write_text("%lo(", color, job, font_id.clone());
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text(")", color, job, font_id);
|
||||
write_text("%lo(", color, job, appearance.code_font.clone());
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text(")", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::MipsGot16 => {
|
||||
write_text("%got(", color, job, font_id.clone());
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text(")", color, job, font_id);
|
||||
write_text("%got(", color, job, appearance.code_font.clone());
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text(")", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::MipsCall16 => {
|
||||
write_text("%call16(", color, job, font_id.clone());
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text(")", color, job, font_id);
|
||||
write_text("%call16(", color, job, appearance.code_font.clone());
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text(")", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::MipsGpRel16 => {
|
||||
write_text("%gp_rel(", color, job, font_id.clone());
|
||||
write_reloc_name(reloc, color, job, font_id.clone(), appearance);
|
||||
write_text(")", color, job, font_id);
|
||||
write_text("%gp_rel(", color, job, appearance.code_font.clone());
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
write_text(")", color, job, appearance.code_font.clone());
|
||||
}
|
||||
ObjRelocKind::PpcRel24 | ObjRelocKind::PpcRel14 | ObjRelocKind::Mips26 => {
|
||||
write_reloc_name(reloc, color, job, font_id, appearance);
|
||||
write_reloc_name(reloc, color, background_color, job, appearance);
|
||||
}
|
||||
ObjRelocKind::Absolute | ObjRelocKind::MipsGpRel32 => {
|
||||
write_text("[INVALID]", color, job, font_id);
|
||||
write_text("[INVALID]", color, job, appearance.code_font.clone());
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -102,8 +133,9 @@ fn write_ins(
|
||||
diff_kind: &ObjInsDiffKind,
|
||||
args: &[Option<ObjInsArgDiff>],
|
||||
base_addr: u32,
|
||||
job: &mut LayoutJob,
|
||||
ui: &mut egui::Ui,
|
||||
appearance: &Appearance,
|
||||
ins_view_state: &mut FunctionViewState,
|
||||
) {
|
||||
let base_color = match diff_kind {
|
||||
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
|
||||
@@ -113,49 +145,96 @@ fn write_ins(
|
||||
ObjInsDiffKind::Delete => appearance.delete_color,
|
||||
ObjInsDiffKind::Insert => appearance.insert_color,
|
||||
};
|
||||
write_text(
|
||||
&format!("{:<11}", ins.mnemonic),
|
||||
match diff_kind {
|
||||
ObjInsDiffKind::OpMismatch => appearance.replace_color,
|
||||
_ => base_color,
|
||||
},
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
);
|
||||
|
||||
let highlighted_op =
|
||||
matches!(ins_view_state.highlight, HighlightKind::Opcode(op) if op == ins.op);
|
||||
let op_label = RichText::new(ins.mnemonic.clone())
|
||||
.font(appearance.code_font.clone())
|
||||
.color(if highlighted_op {
|
||||
appearance.emphasized_text_color
|
||||
} else {
|
||||
match diff_kind {
|
||||
ObjInsDiffKind::OpMismatch => appearance.replace_color,
|
||||
_ => base_color,
|
||||
}
|
||||
})
|
||||
.background_color(if highlighted_op {
|
||||
appearance.deemphasized_text_color
|
||||
} else {
|
||||
Color32::TRANSPARENT
|
||||
});
|
||||
if ui
|
||||
.add(Label::new(op_label).sense(Sense::click()))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins))
|
||||
.clicked()
|
||||
{
|
||||
if highlighted_op {
|
||||
ins_view_state.highlight = HighlightKind::None;
|
||||
} else {
|
||||
ins_view_state.highlight = HighlightKind::Opcode(ins.op);
|
||||
}
|
||||
}
|
||||
let space_width = ui.fonts(|f| f.glyph_width(&appearance.code_font, ' '));
|
||||
ui.add_space(space_width * (max(11, ins.mnemonic.len()) - ins.mnemonic.len()) as f32);
|
||||
|
||||
let mut writing_offset = false;
|
||||
for (i, arg) in ins.args.iter().enumerate() {
|
||||
let mut job = LayoutJob::default();
|
||||
if i == 0 {
|
||||
write_text(" ", base_color, job, appearance.code_font.clone());
|
||||
write_text(" ", base_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
if i > 0 && !writing_offset {
|
||||
write_text(", ", base_color, job, appearance.code_font.clone());
|
||||
write_text(", ", base_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
let color = if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) {
|
||||
let highlighted_arg = match &ins_view_state.highlight {
|
||||
HighlightKind::Symbol(v) => {
|
||||
matches!(arg, ObjInsArg::Reloc | ObjInsArg::RelocWithBase)
|
||||
&& matches!(&ins.reloc, Some(reloc) if &reloc.target.name == v)
|
||||
}
|
||||
HighlightKind::Address(v) => {
|
||||
matches!(arg, ObjInsArg::BranchOffset(offset) if (offset + ins.address as i32 - base_addr as i32) as u32 == *v)
|
||||
}
|
||||
HighlightKind::Arg(v) => v == arg,
|
||||
_ => false,
|
||||
};
|
||||
let color = if highlighted_arg {
|
||||
appearance.emphasized_text_color
|
||||
} else if let Some(diff) = args.get(i).and_then(|a| a.as_ref()) {
|
||||
appearance.diff_colors[diff.idx % appearance.diff_colors.len()]
|
||||
} else {
|
||||
base_color
|
||||
};
|
||||
let text_format = TextFormat {
|
||||
font_id: appearance.code_font.clone(),
|
||||
color,
|
||||
background: if highlighted_arg {
|
||||
appearance.deemphasized_text_color
|
||||
} else {
|
||||
Color32::TRANSPARENT
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let mut new_writing_offset = false;
|
||||
match arg {
|
||||
ObjInsArg::PpcArg(arg) => match arg {
|
||||
Argument::Offset(val) => {
|
||||
write_text(&format!("{val}"), color, job, appearance.code_font.clone());
|
||||
write_text("(", base_color, job, appearance.code_font.clone());
|
||||
writing_offset = true;
|
||||
continue;
|
||||
job.append(&format!("{val}"), 0.0, text_format);
|
||||
write_text("(", base_color, &mut job, appearance.code_font.clone());
|
||||
new_writing_offset = true;
|
||||
}
|
||||
Argument::Uimm(_) | Argument::Simm(_) => {
|
||||
write_text(&format!("{arg}"), color, job, appearance.code_font.clone());
|
||||
job.append(&format!("{arg}"), 0.0, text_format);
|
||||
}
|
||||
_ => {
|
||||
write_text(&format!("{arg}"), color, job, appearance.code_font.clone());
|
||||
job.append(&format!("{arg}"), 0.0, text_format);
|
||||
}
|
||||
},
|
||||
ObjInsArg::Reloc => {
|
||||
write_reloc(
|
||||
ins.reloc.as_ref().unwrap(),
|
||||
base_color,
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
text_format.background,
|
||||
&mut job,
|
||||
appearance,
|
||||
);
|
||||
}
|
||||
@@ -163,41 +242,46 @@ fn write_ins(
|
||||
write_reloc(
|
||||
ins.reloc.as_ref().unwrap(),
|
||||
base_color,
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
text_format.background,
|
||||
&mut job,
|
||||
appearance,
|
||||
);
|
||||
write_text("(", base_color, job, appearance.code_font.clone());
|
||||
writing_offset = true;
|
||||
continue;
|
||||
write_text("(", base_color, &mut job, appearance.code_font.clone());
|
||||
new_writing_offset = true;
|
||||
}
|
||||
ObjInsArg::MipsArg(str) => {
|
||||
write_text(
|
||||
str.strip_prefix('$').unwrap_or(str),
|
||||
color,
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
);
|
||||
job.append(str.strip_prefix('$').unwrap_or(str), 0.0, text_format);
|
||||
}
|
||||
ObjInsArg::MipsArgWithBase(str) => {
|
||||
write_text(
|
||||
str.strip_prefix('$').unwrap_or(str),
|
||||
color,
|
||||
job,
|
||||
appearance.code_font.clone(),
|
||||
);
|
||||
write_text("(", base_color, job, appearance.code_font.clone());
|
||||
writing_offset = true;
|
||||
continue;
|
||||
job.append(str.strip_prefix('$').unwrap_or(str), 0.0, text_format);
|
||||
write_text("(", base_color, &mut job, appearance.code_font.clone());
|
||||
new_writing_offset = true;
|
||||
}
|
||||
ObjInsArg::BranchOffset(offset) => {
|
||||
let addr = offset + ins.address as i32 - base_addr as i32;
|
||||
write_text(&format!("{addr:x}"), color, job, appearance.code_font.clone());
|
||||
job.append(&format!("{addr:x}"), 0.0, text_format);
|
||||
}
|
||||
}
|
||||
if writing_offset {
|
||||
write_text(")", base_color, job, appearance.code_font.clone());
|
||||
writing_offset = false;
|
||||
write_text(")", base_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
writing_offset = new_writing_offset;
|
||||
if ui
|
||||
.add(Label::new(job).sense(Sense::click()))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins))
|
||||
.clicked()
|
||||
{
|
||||
if highlighted_arg {
|
||||
ins_view_state.highlight = HighlightKind::None;
|
||||
} else if matches!(arg, ObjInsArg::Reloc | ObjInsArg::RelocWithBase) {
|
||||
ins_view_state.highlight =
|
||||
HighlightKind::Symbol(ins.reloc.as_ref().unwrap().target.name.clone());
|
||||
} else if let ObjInsArg::BranchOffset(offset) = arg {
|
||||
ins_view_state.highlight =
|
||||
HighlightKind::Address((offset + ins.address as i32 - base_addr as i32) as u32);
|
||||
} else {
|
||||
ins_view_state.highlight = HighlightKind::Arg(arg.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -209,6 +293,10 @@ fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns, appearance: &Appearance) {
|
||||
|
||||
ui.label(format!("{:02X?}", ins.code.to_be_bytes()));
|
||||
|
||||
if let Some(orig) = &ins.orig {
|
||||
ui.label(format!("Original: {}", orig));
|
||||
}
|
||||
|
||||
for arg in &ins.args {
|
||||
if let ObjInsArg::PpcArg(arg) = arg {
|
||||
match arg {
|
||||
@@ -316,7 +404,9 @@ fn asm_row_ui(
|
||||
ins_diff: &ObjInsDiff,
|
||||
symbol: &ObjSymbol,
|
||||
appearance: &Appearance,
|
||||
ins_view_state: &mut FunctionViewState,
|
||||
) {
|
||||
ui.spacing_mut().item_spacing.x = 0.0;
|
||||
if ins_diff.kind != ObjInsDiffKind::None {
|
||||
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
|
||||
}
|
||||
@@ -345,34 +435,95 @@ fn asm_row_ui(
|
||||
);
|
||||
pad = 12 - line_str.len();
|
||||
}
|
||||
write_text(
|
||||
&format!("{:<1$}", format!("{:x}: ", ins.address - symbol.address as u32), pad),
|
||||
base_color,
|
||||
&mut job,
|
||||
appearance.code_font.clone(),
|
||||
let base_addr = symbol.address as u32;
|
||||
let addr_highlight = matches!(
|
||||
&ins_view_state.highlight,
|
||||
HighlightKind::Address(v) if *v == (ins.address - base_addr)
|
||||
);
|
||||
if let Some(branch) = &ins_diff.branch_from {
|
||||
write_text(
|
||||
"~> ",
|
||||
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
|
||||
&mut job,
|
||||
appearance.code_font.clone(),
|
||||
);
|
||||
} else {
|
||||
write_text(" ", base_color, &mut job, appearance.code_font.clone());
|
||||
let addr_string = format!("{:x}", ins.address - symbol.address as u32);
|
||||
pad -= addr_string.len();
|
||||
job.append(&addr_string, 0.0, TextFormat {
|
||||
font_id: appearance.code_font.clone(),
|
||||
color: if addr_highlight { appearance.emphasized_text_color } else { base_color },
|
||||
background: if addr_highlight {
|
||||
appearance.deemphasized_text_color
|
||||
} else {
|
||||
Color32::TRANSPARENT
|
||||
},
|
||||
..Default::default()
|
||||
});
|
||||
if ui
|
||||
.add(Label::new(job).sense(Sense::click()))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins))
|
||||
.clicked()
|
||||
{
|
||||
if addr_highlight {
|
||||
ins_view_state.highlight = HighlightKind::None;
|
||||
} else {
|
||||
ins_view_state.highlight = HighlightKind::Address(ins.address - base_addr);
|
||||
}
|
||||
}
|
||||
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, symbol.address as u32, &mut job, appearance);
|
||||
|
||||
let mut job = LayoutJob::default();
|
||||
let space_width = ui.fonts(|f| f.glyph_width(&appearance.code_font, ' '));
|
||||
let spacing = space_width * pad as f32;
|
||||
job.append(": ", 0.0, TextFormat {
|
||||
font_id: appearance.code_font.clone(),
|
||||
color: base_color,
|
||||
..Default::default()
|
||||
});
|
||||
if let Some(branch) = &ins_diff.branch_from {
|
||||
job.append("~> ", spacing, TextFormat {
|
||||
font_id: appearance.code_font.clone(),
|
||||
color: appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
|
||||
..Default::default()
|
||||
});
|
||||
} else {
|
||||
job.append(" ", spacing, TextFormat {
|
||||
font_id: appearance.code_font.clone(),
|
||||
color: base_color,
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
ui.add(Label::new(job));
|
||||
write_ins(ins, &ins_diff.kind, &ins_diff.arg_diff, base_addr, ui, appearance, ins_view_state);
|
||||
if let Some(branch) = &ins_diff.branch_to {
|
||||
let mut job = LayoutJob::default();
|
||||
write_text(
|
||||
" ~>",
|
||||
appearance.diff_colors[branch.branch_idx % appearance.diff_colors.len()],
|
||||
&mut job,
|
||||
appearance.code_font.clone(),
|
||||
);
|
||||
ui.add(Label::new(job));
|
||||
}
|
||||
ui.add(Label::new(job).sense(Sense::click()))
|
||||
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins, appearance))
|
||||
.context_menu(|ui| ins_context_menu(ui, ins));
|
||||
}
|
||||
|
||||
fn asm_col_ui(
|
||||
row: &mut TableRow<'_, '_>,
|
||||
ins_diff: &ObjInsDiff,
|
||||
symbol: &ObjSymbol,
|
||||
appearance: &Appearance,
|
||||
ins_view_state: &mut FunctionViewState,
|
||||
) {
|
||||
let (_, response) = row.col(|ui| {
|
||||
asm_row_ui(ui, ins_diff, symbol, appearance, ins_view_state);
|
||||
});
|
||||
if let Some(ins) = &ins_diff.ins {
|
||||
response
|
||||
.on_hover_ui_at_pointer(|ui| {
|
||||
ins_hover_ui(ui, ins, appearance);
|
||||
})
|
||||
.context_menu(|ui| {
|
||||
ins_context_menu(ui, ins);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn empty_col_ui(row: &mut TableRow<'_, '_>) {
|
||||
row.col(|ui| {
|
||||
ui.label("");
|
||||
});
|
||||
}
|
||||
|
||||
fn asm_table_ui(
|
||||
@@ -381,22 +532,35 @@ fn asm_table_ui(
|
||||
right_obj: Option<&ObjInfo>,
|
||||
selected_symbol: &SymbolReference,
|
||||
appearance: &Appearance,
|
||||
ins_view_state: &mut FunctionViewState,
|
||||
) -> Option<()> {
|
||||
let left_symbol = left_obj.and_then(|obj| find_symbol(obj, selected_symbol));
|
||||
let right_symbol = right_obj.and_then(|obj| find_symbol(obj, selected_symbol));
|
||||
let instructions_len = left_symbol.or(right_symbol).map(|s| s.instructions.len())?;
|
||||
table.body(|body| {
|
||||
body.rows(appearance.code_font.size, instructions_len, |row_index, mut row| {
|
||||
row.col(|ui| {
|
||||
if let Some(symbol) = left_symbol {
|
||||
asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
|
||||
}
|
||||
});
|
||||
row.col(|ui| {
|
||||
if let Some(symbol) = right_symbol {
|
||||
asm_row_ui(ui, &symbol.instructions[row_index], symbol, appearance);
|
||||
}
|
||||
});
|
||||
if let Some(symbol) = left_symbol {
|
||||
asm_col_ui(
|
||||
&mut row,
|
||||
&symbol.instructions[row_index],
|
||||
symbol,
|
||||
appearance,
|
||||
ins_view_state,
|
||||
);
|
||||
} else {
|
||||
empty_col_ui(&mut row);
|
||||
}
|
||||
if let Some(symbol) = right_symbol {
|
||||
asm_col_ui(
|
||||
&mut row,
|
||||
&symbol.instructions[row_index],
|
||||
symbol,
|
||||
appearance,
|
||||
ins_view_state,
|
||||
);
|
||||
} else {
|
||||
empty_col_ui(&mut row);
|
||||
}
|
||||
});
|
||||
});
|
||||
Some(())
|
||||
@@ -517,5 +681,6 @@ pub fn function_diff_ui(ui: &mut egui::Ui, state: &mut DiffViewState, appearance
|
||||
result.second_obj.as_ref(),
|
||||
selected_symbol,
|
||||
appearance,
|
||||
&mut state.function_state,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ use crate::{
|
||||
Job, JobQueue, JobResult,
|
||||
},
|
||||
obj::{ObjInfo, ObjSection, ObjSectionKind, ObjSymbol, ObjSymbolFlags},
|
||||
views::{appearance::Appearance, write_text},
|
||||
views::{appearance::Appearance, function_diff::FunctionViewState, write_text},
|
||||
};
|
||||
|
||||
pub struct SymbolReference {
|
||||
@@ -35,6 +35,7 @@ pub struct DiffViewState {
|
||||
pub build: Option<Box<ObjDiffResult>>,
|
||||
pub current_view: View,
|
||||
pub symbol_state: SymbolViewState,
|
||||
pub function_state: FunctionViewState,
|
||||
pub search: String,
|
||||
pub queue_build: bool,
|
||||
pub build_running: bool,
|
||||
@@ -46,6 +47,7 @@ pub struct SymbolViewState {
|
||||
pub selected_symbol: Option<SymbolReference>,
|
||||
pub reverse_fn_order: bool,
|
||||
pub disable_reverse_fn_order: bool,
|
||||
pub show_hidden_symbols: bool,
|
||||
}
|
||||
|
||||
impl DiffViewState {
|
||||
@@ -135,6 +137,9 @@ fn symbol_ui(
|
||||
state: &mut SymbolViewState,
|
||||
appearance: &Appearance,
|
||||
) -> Option<View> {
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Hidden) && !state.show_hidden_symbols {
|
||||
return None;
|
||||
}
|
||||
let mut ret = None;
|
||||
let mut job = LayoutJob::default();
|
||||
let name: &str =
|
||||
@@ -154,6 +159,9 @@ fn symbol_ui(
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Weak) {
|
||||
write_text("w", appearance.text_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
if symbol.flags.0.contains(ObjSymbolFlags::Hidden) {
|
||||
write_text("h", appearance.deemphasized_text_color, &mut job, appearance.code_font.clone());
|
||||
}
|
||||
write_text("] ", appearance.text_color, &mut job, appearance.code_font.clone());
|
||||
if let Some(match_percent) = symbol.match_percent {
|
||||
write_text("(", appearance.text_color, &mut job, appearance.code_font.clone());
|
||||
@@ -335,13 +343,9 @@ pub fn symbol_diff_ui(ui: &mut Ui, state: &mut DiffViewState, appearance: &Appea
|
||||
}
|
||||
});
|
||||
|
||||
ui.add_enabled(
|
||||
!symbol_state.disable_reverse_fn_order,
|
||||
egui::Checkbox::new(
|
||||
&mut symbol_state.reverse_fn_order,
|
||||
"Reverse function order (-inline deferred)",
|
||||
),
|
||||
);
|
||||
if ui.add_enabled(!state.build_running, egui::Button::new("Build")).clicked() {
|
||||
state.queue_build = true;
|
||||
}
|
||||
},
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user