diff --git a/Cargo.lock b/Cargo.lock index 4742a8d9b..7c53a4f88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2819,6 +2819,7 @@ dependencies = [ "miden-integration-tests-rust-fib", "miden-processor", "miden-stdlib", + "midenc-compile", "midenc-session", "proptest", "rustc-demangle", diff --git a/codegen/masm/src/masm/module.rs b/codegen/masm/src/masm/module.rs index afcc87ccb..96edcb69f 100644 --- a/codegen/masm/src/masm/module.rs +++ b/codegen/masm/src/masm/module.rs @@ -182,7 +182,7 @@ impl Module { imported.insert(import.alias.to_string(), path.clone()); if let Some(imported_fns) = self.imports.imported(&import.alias) { for import_fn in imported_fns.iter().copied() { - let fname = import_fn.to_string(); + let fname = import_fn.function.name; let name = masm::ProcedureName::try_from(fname.as_str()) .expect("invalid function name"); let id = masm::ProcedureId::from_name(fname.as_str(), &path); diff --git a/frontend-wasm/src/code_translator/tests.rs b/frontend-wasm/src/code_translator/tests.rs index e3f21915a..ca3319206 100644 --- a/frontend-wasm/src/code_translator/tests.rs +++ b/frontend-wasm/src/code_translator/tests.rs @@ -3,7 +3,7 @@ use core::fmt::Write; use expect_test::expect; use miden_hir::Ident; -use crate::{test_utils::test_diagnostics, translate_module, WasmTranslationConfig}; +use crate::{test_utils::test_diagnostics, translate, WasmTranslationConfig}; /// Check IR generated for a Wasm op(s). /// Wrap Wasm ops in a function and check the IR generated for the entry block of that function. @@ -19,7 +19,9 @@ fn check_op(wat_op: &str, expected_ir: expect_test::Expect) { ); let wasm = wat::parse_str(wat).unwrap(); let diagnostics = test_diagnostics(); - let module = translate_module(&wasm, &WasmTranslationConfig::default(), &diagnostics).unwrap(); + let module = translate(&wasm, &WasmTranslationConfig::default(), &diagnostics) + .unwrap() + .unwrap_one_module(); let func = module.function(Ident::from("test_wrapper")).unwrap(); // let fref = module.get_funcref_by_name("test_wrapper").unwrap(); // let func = module.get_function(fref).unwrap(); diff --git a/frontend-wasm/src/lib.rs b/frontend-wasm/src/lib.rs index 99e9f9bef..9553924d3 100644 --- a/frontend-wasm/src/lib.rs +++ b/frontend-wasm/src/lib.rs @@ -20,9 +20,25 @@ mod translation_utils; #[cfg(test)] mod test_utils; -pub use self::{ - component::build_ir::translate_component, - config::*, - error::WasmError, - module::build_ir::{translate_module, translate_module_as_component}, -}; +use component::build_ir::translate_component; +use error::WasmResult; +use miden_diagnostics::DiagnosticsHandler; +use module::build_ir::translate_module_as_component; + +pub use self::{config::*, error::WasmError}; + +/// Translate a valid Wasm core module or Wasm Component Model binary into Miden +/// IR Component +pub fn translate( + wasm: &[u8], + config: &WasmTranslationConfig, + diagnostics: &DiagnosticsHandler, +) -> WasmResult { + if wasm[4..8] == [0x01, 0x00, 0x00, 0x00] { + // Wasm core module + // see https://github.com/WebAssembly/component-model/blob/main/design/mvp/Binary.md#component-definitions + translate_module_as_component(wasm, config, diagnostics) + } else { + translate_component(wasm, config, diagnostics) + } +} diff --git a/frontend-wasm/src/module/build_ir.rs b/frontend-wasm/src/module/build_ir.rs index 3a33e6983..9395dad2d 100644 --- a/frontend-wasm/src/module/build_ir.rs +++ b/frontend-wasm/src/module/build_ir.rs @@ -17,33 +17,6 @@ use crate::{ WasmError, WasmTranslationConfig, }; -/// Translate a valid Wasm core module binary into Miden IR module -pub fn translate_module( - wasm: &[u8], - config: &WasmTranslationConfig, - diagnostics: &DiagnosticsHandler, -) -> WasmResult { - let wasm_features = WasmFeatures::default(); - let mut validator = Validator::new_with_features(wasm_features); - let parser = wasmparser::Parser::new(0); - let mut module_types_builder = Default::default(); - let mut parsed_module = ModuleEnvironment::new( - config, - &mut validator, - &mut module_types_builder, - ) - .parse(parser, wasm, diagnostics)?; - parsed_module.module.set_name_fallback(config.source_name.clone()); - if let Some(name_override) = config.override_name.as_ref() { - parsed_module.module.set_name_override(name_override.clone()); - } - let module_types = module_types_builder.finish(); - - let mut module_state = - ModuleTranslationState::new(&parsed_module.module, &module_types, vec![]); - build_ir_module(&mut parsed_module, &module_types, &mut module_state, config, diagnostics) -} - /// Translate a valid Wasm core module binary into Miden IR component building /// component imports for well-known Miden ABI functions /// diff --git a/frontend-wasm/src/module/module_env.rs b/frontend-wasm/src/module/module_env.rs index d02c563e9..0e067017f 100644 --- a/frontend-wasm/src/module/module_env.rs +++ b/frontend-wasm/src/module/module_env.rs @@ -616,6 +616,9 @@ impl<'a, 'data> ModuleEnvironment<'a, 'data> { } } wasmparser::Name::Module { name, .. } => { + // Module name ends with `.wasm`, + // remove it if its there since MASM doesn't yet allow dots in the module name + let name = name.trim_end_matches(".wasm"); self.result.module.name_section.module_name = Some(Ident::from(name)); } wasmparser::Name::Local(reader) => { diff --git a/hir/src/component/mod.rs b/hir/src/component/mod.rs index f4e2a7f17..f9ac9a506 100644 --- a/hir/src/component/mod.rs +++ b/hir/src/component/mod.rs @@ -175,6 +175,12 @@ impl Component { pub fn exports(&self) -> &BTreeMap { &self.exports } + + /// Extracts the single module from this component, panicking if there is not exactly one. + pub fn unwrap_one_module(self) -> Box { + assert_eq!(self.modules.len(), 1, "Expected exactly one module in the component"); + self.to_modules().drain(..).next().unwrap().1 + } } impl fmt::Display for Component { diff --git a/midenc-compile/src/stages/link.rs b/midenc-compile/src/stages/link.rs index f6f313437..79762221e 100644 --- a/midenc-compile/src/stages/link.rs +++ b/midenc-compile/src/stages/link.rs @@ -1,3 +1,5 @@ +use midenc_session::ProjectType; + use super::*; /// This type is used to represent the fact that depending on @@ -21,14 +23,19 @@ impl Stage for LinkerStage { _analyses: &mut AnalysisManager, session: &Session, ) -> CompilerResult { - if session.should_link() { - let mut builder = hir::ProgramBuilder::new(&session.diagnostics); - for module in input.into_iter() { - builder.add_module(module)?; + match session.project_type { + ProjectType::Program => { + if session.should_link() { + let mut builder = hir::ProgramBuilder::new(&session.diagnostics); + for module in input.into_iter() { + builder.add_module(module)?; + } + Ok(MaybeLinked::Linked(builder.link()?)) + } else { + Ok(MaybeLinked::Unlinked(input.into_iter().collect())) + } } - Ok(MaybeLinked::Linked(builder.link()?)) - } else { - Ok(MaybeLinked::Unlinked(input.into_iter().collect())) + ProjectType::Library => Ok(MaybeLinked::Unlinked(input.into_iter().collect())), } } } diff --git a/midenc-compile/src/stages/parse.rs b/midenc-compile/src/stages/parse.rs index d4e4044af..1ff5797d8 100644 --- a/midenc-compile/src/stages/parse.rs +++ b/midenc-compile/src/stages/parse.rs @@ -116,9 +116,9 @@ impl ParseStage { session: &Session, config: &WasmTranslationConfig, ) -> CompilerResult { - let module = wasm::translate_module(bytes, config, &session.diagnostics)?; + let module = wasm::translate(bytes, config, &session.diagnostics)?.unwrap_one_module(); - Ok(ParseOutput::Hir(Box::new(module))) + Ok(ParseOutput::Hir(module)) } fn parse_hir_from_wat_file( @@ -132,9 +132,9 @@ impl ParseStage { ..Default::default() }; let wasm = wat::parse_file(path)?; - let module = wasm::translate_module(&wasm, &config, &session.diagnostics)?; + let module = wasm::translate(&wasm, &config, &session.diagnostics)?.unwrap_one_module(); - Ok(ParseOutput::Hir(Box::new(module))) + Ok(ParseOutput::Hir(module)) } fn parse_hir_from_wat_bytes( @@ -144,8 +144,8 @@ impl ParseStage { config: &WasmTranslationConfig, ) -> CompilerResult { let wasm = wat::parse_bytes(bytes)?; - let module = wasm::translate_module(&wasm, config, &session.diagnostics)?; + let module = wasm::translate(&wasm, config, &session.diagnostics)?.unwrap_one_module(); - Ok(ParseOutput::Hir(Box::new(module))) + Ok(ParseOutput::Hir(module)) } } diff --git a/midenc-session/src/inputs.rs b/midenc-session/src/inputs.rs index f20b7ad5a..427571816 100644 --- a/midenc-session/src/inputs.rs +++ b/midenc-session/src/inputs.rs @@ -53,10 +53,14 @@ impl InputFile { let mut input = Vec::with_capacity(1024); std::io::stdin().read_to_end(&mut input)?; - let file_type = FileType::detect(&input)?; + Self::from_bytes(input, name) + } + + pub fn from_bytes(bytes: Vec, name: FileName) -> Result { + let file_type = FileType::detect(&bytes)?; match file_type { FileType::Hir | FileType::Wasm | FileType::Wat => Ok(Self { - file: InputType::Stdin { name, input }, + file: InputType::Stdin { name, input: bytes }, file_type, }), // We do not yet have frontends for these file types diff --git a/tests/integration/Cargo.toml b/tests/integration/Cargo.toml index 89e707eca..46d531814 100644 --- a/tests/integration/Cargo.toml +++ b/tests/integration/Cargo.toml @@ -21,6 +21,7 @@ miden-processor.workspace = true miden-stdlib.workspace = true miden-diagnostics.workspace = true midenc-session.workspace = true +midenc-compile.workspace = true expect-test = "1.4.1" miden-integration-tests-rust-fib = { path = "../rust-apps/fib" } wasmprinter = "0.2.63" diff --git a/tests/integration/expected/add_felt.masm b/tests/integration/expected/add_felt.masm index 2262c117f..d5325c4f2 100644 --- a/tests/integration/expected/add_felt.masm +++ b/tests/integration/expected/add_felt.masm @@ -5,665 +5,11 @@ export.entrypoint add end -mod intrinsics::i32 +mod zzz_entrypoint_module -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end +use.add_felt -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - -program - -use add_felt - -begin +export.entrypoint_wrapper exec.add_felt::entrypoint end + diff --git a/tests/integration/expected/components/add_wasm_component.hir b/tests/integration/expected/components/add_wasm_component.hir index 065903368..55014a7ed 100644 --- a/tests/integration/expected/components/add_wasm_component.hir +++ b/tests/integration/expected/components/add_wasm_component.hir @@ -1,6 +1,6 @@ (component ;; Modules - (module #add_wasm_component.wasm + (module #add_wasm_component ;; Constants (const (id 0) 0x00100000) diff --git a/tests/integration/expected/components/inc_wasm_component.hir b/tests/integration/expected/components/inc_wasm_component.hir index 80eacc7b4..e5981a858 100644 --- a/tests/integration/expected/components/inc_wasm_component.hir +++ b/tests/integration/expected/components/inc_wasm_component.hir @@ -3,7 +3,7 @@ (lower (("miden:add-package/add-interface@1.0.0" #add) (digest 0x0000000000000000000000000000000000000000000000000000000000000000) (type (func (abi wasm) (param u32) (param u32) (result u32)))) (#miden:add-package/add-interface@1.0.0 #add) ;; Modules - (module #inc_wasm_component.wasm + (module #inc_wasm_component ;; Constants (const (id 0) 0x00100000) diff --git a/tests/integration/expected/div_felt.masm b/tests/integration/expected/div_felt.masm index 5288db37a..be31ab49b 100644 --- a/tests/integration/expected/div_felt.masm +++ b/tests/integration/expected/div_felt.masm @@ -5,665 +5,11 @@ export.entrypoint div end -mod intrinsics::i32 +mod zzz_entrypoint_module -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end +use.div_felt -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - -program - -use div_felt - -begin +export.entrypoint_wrapper exec.div_felt::entrypoint end + diff --git a/tests/integration/expected/eq_felt.masm b/tests/integration/expected/eq_felt.masm index 347ec3797..6b98ed93c 100644 --- a/tests/integration/expected/eq_felt.masm +++ b/tests/integration/expected/eq_felt.masm @@ -7,665 +7,11 @@ export.entrypoint eq end -mod intrinsics::i32 +mod zzz_entrypoint_module -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end +use.eq_felt -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - -program - -use eq_felt - -begin +export.entrypoint_wrapper exec.eq_felt::entrypoint end + diff --git a/tests/integration/expected/ge_felt.masm b/tests/integration/expected/ge_felt.masm index 9b95bf20b..252bed994 100644 --- a/tests/integration/expected/ge_felt.masm +++ b/tests/integration/expected/ge_felt.masm @@ -7,665 +7,11 @@ export.entrypoint neq end -mod intrinsics::i32 +mod zzz_entrypoint_module -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem +use.ge_felt -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - -program - -use ge_felt - -begin +export.entrypoint_wrapper exec.ge_felt::entrypoint end + diff --git a/tests/integration/expected/gt_felt.masm b/tests/integration/expected/gt_felt.masm index e3b73e749..3ceadcba0 100644 --- a/tests/integration/expected/gt_felt.masm +++ b/tests/integration/expected/gt_felt.masm @@ -7,665 +7,11 @@ export.entrypoint neq end -mod intrinsics::i32 +mod zzz_entrypoint_module -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem +use.gt_felt -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - -program - -use gt_felt - -begin +export.entrypoint_wrapper exec.gt_felt::entrypoint end + diff --git a/tests/integration/expected/le_felt.masm b/tests/integration/expected/le_felt.masm index 4e272906c..c8889a51a 100644 --- a/tests/integration/expected/le_felt.masm +++ b/tests/integration/expected/le_felt.masm @@ -1,658 +1,3 @@ -mod intrinsics::i32 - -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - mod le_felt export.entrypoint @@ -661,10 +6,11 @@ export.entrypoint neq end -program +mod zzz_entrypoint_module -use le_felt +use.le_felt -begin +export.entrypoint_wrapper exec.le_felt::entrypoint end + diff --git a/tests/integration/expected/lt_felt.masm b/tests/integration/expected/lt_felt.masm index c31efc284..51f66dcf9 100644 --- a/tests/integration/expected/lt_felt.masm +++ b/tests/integration/expected/lt_felt.masm @@ -1,658 +1,3 @@ -mod intrinsics::i32 - -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - mod lt_felt export.entrypoint @@ -661,10 +6,11 @@ export.entrypoint neq end -program +mod zzz_entrypoint_module -use lt_felt +use.lt_felt -begin +export.entrypoint_wrapper exec.lt_felt::entrypoint end + diff --git a/tests/integration/expected/mul_felt.masm b/tests/integration/expected/mul_felt.masm index dbc7ad2d3..a0a94649a 100644 --- a/tests/integration/expected/mul_felt.masm +++ b/tests/integration/expected/mul_felt.masm @@ -1,658 +1,3 @@ -mod intrinsics::i32 - -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - mod mul_felt export.entrypoint @@ -660,10 +5,11 @@ export.entrypoint mul end -program +mod zzz_entrypoint_module -use mul_felt +use.mul_felt -begin +export.entrypoint_wrapper exec.mul_felt::entrypoint end + diff --git a/tests/integration/expected/neg_felt.masm b/tests/integration/expected/neg_felt.masm index 7401d4e96..dadf37642 100644 --- a/tests/integration/expected/neg_felt.masm +++ b/tests/integration/expected/neg_felt.masm @@ -1,658 +1,3 @@ -mod intrinsics::i32 - -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - mod neg_felt export.entrypoint @@ -660,10 +5,11 @@ export.entrypoint sub end -program +mod zzz_entrypoint_module -use neg_felt +use.neg_felt -begin +export.entrypoint_wrapper exec.neg_felt::entrypoint end + diff --git a/tests/integration/expected/sub_felt.masm b/tests/integration/expected/sub_felt.masm index 7e239c846..f857b8f97 100644 --- a/tests/integration/expected/sub_felt.masm +++ b/tests/integration/expected/sub_felt.masm @@ -1,658 +1,3 @@ -mod intrinsics::i32 - -export.is_signed - push.2147483648 - u32and - push.2147483648 - eq -end - -export.unchecked_neg - u32not - u32wrapping_add.1 -end - -export.checked_neg - dup.0 - push.2147483648 - eq - assertz - exec.unchecked_neg -end - -export.overflowing_add - u32assert2 - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - eq - movup.3 - movup.3 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and -end - -export.wrapping_add - exec.overflowing_add - drop -end - -export.checked_add - exec.overflowing_add - assertz -end - -export.overflowing_sub - u32assert2 - dup.0 - push.2147483648 - eq - if.true - drop - push.2147483647 - dup.1 - exec.is_signed - dup.0 - eq.0 - movup.3 - movup.3 - u32wrapping_add - push.1 - u32wrapping_add - dup.0 - exec.is_signed - movup.3 - neq - movup.2 - and - else - exec.unchecked_neg - exec.overflowing_add - end -end - -export.wrapping_sub - exec.overflowing_sub - drop -end - -export.checked_sub - exec.overflowing_sub - assertz -end - -export.overflowing_mul - u32assert2 - dup.0 - push.2147483648 - eq - dup.2 - push.2147483648 - eq - or - if.true - dup.0 - eq.1 - dup.2 - eq.1 - or - movup.2 - push.4294967295 - eq - movup.2 - push.4294967295 - eq - or - dup.1 - or - push.2147483648 - push.0 - swap.2 - cdrop - swap.1 - not - else - dup.0 - exec.is_signed - dup.2 - exec.is_signed - dup.1 - dup.1 - neq - movdn.4 - movup.3 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - swap.2 - dup.0 - exec.unchecked_neg - movup.2 - cdrop - u32overflowing_mul - dup.1 - exec.is_signed - or - swap.1 - dup.0 - exec.unchecked_neg - movup.3 - cdrop - swap.1 - end -end - -export.wrapping_mul - exec.overflowing_mul - drop -end - -export.checked_mul - exec.overflowing_mul - assertz -end - -export.checked_div - u32assert2 - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.4 - cdrop - dup.1 - exec.unchecked_neg - dup.2 - swap.1 - movup.3 - exec.is_signed - dup.0 - movdn.5 - cdrop - u32div - movdn.2 - neq - dup.1 - exec.unchecked_neg - swap.1 - cdrop -end - -export.icmp - dup.1 - dup.1 - push.2147483648 - u32and - swap.1 - push.2147483648 - u32and - eq.0 - swap.1 - eq.0 - swap.1 - dup.1 - neq - if.true - movdn.2 - drop - drop - push.4294967295 - push.1 - swap.2 - cdrop - else - drop - dup.1 - dup.1 - u32gt - movdn.2 - u32lt - push.0 - push.4294967295 - push.1 - swap.3 - cdrop - swap.2 - cdrop - end -end - -export.is_lt - exec.icmp - push.4294967295 - eq -end - -export.is_lte - exec.icmp - neq.1 -end - -export.is_gt - exec.icmp - eq.1 -end - -export.is_gte - exec.icmp - push.4294967295 - neq -end - -export.pow2 - dup.0 - push.31 - u32lt - assert - push.1 - swap.1 - u32shl -end - -export.ipow - dup.0 - push.31 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - push.1 - push.0 - swap.2 - cdrop - swap.1 - drop - else - push.1 - dup.1 - push.1 - u32gt - while.true - dup.2 - dup.1 - u32wrapping_mul - dup.2 - push.1 - u32and - eq.1 - cdrop - swap.1 - u32div.2 - movup.2 - dup.0 - u32wrapping_mul - swap.1 - movup.2 - dup.1 - push.1 - u32gt - end - swap.1 - drop - u32wrapping_mul - end -end - -export.checked_shr - dup.0 - push.32 - u32lt - assert - dup.0 - eq.0 - dup.2 - eq.0 - or - if.true - eq.0 - swap.1 - push.0 - swap.2 - cdrop - else - dup.1 - push.2147483648 - u32and - push.2147483648 - eq - if.true - swap.1 - dup.1 - u32shr - push.1 - dup.2 - u32shl - sub.1 - push.32 - movup.3 - sub - u32shl - u32or - u32assert - else - u32shr - u32assert - end - end -end - -mod intrinsics::mem - -export.extract_element - dup.0 - push.3 - lte - assert - dup.0 - push.3 - lt - movdn.5 - dup.0 - push.2 - lt - movdn.5 - push.1 - lt - cdrop - movup.3 - cdrop - movup.2 - cdrop -end - -proc.load_felt_unchecked - padw - movup.4 - mem_loadw - movup.4 - exec.extract_element -end - -export.load_felt - movup.2 - assertz - exec.load_felt_unchecked -end - -export.load_sw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - exec.load_felt_unchecked - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.3 - movup.3 - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movdn.2 - movdn.2 - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - dup.2 - u32shl - swap.1 - push.32 - movup.3 - u32overflowing_sub - assertz - u32shr - u32or - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movdn.4 - drop - drop - drop - push.32 - dup.3 - u32overflowing_sub - assertz - u32shr - swap.1 - padw - movup.4 - mem_loadw - drop - drop - drop - movup.2 - u32shl - u32or - end - end - end - end -end - -export.realign_dw - dup.3 - u32shl - movdn.2 - dup.0 - push.32 - dup.4 - u32shr - movup.4 - u32or - movdn.2 - dup.3 - u32shl - swap.1 - push.32 - movup.4 - u32shr - u32or - swap.1 -end - -export.load_dw - dup.2 - eq.0 - dup.3 - push.8 - u32lt - assert - if.true - movup.2 - drop - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - movup.3 - drop - else - swap.1 - eq.2 - if.true - padw - movup.4 - mem_loadw - drop - drop - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - movup.4 - padw - movup.4 - mem_loadw - drop - drop - drop - end - end - end - else - dup.1 - eq.0 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - movup.4 - drop - exec.realign_dw - else - dup.1 - eq.1 - if.true - swap.1 - drop - padw - movup.4 - mem_loadw - drop - exec.realign_dw - else - swap.1 - eq.2 - if.true - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - movup.4 - drop - drop - drop - swap.1 - padw - movup.4 - mem_loadw - drop - drop - exec.realign_dw - else - dup.0 - u32overflowing_add.1 - assertz - padw - movup.4 - mem_loadw - movup.4 - movup.4 - drop - drop - movup.2 - padw - movup.4 - mem_loadw - drop - drop - drop - exec.realign_dw - end - end - end - end -end - mod sub_felt export.entrypoint @@ -660,10 +5,11 @@ export.entrypoint sub end -program +mod zzz_entrypoint_module -use sub_felt +use.sub_felt -begin +export.entrypoint_wrapper exec.sub_felt::entrypoint end + diff --git a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir index 3cee9890f..9883c1a24 100644 --- a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir +++ b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet.hir @@ -38,7 +38,7 @@ ) ) - (module #basic_wallet.wasm + (module #basic_wallet ;; Constants (const (id 0) 0x00100000) diff --git a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir index 938b5f479..4ec5979a3 100644 --- a/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir +++ b/tests/integration/expected/wit_sdk_basic_wallet/basic_wallet_p2id_note.hir @@ -28,7 +28,7 @@ ) ) - (module #basic_wallet_p2id_note.wasm + (module #basic_wallet_p2id_note ;; Constants (const (id 0) 0x00100000) diff --git a/tests/integration/src/compiler_test.rs b/tests/integration/src/compiler_test.rs index fb73a1382..92ce6b53c 100644 --- a/tests/integration/src/compiler_test.rs +++ b/tests/integration/src/compiler_test.rs @@ -10,20 +10,20 @@ use std::{ }; use miden_assembly::{Assembler, AssemblyContext}; -use miden_codegen_masm::MasmCompiler; +use miden_codegen_masm::{Function, MasmCompiler, Module}; use miden_diagnostics::{ term::termcolor::ColorChoice, CodeMap, DefaultEmitter, DiagnosticsConfig, DiagnosticsHandler, Emitter, NullEmitter, SourceSpan, Verbosity, }; -use miden_frontend_wasm::{ - translate_component, translate_module, translate_module_as_component, WasmTranslationConfig, -}; +use miden_frontend_wasm::{translate, WasmTranslationConfig}; use miden_hir::{ pass::{AnalysisManager, RewritePass, RewriteSet}, - FunctionIdent, Ident, ModuleRewritePassAdapter, ProgramBuilder, Symbol, + FunctionIdent, Ident, ModuleRewritePassAdapter, ProgramBuilder, Signature, Symbol, }; use miden_stdlib::StdLibrary; -use midenc_session::{InputFile, Session}; +use midenc_session::{ + InputFile, InputType, Options, OutputType, OutputTypeSpec, OutputTypes, ProjectType, Session, +}; use crate::cargo_proj::project; @@ -91,13 +91,11 @@ pub struct CompilerTest { /// The Wasm translation configuration pub config: WasmTranslationConfig, /// The compiler session - pub session: Session, + pub session: Arc, /// The source code used to compile the test pub source: CompilerTestSource, /// The entrypoint function to use when building the IR entrypoint: Option, - /// The compiled Wasm component/module - pub wasm_bytes: Vec, /// The compiled IR pub hir: Option, /// The compiled MASM @@ -159,12 +157,12 @@ impl CompilerTest { assert_eq!(wasm_artifacts.len(), 1, "Expected one Wasm artifact"); let wasm_comp_path = &wasm_artifacts.first().unwrap(); let artifact_name = wasm_comp_path.file_stem().unwrap().to_str().unwrap().to_string(); + let input_file = InputFile::from_path(wasm_comp_path).unwrap(); Self { config, - session: default_session(), + session: default_session(input_file), source: CompilerTestSource::RustCargoComponent { artifact_name }, entrypoint: None, - wasm_bytes: fs::read(wasm_artifacts.first().unwrap()).unwrap(), hir: None, ir_masm: None, } @@ -233,20 +231,20 @@ impl CompilerTest { assert_eq!(wasm_artifacts.len(), 1, "Expected one Wasm artifact"); let wasm_comp_path = &wasm_artifacts.first().unwrap(); let artifact_name = wasm_comp_path.file_stem().unwrap().to_str().unwrap().to_string(); - // dbg!(&artifact_name); + dbg!(&artifact_name); let entrypoint = entry_func_name.map(|func_name| FunctionIdent { module: Ident::new(Symbol::intern(artifact_name.clone()), SourceSpan::default()), function: Ident::new(Symbol::intern(func_name.to_string()), SourceSpan::default()), }); + let input_file = InputFile::from_path(wasm_artifacts.first().unwrap()).unwrap(); Self { config: WasmTranslationConfig { override_name: Some(artifact_name.to_string().into()), ..Default::default() }, - session: default_session(), + session: default_session(input_file), source: CompilerTestSource::RustCargoLib { artifact_name }, entrypoint, - wasm_bytes: fs::read(wasm_artifacts.first().unwrap()).unwrap(), hir: None, ir_masm: None, } @@ -292,12 +290,13 @@ impl CompilerTest { .join(artifact_name) .with_extension("wasm"); // dbg!(&target_bin_file_path); - let mut target_bin_file = fs::File::open(target_bin_file_path).unwrap(); - let mut wasm_bytes = vec![]; - Read::read_to_end(&mut target_bin_file, &mut wasm_bytes).unwrap(); - fs::remove_dir_all(target_dir).unwrap(); + // let mut target_bin_file = fs::File::open(target_bin_file_path).unwrap(); + // let mut wasm_bytes = vec![]; + // Read::read_to_end(&mut target_bin_file, &mut wasm_bytes).unwrap(); + // fs::remove_dir_all(target_dir).unwrap(); - let session = default_session(); + let input_file = InputFile::from_path(target_bin_file_path).unwrap(); + let session = default_session(input_file); let entrypoint = FunctionIdent { module: Ident::new(Symbol::intern(artifact_name), SourceSpan::default()), function: Ident::new(Symbol::intern(entrypoint.to_string()), SourceSpan::default()), @@ -312,7 +311,6 @@ impl CompilerTest { cargo_project_folder_name: cargo_project_folder.to_string(), artifact_name: artifact_name.to_string(), }, - wasm_bytes, entrypoint: Some(entrypoint), hir: None, ir_masm: None, @@ -321,8 +319,8 @@ impl CompilerTest { /// Set the Rust source code to compile pub fn rust_source_program(rust_source: &str) -> Self { - let wasm_bytes = compile_rust_file(rust_source); - let session = default_session(); + let wasm_file = compile_rust_file(rust_source); + let session = default_session(wasm_file); CompilerTest { config: WasmTranslationConfig { override_name: Some("noname".into()), @@ -330,7 +328,6 @@ impl CompilerTest { }, session, source: CompilerTestSource::Rust(rust_source.to_string()), - wasm_bytes, entrypoint: None, hir: None, ir_masm: None, @@ -354,8 +351,8 @@ impl CompilerTest { "#, rust_source ); - let wasm_bytes = compile_rust_file(&rust_source); - let session = default_session(); + let wasm_file = compile_rust_file(&rust_source); + let session = default_session(wasm_file); let entrypoint = FunctionIdent { module: Ident { name: Symbol::intern("noname"), @@ -374,7 +371,6 @@ impl CompilerTest { }, session, source: CompilerTestSource::Rust(rust_source.to_string()), - wasm_bytes, entrypoint: Some(entrypoint), hir: None, ir_masm: None, @@ -447,8 +443,8 @@ impl CompilerTest { /// Compare the compiled Wasm against the expected output pub fn expect_wasm(&self, expected_wat_file: expect_test::ExpectFile) { - let wasm_bytes = self.wasm_bytes.as_ref(); - let wat = demangle(&wasm_to_wat(wasm_bytes)); + let wasm_bytes = self.wasm_bytes(); + let wat = demangle(&wasm_to_wat(&wasm_bytes)); expected_wat_file.assert_eq(&wat); } @@ -456,27 +452,25 @@ impl CompilerTest { use miden_hir_transform as transforms; match &self.source { CompilerTestSource::RustCargoComponent { .. } => { - // Wasm component is expectedAA + // Wasm component is expected let ir_component = - translate_component(&self.wasm_bytes, &self.config, &self.session.diagnostics) + translate(&self.wasm_bytes(), &self.config, &self.session.diagnostics) .expect("Failed to translate Wasm to IR component"); Box::new(ir_component).into() } CompilerTestSource::RustCargoLib { .. } => { // Wasm module compiled as a module - let ir_component = translate_module_as_component( - &self.wasm_bytes, - &self.config, - &self.session.diagnostics, - ) - .expect("Failed to translate Wasm module to IR component"); + let ir_component = + translate(&self.wasm_bytes(), &self.config, &self.session.diagnostics) + .expect("Failed to translate Wasm module to IR component"); Box::new(ir_component).into() } _ => { // Wasm module compiled as a program let mut ir_module = - translate_module(&self.wasm_bytes, &self.config, &self.session.diagnostics) - .expect("Failed to translate Wasm to IR module"); + translate(&self.wasm_bytes(), &self.config, &self.session.diagnostics) + .expect("Failed to translate Wasm to IR module") + .unwrap_one_module(); let mut analyses = AnalysisManager::new(); let mut rewrites = RewriteSet::default(); @@ -487,9 +481,8 @@ impl CompilerTest { .apply(&mut ir_module, &mut analyses, &self.session) .expect("Failed to apply rewrites"); - let mut builder = ProgramBuilder::new(&self.session.diagnostics) - .with_module(Box::new(ir_module)) - .unwrap(); + let mut builder = + ProgramBuilder::new(&self.session.diagnostics).with_module(ir_module).unwrap(); if let Some(entrypoint) = self.entrypoint.as_ref() { builder = builder.with_entrypoint(entrypoint.clone()); } @@ -578,17 +571,7 @@ impl CompilerTest { let hir = self.hir.take().expect("IR is not compiled"); let ir_masm = match hir { HirArtifact::Program(hir_program) => compiler.compile(hir_program).unwrap(), - HirArtifact::Component(hir_component) => { - let ir_module = hir_component.to_modules().drain(..).next().unwrap().1; - let mut builder = ProgramBuilder::new(&self.session.diagnostics) - .with_module(ir_module) - .unwrap(); - if let Some(entrypoint) = self.entrypoint.as_ref() { - builder = builder.with_entrypoint(entrypoint.clone()); - } - let hir_program = builder.link().expect("Failed to link IR program"); - compiler.compile(hir_program).unwrap() - } + HirArtifact::Component(_) => self.compile_wasm_to_masm_program(), HirArtifact::Module(_) => { todo!("Module to MASM compilation is not implemented yet") } @@ -598,6 +581,44 @@ impl CompilerTest { } self.ir_masm.clone().unwrap() } + + /// The compiled Wasm component/module + fn wasm_bytes(&self) -> Vec { + match &self.session.input.file { + InputType::Real(file_path) => fs::read(file_path).unwrap(), + InputType::Stdin { name: _, input } => input.clone(), + } + } + + fn compile_wasm_to_masm_program(&self) -> Box { + match midenc_compile::compile_to_memory(self.session.clone()).unwrap() { + midenc_compile::Compiled::Program(p) => p, + midenc_compile::Compiled::Modules(modules) => { + assert_eq!(modules.len(), 1, "Expected one module"); + let mut program = miden_codegen_masm::Program::new(); + for module in modules.into_iter() { + program.insert(module); + } + if let Some(entrypoint) = self.entrypoint { + // Start module name with "zzz_" to ensure it is the last module in the program + // due to the RBTree ordering (used to store modules of a program) + let module_name = "zzz_entrypoint_module"; + let func_name = format!("{module_name}::entrypoint_wrapper"); + let mut entrypoint_function = + Function::new(func_name.parse().unwrap(), Signature::new(vec![], vec![])); + entrypoint_function.attrs.set(miden_hir::attributes::ENTRYPOINT); + let body = entrypoint_function.block_mut(entrypoint_function.body.id()); + body.push(miden_hir::MasmOp::Exec(entrypoint)); + let mut module = + Module::new(Ident::with_empty_span(Symbol::intern(module_name))); + module.push_back(Box::new(entrypoint_function)); + module.imports.add(entrypoint); + program.insert(Box::new(module)); + } + program.into() + } + } + } } /// Get the directory for the top-level workspace @@ -656,7 +677,7 @@ fn wasm_to_wat(wasm_bytes: &[u8]) -> String { let wat = wasm_printer.print(wasm_bytes.as_ref()).unwrap(); wat } -fn compile_rust_file(rust_source: &str) -> Vec { +fn compile_rust_file(rust_source: &str) -> InputFile { let rustc_opts = [ "-C", "opt-level=z", // optimize for size @@ -685,9 +706,7 @@ fn compile_rust_file(rust_source: &str) -> Vec { eprintln!("{}", String::from_utf8_lossy(&output.stderr)); panic!("Rust to Wasm compilation failed!"); } - let wasm = fs::read(&output_file).unwrap(); - fs::remove_dir_all(proj_dir).unwrap(); - return wasm; + InputFile::from_path(output_file).unwrap() } fn default_emitter(verbosity: Verbosity, color: ColorChoice) -> Arc { @@ -713,17 +732,16 @@ fn make_diagnostics() -> DiagnosticsHandler { } /// Create a default session for testing -pub fn default_session() -> Session { - let session = Session::new( - Default::default(), - InputFile::from_path("test.hir").unwrap(), - None, - None, - None, - Default::default(), - None, - ); - session +pub fn default_session(input_file: InputFile) -> Arc { + let output_type = OutputType::Masm; + let output_types = OutputTypes::new(vec![OutputTypeSpec { + output_type, + path: None, + }]); + let options = Options::default().with_output_types(output_types); + let session = Session::new(Default::default(), input_file, None, None, None, options, None) + .with_project_type(ProjectType::Library); + Arc::new(session) } fn hash_string(inputs: &str) -> String {