Expand description
NeoVM Bytecode Generation Module
Converts the intermediate representation (IR) to NeoVM bytecode. This module handles the low-level emission of NeoVM opcodes and manages function dispatch, storage operations, and syscall generation.
ยงArchitecture
The bytecode generator works in several phases:
- Function dispatch - Generates entry point with method selector routing
- IR lowering - Converts IR instructions to NeoVM opcodes
- Optimization - Applies peephole optimizations to reduce bytecode size
- Patching - Resolves function call targets and jump addresses
ยงNeoVM Opcodes
Key opcodes used:
0x00-0x20- Push operations (PUSH0, PUSHINT8, etc.)0x40- RET (return from function)0x41- SYSCALL (invoke system call)0x45-0x4D- Control flow (JMP, JMPIF, CALL, etc.)
ยงStorage Model
Storage keys are computed using SHA-256 hashing of variable names and mapping keys, following Neo N3 storage conventions.
Structsยง
- Bytecode
Build ๐Output - Call
Patch ๐ - Method
Token ๐Key - Method
Token ๐Patch - Struct
Array ๐Element Access - Struct
Field ๐Access
Constantsยง
- CALLFLAGS_
ALL ๐ - Neo N3 uses CallFlags bitmask values.
- CALLFLAGS_
READ_ ๐ONLY - Read-only call flags (ReadStates | AllowCall).
- NATIVE_
CONTRACT_ ๐MANAGEMENT_ HASH_ LE - NATIVE_
CRYPTOLIB_ ๐HASH_ LE - NATIVE_
GAS_ ๐HASH_ LE - NATIVE_
LEDGER_ ๐HASH_ LE - NATIVE_
NEO_ ๐HASH_ LE - Native contract script hashes as they must be pushed onto the NeoVM stack (UInt160 little-endian byte order).
- NATIVE_
NOTARY_ ๐HASH_ LE - NATIVE_
ORACLE_ ๐HASH_ LE - NATIVE_
POLICY_ ๐HASH_ LE - NATIVE_
ROLE_ ๐MANAGEMENT_ HASH_ LE - NATIVE_
STDLIB_ ๐HASH_ LE - NATIVE_
TREASURY_ ๐HASH_ LE
Functionsยง
- append_
default_ ๐value - apply_
method_ ๐tokens - disassemble_
neovm_ ๐bytecode - emit_
abi_ ๐decode - emit_
abi_ ๐encode - emit_
array_ ๐get - emit_
array_ ๐set - emit_
binary_ ๐op - emit_
builtin_ ๐call - emit_
coerce_ ๐storage_ value - emit_
contract_ ๐call - emit_
contract_ ๐call_ with_ flags - emit_
convert ๐ - emit_
deploy_ ๐contract - emit_
ecrecover ๐ - emit_
event ๐ - emit_
event_ ๐by_ name - emit_
event_ ๐payload - emit_
get_ ๐contract - emit_
get_ ๐contract_ script - emit_
get_ ๐neo_ account_ state - emit_
ir_ ๐function - emit_
is_ ๐type - emit_
keccak256 ๐ - emit_
load_ ๐local - emit_
load_ ๐mapping - emit_
load_ ๐parameter - emit_
load_ ๐runtime_ value - emit_
load_ ๐state - emit_
load_ ๐storage_ dynamic - emit_
load_ ๐struct_ array_ element - emit_
load_ ๐struct_ field - emit_
load_ ๐struct_ value_ from_ slot - emit_
mapping_ ๐slot - emit_
native_ ๐call - emit_
native_ ๐contract_ call - emit_
new_ ๐array - emit_
new_ ๐buffer - emit_
notify_ ๐serialized - emit_
runtime_ ๐check_ witness - emit_
runtime_ ๐notify - emit_
serialize_ ๐key - emit_
storage_ ๐delete - emit_
storage_ ๐find - emit_
storage_ ๐get - emit_
storage_ ๐put - emit_
store_ ๐local - emit_
store_ ๐mapping - emit_
store_ ๐state - emit_
store_ ๐struct_ array_ element - emit_
store_ ๐struct_ field - emit_
store_ ๐struct_ value_ to_ slot - emit_
struct_ ๐field_ slot - emit_
syscall ๐ - emit_
syscall_ ๐builtin - emit_
verify_ ๐signature - fmt_
target ๐ - generate_
contract_ ๐bytecode - is_
void_ ๐syscall - native_
contract_ ๐hash - native_
method_ ๐call_ flags - native_
method_ ๐has_ return_ value - native_
method_ ๐is_ mutating - push_
data ๐ - push_
integer_ ๐bigint - push_
literal_ ๐value - stack_
item_ ๐type_ code - take ๐
- take_i8 ๐
- take_
i16 ๐ - take_
i32 ๐ - take_
i64 ๐ - take_u8 ๐
- take_
u16 ๐ - take_
u32 ๐