Skip to content

Commit

Permalink
Introduce ZkasmEnvironment
Browse files Browse the repository at this point in the history
This PR forks DummyEnvironment that we used before, as we will need to change it to enable memory operations.
At this point, there are no changes to the environment and this should be a no-op.

In the past, we relied on DummyEnvironment which is only useful in testing, but in reality, we need a dedicated environment suited for ZKASM machine.
  • Loading branch information
aborg-dev committed Dec 11, 2023
1 parent 7aba01f commit 2e7b22a
Show file tree
Hide file tree
Showing 4 changed files with 962 additions and 7 deletions.
12 changes: 6 additions & 6 deletions cranelift/filetests/src/test_zkasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod tests {
use cranelift_codegen::ir::ExternalName;
use cranelift_codegen::isa::zkasm;
use cranelift_codegen::{settings, FinalizedMachReloc, FinalizedRelocTarget};
use cranelift_wasm::{translate_module, DummyEnvironment};
use cranelift_wasm::{translate_module, ZkasmEnvironment};

fn setup() {
let _ = env_logger::builder().is_test(true).try_init();
Expand Down Expand Up @@ -142,20 +142,20 @@ mod tests {
let isa = isa_builder
.finish(settings::Flags::new(flag_builder))
.unwrap();
let mut dummy_environ = DummyEnvironment::new(isa.frontend_config());
translate_module(wasm_module, &mut dummy_environ).unwrap();
let mut zkasm_environ = ZkasmEnvironment::new(isa.frontend_config());
translate_module(wasm_module, &mut zkasm_environ).unwrap();

let mut program: Vec<String> = Vec::new();
let start_func = dummy_environ
let start_func = zkasm_environ
.info
.start_func
.expect("Must have a start function");
// TODO: Preamble should be generated by a linker and/or clift itself.
program.append(&mut generate_preamble(start_func.index()));

let num_func_imports = dummy_environ.get_num_func_imports();
let num_func_imports = zkasm_environ.get_num_func_imports();
let mut context = cranelift_codegen::Context::new();
for (def_index, func) in dummy_environ.info.function_bodies.iter() {
for (def_index, func) in zkasm_environ.info.function_bodies.iter() {
let func_index = num_func_imports + def_index.index();
program.push(format!("function_{}:", func_index));

Expand Down
2 changes: 2 additions & 0 deletions cranelift/wasm/src/environ/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
mod dummy;
#[macro_use]
mod spec;
mod zkasm;

pub use crate::environ::dummy::{
DummyEnvironment, DummyFuncEnvironment, DummyModuleInfo, ExpectedReachability,
};
pub use crate::environ::spec::{
FuncEnvironment, GlobalVariable, ModuleEnvironment, TargetEnvironment,
};
pub use crate::environ::zkasm::{ZkasmEnvironment, ZkasmFuncEnvironment, ZkasmModuleInfo};
Loading

0 comments on commit 2e7b22a

Please sign in to comment.