runmat_ignition/
bytecode.rs1#[cfg(feature = "native-accel")]
2use crate::accel_graph::build_accel_graph;
3use crate::compiler::Compiler;
4use crate::functions::{Bytecode, UserFunction};
5use runmat_hir::HirProgram;
6use std::collections::HashMap;
7
8pub fn compile(prog: &HirProgram) -> Result<Bytecode, String> {
9 let mut c = Compiler::new(prog);
10 c.compile_program(prog)?;
11 #[cfg(feature = "native-accel")]
12 let accel_graph = build_accel_graph(&c.instructions, &c.var_types);
13 #[cfg(feature = "native-accel")]
14 let fusion_groups = accel_graph.detect_fusion_groups();
15 Ok(Bytecode {
16 instructions: c.instructions,
17 var_count: c.var_count,
18 functions: c.functions,
19 var_types: c.var_types,
20 #[cfg(feature = "native-accel")]
21 accel_graph: Some(accel_graph),
22 #[cfg(feature = "native-accel")]
23 fusion_groups,
24 })
25}
26
27pub fn compile_with_functions(
28 prog: &HirProgram,
29 existing_functions: &HashMap<String, UserFunction>,
30) -> Result<Bytecode, String> {
31 let mut c = Compiler::new(prog);
32 c.functions = existing_functions.clone();
33 c.compile_program(prog)?;
34 #[cfg(feature = "native-accel")]
35 let accel_graph = build_accel_graph(&c.instructions, &c.var_types);
36 #[cfg(feature = "native-accel")]
37 let fusion_groups = accel_graph.detect_fusion_groups();
38 Ok(Bytecode {
39 instructions: c.instructions,
40 var_count: c.var_count,
41 functions: c.functions,
42 var_types: c.var_types,
43 #[cfg(feature = "native-accel")]
44 accel_graph: Some(accel_graph),
45 #[cfg(feature = "native-accel")]
46 fusion_groups,
47 })
48}