Skip to content

Commit

Permalink
Staged
Browse files Browse the repository at this point in the history
  • Loading branch information
mohanson committed Nov 12, 2024
1 parent 300e54f commit fefa338
Show file tree
Hide file tree
Showing 2 changed files with 183 additions and 89 deletions.
49 changes: 2 additions & 47 deletions tests/machine_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use bytes::Bytes;
use ckb_vm::cost_model::constant_cycles;
#[cfg(has_asm)]
use ckb_vm::machine::asm::{AsmCoreMachine, AsmMachine};
use ckb_vm::machine::{trace::TraceMachine, DefaultCoreMachine, VERSION1, VERSION2};
use ckb_vm::machine::{trace::TraceMachine, DefaultCoreMachine, VERSION2};
use ckb_vm::registers::{A0, A7};
use ckb_vm::{
DefaultMachineBuilder, Error, Register, SparseMemory, SupportMachine, Syscalls, WXorXMemory,
ISA_A, ISA_B, ISA_IMC, ISA_MOP,
ISA_A, ISA_B, ISA_IMC,
};

pub struct SleepSyscall {}
Expand All @@ -29,51 +29,6 @@ impl<Mac: SupportMachine> Syscalls<Mac> for SleepSyscall {
}
}

#[cfg(has_asm)]
pub fn asm_mop(path: &str, args: Vec<Bytes>, version: u32) -> AsmMachine {
let buffer: Bytes = std::fs::read(path).unwrap().into();
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, version, u64::MAX);
let core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
.instruction_cycle_func(Box::new(constant_cycles))
.syscall(Box::new(SleepSyscall {}))
.build();
let mut machine = AsmMachine::new(core);
let mut argv = vec![Bytes::from("main")];
argv.extend_from_slice(&args);
machine.load_program(&buffer, &argv).unwrap();
machine
}

pub fn int_v1_mop(
path: &str,
args: Vec<Bytes>,
) -> TraceMachine<DefaultCoreMachine<u64, WXorXMemory<SparseMemory<u64>>>> {
int_mop(path, args, VERSION1)
}

pub fn int_mop(
path: &str,
args: Vec<Bytes>,
version: u32,
) -> TraceMachine<DefaultCoreMachine<u64, WXorXMemory<SparseMemory<u64>>>> {
let buffer: Bytes = std::fs::read(path).unwrap().into();
let core_machine = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
ISA_IMC | ISA_B | ISA_MOP,
version,
u64::MAX,
);
let mut machine = TraceMachine::new(
DefaultMachineBuilder::new(core_machine)
.instruction_cycle_func(Box::new(constant_cycles))
.syscall(Box::new(SleepSyscall {}))
.build(),
);
let mut argv = vec![Bytes::from("main")];
argv.extend_from_slice(&args);
machine.load_program(&buffer, &argv).unwrap();
machine
}

#[cfg(has_asm)]
pub fn asm_v2_imacb(path: &str) -> AsmMachine {
let buffer: Bytes = std::fs::read(path).unwrap().into();
Expand Down
Loading

0 comments on commit fefa338

Please sign in to comment.