HDLRuby 2.10.3 → 2.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) 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 +4 -1
  23. data/lib/HDLRuby/hdr_samples/dff_override.rb +76 -0
  24. data/lib/HDLRuby/hdr_samples/print_bench.rb +62 -0
  25. data/lib/HDLRuby/hdr_samples/rom.rb +5 -3
  26. data/lib/HDLRuby/hdr_samples/simple_counter_bench.rb +43 -0
  27. data/lib/HDLRuby/hdr_samples/with_values.rb +14 -0
  28. data/lib/HDLRuby/hdrcc.rb +84 -21
  29. data/lib/HDLRuby/hruby_bstr.rb +1175 -917
  30. data/lib/HDLRuby/hruby_high.rb +267 -97
  31. data/lib/HDLRuby/hruby_high_fullname.rb +82 -0
  32. data/lib/HDLRuby/hruby_low.rb +110 -71
  33. data/lib/HDLRuby/hruby_low2c.rb +7 -0
  34. data/lib/HDLRuby/hruby_low_mutable.rb +1 -1
  35. data/lib/HDLRuby/hruby_low_without_namespace.rb +2 -1
  36. data/lib/HDLRuby/hruby_rcsim.rb +978 -0
  37. data/lib/HDLRuby/hruby_rsim.rb +1134 -0
  38. data/lib/HDLRuby/hruby_rsim_vcd.rb +322 -0
  39. data/lib/HDLRuby/hruby_values.rb +362 -18
  40. data/lib/HDLRuby/hruby_verilog.rb +21 -3
  41. data/lib/HDLRuby/std/handshakes.rb +1 -1
  42. data/lib/HDLRuby/version.rb +1 -1
  43. metadata +25 -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
@@ -11,7 +11,10 @@ system :dff_bench do
11
11
  inner :d, :clk, :rst
12
12
  inner :q
13
13
 
14
- dff(:my_dff).(d,clk,rst,q)
14
+ # dff(:my_dff).(d,clk,rst,q)
15
+ dff(:my_dff).(d,clk)
16
+ q <= my_dff.q
17
+ my_dff.rst <= rst
15
18
 
16
19
  timed do
17
20
  clk <= 0
@@ -0,0 +1,76 @@
1
+ # A simple D-FF with overridable part.
2
+ system :dff do
3
+ input :d, :clk, :rst
4
+ output :q
5
+
6
+ sub(:process) do
7
+ (q <= d & ~rst).at(clk.posedge)
8
+ end
9
+ end
10
+
11
+ # A new dff overriding process.
12
+ system :dff_neg, dff do
13
+ sub(:process) do
14
+ (q <= d & ~rst).at(clk.negedge)
15
+ end
16
+ end
17
+
18
+ # A benchmark for the dff.
19
+ system :dff_bench do
20
+ inner :d, :clk, :rst
21
+ inner :q
22
+
23
+ dff_neg(:my_dff).(d,clk,rst,q)
24
+ # dff(:my_dff).(d,clk,rst,q)
25
+
26
+ timed do
27
+ clk <= 1
28
+ rst <= 0
29
+ d <= _z
30
+ !10.ns
31
+ clk <= 0
32
+ rst <= 0
33
+ d <= _z
34
+ !10.ns
35
+ clk <= 1
36
+ rst <= 1
37
+ d <= _z
38
+ !10.ns
39
+ clk <= 0
40
+ rst <= 1
41
+ d <= _z
42
+ !10.ns
43
+ clk <= 1
44
+ rst <= 0
45
+ d <= 1
46
+ !10.ns
47
+ clk <= 0
48
+ rst <= 0
49
+ d <= 1
50
+ !10.ns
51
+ clk <= 1
52
+ rst <= 0
53
+ d <= 1
54
+ !10.ns
55
+ clk <= 0
56
+ rst <= 0
57
+ d <= 1
58
+ !10.ns
59
+ clk <= 1
60
+ rst <= 0
61
+ d <= 0
62
+ !10.ns
63
+ clk <= 0
64
+ rst <= 0
65
+ d <= 0
66
+ !10.ns
67
+ clk <= 1
68
+ rst <= 0
69
+ d <= 0
70
+ !10.ns
71
+ clk <= 0
72
+ rst <= 0
73
+ d <= 0
74
+ !10.ns
75
+ end
76
+ end
@@ -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
@@ -37,6 +37,20 @@ system :with_values do
37
37
  v64 <= 128
38
38
  v96 <= 128
39
39
  !10.ns
40
+ v8 <= -1
41
+ v16 <= -1
42
+ v32 <= -1
43
+ v56 <= -1
44
+ v64 <= -1
45
+ v96 <= -1
46
+ !10.ns
47
+ v8 <= -2
48
+ v16 <= -2
49
+ v32 <= -2
50
+ v56 <= -2
51
+ v64 <= -2
52
+ v96 <= -2
53
+ !10.ns
40
54
  v16 <= 0x1000
41
55
  v32 <= 0x1000
42
56
  v56 <= 0x1000
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -36,6 +36,22 @@ if ARGV.include?("-I") || ARGV.include?("--interactive") then
36
36
  abort
37
37
  end
38
38
 
39
+
40
+ begin
41
+ # We can check the memory.
42
+ require 'get_process_mem'
43
+ $memory_check = GetProcessMem.new
44
+ def show_mem
45
+ " | "+$memory_check.bytes.to_s+"B"
46
+ end
47
+ rescue LoadError
48
+ # We cannot check the memory.
49
+ def show_mem
50
+ ""
51
+ end
52
+ end
53
+
54
+
39
55
  require 'fileutils'
40
56
  require 'tempfile'
41
57
  require 'HDLRuby'
@@ -67,6 +83,7 @@ require 'HDLRuby/backend/hruby_c_allocator'
67
83
 
68
84
  require 'HDLRuby/version.rb'
69
85
 
86
+
70
87
  ##
71
88
  # HDLRuby compiler interface program
72
89
  #####################################
@@ -346,10 +363,22 @@ $optparse = OptionParser.new do |opts|
346
363
  opts.on("--allocate=LOW,HIGH,WORD","Allocate signals to addresses") do |v|
347
364
  $options[:allocate] = v
348
365
  end
349
- 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|
350
371
  $options[:clang] = v
351
372
  $options[:multiple] = v
352
- $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
353
382
  end
354
383
  opts.on("--vcd", "The simulator will generate a vcd file") do |v|
355
384
  $options[:vcd] = v
@@ -525,7 +554,7 @@ if $options[:syntax] then
525
554
  $output << $loader.show_all
526
555
  exit
527
556
  end
528
- HDLRuby.show Time.now
557
+ HDLRuby.show "#{Time.now}#{show_mem}"
529
558
  HDLRuby.show "##### Starting parser #####"
530
559
 
531
560
  if $options[:debug] then
@@ -538,12 +567,12 @@ end
538
567
 
539
568
  # Generate the result.
540
569
  # Get the top systemT.
541
- HDLRuby.show Time.now
542
- $top_system = $top_instance.to_low.systemT
570
+ HDLRuby.show "#{Time.now}#{show_mem}"
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
543
573
  $top_intance = nil # Free as much memory as possible.
544
574
  HDLRuby.show "##### Top system built #####"
545
- HDLRuby.show Time.now
546
-
575
+ HDLRuby.show "#{Time.now}#{show_mem}"
547
576
 
548
577
  # # Apply the pre drivers if any.
549
578
  # Hdecorator.each_with_property(:pre_driver) do |obj, value|
@@ -613,19 +642,19 @@ elsif $options[:clang] then
613
642
  # Coverts the par blocks in seq blocks to seq blocks to match
614
643
  # the simulation engine.
615
644
  systemT.par_in_seq2seq!
616
- HDLRuby.show Time.now
645
+ HDLRuby.show "#{Time.now}#{show_mem}"
617
646
  HDLRuby.show "connections_to_behaviors step..."
618
647
  # Converts the connections to behaviors.
619
648
  systemT.connections_to_behaviors!
620
- HDLRuby.show Time.now
649
+ HDLRuby.show "#{Time.now}#{show_mem}"
621
650
  # Break the RefConcat.
622
651
  HDLRuby.show "concat_assigns step..."
623
652
  systemT.break_concat_assigns!
624
- HDLRuby.show Time.now
653
+ HDLRuby.show "#{Time.now}#{show_mem}"
625
654
  # Explicits the types.
626
655
  HDLRuby.show "explicit_types step..."
627
656
  systemT.explicit_types!
628
- HDLRuby.show Time.now
657
+ HDLRuby.show "#{Time.now}#{show_mem}"
629
658
  end
630
659
  # Generate the C.
631
660
  if $options[:multiple] then
@@ -729,11 +758,12 @@ elsif $options[:clang] then
729
758
  $output << HDLRuby::Low::Low2C.main(top_system,
730
759
  *top_system.each_systemT_deep.to_a)
731
760
  end
732
- if $options[:sim] then
761
+ if $options[:csim] then
733
762
  # Simulation mode, compile and exectute.
734
763
  # Path of the simulator core files.
735
- # simdir = File.dirname(__FILE__) + "/sim/"
736
- $simdir = $hdr_dir + "/sim/"
764
+ # $simdir = $hdr_dir + "sim/"
765
+ # puts "$hdr_dir=#{$hdr_dir}"
766
+ $simdir = $hdr_dir + "/../../ext/hruby_sim/"
737
767
  # Generate and execute the simulation commands.
738
768
  # Kernel.system("cp -n #{simdir}* #{$output}/; cd #{$output}/ ; make -s ; ./hruby_simulator")
739
769
  Dir.entries($simdir).each do |filename|
@@ -768,23 +798,23 @@ elsif $options[:verilog] then
768
798
  # HDLRuby.show Time.now
769
799
  HDLRuby.show "to_upper_space! step..."
770
800
  systemT.to_upper_space!
771
- HDLRuby.show Time.now
801
+ HDLRuby.show "#{Time.now}#{show_mem}"
772
802
  end
773
803
  HDLRuby.show "to_global_space! step (global)..."
774
804
  $top_system.to_global_systemTs!
775
- HDLRuby.show Time.now
805
+ HDLRuby.show "#{Time.now}#{show_mem}"
776
806
  $top_system.each_systemT_deep do |systemT|
777
807
  ## systemT.break_types!
778
808
  ## systemT.expand_types!
779
809
  HDLRuby.show "par_in_seq2seq! step..."
780
810
  systemT.par_in_seq2seq!
781
- HDLRuby.show Time.now
811
+ HDLRuby.show "#{Time.now}#{show_mem}"
782
812
  HDLRuby.show "initial_concat_to_timed! step..."
783
813
  systemT.initial_concat_to_timed!
784
- HDLRuby.show Time.now
814
+ HDLRuby.show "#{Time.now}#{show_mem}"
785
815
  HDLRuby.show "with_port! step..."
786
816
  systemT.with_port!
787
- HDLRuby.show Time.now
817
+ HDLRuby.show "#{Time.now}#{show_mem}"
788
818
  end
789
819
  # # Verilog generation
790
820
  # $output << top_system.to_verilog
@@ -809,7 +839,8 @@ elsif $options[:verilog] then
809
839
  # Open the file for current systemT
810
840
  outfile = File.open($name,"w")
811
841
  # Generate the Verilog code in to.
812
- outfile << systemT.to_verilog
842
+ # outfile << systemT.to_verilog
843
+ outfile << systemT.to_verilog($options[:vcd])
813
844
  # Close the file.
814
845
  outfile.close
815
846
  # Clears the name.
@@ -821,6 +852,38 @@ elsif $options[:verilog] then
821
852
  $output << systemT.to_verilog
822
853
  end
823
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}"
824
887
  elsif $options[:vhdl] then
825
888
  # top_system = $top_instance.to_low.systemT
826
889
  # top_system = $top_system
@@ -875,7 +938,7 @@ elsif $options[:vhdl] then
875
938
  end
876
939
 
877
940
  HDLRuby.show "##### Code generated #####"
878
- HDLRuby.show Time.now
941
+ HDLRuby.show "#{Time.now}#{show_mem}"
879
942
 
880
943
  # # Apply the post drivers if any.
881
944
  # Hdecorator.each_with_property(:post_driver) do |obj, value|