cairo_lang_sierra/extensions/modules/
debug.rs

1use super::array::ArrayType;
2use super::felt252::Felt252Type;
3use crate::define_libfunc_hierarchy;
4use crate::extensions::lib_func::{
5    LibfuncSignature, SierraApChange, SignatureSpecializationContext,
6};
7use crate::extensions::{NamedType, NoGenericArgsGenericLibfunc, SpecializationError};
8
9define_libfunc_hierarchy! {
10    pub enum DebugLibfunc {
11        Print(PrintLibfunc),
12    }, DebugConcreteLibfunc
13}
14
15/// Libfunc for debug printing.
16#[derive(Default)]
17pub struct PrintLibfunc {}
18impl NoGenericArgsGenericLibfunc for PrintLibfunc {
19    const STR_ID: &'static str = "print";
20
21    fn specialize_signature(
22        &self,
23        context: &dyn SignatureSpecializationContext,
24    ) -> Result<LibfuncSignature, SpecializationError> {
25        // TODO(spapini): We should get a StringView, which is something like
26        // (Span<StringLimb>, len), or something like that.
27        let felt252_ty = context.get_concrete_type(Felt252Type::id(), &[])?;
28        let arr_type = context.get_wrapped_concrete_type(ArrayType::id(), felt252_ty)?;
29        Ok(LibfuncSignature::new_non_branch(vec![arr_type], vec![], SierraApChange::Known {
30            new_vars_only: true,
31        }))
32    }
33}