Skip to content

Commit

Permalink
feat: accept pc offset arguments for commands
Browse files Browse the repository at this point in the history
  • Loading branch information
dxrcy committed Dec 20, 2024
1 parent b4d0fbc commit 1e9b09b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
12 changes: 8 additions & 4 deletions src/debugger/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ pub enum ValueError {
MalformedValue {},
MalformedInteger {},
MalformedLabel {},
MalformedPCOffset {},
IntegerTooLarge {},
}

Expand Down Expand Up @@ -124,16 +125,19 @@ impl fmt::Display for CommandError {
)?;
}
ValueError::MalformedValue {} => {
write!(f, "Malformed argument")?;
write!(f, "Invalid value")?;
}
ValueError::MalformedInteger {} => {
write!(f, "Malformed integer argument")?;
write!(f, "Malformed integer")?;
}
ValueError::MalformedLabel {} => {
write!(f, "Malformed label argument")?;
write!(f, "Malformed label")?;
}
ValueError::MalformedPCOffset {} => {
write!(f, "Malformed program counter offset")?;
}
ValueError::IntegerTooLarge {} => {
write!(f, "Integer argument too large")?;
write!(f, "Integer too large")?;
}
}
}
Expand Down
16 changes: 9 additions & 7 deletions src/debugger/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ impl<'a> CommandIter<'a> {

Some(Argument::Label(label)) => Ok(Location::Memory(MemoryLocation::Label(label))),

// TODO(feat): Accept pc offset arguments ?
Some(value) => Err(ArgumentError::InvalidValue {
argument_name,
error: ValueError::MismatchedType {
Expand Down Expand Up @@ -314,10 +315,12 @@ impl<'a> CommandIter<'a> {

Some(Argument::Label(label)) => Ok(MemoryLocation::Label(label)),

Some(Argument::PCOffset(offset)) => Ok(MemoryLocation::PCOffset(offset)),

Some(value) => Err(ArgumentError::InvalidValue {
argument_name,
error: ValueError::MismatchedType {
expected_type: "address or label",
expected_type: "address, label, or program counter offset",
actual_type: value.kind(),
},
}),
Expand Down Expand Up @@ -493,6 +496,8 @@ impl<'a> CommandIter<'a> {
Some(register)
}

// TODO(fix): Should `x1h` be skipped as an integer, and be parsed as a label?

/// Parse and consume the next integer argument.
///
/// Extremely liberal in accepted syntax.
Expand Down Expand Up @@ -710,12 +715,9 @@ impl<'a> CommandIter<'a> {
self.set_base();
let offset = resize_int(self.next_integer_token(false)?.unwrap_or(0))?;

println!("{}", offset);

if !self.is_end_of_argument() {
// TODO(feat): Custom error
return Err(ValueError::MalformedLabel {});
}
debug_assert!(
self.is_end_of_argument(),
"should have consumed characters until end of argument, whether integer succesfully parsed or not");
self.set_base();
Ok(Some(offset))
}
Expand Down

0 comments on commit 1e9b09b

Please sign in to comment.