Crates.io | source_generator |
lib.rs | source_generator |
version | 0.0.3 |
source | src |
created_at | 2023-01-15 16:04:10.794909 |
updated_at | 2023-05-17 14:40:23.597704 |
description | Basic source code generation features |
homepage | |
repository | https://github.com/JohannesKutning/source_generator |
max_upload_size | |
id | 759547 |
size | 198,687 |
A library with basic source code generation features for application with the need of source code 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;