-
Notifications
You must be signed in to change notification settings - Fork 174
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
205 additions
and
60 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
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 |
---|---|---|
|
@@ -14,6 +14,7 @@ mod field_ops; | |
mod io_ops; | ||
mod stack_ops; | ||
mod sys_ops; | ||
mod trace; | ||
mod u32_ops; | ||
|
||
mod constants; | ||
|
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,29 @@ | ||
use super::{ | ||
parse_param_with_constant_lookup, | ||
Instruction::*, | ||
LocalConstMap, | ||
Node::{self, Instruction}, | ||
ParsingError, Token, | ||
}; | ||
|
||
// EMIT PARSER | ||
// ================================================================================================ | ||
|
||
/// Returns `Trace` instruction node with the parsed `trace_id`. | ||
/// | ||
/// The `trace_id` can be provided as a constant label or as a u32 value. | ||
/// | ||
/// # Errors | ||
/// Returns an error if the constant does not exist or if the value is not a u32. | ||
pub fn parse_trace(op: &Token, constants: &LocalConstMap) -> Result<Node, ParsingError> { | ||
debug_assert_eq!(op.parts()[0], "trace"); | ||
match op.num_parts() { | ||
0 => unreachable!(), | ||
1 => Err(ParsingError::missing_param(op, "trace.<tace_id>")), | ||
2 => { | ||
let trace_id = parse_param_with_constant_lookup(op, 1, constants)?; | ||
Ok(Instruction(Trace(trace_id))) | ||
} | ||
_ => Err(ParsingError::extra_param(op)), | ||
} | ||
} |
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
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 |
---|---|---|
@@ -1,3 +1,64 @@ | ||
use processor::{ | ||
AdviceExtractor, AdviceProvider, ExecutionError, Host, HostResponse, MemAdviceProvider, | ||
ProcessState, | ||
}; | ||
use vm_core::AdviceInjector; | ||
|
||
mod advice; | ||
mod asmop; | ||
mod event; | ||
mod trace; | ||
|
||
// TEST HOST | ||
// ================================================================================================ | ||
pub struct TestHost<A> { | ||
pub adv_provider: A, | ||
pub event_handler: Vec<u32>, | ||
pub trace_handler: Vec<u32>, | ||
} | ||
|
||
impl Default for TestHost<MemAdviceProvider> { | ||
fn default() -> Self { | ||
Self { | ||
adv_provider: MemAdviceProvider::default(), | ||
event_handler: Vec::new(), | ||
trace_handler: Vec::new(), | ||
} | ||
} | ||
} | ||
|
||
impl<A: AdviceProvider> Host for TestHost<A> { | ||
fn get_advice<S: ProcessState>( | ||
&mut self, | ||
process: &S, | ||
extractor: AdviceExtractor, | ||
) -> Result<HostResponse, ExecutionError> { | ||
self.adv_provider.get_advice(process, &extractor) | ||
} | ||
|
||
fn set_advice<S: ProcessState>( | ||
&mut self, | ||
process: &S, | ||
injector: AdviceInjector, | ||
) -> Result<HostResponse, ExecutionError> { | ||
self.adv_provider.set_advice(process, &injector) | ||
} | ||
|
||
fn on_event<S: ProcessState>( | ||
&mut self, | ||
_process: &S, | ||
event_id: u32, | ||
) -> Result<HostResponse, ExecutionError> { | ||
self.event_handler.push(event_id); | ||
Ok(HostResponse::None) | ||
} | ||
|
||
fn on_trace<S: ProcessState>( | ||
&mut self, | ||
_process: &S, | ||
trace_id: u32, | ||
) -> Result<HostResponse, ExecutionError> { | ||
self.trace_handler.push(trace_id); | ||
Ok(HostResponse::None) | ||
} | ||
} |
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,22 @@ | ||
use super::TestHost; | ||
use assembly::Assembler; | ||
|
||
#[test] | ||
fn test_trace_handling() { | ||
let source = "\ | ||
begin | ||
push.1 | ||
trace.1 | ||
push.2 | ||
trace.2 | ||
end"; | ||
|
||
// compile and execute program | ||
let program = Assembler::default().compile(source).unwrap(); | ||
let mut host = TestHost::default(); | ||
processor::execute(&program, Default::default(), &mut host, Default::default()).unwrap(); | ||
|
||
// make sure traces were handled correctly | ||
let expected = vec![1, 2]; | ||
assert_eq!(host.trace_handler, expected); | ||
} |
Oops, something went wrong.