fn emit_vivado_tcl(
    sess: &Session,
    matches: &ArgMatches,
    targets: TargetSet,
    srcs: Vec<SourceGroup>,
) -> Result<()> {
    // Determine the components that are part of the output.
    #[derive(Default)]
    struct OutputComponents {
        include_dirs: bool,
        defines: bool,
        sources: bool,
    }
    let mut output_components = OutputComponents::default();
    if !matches.is_present("only-defines")
        && !matches.is_present("only-includes")
        && !matches.is_present("only-sources")
    {
        // Print everything if user specified no restriction.
        output_components = OutputComponents {
            include_dirs: true,
            defines: true,
            sources: true,
        };
    } else {
        if matches.is_present("only-defines") {
            output_components.defines = true;
        }
        if matches.is_present("only-includes") {
            output_components.include_dirs = true;
        }
        if matches.is_present("only-sources") {
            output_components.sources = true;
        }
    }

    println!("{}", header_tcl(sess));
    let mut include_dirs = vec![];
    let mut defines: Vec<(String, Option<String>)> = vec![];
    let filesets = if matches.is_present("no-simset") {
        vec![""]
    } else {
        vec!["", " -simset"]
    };
    for src in srcs {
        for i in src.clone().get_incdirs() {
            include_dirs.push(relativize_path(i, sess.root));
        }
        separate_files_in_group(
            src,
            |f| match f {
                SourceFile::File(p) => match p.extension().and_then(std::ffi::OsStr::to_str) {
                    Some("sv") | Some("v") | Some("vp") => Some(SourceType::Verilog),
                    Some("vhd") | Some("vhdl") => Some(SourceType::Vhdl),
                    _ => None,
                },
                _ => None,
            },
            |src, _ty, files| {
                let mut lines = vec![];
                lines.push("add_files -norecurse -fileset [current_fileset] [list".to_owned());
                for file in files {
                    let p = match file {
                        SourceFile::File(p) => p,
                        _ => continue,
                    };
                    lines.push(relativize_path(p, sess.root));
                }
                if output_components.sources {
                    println!("{} \\\n]", lines.join(" \\\n    "));
                }
                defines.extend(
                    src.defines
                        .iter()
                        .map(|(k, &v)| (k.to_string(), v.map(String::from))),
                );
            },
        );
    }
    if !include_dirs.is_empty() && output_components.include_dirs {
        include_dirs.sort();
        include_dirs.dedup();
        for arg in &filesets {
            println!("");
            println!(
                "set_property include_dirs [list \\\n    {} \\\n] [current_fileset{}]",
                include_dirs.join(" \\\n    "),
                arg
            );
        }
    }
    defines.extend(
        targets
            .iter()
            .map(|t| (format!("TARGET_{}", t.to_uppercase()), None)),
    );
    add_defines_from_matches(&mut defines, matches);
    if !defines.is_empty() && output_components.defines {
        defines.sort();
        defines.dedup();
        for arg in &filesets {
            println!("");
            println!("set_property verilog_define [list \\");
            for (k, v) in &defines {
                let s = match v {
                    Some(s) => format!("{}={}", k, s),
                    None => format!("{}", k),
                };
                println!("    {} \\", s);
            }
            println!("] [current_fileset{}]", arg);
        }
    }
    Ok(())
}
/// Emit a script to add sources to Vivado.
Emit a script to add sources to Vivado.
Emit a script to add sources to Vivado .
fn emit_vivado_tcl(
    sess: &Session,
    matches: &ArgMatches,
    targets: TargetSet,
    srcs: Vec<SourceGroup>,
) -> Result<()> {
    // Determine the components that are part of the output.
    #[derive(Default)]
    struct OutputComponents {
        include_dirs: bool,
        defines: bool,
        sources: bool,
    }
    let mut output_components = OutputComponents::default();
    if !matches.is_present("only-defines")
        && !matches.is_present("only-includes")
        && !matches.is_present("only-sources")
    {
        // Print everything if user specified no restriction.
        output_components = OutputComponents {
            include_dirs: true,
            defines: true,
            sources: true,
        };
    } else {
        if matches.is_present("only-defines") {
            output_components.defines = true;
        }
        if matches.is_present("only-includes") {
            output_components.include_dirs = true;
        }
        if matches.is_present("only-sources") {
            output_components.sources = true;
        }
    }
    println!("{}", header_tcl(sess));
    let mut include_dirs = vec![];
    let mut defines: Vec<(String, Option<String>)> = vec![];
    let filesets = if matches.is_present("no-simset") {
        vec![""]
    } else {
        vec!["", " -simset"]
    };
    for src in srcs {
        for i in src.clone().get_incdirs() {
            include_dirs.push(relativize_path(i, sess.root));
        }
        separate_files_in_group(
            src,
            |f| match f {
                SourceFile::File(p) => match p.extension().and_then(std::ffi::OsStr::to_str) {
                    Some("sv") | Some("v") | Some("vp") => Some(SourceType::Verilog),
                    Some("vhd") | Some("vhdl") => Some(SourceType::Vhdl),
                    _ => None,
                },
                _ => None,
            },
            |src, _ty, files| {
                let mut lines = vec![];
                lines.push("add_files -norecurse -fileset [current_fileset] [list".to_owned());
                for file in files {
                    let p = match file {
                        SourceFile::File(p) => p,
                        _ => continue,
                    };
                    lines.push(relativize_path(p, sess.root));
                }
                if output_components.sources {
                    println!("{} \\\n]", lines.join(" \\\n    "));
                }
                defines.extend(
                    src.defines
                        .iter()
                        .map(|(k, &v)| (k.to_string(), v.map(String::from))),
                );
            },
        );
    }
    if !include_dirs.is_empty() && output_components.include_dirs {
        include_dirs.sort();
        include_dirs.dedup();
        for arg in &filesets {
            println!("");
            println!(
                "set_property include_dirs [list \\\n    {} \\\n] [current_fileset{}]",
                include_dirs.join(" \\\n    "),
                arg
            );
        }
    }
    defines.extend(
        targets
            .iter()
            .map(|t| (format!("TARGET_{}", t.to_uppercase()), None)),
    );
    add_defines_from_matches(&mut defines, matches);
    if !defines.is_empty() && output_components.defines {
        defines.sort();
        defines.dedup();
        for arg in &filesets {
            println!("");
            println!("set_property verilog_define [list \\");
            for (k, v) in &defines {
                let s = match v {
                    Some(s) => format!("{}={}", k, s),
                    None => format!("{}", k),
                };
                println!("    {} \\", s);
            }
            println!("] [current_fileset{}]", arg);
        }
    }
    Ok(())
}
fn emit_vivado_tcl ( sess : & Session , matches : & ArgMatches , targets : TargetSet , srcs : Vec < SourceGroup > , ) -> Result < ( ) > { // Determine the components that are part of the output. # [ derive ( Default ) ] struct OutputComponents { include_dirs : bool , defines : bool , sources : bool , } let mut output_components = OutputComponents :: default ( ) ; if ! matches . is_present ( " " ) && ! matches . is_present ( " " ) && ! matches . is_present ( " " ) { // Print everything if user specified no restriction. output_components = OutputComponents { include_dirs : true , defines : true , sources : true , } ; } else { if matches . is_present ( " " ) { output_components . defines = true ; } if matches . is_present ( " " ) { output_components . include_dirs = true ; } if matches . is_present ( " " ) { output_components . sources = true ; } } println ! ( " " header_tcl ( sess ) ) ; let mut include_dirs = vec ! [ ] ; let mut defines : Vec < ( String , Option < String > ) > = vec ! [ ] ; let filesets = if matches . is_present ( " " ) { vec ! [ " " ] } else { vec ! [ " " " " ] } ; for src in srcs { for i in src . clone ( ) . get_incdirs ( ) { include_dirs . push ( relativize_path ( i , sess . root ) ) ; } separate_files_in_group ( src , | f | match f { SourceFile :: File ( p ) => match p . extension ( ) . and_then ( std :: ffi :: OsStr :: to_str ) { Some ( " " ) | Some ( " " ) | Some ( " " ) => Some ( SourceType :: Verilog ) , Some ( " " ) | Some ( " " ) => Some ( SourceType :: Vhdl ) , _ => None , } , _ => None , } , | src , _ty , files | { let mut lines = vec ! [ ] ; lines . push ( " " . to_owned ( ) ) ; for file in files { let p = match file { SourceFile :: File ( p ) => p , _ => continue , } ; lines . push ( relativize_path ( p , sess . root ) ) ; } if output_components . sources { println ! ( " \\ \n " lines join ( " \\ \n " ) ) ; } defines . extend ( src . defines . iter ( ) . map ( | ( k , & v ) | ( k . to_string ( ) , v . map ( String :: from ) ) ) , ) ; } , ) ; } if ! include_dirs . is_empty ( ) && output_components . include_dirs { include_dirs . sort ( ) ; include_dirs . dedup ( ) ; for arg in & filesets { println ! ( " " ) ; println ! ( " \\ \n \\ \n " include_dirs join ( " \\ \n " ) arg ) ; } } defines . extend ( targets . iter ( ) . map ( | t | ( format ! ( " " t to_uppercase ( ) ) , None ) ) , ) ; add_defines_from_matches ( & mut defines , matches ) ; if ! defines . is_empty ( ) && output_components . defines { defines . sort ( ) ; defines . dedup ( ) ; for arg in & filesets { println ! ( " " ) ; println ! ( " \\ " ) ; for ( k , v ) in & defines { let s = match v { Some ( s ) => format ! ( " " k s ) , None => format ! ( " " k ) , } ; println ! ( " \\ " s ) ; } println ! ( " " arg ) ; } } Ok ( ( ) ) }
Emit a script to add sources to Vivado.
Emit a script to add sources to Vivado .
sess
&Session
matches
&ArgMatches
targets
TargetSet
srcs
Vec<SourceGroup>
sess
&Session
matches
&ArgMatches
targets
TargetSet
srcs
Vec<SourceGroup>