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    ModuleParser, 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    module,
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::LinkerError;
47#[cfg(feature = "std")]
48pub use self::project::{
49    AssemblyInterrupted, InterruptedTargetRole, MasmSourceProvider, ProjectAssembler,
50    ProjectSourceInputs, ProjectSourceProvenanceInputs, ProjectSourceProvider,
51    ProjectTargetSelector, ResolvedPackage, SourceFileProvenance, SourceProviderRegistry,
52    TargetAssemblyContext,
53};
54pub use self::{
55    assembler::Assembler,
56    linker::Linkage,
57    procedure::{Procedure, ProcedureContext},
58};
59
60// CONSTANTS
61// ================================================================================================
62
63/// The maximum number of bits by which a u32 value can be shifted in a bitwise operation.
64const MAX_U32_SHIFT_VALUE: u8 = 31;
65
66/// The maximum number of bits by which a u32 value can be rotated in a bitwise operation.
67const MAX_U32_ROTATE_VALUE: u8 = 31;
68
69/// The maximum number of bits allowed for the exponent parameter for exponentiation instructions.
70const MAX_EXP_BITS: u8 = 64;
71
72// HELPERS
73// ================================================================================================
74
75/// Pushes the provided value onto the stack using the most optimal sequence of operations.
76fn push_value_ops(value: Felt) -> alloc::vec::Vec<Operation> {
77    use miden_core::operations::Operation::*;
78
79    if value == ZERO {
80        vec![Pad]
81    } else if value == ONE {
82        vec![Pad, Incr]
83    } else {
84        vec![Push(value)]
85    }
86}