Skip to content

Commit

Permalink
Every label in the assembly listing is now clickable.
Browse files Browse the repository at this point in the history
  • Loading branch information
WINSDK committed Apr 19, 2024
1 parent ac7eed0 commit 985466d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
8 changes: 4 additions & 4 deletions gui/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ impl WinitQueue {
}
}

pub struct UIQueue {
pub struct UiQueue {
inner: crossbeam_queue::ArrayQueue<UIEvent>,
}

impl UIQueue {
impl UiQueue {
pub fn push(&self, event: UIEvent) {
let _ = self.inner.push(event);
}
Expand All @@ -91,7 +91,7 @@ pub struct UI {
instance: wgpu_backend::Instance<'static>,
egui_render_pass: wgpu_backend::egui::Pipeline,
platform: winit_backend::Platform,
ui_queue: Arc<UIQueue>,
ui_queue: Arc<UiQueue>,
}

impl UI {
Expand All @@ -110,7 +110,7 @@ impl UI {
#[cfg(target_family = "unix")]
let arch = Arch::new();

let ui_queue = Arc::new(UIQueue {
let ui_queue = Arc::new(UiQueue {
inner: crossbeam_queue::ArrayQueue::new(100),
});

Expand Down
6 changes: 3 additions & 3 deletions gui/src/panes/functions.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::common::*;
use crate::{UIQueue, UIEvent};
use crate::{UiQueue, UIEvent};
use config::CONFIG;
use processor_shared::Addressed;
use processor::Processor;
Expand All @@ -8,15 +8,15 @@ use tokenizing::{colors, Token};

pub struct Functions {
processor: Arc<Processor>,
ui_queue: Arc<UIQueue>,
ui_queue: Arc<UiQueue>,
lines: Vec<(usize, Vec<Token>)>,
lines_count: usize,
min_row: usize,
max_row: usize,
}

impl Functions {
pub fn new(processor: Arc<Processor>, ui_queue: Arc<UIQueue>) -> Self {
pub fn new(processor: Arc<Processor>, ui_queue: Arc<UiQueue>) -> Self {
let function_count = processor.index.named_funcs_count();

Self {
Expand Down
61 changes: 55 additions & 6 deletions gui/src/panes/listing.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
use crate::{common::*, UIQueue};
use crate::{common::*, UIEvent, UiQueue};
use config::CONFIG;
use debugvault::Index;
use egui::mutex::RwLock;
use egui::Color32;
use infinite_scroll::{Callback, InfiniteScroll};
use processor::{Block, BlockContent, Processor};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
use tokenizing::{colors, TokenStream};
use tokenizing::{colors, Token, TokenStream};

pub struct Listing {
processor: Arc<Processor>,
#[allow(dead_code)]
ui_queue: Arc<UIQueue>,
ui_queue: Arc<UiQueue>,
boundaries: Arc<RwLock<Vec<usize>>>,
scroll: InfiniteScroll<Block, usize>,
reset_position: Arc<AtomicUsize>,
Expand All @@ -20,7 +21,7 @@ pub struct Listing {
}

impl Listing {
pub fn new(processor: Arc<Processor>, ui_queue: Arc<UIQueue>) -> Self {
pub fn new(processor: Arc<Processor>, ui_queue: Arc<UiQueue>) -> Self {
let boundaries: Arc<RwLock<Vec<usize>>> = Arc::default();

{
Expand Down Expand Up @@ -170,6 +171,21 @@ impl Listing {
}
}

fn split_instruction_by_label(tokens: Vec<Token>) -> (Vec<Token>, Vec<Token>, Vec<Token>) {
let start = tokens.iter().position(|token| token.text.contains('<'));
let end = tokens.iter().rposition(|token| token.text.contains('>'));

if let (Some(start), Some(end)) = (start, end) {
return (
tokens[..start].to_vec(),
tokens[start..=end].to_vec(),
tokens[end + 1..].to_vec(),
);
}

(tokens, Vec::new(), Vec::new())
}

fn draw_horizontal_line(ui: &mut egui::Ui) {
let thickness = 1.0;
let y = ui.cursor().min.y;
Expand All @@ -185,6 +201,25 @@ fn draw_horizontal_line(ui: &mut egui::Ui) {
ui.painter().extend(dashed_line);
}

fn draw_instruction(ui: &mut egui::Ui, tokens: Vec<Token>, index: &Index, ui_queue: &UiQueue) {
let (a, b, c) = split_instruction_by_label(tokens);
let label = tokens_to_layoutjob(b);
let label_text = label.text.clone();

ui.horizontal(|ui| {
ui.style_mut().spacing.item_spacing.x = 0.0;

ui.label(tokens_to_layoutjob(a));
if ui.link(label).clicked() {
let label_without_arrows = &label_text[1..][..label_text.len() - 2];
if let Some(addr) = index.get_func_by_name(label_without_arrows) {
ui_queue.push(UIEvent::GotoAddr(addr));
}
}
ui.label(tokens_to_layoutjob(c));
});
}

impl Display for Listing {
fn show(&mut self, ui: &mut egui::Ui) {
let area = egui::ScrollArea::vertical()
Expand All @@ -209,7 +244,21 @@ impl Display for Listing {

let mut stream = TokenStream::new();
block.tokenize(&mut stream);
ui.label(tokens_to_layoutjob(stream.inner));

match block.content {
BlockContent::Instruction { .. } => {
draw_instruction(ui, stream.inner, &self.processor.index, &self.ui_queue);
}
BlockContent::Label { .. } => {
if ui.link(tokens_to_layoutjob(stream.inner)).clicked() {
self.ui_queue.push(UIEvent::GotoAddr(block.addr));
}
}
_ => {
ui.label(tokens_to_layoutjob(stream.inner));
}
}

idx += 1;
});

Expand Down Expand Up @@ -237,7 +286,7 @@ impl Display for Listing {
Color32::from_rgb(
(color[0] as f32 * 1.1) as u8,
(color[1] as f32 * 1.1) as u8,
(color[2] as f32 * 1.1) as u8
(color[2] as f32 * 1.1) as u8,
)
},
egui::Stroke::new(2.5, egui::Color32::BLACK),
Expand Down
4 changes: 2 additions & 2 deletions gui/src/panes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ impl egui_tiles::Behavior<Identifier> for Tabs {
pub struct Panels {
tree: Tree<Identifier>,
panes: Tabs,
ui_queue: Arc<crate::UIQueue>,
ui_queue: Arc<crate::UiQueue>,
#[allow(dead_code)] // used on windows and linux for top bar
winit_queue: WinitQueue,
loading: bool,
}

impl Panels {
pub fn new(ui_queue: Arc<crate::UIQueue>, winit_queue: WinitQueue) -> Self {
pub fn new(ui_queue: Arc<crate::UiQueue>, winit_queue: WinitQueue) -> Self {
let mut tiles = Tiles::default();
let tabs = vec![
tiles.insert_pane(DISASSEMBLY),
Expand Down

0 comments on commit 985466d

Please sign in to comment.