Skip to content

Commit

Permalink
Clean up disassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
Granddave committed Dec 20, 2023
1 parent 3ae0c53 commit 6f2f93f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/bin/dism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn main() {
let input = std::env::args().nth(1).expect("Filename missing");
let bytes = std::fs::read(input).expect("Unable to read file");

let mut disassembler = Disassembler::default(bytes);
let mut disassembler = Disassembler::new(bytes);
let ast = disassembler.disassemble_code();

let mut listing = Listing::default(ast);
Expand Down
18 changes: 4 additions & 14 deletions src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,16 @@ use crate::ast::{ASTAddressingMode, ASTInstruction, ASTInstructionNode, ASTNode,

pub mod listing;

#[derive(Debug)]
#[derive(Debug, Default)]
pub struct Disassembler {
input: Vec<u8>,
starting_address: usize,
curr_ix: usize,
}

impl Disassembler {
#[tracing::instrument]
pub fn new(input: Vec<u8>, starting_address: usize) -> Self {
Self {
input,
starting_address,
curr_ix: 0,
}
}

#[tracing::instrument]
pub fn default(input: Vec<u8>) -> Self {
Self::new(input, 0x0600)
pub fn new(input: Vec<u8>) -> Self {
Self { input, curr_ix: 0 }
}

#[tracing::instrument]
Expand Down Expand Up @@ -183,7 +173,7 @@ mod tests {
];

for (input, expected) in tests {
let mut disassembler = Disassembler::default(input);
let mut disassembler = Disassembler::new(input);
let actual = disassembler.disassemble_code();
assert_eq!(actual, expected);
}
Expand Down
2 changes: 0 additions & 2 deletions src/disassembler/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::ast::{ASTInstructionNode, ASTNode};
#[derive(Debug)]
pub struct Listing {
ast: Vec<ASTNode>,
start_address: usize,
current_address: usize,
str: String,
}
Expand All @@ -13,7 +12,6 @@ impl Listing {
pub fn new(ast: Vec<ASTNode>, start_address: usize) -> Self {
Self {
ast,
start_address,
current_address: start_address,
str: String::new(),
}
Expand Down

0 comments on commit 6f2f93f

Please sign in to comment.