HDLRuby 2.10.5 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/HDLRuby.gemspec +1 -0
  3. data/README.md +8 -4
  4. data/Rakefile +8 -0
  5. data/{lib/HDLRuby/sim/Makefile → ext/hruby_sim/Makefile_csim} +0 -0
  6. data/ext/hruby_sim/extconf.rb +13 -0
  7. data/ext/hruby_sim/hruby_rcsim_build.c +1188 -0
  8. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim.h +255 -16
  9. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_calc.c +310 -181
  10. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_core.c +34 -17
  11. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_list.c +0 -0
  12. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_stack_calc.c +4 -1
  13. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_stack_calc.c.sav +0 -0
  14. data/ext/hruby_sim/hruby_sim_tree_calc.c +375 -0
  15. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_vcd.c +5 -5
  16. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_sim_vizualize.c +2 -2
  17. data/{lib/HDLRuby/sim → ext/hruby_sim}/hruby_value_pool.c +4 -1
  18. data/lib/HDLRuby/hdr_samples/bstr_bench.rb +2 -0
  19. data/lib/HDLRuby/hdr_samples/case_bench.rb +2 -2
  20. data/lib/HDLRuby/hdr_samples/counter_bench.rb +0 -1
  21. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +46 -0
  22. data/lib/HDLRuby/hdr_samples/dff_bench.rb +1 -1
  23. data/lib/HDLRuby/hdr_samples/print_bench.rb +62 -0
  24. data/lib/HDLRuby/hdr_samples/rom.rb +5 -3
  25. data/lib/HDLRuby/hdr_samples/simple_counter_bench.rb +43 -0
  26. data/lib/HDLRuby/hdrcc.rb +54 -8
  27. data/lib/HDLRuby/hruby_bstr.rb +1175 -917
  28. data/lib/HDLRuby/hruby_high.rb +200 -90
  29. data/lib/HDLRuby/hruby_high_fullname.rb +82 -0
  30. data/lib/HDLRuby/hruby_low.rb +41 -23
  31. data/lib/HDLRuby/hruby_low2c.rb +7 -0
  32. data/lib/HDLRuby/hruby_rcsim.rb +978 -0
  33. data/lib/HDLRuby/hruby_rsim.rb +1134 -0
  34. data/lib/HDLRuby/hruby_rsim_vcd.rb +322 -0
  35. data/lib/HDLRuby/hruby_values.rb +362 -18
  36. data/lib/HDLRuby/hruby_verilog.rb +21 -3
  37. data/lib/HDLRuby/version.rb +1 -1
  38. metadata +24 -13
@@ -44,7 +44,9 @@ Value get_value() {
44
44
  }
45
45
  }
46
46
  /* Readjust the position in the pool and return the value. */
47
- return pool_values[pool_pos++];
47
+ // return pool_values[pool_pos++];
48
+ Value res = pool_values[pool_pos++];
49
+ return res;
48
50
  }
49
51
 
50
52
  /** Get the current top value. */
@@ -59,6 +61,7 @@ Value get_top_value() {
59
61
 
60
62
  /** Frees the last value of the pool. */
61
63
  void free_value() {
64
+ if (pool_pos <= 0) { printf("Pool error!\n");exit(1);}
62
65
  if (pool_pos > 0) pool_pos--;
63
66
  }
64
67
 
@@ -10,5 +10,7 @@ system :bstr_bench do
10
10
  !10.ns
11
11
  val <= -25
12
12
  !10.ns
13
+ val <= -32
14
+ !10.ns
13
15
  end
14
16
  end
@@ -1,7 +1,7 @@
1
1
  # Test the comparison operators.
2
2
 
3
- # A benchmark for the if statement.
4
- system :if_bench do
3
+ # A benchmark for the case statement.
4
+ system :case_bench do
5
5
  [8].inner :x, :z
6
6
 
7
7
  par do
@@ -17,7 +17,6 @@ system :counter do
17
17
 
18
18
 
19
19
  par do
20
- add.(q,0)
21
20
  hif(rst) { [cc,qq] <= 0 }
22
21
  helse do
23
22
  add.(q,1,[cc,qq])
@@ -0,0 +1,46 @@
1
+ # A simple D-FF
2
+ system :dff do
3
+ input :clk, :d
4
+ output q: 0
5
+
6
+ (q <= d).at(clk.posedge)
7
+ end
8
+
9
+ # A benchmark for the dff.
10
+ system :dff_bench do
11
+ inner :clk
12
+ inner :d0, :q0, :d1, :q1
13
+
14
+ dff(:my_dff0).(clk,d0,q0)
15
+ dff(:my_dff1).(d0,d1,q1)
16
+
17
+ d0 <= ~q0
18
+ d1 <= ~q1
19
+
20
+ timed do
21
+ clk <= 0
22
+ !10.ns
23
+ clk <= 1
24
+ !10.ns
25
+ clk <= 0
26
+ !10.ns
27
+ clk <= 1
28
+ !10.ns
29
+ clk <= 0
30
+ !10.ns
31
+ clk <= 1
32
+ !10.ns
33
+ clk <= 0
34
+ !10.ns
35
+ clk <= 1
36
+ !10.ns
37
+ clk <= 0
38
+ !10.ns
39
+ clk <= 1
40
+ !10.ns
41
+ clk <= 0
42
+ !10.ns
43
+ clk <= 1
44
+ !10.ns
45
+ end
46
+ end
@@ -14,7 +14,7 @@ system :dff_bench do
14
14
  # dff(:my_dff).(d,clk,rst,q)
15
15
  dff(:my_dff).(d,clk)
16
16
  q <= my_dff.q
17
- my_dff.clk <= clk
17
+ my_dff.rst <= rst
18
18
 
19
19
  timed do
20
20
  clk <= 0
@@ -0,0 +1,62 @@
1
+ ##
2
+ # A simple system for testing hw print and strings.
3
+ ######################################################
4
+
5
+ system :with_print do
6
+ input :clk, :rst
7
+ [4].output :counter
8
+
9
+ seq(clk.posedge) do
10
+ hif(rst) do
11
+ counter <= 0
12
+ end
13
+ helse do
14
+ counter <= counter + 1
15
+ hprint("In '#{__FILE__}' line #{__LINE__}: ")
16
+ hprint("Counter=", counter, "\n")
17
+ end
18
+ end
19
+ end
20
+
21
+ # A benchmark for the dff.
22
+ system :with_print_bench do
23
+ inner :clk, :rst
24
+ [4].inner :counter
25
+
26
+ with_print(:my_print).(clk,rst,counter)
27
+
28
+ timed do
29
+ clk <= 0
30
+ rst <= 0
31
+ !10.ns
32
+ clk <= 1
33
+ rst <= 0
34
+ !10.ns
35
+ clk <= 0
36
+ rst <= 1
37
+ !10.ns
38
+ clk <= 1
39
+ rst <= 1
40
+ !10.ns
41
+ clk <= 0
42
+ rst <= 0
43
+ !10.ns
44
+ clk <= 1
45
+ !10.ns
46
+ clk <= 0
47
+ !10.ns
48
+ clk <= 1
49
+ !10.ns
50
+ clk <= 0
51
+ !10.ns
52
+ clk <= 1
53
+ !10.ns
54
+ clk <= 0
55
+ !10.ns
56
+ clk <= 1
57
+ !10.ns
58
+ end
59
+
60
+
61
+ # cur_system.properties[:pre_driver] = "drivers/hw_print.rb", :hw_print_generator
62
+ end
@@ -6,9 +6,11 @@ system :rom4_8 do
6
6
  [2..0].input :addr
7
7
  [7..0].output :data0,:data1,:data2
8
8
 
9
- bit[7..0][0..7].constant content0: [0,1,2,3,4,5,6,7]
10
- signed[7..0][-8].constant content1: [0,1,2,3,4,5,6,7]
11
- typ[-8].constant content2: (8).times.to_a
9
+ bit[7..0][0..7].constant content0: [_00000000,_00000001,_00000010,_00000011,
10
+ _00000100,_00000101,_00000110,_00000111]
11
+ signed[7..0][-8].constant content1: [_sh00,_sh01,_sh02,_sh03,
12
+ _sh04,_sh05,_sh06,_sh07]
13
+ typ[-8].constant content2: (8).times.map {|i| i.to_expr.as(typ) }.reverse
12
14
 
13
15
  data0 <= content0[addr]
14
16
  data1 <= content1[addr]
@@ -0,0 +1,43 @@
1
+ # A benchmark for very simple counters.
2
+ # Also test the use of ~ on the clock.
3
+ system :counter_bench do
4
+ inner :clk, :rst
5
+ [3].inner :counter
6
+ [4].inner :counter2
7
+
8
+ par(clk.posedge) do
9
+ hif(rst) { counter <= 0 }
10
+ helse { counter <= counter + 1 }
11
+ end
12
+
13
+ par(clk.posedge) do
14
+ hif(rst) { counter2 <= 0 }
15
+ helse { counter2 <= counter2 + 1 }
16
+ end
17
+
18
+
19
+ timed do
20
+ clk <= 0
21
+ rst <= 0
22
+ !10.ns
23
+ clk <= 1
24
+ rst <= 0
25
+ !10.ns
26
+ clk <= ~clk
27
+ rst <= 1
28
+ !10.ns
29
+ clk <= ~clk
30
+ !10.ns
31
+ clk <= ~clk
32
+ rst <= 0
33
+ !10.ns
34
+ clk <= ~clk
35
+ !10.ns
36
+ 10.times do
37
+ clk <= ~clk
38
+ !10.ns
39
+ clk <= ~clk
40
+ !10.ns
41
+ end
42
+ end
43
+ end
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -363,10 +363,22 @@ $optparse = OptionParser.new do |opts|
363
363
  opts.on("--allocate=LOW,HIGH,WORD","Allocate signals to addresses") do |v|
364
364
  $options[:allocate] = v
365
365
  end
366
- opts.on("-S", "--sim","Output in C format (simulator)") do |v|
366
+ opts.on("-S","--sim","Default simulator (hybrid C-Ruby)") do |v|
367
+ $options[:rcsim] = v
368
+ $options[:multiple] = v
369
+ end
370
+ opts.on("--csim","Standalone C-based simulator") do |v|
367
371
  $options[:clang] = v
368
372
  $options[:multiple] = v
369
- $options[:sim] = v
373
+ $options[:csim] = v
374
+ end
375
+ opts.on("--rsim","Ruby-based simulator") do |v|
376
+ $options[:rsim] = v
377
+ $options[:multiple] = v
378
+ end
379
+ opts.on("--rcsim","Hybrid C-Ruby-based simulator") do |v|
380
+ $options[:rcsim] = v
381
+ $options[:multiple] = v
370
382
  end
371
383
  opts.on("--vcd", "The simulator will generate a vcd file") do |v|
372
384
  $options[:vcd] = v
@@ -556,12 +568,12 @@ end
556
568
  # Generate the result.
557
569
  # Get the top systemT.
558
570
  HDLRuby.show "#{Time.now}#{show_mem}"
559
- $top_system = $top_instance.to_low.systemT
571
+ # Ruby simulation uses the HDLRuby::High tree, other the HDLRuby::Lowais used
572
+ $top_system = ($options[:rsim] || $options[:rcsim]) ? $top_instance.systemT : $top_instance.to_low.systemT
560
573
  $top_intance = nil # Free as much memory as possible.
561
574
  HDLRuby.show "##### Top system built #####"
562
575
  HDLRuby.show "#{Time.now}#{show_mem}"
563
576
 
564
-
565
577
  # # Apply the pre drivers if any.
566
578
  # Hdecorator.each_with_property(:pre_driver) do |obj, value|
567
579
  # unless value.is_a?(Array) && value.size == 2 then
@@ -746,11 +758,12 @@ elsif $options[:clang] then
746
758
  $output << HDLRuby::Low::Low2C.main(top_system,
747
759
  *top_system.each_systemT_deep.to_a)
748
760
  end
749
- if $options[:sim] then
761
+ if $options[:csim] then
750
762
  # Simulation mode, compile and exectute.
751
763
  # Path of the simulator core files.
752
- # simdir = File.dirname(__FILE__) + "/sim/"
753
- $simdir = $hdr_dir + "/sim/"
764
+ # $simdir = $hdr_dir + "sim/"
765
+ # puts "$hdr_dir=#{$hdr_dir}"
766
+ $simdir = $hdr_dir + "/../../ext/hruby_sim/"
754
767
  # Generate and execute the simulation commands.
755
768
  # Kernel.system("cp -n #{simdir}* #{$output}/; cd #{$output}/ ; make -s ; ./hruby_simulator")
756
769
  Dir.entries($simdir).each do |filename|
@@ -826,7 +839,8 @@ elsif $options[:verilog] then
826
839
  # Open the file for current systemT
827
840
  outfile = File.open($name,"w")
828
841
  # Generate the Verilog code in to.
829
- outfile << systemT.to_verilog
842
+ # outfile << systemT.to_verilog
843
+ outfile << systemT.to_verilog($options[:vcd])
830
844
  # Close the file.
831
845
  outfile.close
832
846
  # Clears the name.
@@ -838,6 +852,38 @@ elsif $options[:verilog] then
838
852
  $output << systemT.to_verilog
839
853
  end
840
854
  end
855
+ elsif $options[:rsim] then
856
+ HDLRuby.show "Loading Ruby-level simulator..."
857
+ HDLRuby.show "#{Time.now}#{show_mem}"
858
+ # Ruby-level simulation.
859
+ require 'HDLRuby/hruby_rsim.rb'
860
+ # Is VCD output is required.
861
+ if $options[:vcd] then
862
+ # Yes
863
+ require "HDLRuby/hruby_rsim_vcd.rb"
864
+ vcdout = File.open($output+"/hruby_simulator.vcd","w")
865
+ $top_system.sim(vcdout)
866
+ vcdout.close
867
+ else
868
+ # No
869
+ $top_system.sim($stdout)
870
+ end
871
+ HDLRuby.show "End of Ruby-level simulation..."
872
+ HDLRuby.show "#{Time.now}#{show_mem}"
873
+ elsif $options[:rcsim] then
874
+ HDLRuby.show "Building the hybrid C-Ruby-level simulator..."
875
+ HDLRuby.show "#{Time.now}#{show_mem}"
876
+ # C-Ruby-level simulation.
877
+ require 'HDLRuby/hruby_rcsim.rb'
878
+ # Merge the included from the top system.
879
+ $top_system.merge_included!
880
+ # Generate the C data structures.
881
+ $top_system.to_rcsim
882
+ HDLRuby.show "Executing the hybrid C-Ruby-level simulator..."
883
+ HDLRuby.show "#{Time.now}#{show_mem}"
884
+ HDLRuby::High.rcsim($top_system,"hruby_simulator",$output,$options[:vcd] && true)
885
+ HDLRuby.show "End of hybrid C-Ruby-level simulation..."
886
+ HDLRuby.show "#{Time.now}#{show_mem}"
841
887
  elsif $options[:vhdl] then
842
888
  # top_system = $top_instance.to_low.systemT
843
889
  # top_system = $top_system