openvm_circuit/system/program/
bus.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use std::iter;

use openvm_stark_backend::{interaction::InteractionBuilder, p3_field::AbstractField};

#[derive(Debug, Clone, Copy)]
pub struct ProgramBus(pub usize);

impl ProgramBus {
    pub fn send_instruction<AB: InteractionBuilder, E: Into<AB::Expr>>(
        &self,
        builder: &mut AB,
        pc: impl Into<AB::Expr>,
        opcode: impl Into<AB::Expr>,
        operands: impl IntoIterator<Item = E>,
        multiplicity: impl Into<AB::Expr>,
    ) {
        builder.push_send(
            self.0,
            [pc.into(), opcode.into()].into_iter().chain(
                operands
                    .into_iter()
                    .map(Into::into)
                    .chain(iter::repeat(AB::Expr::ZERO))
                    .take(7),
            ),
            multiplicity,
        );
    }
}