Skip to main content

xlsynth_codegen/
lib.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Deterministic, Rust-native SystemVerilog generation for XLS block IR and
4//! DSLX types.
5
6mod arithmetic;
7mod block;
8mod error;
9mod hierarchy;
10mod ops;
11mod options;
12mod priority;
13mod slicing;
14mod stages;
15pub mod sv_bridge_builder;
16
17pub use block::inline_invokes_for_codegen;
18pub use error::BlockCodegenError;
19pub use options::{BlockCodegenOptions, BlockCodegenOutput, BlockCodegenWithRegisterNames, Layout};
20
21use xlsynth_pir::ir::Package;
22
23/// Emits the selected block and its transitive block dependencies.
24/// Call [`inline_invokes_for_codegen`] first if those blocks contain function
25/// calls.
26pub fn emit_system_verilog(
27    package: &Package,
28    options: &BlockCodegenOptions,
29) -> Result<BlockCodegenOutput, BlockCodegenError> {
30    block::emit_package(package, options, None)
31}
32
33/// Emits the RTL and records the allocated signal name for each representable
34/// register in the selected top block.
35/// The same input requirements apply as for [`emit_system_verilog`].
36pub fn emit_system_verilog_with_register_names(
37    package: &Package,
38    options: &BlockCodegenOptions,
39) -> Result<BlockCodegenWithRegisterNames, BlockCodegenError> {
40    let mut top_register_names = std::collections::BTreeMap::new();
41    let rtl = block::emit_package(package, options, Some(&mut top_register_names))?;
42    Ok(BlockCodegenWithRegisterNames {
43        system_verilog: rtl.system_verilog,
44        top_register_names,
45    })
46}