miden_assembly/
lib.rs

1#![no_std]
2#![doc = include_str!("../README.md")]
3
4#[macro_use]
5extern crate alloc;
6
7#[cfg(any(test, feature = "std"))]
8extern crate std;
9
10use miden_core::{ONE, ZERO};
11
12mod assembler;
13mod basic_block_builder;
14mod fmp;
15mod instruction;
16pub mod linker;
17mod mast_forest_builder;
18mod procedure;
19
20#[cfg(test)]
21mod mast_forest_merger_tests;
22#[cfg(any(test, feature = "testing"))]
23pub mod testing;
24#[cfg(test)]
25mod tests;
26
27// Re-exported for downstream crates
28pub use miden_assembly_syntax::{
29    KernelLibrary, Library, ModuleParser, Parse, ParseOptions, Path, PathBuf, ast,
30    ast::{GlobalItemIndex, ModuleIndex},
31    debuginfo::{
32        self, DefaultSourceManager, SourceFile, SourceId, SourceManager, SourceSpan, Span, Spanned,
33    },
34    diagnostics,
35    diagnostics::{Report, report},
36    library,
37};
38/// Syntax components for the Miden Assembly AST
39/// Merkelized abstract syntax tree (MAST) components defining Miden VM programs.
40pub use miden_core::{mast, utils};
41
42#[doc(hidden)]
43pub use self::linker::{LinkLibraryKind, LinkerError};
44pub use self::{
45    assembler::Assembler,
46    procedure::{Procedure, ProcedureContext},
47};
48
49// CONSTANTS
50// ================================================================================================
51
52/// The maximum number of elements that can be popped from the advice stack in a single `adv_push`
53/// instruction.
54const ADVICE_READ_LIMIT: u8 = 16;
55
56/// The maximum number of bits by which a u32 value can be shifted in a bitwise operation.
57const MAX_U32_SHIFT_VALUE: u8 = 31;
58
59/// The maximum number of bits by which a u32 value can be rotated in a bitwise operation.
60const MAX_U32_ROTATE_VALUE: u8 = 31;
61
62/// The maximum number of bits allowed for the exponent parameter for exponentiation instructions.
63const MAX_EXP_BITS: u8 = 64;
64
65// HELPERS
66// ================================================================================================
67
68/// Pushes the provided value onto the stack using the most optimal sequence of operations.
69fn push_value_ops(value: miden_core::Felt) -> alloc::vec::Vec<miden_core::Operation> {
70    use miden_core::Operation::*;
71
72    if value == ZERO {
73        vec![Pad]
74    } else if value == ONE {
75        vec![Pad, Incr]
76    } else {
77        vec![Push(value)]
78    }
79}