Skip to main content

xlsynth_driver/
toolchain_config.rs

1// SPDX-License-Identifier: Apache-2.0
2
3use clap::ArgMatches;
4use serde::Deserialize;
5
6#[derive(Deserialize, Debug)]
7pub struct ToolchainConfig {
8    /// Directory path for the XLS toolset, e.g. codegen_main, opt_main, etc.
9    pub tool_path: Option<String>,
10    pub dslx: Option<DslxConfig>,
11    pub codegen: Option<CodegenConfig>,
12}
13
14#[derive(Deserialize, Debug)]
15pub struct DslxConfig {
16    pub type_inference_v2: Option<bool>,
17    pub dslx_stdlib_path: Option<String>,
18    pub dslx_path: Option<Vec<String>>,
19    pub warnings_as_errors: Option<bool>,
20    pub enable_warnings: Option<Vec<String>>,
21    pub disable_warnings: Option<Vec<String>>,
22}
23
24#[derive(Deserialize, Debug)]
25pub struct CodegenConfig {
26    pub gate_format: Option<String>,
27    pub assert_format: Option<String>,
28    pub use_system_verilog: Option<bool>,
29    pub add_invariant_assertions: Option<bool>,
30    pub array_index_bounds_checking: Option<bool>,
31}
32
33/// Helper for extracting the DSLX standard library path from the command line
34/// flag, if specified, or the toolchain config if it's present and the cmdline
35/// flag isn't specified.
36pub fn get_dslx_stdlib_path(
37    matches: &ArgMatches,
38    config: &Option<ToolchainConfig>,
39) -> Option<String> {
40    let dslx_stdlib_path = matches.get_one::<String>("dslx_stdlib_path");
41    if let Some(dslx_stdlib_path) = dslx_stdlib_path {
42        Some(dslx_stdlib_path.to_string())
43    } else if let Some(config) = config {
44        config
45            .dslx
46            .as_ref()
47            .and_then(|d| d.dslx_stdlib_path.clone())
48    } else {
49        None
50    }
51}
52
53/// Helper for retrieving supplemental DSLX search paths from the command line
54/// flag, if specified, or the toolchain config if it's present and the cmdline
55/// flag isn't specified.
56pub fn get_dslx_path(matches: &ArgMatches, config: &Option<ToolchainConfig>) -> Option<String> {
57    let dslx_path = matches.get_one::<String>("dslx_path");
58    if let Some(dslx_path) = dslx_path {
59        Some(dslx_path.to_string())
60    } else if let Some(config) = config {
61        let dslx_path = config
62            .dslx
63            .as_ref()
64            .and_then(|d| d.dslx_path.as_deref())
65            .unwrap_or(&[]);
66        Some(dslx_path.join(";"))
67    } else {
68        None
69    }
70}