qudit_tensor/bytecode/
bytecode.rs

1use std::sync::{Arc, Mutex};
2
3// use aligned_vec::CACHELINE_ALIGN;
4// use faer_entity::Entity;
5
6// use crate::sim::qvm::QVMType;
7
8use qudit_expr::ExpressionCache;
9
10use super::{BytecodeInstruction, TensorBuffer};
11
12#[derive(Clone)]
13pub struct Bytecode {
14    // pub expressions: Vec<(TensorExpression, Option<ParamIndices>, String)>,
15    pub expressions: Arc<Mutex<ExpressionCache>>,
16    pub const_code: Vec<BytecodeInstruction>,
17    pub dynamic_code: Vec<BytecodeInstruction>,
18    pub buffers: Vec<TensorBuffer>,
19    pub out_buffer: usize,
20    pub num_params: usize,
21}
22
23impl Bytecode {
24    pub fn print_buffers(&self) {
25        println!("Buffers:");
26        for (i, buffer) in self.buffers.iter().enumerate() {
27            println!("  {}: {:?}", i, buffer);
28        }
29    }
30}
31
32impl std::fmt::Debug for Bytecode {
33    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
34        if !self.const_code.is_empty() {
35            writeln!(f, ".const")?;
36            for inst in &self.const_code {
37                writeln!(f, "    {:?}", inst)?;
38            }
39        }
40        if !self.dynamic_code.is_empty() {
41            write!(f, "\n.dynamic\n")?;
42            for inst in &self.dynamic_code {
43                writeln!(f, "    {:?}", inst)?;
44            }
45        }
46        Ok(())
47    }
48}