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 f7b9f20 commit b0e4833
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 16 deletions.
1 change: 1 addition & 0 deletions definitions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ pub const DEFAULT_MEMORY_SIZE: usize = 4 << 20; // 4 MB
pub const ISA_IMC: u8 = 0b0000_0000;
pub const ISA_B: u8 = 0b0000_0001;
pub const ISA_MOP: u8 = 0b0000_0010;
// Extension ISA_A is not enabled in ckb 2nd hardfork(aka, meepo hardfork)
pub const ISA_A: u8 = 0b0000_0100;
4 changes: 2 additions & 2 deletions examples/ckb-vm-runner.rs → examples/ckb_vm_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl<Mac: SupportMachine> Syscalls<Mac> for DebugSyscall {
#[cfg(has_asm)]
fn main_asm(code: Bytes, args: Vec<Bytes>) -> Result<(), Box<dyn std::error::Error>> {
let asm_core = ckb_vm::machine::asm::AsmCoreMachine::new(
ckb_vm::ISA_IMC | ckb_vm::ISA_B | ckb_vm::ISA_MOP | ckb_vm::ISA_A,
ckb_vm::ISA_IMC | ckb_vm::ISA_B | ckb_vm::ISA_MOP,
ckb_vm::machine::VERSION2,
u64::MAX,
);
Expand All @@ -64,7 +64,7 @@ fn main_asm(code: Bytes, args: Vec<Bytes>) -> Result<(), Box<dyn std::error::Err
#[cfg(not(has_asm))]
fn main_int(code: Bytes, args: Vec<Bytes>) -> Result<(), Box<dyn std::error::Error>> {
let core_machine = ckb_vm::DefaultCoreMachine::<u64, ckb_vm::SparseMemory<u64>>::new(
ckb_vm::ISA_IMC | ckb_vm::ISA_B | ckb_vm::ISA_MOP | ckb_vm::ISA_A,
ckb_vm::ISA_IMC | ckb_vm::ISA_B | ckb_vm::ISA_MOP,
ckb_vm::machine::VERSION2,
u64::MAX,
);
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub fn run<R: Register, M: Memory<REG = R> + Default>(
args: &[Bytes],
) -> Result<i8, Error> {
let core_machine = DefaultCoreMachine::<R, WXorXMemory<M>>::new_with_memory(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
ISA_IMC | ISA_B | ISA_MOP,
machine::VERSION2,
u64::MAX,
WXorXMemory::new(M::default()),
Expand All @@ -57,7 +57,7 @@ pub fn run_with_memory<R: Register, M: Memory<REG = R>>(
memory: M,
) -> Result<i8, Error> {
let core_machine = DefaultCoreMachine::<R, WXorXMemory<M>>::new_with_memory(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
ISA_IMC | ISA_B | ISA_MOP,
machine::VERSION2,
u64::MAX,
WXorXMemory::new(memory),
Expand Down
12 changes: 5 additions & 7 deletions tests/test_spawn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ckb_vm::machine::{trace::TraceMachine, DefaultCoreMachine, VERSION2};
use ckb_vm::registers::{A0, A1, A2, A7};
use ckb_vm::{
DefaultMachineBuilder, Error, Memory, Register, SparseMemory, SupportMachine, Syscalls,
WXorXMemory, ISA_A, ISA_B, ISA_IMC, ISA_MOP,
WXorXMemory, ISA_B, ISA_IMC, ISA_MOP,
};
use std::sync::{Arc, Mutex};

Expand Down Expand Up @@ -80,7 +80,7 @@ impl<Mac: SupportMachine> Syscalls<Mac> for IntSpawnSyscall {
}
let buffer: Bytes = std::fs::read(path).unwrap().into();
let machine_core = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
ISA_IMC | ISA_B | ISA_MOP,
VERSION2,
u64::MAX,
);
Expand Down Expand Up @@ -141,8 +141,7 @@ impl<Mac: SupportMachine> Syscalls<Mac> for AsmSpawnSyscall {
addr += 8;
}
let buffer: Bytes = std::fs::read(path).unwrap().into();
let machine_core_asm =
AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B | ISA_MOP, VERSION2, u64::MAX);
let machine_core_asm = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION2, u64::MAX);
let machine_core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(machine_core_asm)
.instruction_cycle_func(Box::new(constant_cycles))
.syscall(Box::new(AsmSpawnSyscall {
Expand All @@ -163,7 +162,7 @@ pub fn test_spawn_int() {
let cur_sp = stack_depth();
let min_sp = Arc::new(Mutex::new(u64::MAX));
let machine_core = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
ISA_IMC | ISA_B | ISA_MOP,
VERSION2,
u64::MAX,
);
Expand All @@ -190,8 +189,7 @@ pub fn test_spawn_asm() {
let buffer = std::fs::read("tests/programs/spawn").unwrap().into();
let cur_sp = stack_depth();
let min_sp = Arc::new(Mutex::new(u64::MAX));
let machine_core_asm =
AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B | ISA_MOP, VERSION2, u64::MAX);
let machine_core_asm = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION2, u64::MAX);
let machine_core = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(machine_core_asm)
.instruction_cycle_func(Box::new(constant_cycles))
.syscall(Box::new(AsmSpawnSyscall {
Expand Down
10 changes: 5 additions & 5 deletions tests/test_versions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use ckb_vm::machine::{VERSION0, VERSION1, VERSION2};
use ckb_vm::memory::{FLAG_DIRTY, FLAG_FREEZED};
use ckb_vm::{
CoreMachine, DefaultCoreMachine, DefaultMachine, DefaultMachineBuilder, Error, Memory,
SparseMemory, TraceMachine, WXorXMemory, ISA_A, ISA_B, ISA_IMC, ISA_MOP, RISCV_PAGESIZE,
SparseMemory, TraceMachine, WXorXMemory, ISA_B, ISA_IMC, ISA_MOP, RISCV_PAGESIZE,
};
use std::fs;

Expand Down Expand Up @@ -345,7 +345,7 @@ pub fn test_asm_version1_asm_trace_bug() {
let buffer = fs::read("tests/programs/asm_trace_bug").unwrap().into();

let mut machine = {
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B | ISA_MOP, VERSION1, 2000);
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION1, 2000);
let machine = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
.instruction_cycle_func(Box::new(constant_cycles))
.build();
Expand All @@ -362,7 +362,7 @@ pub fn test_asm_version2_asm_trace_bug() {
let buffer = fs::read("tests/programs/asm_trace_bug").unwrap().into();

let mut machine = {
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_A | ISA_B | ISA_MOP, VERSION2, 2000);
let asm_core = AsmCoreMachine::new(ISA_IMC | ISA_B | ISA_MOP, VERSION2, 2000);
let machine = DefaultMachineBuilder::<Box<AsmCoreMachine>>::new(asm_core)
.instruction_cycle_func(Box::new(constant_cycles))
.build();
Expand All @@ -383,7 +383,7 @@ pub fn test_trace_version1_asm_trace_bug() {

let mut machine = {
let core_machine = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
ISA_IMC | ISA_B | ISA_MOP,
VERSION1,
2000,
);
Expand All @@ -405,7 +405,7 @@ pub fn test_trace_version2_asm_trace_bug() {

let mut machine = {
let core_machine = DefaultCoreMachine::<u64, WXorXMemory<SparseMemory<u64>>>::new(
ISA_IMC | ISA_A | ISA_B | ISA_MOP,
ISA_IMC | ISA_B | ISA_MOP,
VERSION2,
2000,
);
Expand Down

0 comments on commit b0e4833

Please sign in to comment.