-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplify debug utils. * Add auto breakpoint. * Fix stuff.
- Loading branch information
1 parent
72d10b7
commit fa2fa40
Showing
4 changed files
with
120 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#![cfg(feature = "with-debug-utils")] | ||
|
||
use super::{debug_utils::DebugUtils, MetadataStorage}; | ||
use cairo_lang_sierra::ids::ConcreteTypeId; | ||
use melior::ir::{Block, Location}; | ||
use std::collections::HashSet; | ||
|
||
#[derive(Clone, Debug, Eq, Hash, PartialEq)] | ||
pub enum BreakpointEvent { | ||
EnumInit { | ||
type_id: ConcreteTypeId, | ||
variant_idx: usize, | ||
}, | ||
} | ||
|
||
#[derive(Clone, Debug, Default)] | ||
pub struct AutoBreakpoint { | ||
events: HashSet<BreakpointEvent>, | ||
} | ||
|
||
impl AutoBreakpoint { | ||
pub fn add_event(&mut self, event: BreakpointEvent) { | ||
self.events.insert(event); | ||
} | ||
|
||
pub fn has_event(&self, event: &BreakpointEvent) -> bool { | ||
self.events.contains(event) | ||
} | ||
|
||
pub fn maybe_breakpoint( | ||
&self, | ||
block: &Block, | ||
location: Location, | ||
metadata: &MetadataStorage, | ||
event: &BreakpointEvent, | ||
) { | ||
if self.has_event(event) { | ||
metadata | ||
.get::<DebugUtils>() | ||
.unwrap() | ||
.debug_breakpoint_trap(block, location) | ||
.unwrap(); | ||
} | ||
} | ||
} |
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