Skip to main content

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