/// Emit the code for a variable or net declaration.
Emit the code for a variable or net declaration.
Emit the code for a variable or net declaration .
fn emit_varnet_decl(
        &mut self,
        decl_id: NodeId,
        ty: &'gcx UnpackedType<'gcx>,
        env: ParamEnv,
        default: Option<NodeId>,
    ) -> Result<HybridValue> {
        // Check if this is a variable or a net declaration.
        let (is_var, name) = match self.hir_of(decl_id)? {
            HirNode::VarDecl(x) => (x.kind.is_var(), x.name.value.as_str()),
            HirNode::IntPort(x) => (x.kind.is_var(), x.name.value.as_str()),
            x => unreachable!("emit_varnet_decl on HIR {:?}", x),
        };
        // Differentiate between variable and net declarations, which have
        // slightly different semantics regarding their initial value.
        if is_var {
            // For variables we require that the initial value is a
            // constant.
            let init = self.emit_const(
                match default {
                    Some(expr) => self.constant_value_of(expr, env),
                    None => self.type_default_value(ty),
                },
                env,
                self.span(default.unwrap_or(decl_id)),
            )?;
            Ok((
                self.builder.ins().sig(init.0),
                circt::llhd::SignalOp::new(
                    self.mlir_builder,
                    &self.unique_names.add(&name),
                    init.1,
                )
                .into(),
            ))
        } else {
            // For nets we simply emit the initial value as a signal, then
            // short-circuit it with the net declaration.
            let zero = self.emit_const(self.type_default_value(ty), env, self.span(decl_id))?;
            let net = (
                self.builder.ins().sig(zero.0),
                circt::llhd::SignalOp::new(
                    self.mlir_builder,
                    &self.unique_names.add(&name),
                    zero.1,
                )
                .into(),
            );
            if let Some(default) = default {
                let init = self.emit_rvalue_mode(default, env, Mode::Signal)?;
                self.builder.ins().con(net.0, init.0);
                circt::llhd::ConnectOp::new(self.mlir_builder, net.1, init.1);
            }
            Ok(net)
        }
    }
fn emit_varnet_decl ( & mut self , decl_id : NodeId , ty : & ' gcx UnpackedType < ' gcx > , env : ParamEnv , default : Option < NodeId > , ) -> Result < HybridValue > { // Check if this is a variable or a net declaration. let ( is_var , name ) = match self . hir_of ( decl_id ) ? { HirNode :: VarDecl ( x ) => ( x . kind . is_var ( ) , x . name . value . as_str ( ) ) , HirNode :: IntPort ( x ) => ( x . kind . is_var ( ) , x . name . value . as_str ( ) ) , x => unreachable ! ( " " x ) , } ; // Differentiate between variable and net declarations, which have // slightly different semantics regarding their initial value. if is_var { // For variables we require that the initial value is a // constant. let init = self . emit_const ( match default { Some ( expr ) => self . constant_value_of ( expr , env ) , None => self . type_default_value ( ty ) , } , env , self . span ( default . unwrap_or ( decl_id ) ) , ) ? ; Ok ( ( self . builder . ins ( ) . sig ( init . 0 ) , circt :: llhd :: SignalOp :: new ( self . mlir_builder , & self . unique_names . add ( & name ) , init . 1 , ) . into ( ) , ) ) } else { // For nets we simply emit the initial value as a signal, then // short-circuit it with the net declaration. let zero = self . emit_const ( self . type_default_value ( ty ) , env , self . span ( decl_id ) ) ? ; let net = ( self . builder . ins ( ) . sig ( zero . 0 ) , circt :: llhd :: SignalOp :: new ( self . mlir_builder , & self . unique_names . add ( & name ) , zero . 1 , ) . into ( ) , ) ; if let Some ( default ) = default { let init = self . emit_rvalue_mode ( default , env , Mode :: Signal ) ? ; self . builder . ins ( ) . con ( net . 0 , init . 0 ) ; circt :: llhd :: ConnectOp :: new ( self . mlir_builder , net . 1 , init . 1 ) ; } Ok ( net ) } }
Emit the code for a variable or net declaration.
Emit the code for a variable or net declaration .
&mut self
decl_id
NodeId
ty
&'gcx UnpackedType<'gcx>
env
ParamEnv
default
Option<NodeId>