xlsynth_codegen/options.rs
1// SPDX-License-Identifier: Apache-2.0
2
3use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6use xlsynth::vast_helpers_options::CodegenOptions;
7
8/// Controls whether a block is presented in register-delimited stage sections.
9#[derive(Clone, Copy, Debug, Default, Eq, PartialEq, Deserialize, Serialize)]
10#[serde(rename_all = "snake_case")]
11pub enum Layout {
12 /// Emit declarations and logic in ordinary dependency order.
13 #[default]
14 None,
15 /// Partition feed-forward logic into explicitly labeled pipeline stages.
16 Pipeline,
17}
18
19/// Configures faithful SystemVerilog emission of an existing block.
20#[derive(Clone, Debug, Deserialize, Serialize)]
21#[serde(default, deny_unknown_fields)]
22pub struct BlockCodegenOptions {
23 /// Overrides package top selection when present.
24 pub top: Option<String>,
25 /// Controls declaration and pipeline-stage layout.
26 pub layout: Layout,
27 /// Overrides the generated top module name when present.
28 pub module_name: Option<String>,
29 /// Clamps dynamic array reads to the last valid element when enabled.
30 pub array_index_bounds_checking: bool,
31 /// Emits every representable operation as its own named assignment.
32 pub separate_lines: bool,
33 /// Bounds expression nesting before introducing a named intermediate.
34 pub max_inline_depth: usize,
35 /// Preserves SystemVerilog type annotations on block ports.
36 pub emit_sv_types: bool,
37 /// Emits assert operations present in the input block.
38 pub emit_asserts: bool,
39 /// Supplies optional register-lowering templates and related options.
40 pub register_codegen_options: Option<CodegenOptions>,
41}
42
43impl Default for BlockCodegenOptions {
44 fn default() -> Self {
45 Self {
46 top: None,
47 layout: Layout::None,
48 module_name: None,
49 array_index_bounds_checking: true,
50 separate_lines: false,
51 max_inline_depth: 5,
52 emit_sv_types: true,
53 emit_asserts: true,
54 register_codegen_options: None,
55 }
56 }
57}
58
59/// Contains the emitted SystemVerilog source.
60#[derive(Clone, Debug, Eq, PartialEq)]
61pub struct BlockCodegenOutput {
62 /// Complete, deterministically ordered SystemVerilog source.
63 pub system_verilog: String,
64}
65
66/// Generated RTL together with the signal names needed to initialize top
67/// block state in a simulator.
68#[derive(Clone, Debug, Eq, PartialEq)]
69pub struct BlockCodegenWithRegisterNames {
70 pub system_verilog: String,
71 /// Top block register names in IR mapped to their emitted RTL signals.
72 /// Zero-width registers have no signal and are omitted.
73 pub top_register_names: BTreeMap<String, String>,
74}