cairo_lang_executable/
executable.rs1use cairo_lang_casm::assembler::AssembledCairoProgram;
2use cairo_lang_casm::casm;
3use cairo_vm::types::builtin_name::BuiltinName;
4use itertools::chain;
5use serde::{Deserialize, Serialize};
6
7use crate::compile::CompiledFunction;
8
9#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Executable {
12 pub program: AssembledCairoProgram,
14 pub entrypoints: Vec<ExecutableEntryPoint>,
16}
17
18impl Executable {
19 pub fn new(compiled: CompiledFunction) -> Self {
21 let non_returning_header = casm! {
22 ap += (compiled.wrapper.builtins.len());
23 call rel 4;
24 jmp rel 0;
25 };
26 Self {
27 program: compiled.program.assemble_ex(
28 chain!(&non_returning_header.instructions, &compiled.wrapper.header),
29 &compiled.wrapper.footer,
30 ),
31 entrypoints: vec![
32 ExecutableEntryPoint {
33 builtins: compiled.wrapper.builtins.clone(),
34 offset: 0,
35 kind: EntryPointKind::Standalone,
36 },
37 ExecutableEntryPoint {
38 builtins: compiled.wrapper.builtins,
39 offset: non_returning_header.current_code_offset,
40 kind: EntryPointKind::Bootloader,
41 },
42 ],
43 }
44 }
45}
46
47#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct ExecutableEntryPoint {
50 pub builtins: Vec<BuiltinName>,
52 pub offset: usize,
54 pub kind: EntryPointKind,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize)]
60pub enum EntryPointKind {
61 Bootloader,
65 Standalone,
70}