pub fn emit_module_with_env(
        &mut self,
        id: NodeId,
        env: ParamEnv,
    ) -> Result<Rc<EmittedModule<'gcx>>> {
        if let Some(x) = self.tables.module_defs.get(&id.env(env)) {
            return x.clone();
        }
        let hir = match self.hir_of(id)? {
            HirNode::Module(m) => m,
            _ => panic!("expected {:?} to be a module", id),
        };
        info!("Emit module `{}` with {:?}", hir.name, env);

        // Emit detailed port information if requested.
        if self.sess().has_verbosity(Verbosity::PORTS) {
            emit_port_details(self.cx, hir, env);
        }

        // Determine entity type and port names.
        let ports = self.determine_module_ports(&hir.ports_new.int, env)?;

        // Pick an entity name.
        let mut entity_name: String = hir.name.value.into();
        if env != self.default_param_env() {
            entity_name.push_str(&format!(".param{}", env.0));
        }
        let name = llhd::ir::UnitName::Global(entity_name.clone());

        // Create MLIR entity.
        let mlir_cx = self.into_mlir.context();
        let mut mlir_builder = mlir::Builder::new(mlir_cx);
        mlir_builder.set_loc(span_to_loc(mlir_cx, hir.span()));
        mlir_builder.set_insertion_point_to_end(self.into_mlir.block());
        let mut entity_op = circt::llhd::EntityLikeBuilder::new(&entity_name);
        for port in ports.inputs.iter() {
            entity_op.add_input(&port.name, port.mty);
        }
        for port in ports.outputs.iter() {
            entity_op.add_output(&port.name, port.mty);
        }
        let entity_op = entity_op.build_entity(&mut mlir_builder);
        mlir_builder.set_insertion_point_to_start(entity_op.block());

        // Create entity.
        let mut ent =
            llhd::ir::UnitData::new(llhd::ir::UnitKind::Entity, name.clone(), ports.sig.clone());
        let mut builder = llhd::ir::UnitBuilder::new_anonymous(&mut ent);
        self.tables
            .module_signatures
            .insert(id.env(env), (name, ports.sig.clone()));
        let mut values = HashMap::new();
        let mut gen = UnitGenerator::new(self, &mut builder, &mut values, &mut mlir_builder);

        // Assign proper port names and collect ports into a lookup table.
        for (index, port) in ports.inputs.iter().enumerate() {
            let arg = gen.builder.input_arg(index);
            gen.builder.set_name(arg, port.name.clone());
            gen.values
                .insert(port.accnode, (arg, entity_op.input(index)));
        }
        for (index, port) in ports.outputs.iter().enumerate() {
            let arg = gen.builder.output_arg(index);
            gen.builder.set_name(arg, port.name.clone());
            gen.values
                .insert(port.accnode, (arg, entity_op.output(index)));
        }

        debug!("  Ports:");
        for (node, value) in gen.values.iter() {
            debug!(
                "    {:?} = {:?} (type {})",
                node,
                value,
                gen.llhd_type(value.0),
            );
        }

        // Emit the actual contents of the entity.
        gen.emit_module_block(id, env, &hir.block, &entity_name)?;

        // Assign default values to undriven output ports.
        for port in ports.outputs.iter() {
            let value = gen.values[&port.accnode];
            let driven = gen
                .builder
                .all_insts()
                .any(|inst| match gen.builder[inst].opcode() {
                    llhd::ir::Opcode::Drv => gen.builder[inst].args()[0] == value.0,
                    llhd::ir::Opcode::Inst => gen.builder[inst].output_args().contains(&value.0),
                    _ => false,
                });
            if driven {
                continue;
            }
            let default_value = gen.emit_const(
                if let Some(default) = port.default {
                    gen.constant_value_of(default, env)
                } else {
                    gen.type_default_value(port.ty)
                },
                env,
                port.port.span(),
            )?;
            let zero_time = gen.mk_const_time(&num::zero(), 1, 0);
            gen.mk_drv(value, default_value, zero_time);
        }

        let unit = self.into.add_unit(ent);
        let result = Ok(Rc::new(EmittedModule {
            unit,
            mlir_symbol: entity_name.clone(),
            ports,
        }));
        self.tables.module_defs.insert(id.env(env), result.clone());
        result
    }
/// Emit the code for a module and all its dependent modules.
Emit the code for a module and all its dependent modules.
Emit the code for a module and all its dependent modules .
pub fn emit_module_with_env(
        &mut self,
        id: NodeId,
        env: ParamEnv,
    ) -> Result<Rc<EmittedModule<'gcx>>> {
        if let Some(x) = self.tables.module_defs.get(&id.env(env)) {
            return x.clone();
        }
        let hir = match self.hir_of(id)? {
            HirNode::Module(m) => m,
            _ => panic!("expected {:?} to be a module", id),
        };
        info!("Emit module `{}` with {:?}", hir.name, env);
        // Emit detailed port information if requested.
        if self.sess().has_verbosity(Verbosity::PORTS) {
            emit_port_details(self.cx, hir, env);
        }
        // Determine entity type and port names.
        let ports = self.determine_module_ports(&hir.ports_new.int, env)?;
        // Pick an entity name.
        let mut entity_name: String = hir.name.value.into();
        if env != self.default_param_env() {
            entity_name.push_str(&format!(".param{}", env.0));
        }
        let name = llhd::ir::UnitName::Global(entity_name.clone());
        // Create MLIR entity.
        let mlir_cx = self.into_mlir.context();
        let mut mlir_builder = mlir::Builder::new(mlir_cx);
        mlir_builder.set_loc(span_to_loc(mlir_cx, hir.span()));
        mlir_builder.set_insertion_point_to_end(self.into_mlir.block());
        let mut entity_op = circt::llhd::EntityLikeBuilder::new(&entity_name);
        for port in ports.inputs.iter() {
            entity_op.add_input(&port.name, port.mty);
        }
        for port in ports.outputs.iter() {
            entity_op.add_output(&port.name, port.mty);
        }
        let entity_op = entity_op.build_entity(&mut mlir_builder);
        mlir_builder.set_insertion_point_to_start(entity_op.block());
        // Create entity.
        let mut ent =
            llhd::ir::UnitData::new(llhd::ir::UnitKind::Entity, name.clone(), ports.sig.clone());
        let mut builder = llhd::ir::UnitBuilder::new_anonymous(&mut ent);
        self.tables
            .module_signatures
            .insert(id.env(env), (name, ports.sig.clone()));
        let mut values = HashMap::new();
        let mut gen = UnitGenerator::new(self, &mut builder, &mut values, &mut mlir_builder);
        // Assign proper port names and collect ports into a lookup table.
        for (index, port) in ports.inputs.iter().enumerate() {
            let arg = gen.builder.input_arg(index);
            gen.builder.set_name(arg, port.name.clone());
            gen.values
                .insert(port.accnode, (arg, entity_op.input(index)));
        }
        for (index, port) in ports.outputs.iter().enumerate() {
            let arg = gen.builder.output_arg(index);
            gen.builder.set_name(arg, port.name.clone());
            gen.values
                .insert(port.accnode, (arg, entity_op.output(index)));
        }
        debug!("  Ports:");
        for (node, value) in gen.values.iter() {
            debug!(
                "    {:?} = {:?} (type {})",
                node,
                value,
                gen.llhd_type(value.0),
            );
        }
        // Emit the actual contents of the entity.
        gen.emit_module_block(id, env, &hir.block, &entity_name)?;
        // Assign default values to undriven output ports.
        for port in ports.outputs.iter() {
            let value = gen.values[&port.accnode];
            let driven = gen
                .builder
                .all_insts()
                .any(|inst| match gen.builder[inst].opcode() {
                    llhd::ir::Opcode::Drv => gen.builder[inst].args()[0] == value.0,
                    llhd::ir::Opcode::Inst => gen.builder[inst].output_args().contains(&value.0),
                    _ => false,
                });
            if driven {
                continue;
            }
            let default_value = gen.emit_const(
                if let Some(default) = port.default {
                    gen.constant_value_of(default, env)
                } else {
                    gen.type_default_value(port.ty)
                },
                env,
                port.port.span(),
            )?;
            let zero_time = gen.mk_const_time(&num::zero(), 1, 0);
            gen.mk_drv(value, default_value, zero_time);
        }
        let unit = self.into.add_unit(ent);
        let result = Ok(Rc::new(EmittedModule {
            unit,
            mlir_symbol: entity_name.clone(),
            ports,
        }));
        self.tables.module_defs.insert(id.env(env), result.clone());
        result
    }
pub fn emit_module_with_env ( & mut self , id : NodeId , env : ParamEnv , ) -> Result < Rc < EmittedModule < ' gcx > > > { if let Some ( x ) = self . tables . module_defs . get ( & id . env ( env ) ) { return x . clone ( ) ; } let hir = match self . hir_of ( id ) ? { HirNode :: Module ( m ) => m , _ => panic ! ( " " id ) , } ; info ! ( " " hir name env ) ; // Emit detailed port information if requested. if self . sess ( ) . has_verbosity ( Verbosity :: PORTS ) { emit_port_details ( self . cx , hir , env ) ; } // Determine entity type and port names. let ports = self . determine_module_ports ( & hir . ports_new . int , env ) ? ; // Pick an entity name. let mut entity_name : String = hir . name . value . into ( ) ; if env != self . default_param_env ( ) { entity_name . push_str ( & format ! ( " " env 0 ) ) ; } let name = llhd :: ir :: UnitName :: Global ( entity_name . clone ( ) ) ; // Create MLIR entity. let mlir_cx = self . into_mlir . context ( ) ; let mut mlir_builder = mlir :: Builder :: new ( mlir_cx ) ; mlir_builder . set_loc ( span_to_loc ( mlir_cx , hir . span ( ) ) ) ; mlir_builder . set_insertion_point_to_end ( self . into_mlir . block ( ) ) ; let mut entity_op = circt :: llhd :: EntityLikeBuilder :: new ( & entity_name ) ; for port in ports . inputs . iter ( ) { entity_op . add_input ( & port . name , port . mty ) ; } for port in ports . outputs . iter ( ) { entity_op . add_output ( & port . name , port . mty ) ; } let entity_op = entity_op . build_entity ( & mut mlir_builder ) ; mlir_builder . set_insertion_point_to_start ( entity_op . block ( ) ) ; // Create entity. let mut ent = llhd :: ir :: UnitData :: new ( llhd :: ir :: UnitKind :: Entity , name . clone ( ) , ports . sig . clone ( ) ) ; let mut builder = llhd :: ir :: UnitBuilder :: new_anonymous ( & mut ent ) ; self . tables . module_signatures . insert ( id . env ( env ) , ( name , ports . sig . clone ( ) ) ) ; let mut values = HashMap :: new ( ) ; let mut gen = UnitGenerator :: new ( self , & mut builder , & mut values , & mut mlir_builder ) ; // Assign proper port names and collect ports into a lookup table. for ( index , port ) in ports . inputs . iter ( ) . enumerate ( ) { let arg = gen . builder . input_arg ( index ) ; gen . builder . set_name ( arg , port . name . clone ( ) ) ; gen . values . insert ( port . accnode , ( arg , entity_op . input ( index ) ) ) ; } for ( index , port ) in ports . outputs . iter ( ) . enumerate ( ) { let arg = gen . builder . output_arg ( index ) ; gen . builder . set_name ( arg , port . name . clone ( ) ) ; gen . values . insert ( port . accnode , ( arg , entity_op . output ( index ) ) ) ; } debug ! ( " " ) ; for ( node , value ) in gen . values . iter ( ) { debug ! ( " " node value gen llhd_type ( value 0 ) ) ; } // Emit the actual contents of the entity. gen . emit_module_block ( id , env , & hir . block , & entity_name ) ? ; // Assign default values to undriven output ports. for port in ports . outputs . iter ( ) { let value = gen . values [ & port . accnode ] ; let driven = gen . builder . all_insts ( ) . any ( | inst | match gen . builder [ inst ] . opcode ( ) { llhd :: ir :: Opcode :: Drv => gen . builder [ inst ] . args ( ) [ 0 ] == value . 0 , llhd :: ir :: Opcode :: Inst => gen . builder [ inst ] . output_args ( ) . contains ( & value . 0 ) , _ => false , } ) ; if driven { continue ; } let default_value = gen . emit_const ( if let Some ( default ) = port . default { gen . constant_value_of ( default , env ) } else { gen . type_default_value ( port . ty ) } , env , port . port . span ( ) , ) ? ; let zero_time = gen . mk_const_time ( & num :: zero ( ) , 1 , 0 ) ; gen . mk_drv ( value , default_value , zero_time ) ; } let unit = self . into . add_unit ( ent ) ; let result = Ok ( Rc :: new ( EmittedModule { unit , mlir_symbol : entity_name . clone ( ) , ports , } ) ) ; self . tables . module_defs . insert ( id . env ( env ) , result . clone ( ) ) ; result }
Emit the code for a module and all its dependent modules.
Emit the code for a module and all its dependent modules .
&mut self
id
NodeId
env
ParamEnv
&mut self
id
NodeId
env
ParamEnv