#generation #source #applications #basic #vhdl #port #creation

source_generator

Basic source code generation features

3 releases

0.0.3 May 17, 2023
0.0.2 Jan 15, 2023
0.0.1 Jan 15, 2023

#6 in #vhdl

Download history 5/week @ 2024-02-21 19/week @ 2024-02-28 2/week @ 2024-03-13 61/week @ 2024-03-20 14/week @ 2024-03-27 18/week @ 2024-04-03

93 downloads per month

GPL-3.0 license

120KB
3K SLoC

source_generator

A library with basic source code generation features for application with the need of source code generation.

VHDL Generation

The VHDL source code generation is oriented on the reverse BNF of VHDL 2008 with some simplifications. The example vhdl/adder.rs shows the creation of a simple VHDL adder design.

fn main() -> Result< (), std::io::Error > {
    let mut adder = Entity::new( "adder" );
    adder.add_library_use( LibraryUse::new( "ieee", "numeric_std" ) );
    adder.add_generic( Generic::new_with_default( "SIZE", "positive", "32" ) );
    adder.add_port( Port::new( "a", Direction::IN, "unsigned( SIZE - 1 downto 0 )" ) );
    adder.add_port( Port::new( "b", Direction::IN, "unsigned( SIZE - 1 downto 0 )" ) );
    adder.add_port( Port::new( "c", Direction::OUT, "unsigned( SIZE - 1 downto 0 )" ) );

    let mut rtl = Architecture::new( "rtl", adder );
    rtl.add_signal_assignment( SignalAssignment::new_with_label( "add", "c", "a + b" ));

    let mut vhdl_file = VhdlFile::new( "examples/vhdl/adder.vhd" );
    vhdl_file.add_architecture( rtl );

    vhdl_file.write()?;
}

This design contains an entity with two input ports and one output port. The generated architecture uses an addition of both inputs and writes the result to the output.

Based on this code generation program the follwoing VHDL code is created.

library ieee;
    use ieee.numeric_std.all;

entity adder is
    generic (
        SIZE : positive := 32
    );
    port (
        a : in unsigned( SIZE - 1 downto 0 );
        b : in unsigned( SIZE - 1 downto 0 );
        c : out unsigned( SIZE - 1 downto 0 )
    );
begin
end entity adder;

architecture rtl of adder is
begin
    add: c <= a + b;
end architecture rtl;

Dependencies

~3.5–5MB
~123K SLoC