-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1069 from 0xPolygonMiden/bobbin-debug-decorator
Implement basic Debug decorator
- Loading branch information
Showing
23 changed files
with
273 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use super::{super::DebugOptions, ByteReader, ByteWriter, DeserializationError, ToString}; | ||
|
||
const STACK_ALL: u8 = 0; | ||
const STACK_TOP: u8 = 1; | ||
|
||
/// Writes the provided [DebugOptions] into the provided target. | ||
pub fn write_options_into<W: ByteWriter>(target: &mut W, options: &DebugOptions) { | ||
match options { | ||
DebugOptions::StackAll => target.write_u8(STACK_ALL), | ||
DebugOptions::StackTop(n) => { | ||
target.write_u8(STACK_TOP); | ||
target.write_u16(*n); | ||
} | ||
} | ||
} | ||
|
||
/// Reads [DebugOptions] from the provided source. | ||
pub fn read_options_from<R: ByteReader>( | ||
source: &mut R, | ||
) -> Result<DebugOptions, DeserializationError> { | ||
match source.read_u8()? { | ||
STACK_ALL => Ok(DebugOptions::StackAll), | ||
STACK_TOP => { | ||
let n = source.read_u16()?; | ||
if n == 0 { | ||
return Err(DeserializationError::InvalidValue(n.to_string())); | ||
} | ||
Ok(DebugOptions::StackTop(n)) | ||
} | ||
val => Err(DeserializationError::InvalidValue(val.to_string())), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use super::{ | ||
parse_checked_param, | ||
Instruction::*, | ||
Node::{self, Instruction}, | ||
ParsingError, Token, | ||
}; | ||
use vm_core::DebugOptions; | ||
|
||
// INSTRUCTION PARSERS | ||
// ================================================================================================ | ||
|
||
/// Returns `Debug` instruction node. | ||
/// | ||
/// # Errors | ||
/// Returns an error if the instruction token contains a wrong number of parameters, or if | ||
/// the provided parameters are not valid. | ||
pub fn parse_debug(op: &Token) -> Result<Node, ParsingError> { | ||
debug_assert_eq!(op.parts()[0], "debug"); | ||
if op.num_parts() < 2 { | ||
return Err(ParsingError::missing_param(op, "debug.stack.<debug_params?>")); | ||
} | ||
|
||
let options = match op.parts()[1] { | ||
"stack" => match op.num_parts() { | ||
2 => DebugOptions::StackAll, | ||
3 => { | ||
let n: u16 = parse_checked_param(op, 2, 1..=u16::MAX)?; | ||
DebugOptions::StackTop(n) | ||
} | ||
_ => return Err(ParsingError::extra_param(op)), | ||
}, | ||
_ => return Err(ParsingError::invalid_op(op)), | ||
}; | ||
|
||
Ok(Instruction(Debug(options))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
use core::fmt; | ||
|
||
// DEBUG OPTIONS | ||
// ================================================================================================ | ||
|
||
/// Options of the `Debug` decorator. | ||
/// | ||
/// These options define the debug info which gets printed out when the Debug decorator is | ||
/// executed. | ||
#[derive(Copy, Clone, Debug, Eq, PartialEq)] | ||
pub enum DebugOptions { | ||
/// Print out the entire contents of the stack for the current execution context. | ||
StackAll, | ||
/// Prints out the top n items of the stack for the current context. | ||
StackTop(u16), | ||
} | ||
|
||
impl fmt::Display for DebugOptions { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
match self { | ||
Self::StackAll => write!(f, "stack"), | ||
Self::StackTop(n) => write!(f, "stack.{n}"), | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.