leo_passes/code_generation/mod.rs
1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use crate::Pass;
18
19use leo_errors::Result;
20
21mod expression;
22
23mod program;
24
25mod statement;
26
27mod type_;
28
29mod visitor;
30use visitor::*;
31
32pub struct CodeGenerating;
33
34impl Pass for CodeGenerating {
35 type Input = ();
36 type Output = String;
37
38 const NAME: &str = "CodeGenerating";
39
40 fn do_pass(_input: Self::Input, state: &mut crate::CompilerState) -> Result<Self::Output> {
41 let mut visitor = CodeGeneratingVisitor {
42 state,
43 next_register: 0,
44 current_function: None,
45 variable_mapping: Default::default(),
46 composite_mapping: Default::default(),
47 global_mapping: Default::default(),
48 variant: None,
49 program: &state.ast.ast,
50 program_id: None,
51 finalize_caller: None,
52 next_label: 0,
53 conditional_depth: 0,
54 internal_record_inputs: Default::default(),
55 };
56 let code = visitor.visit_program(visitor.state.ast.as_repr());
57 Ok(code)
58 }
59}