Class: Vertigo::TestBenchGenerator
- Inherits:
-
Object
- Object
- Vertigo::TestBenchGenerator
- Defined in:
- lib/vertigo/tb_generator.rb
Instance Attribute Summary collapse
-
#arch ⇒ Object
Returns the value of attribute arch.
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#clk ⇒ Object
Returns the value of attribute clk.
-
#entity ⇒ Object
Returns the value of attribute entity.
-
#rst ⇒ Object
Returns the value of attribute rst.
Instance Method Summary collapse
- #comment(str) ⇒ Object
- #gen_clock_and_reset ⇒ Object
- #gen_code ⇒ Object
- #gen_header ⇒ Object
- #gen_stim_process ⇒ Object
- #generate_from(ast) ⇒ Object
-
#initialize(options = {}) ⇒ TestBenchGenerator
constructor
A new instance of TestBenchGenerator.
- #instanciate_dut ⇒ Object
- #line(n = 80) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ TestBenchGenerator
Returns a new instance of TestBenchGenerator.
7 8 9 10 |
# File 'lib/vertigo/tb_generator.rb', line 7 def initialize ={} @options= @supplemental_libs_h=[:supplemental_libs_h]||{} end |
Instance Attribute Details
#arch ⇒ Object
Returns the value of attribute arch.
5 6 7 |
# File 'lib/vertigo/tb_generator.rb', line 5 def arch @arch end |
#ast ⇒ Object
Returns the value of attribute ast.
4 5 6 |
# File 'lib/vertigo/tb_generator.rb', line 4 def ast @ast end |
#clk ⇒ Object
Returns the value of attribute clk.
6 7 8 |
# File 'lib/vertigo/tb_generator.rb', line 6 def clk @clk end |
#entity ⇒ Object
Returns the value of attribute entity.
5 6 7 |
# File 'lib/vertigo/tb_generator.rb', line 5 def entity @entity end |
#rst ⇒ Object
Returns the value of attribute rst.
6 7 8 |
# File 'lib/vertigo/tb_generator.rb', line 6 def rst @rst end |
Instance Method Details
#comment(str) ⇒ Object
27 28 29 |
# File 'lib/vertigo/tb_generator.rb', line 27 def comment str "-- #{str}" end |
#gen_clock_and_reset ⇒ Object
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/vertigo/tb_generator.rb', line 87 def gen_clock_and_reset code=Code.new code << line code << comment("clock and reset") code << line code << "#{@reset_name} <= '0','1' after 666 ns;" code.newline code << "#{@clk_name} <= not(#{@clk_name}) after HALF_PERIOD when running else #{@clk_name};" code end |
#gen_code ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vertigo/tb_generator.rb', line 31 def gen_code code=Code.new code << gen_header code << "library ieee;" code << "use ieee.std_logic_1164.all;" code << "use ieee.numeric_std.all;" code.newline code << "entity #{@entity_name}_tb is" code << "end entity;" code.newline code << "architecture bhv of #{@entity_name}_tb is" code.indent=2 code << "constant HALF_PERIOD : time :=5 ns;" code.newline code << "signal #{@clk_name} : std_logic := '0';" code << "signal #{@reset_name} : std_logic := '0';" code.newline code << "signal running : boolean := true;" code.newline code << "procedure wait_cycles(n : natural) is " code << "begin" code.indent=4 code << "for i in 0 to n loop" code.indent=6 code << "wait until rising_edge(#{@clk_name});" code.indent=4 code << "end loop;" code.indent=2 code << "end procedure;" @entity.ports.each do |port| port_name=port.name.str.ljust(@max_length_str) port_type=port.type.str code << "signal #{port_name} : #{port_type};" unless @excluded.include?(port) end code.indent=0 code << "begin" code.indent=2 code << gen_clock_and_reset code << instanciate_dut code << gen_stim_process code.indent=0 code << "end bhv;" code end |
#gen_header ⇒ Object
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vertigo/tb_generator.rb', line 76 def gen_header code=Code.new code << line code << "-- this file was generated automatically by Vertigo Ruby utility" code << "-- date : (d/m/y h:m) #{Time.now.strftime("%d/%m/%Y %k:%M")}" code << "-- author : Jean-Christophe Le Lann - 2014" code << line code.newline code end |
#gen_stim_process ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/vertigo/tb_generator.rb', line 119 def gen_stim_process code=Code.new code << line code << comment("sequential stimuli") code << line code << "stim : process" code << "begin" code.indent=2 code << "report \"running testbench for #{@entity_name}(#{@arch_name})\";" code << "report \"waiting for asynchronous reset\";" code << "wait until #{@reset_name}='1';" code << "wait_cycles(100);" code << "report \"end of simulation\";" code << "running <= false;" code << "wait;" code.indent=0 code << "end process;" code end |
#generate_from(ast) ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/vertigo/tb_generator.rb', line 12 def generate_from ast @ast=ast entity_arch=find_entity_arch() detecting_clk_and_reset(entity_arch) vhdl_tb=gen_code() @tb_name=@entity_name+"_tb" tb_filename=@tb_name+".vhd" File.open(tb_filename,'w'){|f| f.puts vhdl_tb.finalize} puts "=> generated testbench : #{tb_filename}" end |
#instanciate_dut ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vertigo/tb_generator.rb', line 98 def instanciate_dut code=Code.new code << line code << comment("Design Under Test") code << line code << "dut : entity work.#{@entity_name}(#{@arch_name})" code.indent=2 code << "port map (" code.indent=4 @entity.ports.each do |port| port_name=port.name.str.ljust(@max_length_str) port_type=port.type.str code << "#{port_name} => #{port_name}," end code.indent=2 code << ");" code.indent=0 code end |
#line(n = 80) ⇒ Object
23 24 25 |
# File 'lib/vertigo/tb_generator.rb', line 23 def line n=80 "-"*n end |