vhdl_tb 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 61e50cf3e02216bb813808b913f5df66188ed468
4
+ data.tar.gz: 5bb80eccc0368b0626d49662f2910f152d0b52ad
5
+ SHA512:
6
+ metadata.gz: 86aa3ba40f08469e02b7b7fac6a86e6489685d46ef22e09f75c8d224c1e4cade76733039598a11d373ab5c1c0b8f5b61b9b23d3732a2e5553d6b0e9b6b791146
7
+ data.tar.gz: 8aecc52f8f78b2b5c74d09063e2fabccd0e5969ce70b6e8ed82ec9521853e84736bf127a9d708882d27683c36caac0c03d24dedecfbe0c381eb07d47e644912c
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/vhdl_tb'
4
+ generator=VhdlTb.new
5
+ generator.analyze_options(ARGV)
6
+ generator.generate
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/vhdl_tb'
4
+ generator=VhdlTb.new
5
+ generator.analyze_options(ARGV)
6
+ generator.generate
@@ -0,0 +1,63 @@
1
+ -----------------------------------------------------------------
2
+ -- This file was generated automatically by tb_gen Ruby utility
3
+ -- date : <%=Time.now.strftime("(d/m/y) %d/%m/%Y %H:%M")%>
4
+ -- Author : Jean-Christophe Le Lann - 2014
5
+ -----------------------------------------------------------------
6
+ library ieee;
7
+ use ieee.std_logic_1164.all;
8
+ use ieee.numeric_std.all;
9
+
10
+ entity <%=@tb.name%> is
11
+ end entity;
12
+
13
+ architecture bhv of <%=@tb.name%> is
14
+
15
+ constant HALF_PERIOD : time := 5 ns;
16
+
17
+ signal clk : std_logic := '0';
18
+ signal reset_n : std_logic := '0';
19
+ signal sreset : std_logic := '0';
20
+ signal running : boolean := true;
21
+
22
+ procedure wait_cycles(n : natural) is
23
+ begin
24
+ for i in 1 to n loop
25
+ wait until rising_edge(clk);
26
+ end loop;
27
+ end procedure;
28
+
29
+ <%=@entity.ports.collect do |port|
30
+ " signal #{port.name.rjust(@max_length)} : #{port.type}" if not @symtable.include?(port.name)
31
+ end.compact.join(";\n")%>;
32
+
33
+ begin
34
+ -------------------------------------------------------------------
35
+ -- clock and reset
36
+ -------------------------------------------------------------------
37
+ reset_n <= '0','1' after 666 ns;
38
+
39
+ clk <= not(clk) after HALF_PERIOD when running else clk;
40
+
41
+ --------------------------------------------------------------------
42
+ -- Design Under Test
43
+ --------------------------------------------------------------------
44
+ dut : entity work.<%=@entity.name%>(<%=@arch.name%>)
45
+ port map (
46
+ <%=@entity.ports.collect{|port| "\t #{port.name.ljust(@max_length)} => #{port.name}"}.join(",\n")%>);
47
+
48
+ --------------------------------------------------------------------
49
+ -- sequential stimuli
50
+ --------------------------------------------------------------------
51
+ stim : process
52
+ begin
53
+ report "running testbench for <%=@entity.name%>(<%=@arch.name%>)";
54
+ report "waiting for asynchronous reset";
55
+ wait until reset_n='1';
56
+ report "applying stimuli...";
57
+ wait_cycles(100);
58
+ report "end of simulation";
59
+ running <=false;
60
+ wait;
61
+ end process;
62
+
63
+ end bhv;
@@ -0,0 +1,105 @@
1
+ require 'erb'
2
+ require 'pp'
3
+ require 'optparse'
4
+
5
+ Entity = Struct.new("Entity",:name,:ports)
6
+ Architecture = Struct.new("Architecture",:name,:entity)
7
+ Port = Struct.new("Port",:name,:dir,:type)
8
+ Testbench = Struct.new("Testbench",:name)
9
+
10
+ class VhdlTb
11
+
12
+ VERSION = "0.2"
13
+
14
+ def initialize
15
+ #puts __dir__
16
+ banner
17
+ @engine=ERB.new(IO.read "#{__dir__}/template.tb.vhd")
18
+ end
19
+
20
+ def banner
21
+ puts "-- "+"="*60
22
+ puts "-- VHDL testbench generator -- Jean-Christophe Le Lann 2017"
23
+ puts "-- "+"="*60
24
+
25
+ end
26
+
27
+ def analyze_options args
28
+ args << "-h" if args.empty?
29
+
30
+ opt_parser = OptionParser.new do |opts|
31
+ opts.banner = "Usage: vhdl_tb (or tbgen) <filename>"
32
+
33
+ opts.on("-v", "--version", "Prints version") do |n|
34
+ puts VERSION
35
+ abort
36
+ end
37
+
38
+ opts.on("-h", "--help", "Prints this help") do
39
+ puts "Generates testbench in VHDL, from a given file containing an Entity-Architecture couple."
40
+ puts
41
+ puts opts
42
+ abort
43
+ end
44
+ end
45
+
46
+ begin
47
+ opt_parser.parse!(args)
48
+ @args=args
49
+
50
+ rescue Exception => e
51
+ puts e
52
+ #puts e.backtrace
53
+ exit
54
+ end
55
+ end
56
+
57
+ def generate entity_filename=@args.first
58
+ @symtable=[]
59
+ @symtable << "clk"
60
+ @symtable << "reset_n"
61
+ @symtable << "sreset"
62
+ analyze(entity_filename)
63
+ tb_txt=@engine.result(binding)
64
+ tb_filename="#{@tb.name}.vhd"
65
+ File.open(tb_filename,'w'){|f| f.puts tb_txt}
66
+ puts "testbench generated : #{tb_filename}"
67
+ end
68
+
69
+ def analyze entity_filename
70
+ puts "analyzing VHDL file : #{entity_filename}"
71
+ code=IO.read(entity_filename)
72
+ regexp_entity=/entity\s+(\w+)\s+is\s+port\s*\((.*)\).*end\s+/im
73
+ entity_matched = regexp_entity.match(code)
74
+ name,iotext=*entity_matched.captures
75
+
76
+ ioregexp=/(\w+)\s*:\s*(\w+)\s+(.*)\s*;?/ix
77
+ iotab= iotext.scan(ioregexp)
78
+ io= to_port(iotab)
79
+ puts "entity found : #{name} (#{io.size} ports)"
80
+ @entity=Entity.new(name,io)
81
+
82
+ regexp_arch=/architecture\s+(\w+)\s+of\s+(\w+)/im
83
+ arch_matched = regexp_arch.match(code)
84
+ arch_name,entity_name=*arch_matched.captures
85
+ @arch=Architecture.new(arch_name,entity_name)
86
+ @tb=Testbench.new(@entity.name+"_tb")
87
+ end
88
+
89
+ def to_port iotab
90
+ @max_length=0
91
+ iotab.collect do |io|
92
+ name,dir,type=io
93
+ type=type.split(";")[0] #suppress comments
94
+ @max_length=name.size if name.size>@max_length
95
+ Port.new(name,dir,type)
96
+ end
97
+ end
98
+
99
+ end
100
+
101
+ if $PROGRAM_NAME == __FILE__
102
+ raise "you need to provide a VHDL file that contains the entity to test" if ARGV.size==0
103
+ filename=ARGV[0]
104
+ VhdlTb.new.generate(filename)
105
+ end
@@ -0,0 +1,16 @@
1
+ library ieee;
2
+ use ieee.std_logic_1164.all;
3
+ use ieee.numeric_std.all;
4
+
5
+ entity circuit is
6
+ port(
7
+ reset_n : in std_logic;
8
+ clock : in std_logic;
9
+ a,b : in unsigned(7 downto 0);
10
+ f : in unsigned(7 downto 0)
11
+ );
12
+ end circuit;
13
+
14
+ architecture rtl of circuit is
15
+ begin
16
+ end rtl;
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vhdl_tb
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.2'
5
+ platform: ruby
6
+ authors:
7
+ - Jean-Christophe Le Lann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-10-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple testbench generator for VHDL
14
+ email: jean-christophe.le_lann@ensta-bretagne.fr
15
+ executables:
16
+ - vhdl_tb
17
+ - tbgen
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - bin/tbgen
22
+ - bin/vhdl_tb
23
+ - lib/template.tb.vhd
24
+ - lib/vhdl_tb.rb
25
+ - tests/circuit.vhd
26
+ homepage: http://rubygems.org/gems/vhdl_tb
27
+ licenses:
28
+ - MIT
29
+ metadata: {}
30
+ post_install_message:
31
+ rdoc_options: []
32
+ require_paths:
33
+ - lib
34
+ required_ruby_version: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ">="
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ required_rubygems_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ requirements: []
45
+ rubyforge_project:
46
+ rubygems_version: 2.6.12
47
+ signing_key:
48
+ specification_version: 4
49
+ summary: VHDL Testbench generator
50
+ test_files: []