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 id;
16mod instruction;
17pub mod linker;
18mod mast_forest_builder;
19mod procedure;
20
21#[cfg(test)]
22mod mast_forest_merger_tests;
23#[cfg(any(test, feature = "testing"))]
24pub mod testing;
25#[cfg(test)]
26mod tests;
27
28// Re-exported for downstream crates
29pub use miden_assembly_syntax::{
30    KernelLibrary, Library, LibraryNamespace, LibraryPath, ModuleParser, Parse, ParseOptions, ast,
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    id::{GlobalProcedureIndex, ModuleIndex},
47    procedure::{Procedure, ProcedureContext},
48};
49
50// CONSTANTS
51// ================================================================================================
52
53/// The maximum number of elements that can be popped from the advice stack in a single `adv_push`
54/// instruction.
55const ADVICE_READ_LIMIT: u8 = 16;
56
57/// The maximum number of bits by which a u32 value can be shifted in a bitwise operation.
58const MAX_U32_SHIFT_VALUE: u8 = 31;
59
60/// The maximum number of bits by which a u32 value can be rotated in a bitwise operation.
61const MAX_U32_ROTATE_VALUE: u8 = 31;
62
63/// The maximum number of bits allowed for the exponent parameter for exponentiation instructions.
64const MAX_EXP_BITS: u8 = 64;
65
66// HELPERS
67// ================================================================================================
68
69/// Pushes the provided value onto the stack using the most optimal sequence of operations.
70fn push_value_ops(value: miden_core::Felt) -> alloc::vec::Vec<miden_core::Operation> {
71    use miden_core::Operation::*;
72
73    if value == ZERO {
74        vec![Pad]
75    } else if value == ONE {
76        vec![Pad, Incr]
77    } else {
78        vec![Push(value)]
79    }
80}