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.
-
#options ⇒ Object
Returns the value of attribute options.
-
#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.
10 11 12 13 |
# File 'lib/vertigo/tb_generator.rb', line 10 def initialize ={} @options= @supplemental_libs_h=[:supplemental_libs_h]||{} end |
Instance Attribute Details
#arch ⇒ Object
Returns the value of attribute arch.
6 7 8 |
# File 'lib/vertigo/tb_generator.rb', line 6 def arch @arch end |
#ast ⇒ Object
Returns the value of attribute ast.
5 6 7 |
# File 'lib/vertigo/tb_generator.rb', line 5 def ast @ast end |
#clk ⇒ Object
Returns the value of attribute clk.
7 8 9 |
# File 'lib/vertigo/tb_generator.rb', line 7 def clk @clk end |
#entity ⇒ Object
Returns the value of attribute entity.
6 7 8 |
# File 'lib/vertigo/tb_generator.rb', line 6 def entity @entity end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/vertigo/tb_generator.rb', line 8 def @options end |
#rst ⇒ Object
Returns the value of attribute rst.
7 8 9 |
# File 'lib/vertigo/tb_generator.rb', line 7 def rst @rst end |
Instance Method Details
#comment(str) ⇒ Object
35 36 37 |
# File 'lib/vertigo/tb_generator.rb', line 35 def comment str "-- #{str}" end |
#gen_clock_and_reset ⇒ Object
106 107 108 109 110 111 112 113 114 115 |
# File 'lib/vertigo/tb_generator.rb', line 106 def gen_clock_and_reset code=Code.new code << line code << comment("clock and reset") code << line code << "#{@reset_name} <= '0','1' after 123 ns;" code.newline code << "#{@clk_name} <= not(#{@clk_name}) after HALF_PERIOD when running else #{@clk_name};" code end |
#gen_code ⇒ Object
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/vertigo/tb_generator.rb', line 39 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-1 loop" code.indent=6 code << "wait until rising_edge(#{@clk_name});" code.indent=4 code << "end loop;" code.indent=2 code << "end procedure;" code.newline code << "procedure toggle(signal s : inout std_logic) is" code << "begin" code << " wait until rising_edge(clk);" code << " s <=not(s);" code << " wait until rising_edge(clk);" code << " s <=not(s);" code << "end procedure;" code.newline # bug discovered by a student : when he forgets "in" or "out" in entity port... # fix : compact @entity.ports.compact.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.finalize end |
#gen_header ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/vertigo/tb_generator.rb', line 95 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
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/vertigo/tb_generator.rb', line 144 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(10);" code << "wait_cycles(200);" code << "report \"end of simulation\";" code << "running <= false;" code << "wait;" code.indent=0 code << "end process;" code end |
#generate_from(ast) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vertigo/tb_generator.rb', line 15 def generate_from ast begin @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} puts "=> generated testbench : #{tb_filename}" unless [:mute] return tb_filename rescue Exception => e puts e.backtrace end end |
#instanciate_dut ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/vertigo/tb_generator.rb', line 117 def instanciate_dut code=Code.new code << line code << comment("Design Under Test") code << line str="dut : entity work.#{@entity_name}" str+="(#{@arch_name})" if @arch_name code << str code.indent=2 code << "port map (" code.indent=4 @entity.ports.compact.each_with_index do |port,idx| port_name=port.name.str.ljust(@max_length_str) port_type=port.type.str if idx < @entity.ports.size-1 code << "#{port_name} => #{port_name}," else code << "#{port_name} => #{port_name}" end end code.indent=2 code << ");" code.indent=0 code end |
#line(n = 80) ⇒ Object
31 32 33 |
# File 'lib/vertigo/tb_generator.rb', line 31 def line n=80 "-"*n end |