def generate(prj, temp_lib, impl_lib, cell_name, lay_params, sch_params, mdl_params, grid_opts, mdl_dir, mdl_opts=None, impl_cell_name=None): """ generate layout, schematic and model. """ # temp_db = make_tdb(prj, impl_loib, grid_opts) # # print('designing module') # # layout # print(lay_params) # template = temp_db.new_template(params=lay_params, temp_cls=NAND, debug=True) # if impl_cell_name is None: # temp_db.instantiate_layout(prj, template, cell_name, debug=True) # else: # temp_db.instantiate_layout(prj, template, impl_cell_name, debug=True) # generate schematic if sch_params is None: sch_params = {} # sch_params.update(template.sch_params) print(sch_params) sch_db = ModuleDB(prj.tech_info, impl_lib, prj=prj) gen_cls = sch_db.get_schematic_class(temp_lib, cell_name) dsn = sch_db.new_master(gen_cls, params=sch_params) if impl_cell_name is None: sch_db.instantiate_master(DesignOutput.SCHEMATIC, dsn) else: sch_db.instantiate_master(DesignOutput.SCHEMATIC, dsn, top_cell_name=impl_cell_name) # generate model file_name = f"{mdl_dir}/{cell_name}.sv" top_cell_name = cell_name if impl_cell_name is None else impl_cell_name if mdl_opts is None: mdl_opts = {} sch_db.instantiate_model(dsn, mdl_params, top_cell_name=top_cell_name, fname=file_name, **mdl_opts)
def test_design( tmpdir, module_db: ModuleDB, sch_design_params: Dict[str, Any], output_type: DesignOutput, options: Dict[str, Any], gen_output: bool, ) -> None: """Test design() method of each schematic generator.""" if sch_design_params is None: # No schematic tests return impl_cell = sch_design_params['top_cell_name'] extension = get_extension(output_type) if is_model_type(output_type): model_params = sch_design_params.get('model_params', None) if model_params is None: pytest.skip('Cannot find model parameters.') else: model_params = None out_code = int(options.get( 'shell', False)) + 2 * (1 - int(options.get('top_subckt', True))) if output_type is DesignOutput.YAML: base = 'out' else: base = f'out_{out_code}' expect_fname = sch_design_params.get('{}_{}'.format(base, extension), '') if not expect_fname and not gen_output: pytest.skip('Cannot find expected output file.') dsn = get_sch_master(module_db, sch_design_params) out_base_name = '{}.{}'.format(base, extension) path = tmpdir.join(out_base_name) if is_model_type(output_type): module_db.batch_model([(dsn, impl_cell, model_params)], output=output_type, fname=str(path), **options) else: module_db.instantiate_master(output_type, dsn, top_cell_name=impl_cell, fname=str(path), **options) assert path.check(file=1) with path.open('r') as f: actual = f.read() if gen_output: dir_name = pathlib.Path( 'pytest_output') / sch_design_params['test_output_dir'] out_fname = dir_name / out_base_name dir_name.mkdir(parents=True, exist_ok=True) with out_fname.open('w') as f: f.write(actual) expect = actual else: with open(expect_fname, 'r') as f: expect = f.read() if output_type is DesignOutput.YAML: actual_dict = read_yaml_str(actual) expect_dict = read_yaml_str(expect) assert actual_dict == expect_dict else: check_netlist(output_type, actual, expect)