neo_solidity/cli/bytecode.rs
1//! NeoVM Bytecode Generation Module
2//!
3//! Converts the intermediate representation (IR) to NeoVM bytecode. This module
4//! handles the low-level emission of NeoVM opcodes and manages function dispatch,
5//! storage operations, and syscall generation.
6//!
7//! # Architecture
8//!
9//! The bytecode generator works in several phases:
10//! 1. **Function dispatch** - Generates entry point with method selector routing
11//! 2. **IR lowering** - Converts IR instructions to NeoVM opcodes
12//! 3. **Optimization** - Applies peephole optimizations to reduce bytecode size
13//! 4. **Patching** - Resolves function call targets and jump addresses
14//!
15//! # NeoVM Opcodes
16//!
17//! Key opcodes used:
18//! - `0x00-0x20` - Push operations (PUSH0, PUSHINT8, etc.)
19//! - `0x40` - RET (return from function)
20//! - `0x41` - SYSCALL (invoke system call)
21//! - `0x45-0x4D` - Control flow (JMP, JMPIF, CALL, etc.)
22//!
23//! # Storage Model
24//!
25//! Storage keys are computed using SHA-256 hashing of variable names and
26//! mapping keys, following Neo N3 storage conventions.
27
28use neo_solidity::ir::{self, LiteralValue, ValueType};
29use neo_solidity::solidity::{ContractMetadata, FunctionKind, FunctionMetadata};
30
31#[cfg(test)]
32use neo_solidity::solidity::NatspecDoc;
33use num_bigint::BigInt;
34use num_traits::{Signed, ToPrimitive, Zero};
35use std::collections::HashMap;
36
37include!("bytecode/bytecode_core.rs");
38include!("bytecode/bytecode_emit_ir.rs");
39include!("bytecode/bytecode_helpers.rs");
40include!("bytecode/bytecode_builtins.rs");
41include!("bytecode/bytecode_disasm.rs");
42
43#[cfg(test)]
44pub(crate) mod tests;