Skip to content

Commit

Permalink
use a global provider encapsulation
Browse files Browse the repository at this point in the history
  • Loading branch information
Hasekawa-Takumi committed Apr 21, 2024
1 parent ae96ab3 commit 1a01e3d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
12 changes: 3 additions & 9 deletions basic/src/bin/valida.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use p3_baby_bear::BabyBear;

use p3_fri::{FriConfig, TwoAdicFriPcs, TwoAdicFriPcsConfig};
use valida_cpu::MachineWithCpuChip;
use valida_machine::{AdviceProvider, FixedAdviceProvider, Machine, MachineProof, ProgramROM, StdinAdviceProvider, StoppingFlag};
use valida_machine::{AdviceProvider, GlobalAdviceProvider, Machine, MachineProof, ProgramROM, StdinAdviceProvider, StoppingFlag};
use valida_memory::MachineWithMemoryChip;

use valida_elf::{load_executable_file, Program};
Expand Down Expand Up @@ -65,7 +65,7 @@ struct Context {
last_fp_: u32,
recorded_current_fp_: u32,
last_fp_size_: u32,
advice : Box<dyn AdviceProvider>,
advice : GlobalAdviceProvider,
}

impl Context {
Expand All @@ -78,13 +78,7 @@ impl Context {
last_fp_: args.stack_height,
recorded_current_fp_: args.stack_height,
last_fp_size_: 0,
advice: match &args.advice {
Some(file) => {
let mut file = File::open(file).unwrap();
Box::new(FixedAdviceProvider::from_file(&mut file))
}
_ => Box::new(StdinAdviceProvider),
},
advice : GlobalAdviceProvider::new(&args.advice),
};

let Program { code, data } = load_executable_file(
Expand Down
4 changes: 2 additions & 2 deletions machine/src/advice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ impl AdviceProvider for StdinAdviceProvider {
}
}

struct GlobalAdviceProvider {
pub struct GlobalAdviceProvider {
provider : AdviceProviderType,
}
impl GlobalAdviceProvider {
pub fn new(file_name : Option<String>) -> Self {
pub fn new(file_name : &Option<String>) -> Self {
match file_name {
Some(file_name) => {
let mut file = File::open(file_name).unwrap();
Expand Down

0 comments on commit 1a01e3d

Please sign in to comment.