HDLRuby 2.10.3 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
@@ -0,0 +1,82 @@
1
+ require "HDLRuby/hruby_high"
2
+
3
+
4
+
5
+ module HDLRuby::High
6
+
7
+ ##
8
+ # Library for describing adding the fullname method to HDLRuby::High objects.
9
+ #
10
+ ########################################################################
11
+
12
+ class SystemT
13
+
14
+ ## Returns the name of the signal with its hierarchy.
15
+ def fullname
16
+ @fullname ||= (self.parent ? self.parent.fullname + ":" : "") +
17
+ self.name.to_s
18
+ return @fullname
19
+ end
20
+ end
21
+
22
+
23
+ ##
24
+ # Module for extending named classes with fullname (other than SystemT).
25
+ module WithFullname
26
+
27
+ ## Returns the name of the signal with its hierarchy.
28
+ def fullname
29
+ @fullname ||= self.parent.fullname + ":" + self.name.to_s
30
+ return @fullname
31
+ end
32
+
33
+ end
34
+
35
+ class Scope
36
+ include WithFullname
37
+ end
38
+
39
+
40
+ class Behavior
41
+
42
+ ## Returns the name of the signal with its hierarchy.
43
+ def fullname
44
+ return self.parent.fullname
45
+ end
46
+ end
47
+
48
+
49
+ class TimeBehavior
50
+
51
+ ## Returns the name of the signal with its hierarchy.
52
+ def fullname
53
+ return self.parent.fullname
54
+ end
55
+ end
56
+
57
+
58
+ class SignalI
59
+ include WithFullname
60
+ end
61
+
62
+ class SignalC
63
+ include WithFullname
64
+ end
65
+
66
+ class SystemI
67
+ include WithFullname
68
+ end
69
+
70
+ class Code
71
+ # TODO
72
+ end
73
+
74
+ class Block
75
+ include WithFullname
76
+ end
77
+
78
+ class TimeBlock
79
+ include WithFullname
80
+ end
81
+
82
+ end
@@ -57,6 +57,11 @@ module HDLRuby::Low
57
57
  end
58
58
  end
59
59
 
60
+ # Clears the parent.
61
+ def no_parent!
62
+ @parent = nil
63
+ end
64
+
60
65
  # Get the parent scope.
61
66
  def scope
62
67
  cur = self.parent
@@ -190,14 +195,22 @@ module HDLRuby::Low
190
195
  raise AnyError,
191
196
  "Invalid class for a signal instance: #{signal.class}"
192
197
  end
198
+ # if @inputs.include?(signal) then
199
+ # raise AnyError, "SignalI #{signal.name} already present."
200
+ # end
193
201
  if @inputs.include?(signal) then
194
- raise AnyError, "SignalI #{signal.name} already present."
202
+ signal.parent = self
203
+ # Replace the signal.
204
+ old_signal = @inputs[signal.name]
205
+ @inputs.add(signal)
206
+ @interface[@interface.index(old_signal)] = signal
207
+ else
208
+ # Set the parent of the signal.
209
+ signal.parent = self
210
+ # And add the signal.
211
+ @inputs.add(signal)
212
+ @interface << signal
195
213
  end
196
- # Set the parent of the signal.
197
- signal.parent = self
198
- # And add the signal.
199
- @inputs.add(signal)
200
- @interface << signal
201
214
  return signal
202
215
  end
203
216
 
@@ -208,14 +221,22 @@ module HDLRuby::Low
208
221
  raise AnyError,
209
222
  "Invalid class for a signal instance: #{signal.class}"
210
223
  end
224
+ # if @outputs.include?(signal) then
225
+ # raise AnyError, "SignalI #{signal.name} already present."
226
+ # end
211
227
  if @outputs.include?(signal) then
212
- raise AnyError, "SignalI #{signal.name} already present."
228
+ signal.parent = self
229
+ # Replace the signal.
230
+ old_signal = @outputs[signal.name]
231
+ @outputs.add(signal)
232
+ @interface[@interface.index(old_signal)] = signal
233
+ else
234
+ # Set the parent of the signal.
235
+ signal.parent = self
236
+ # And add the signal.
237
+ @outputs.add(signal)
238
+ @interface << signal
213
239
  end
214
- # Set the parent of the signal.
215
- signal.parent = self
216
- # And add the signal.
217
- @outputs.add(signal)
218
- @interface << signal
219
240
  return signal
220
241
  end
221
242
 
@@ -226,14 +247,22 @@ module HDLRuby::Low
226
247
  raise AnyError,
227
248
  "Invalid class for a signal instance: #{signal.class}"
228
249
  end
250
+ # if @inouts.include?(signal) then
251
+ # raise AnyError, "SignalI #{signal.name} already present."
252
+ # end
229
253
  if @inouts.include?(signal) then
230
- raise AnyError, "SignalI #{signal.name} already present."
254
+ signal.parent = self
255
+ # Replace the signal.
256
+ old_signal = @inouts[signal.name]
257
+ @inouts.add(signal)
258
+ @interface[@interface.index(old_signal)] = signal
259
+ else
260
+ # Set the parent of the signal.
261
+ signal.parent = self
262
+ # And add the signal.
263
+ @inouts.add(signal)
264
+ @interface << signal
231
265
  end
232
- # Set the parent of the signal.
233
- signal.parent = self
234
- # And add the signal.
235
- @inouts.add(signal)
236
- @interface << signal
237
266
  return signal
238
267
  end
239
268
 
@@ -571,9 +600,9 @@ module HDLRuby::Low
571
600
  raise AnyError,
572
601
  "Invalid class for a system type: #{systemT.class}"
573
602
  end
574
- if @systemTs.include?(systemT) then
575
- raise AnyError, "SystemT #{systemT.name} already present."
576
- end
603
+ # if @systemTs.include?(systemT) then
604
+ # raise AnyError, "SystemT #{systemT.name} already present."
605
+ # end
577
606
  # Set the parent of the instance
578
607
  systemT.parent = self
579
608
  # puts "systemT = #{systemT}, parent=#{self}"
@@ -623,9 +652,9 @@ module HDLRuby::Low
623
652
  raise AnyError,
624
653
  "Invalid class for a type: #{type.class}"
625
654
  end
626
- if @types.include?(type) then
627
- raise AnyError, "Type #{type.name} already present."
628
- end
655
+ # if @types.include?(type) then
656
+ # raise AnyError, "Type #{type.name} already present."
657
+ # end
629
658
  # Set the parent of the instance
630
659
  type.parent = self
631
660
  # puts "type = #{type}, parent=#{self}"
@@ -676,12 +705,14 @@ module HDLRuby::Low
676
705
  raise AnyError,
677
706
  "Invalid class for a system instance: #{scope.class}"
678
707
  end
679
- if @scopes.include?(scope) then
680
- raise AnyError, "Scope #{scope} already present."
681
- end
708
+ # if @scopes.include?(scope) then
709
+ # raise AnyError, "Scope #{scope} already present."
710
+ # end
682
711
  # Set the parent of the scope
683
712
  scope.parent = self
684
- # Add the instance
713
+ # Remove a former scope with same name if present (override)
714
+ @scopes.delete_if { |sc| sc.name && sc.name == scope.name }
715
+ # Add the scope
685
716
  @scopes << scope
686
717
  end
687
718
 
@@ -732,9 +763,9 @@ module HDLRuby::Low
732
763
  raise AnyError,
733
764
  "Invalid class for a system instance: #{systemI.class}"
734
765
  end
735
- if @systemIs.include?(systemI) then
736
- raise AnyError, "SystemI #{systemI.name} already present."
737
- end
766
+ # if @systemIs.include?(systemI) then
767
+ # raise AnyError, "SystemI #{systemI.name} already present."
768
+ # end
738
769
  # Set the parent of the instance
739
770
  systemI.parent = self
740
771
  # puts "systemI = #{systemI}, parent=#{self}"
@@ -783,9 +814,9 @@ module HDLRuby::Low
783
814
  raise AnyError,
784
815
  "Invalid class for a non-hDLRuby code chunk: #{code.class}"
785
816
  end
786
- if @codes.include?(code) then
787
- raise AnyError, "Code #{code.name} already present."
788
- end
817
+ # if @codes.include?(code) then
818
+ # raise AnyError, "Code #{code.name} already present."
819
+ # end
789
820
  # Set the parent of the code chunk.
790
821
  code.parent = self
791
822
  # puts "code = #{code}, parent=#{self}"
@@ -824,11 +855,9 @@ module HDLRuby::Low
824
855
  raise AnyError,
825
856
  "Invalid class for a signal instance: #{signal.class}"
826
857
  end
827
- # if @inners.has_key?(signal.name) then
828
- if @inners.include?(signal) then
829
- raise AnyError, "SignalI #{signal.name} already present."
830
- end
831
- # @inners[signal.name] = signal
858
+ # if @inners.include?(signal) then
859
+ # raise AnyError, "SignalI #{signal.name} already present."
860
+ # end
832
861
  # Set the parent of the signal.
833
862
  signal.parent = self
834
863
  # And add the signal.
@@ -1432,6 +1461,10 @@ module HDLRuby::Low
1432
1461
  # The bit type leaf.
1433
1462
  class << ( Bit = Type.new(:bit) )
1434
1463
  include LLeaf
1464
+ # Tells if the type is unsigned.
1465
+ def unsigned?
1466
+ return true
1467
+ end
1435
1468
  # Tells if the type fixed point.
1436
1469
  def fixed?
1437
1470
  return true
@@ -1573,10 +1606,11 @@ module HDLRuby::Low
1573
1606
 
1574
1607
  # Comparison for hash: structural comparison.
1575
1608
  def eql?(obj)
1576
- # General type comparison.
1577
- return false unless super(obj)
1609
+ # # General type comparison.
1610
+ # return false unless super(obj)
1578
1611
  # Specific comparison.
1579
1612
  return false unless obj.is_a?(TypeDef)
1613
+ return false unless @name.eql?(obj.name)
1580
1614
  return false unless @def.eql?(obj.def)
1581
1615
  return true
1582
1616
  end
@@ -1651,8 +1685,8 @@ module HDLRuby::Low
1651
1685
 
1652
1686
  # Comparison for hash: structural comparison.
1653
1687
  def eql?(obj)
1654
- # General type comparison.
1655
- return false unless super(obj)
1688
+ # # General type comparison.
1689
+ # return false unless super(obj)
1656
1690
  # Specific comparison.
1657
1691
  return false unless obj.is_a?(TypeVector)
1658
1692
  return false unless @base.eql?(obj.base)
@@ -1843,8 +1877,9 @@ module HDLRuby::Low
1843
1877
 
1844
1878
  # Comparison for hash: structural comparison.
1845
1879
  def eql?(obj)
1846
- # General type comparison.
1847
- return false unless super(obj)
1880
+ # # General type comparison.
1881
+ # return false unless super(obj)
1882
+ return false unless obj.is_a?(TypeTuple)
1848
1883
  # Specific comparison.
1849
1884
  idx = 0
1850
1885
  obj.each_type do |type|
@@ -2499,18 +2534,18 @@ module HDLRuby::Low
2499
2534
  self.value.each_deep(&ruby_block) if self.value
2500
2535
  end
2501
2536
 
2502
- # Comparison for hash: structural comparison.
2503
- def eql?(obj)
2504
- return false unless obj.is_a?(SignalI)
2505
- return false unless @name.eql?(obj.name)
2506
- return false unless @type.eql?(obj.type)
2507
- return true
2508
- end
2537
+ # # Comparison for hash: structural comparison.
2538
+ # def eql?(obj)
2539
+ # return false unless obj.is_a?(SignalI)
2540
+ # return false unless @name.eql?(obj.name)
2541
+ # return false unless @type.eql?(obj.type)
2542
+ # return true
2543
+ # end
2509
2544
 
2510
- # Hash function.
2511
- def hash
2512
- return [@name,@type].hash
2513
- end
2545
+ # # Hash function.
2546
+ # def hash
2547
+ # return [@name,@type].hash
2548
+ # end
2514
2549
 
2515
2550
  # Gets the bit width.
2516
2551
  def width
@@ -2761,10 +2796,9 @@ module HDLRuby::Low
2761
2796
  raise AnyError,
2762
2797
  "Invalid class for a code chunk: #{chunk.class}"
2763
2798
  end
2764
- # if @chunks.has_key?(chunk.name) then
2765
- if @chunks.include?(chunk) then
2766
- raise AnyError, "Code chunk #{chunk.name} already present."
2767
- end
2799
+ # if @chunks.include?(chunk) then
2800
+ # raise AnyError, "Code chunk #{chunk.name} already present."
2801
+ # end
2768
2802
  # Set its parent.
2769
2803
  chunk.parent = self
2770
2804
  # And add it
@@ -4269,11 +4303,9 @@ module HDLRuby::Low
4269
4303
  raise AnyError,
4270
4304
  "Invalid class for a signal instance: #{signal.class}"
4271
4305
  end
4272
- # if @inners.has_key?(signal.name) then
4273
- if @inners.include?(signal) then
4274
- raise AnyError, "SignalI #{signal.name} already present."
4275
- end
4276
- # @inners[signal.name] = signal
4306
+ # if @inners.include?(signal) then
4307
+ # raise AnyError, "SignalI #{signal.name} already present."
4308
+ # end
4277
4309
  # Set its parent.
4278
4310
  signal.parent = self
4279
4311
  # And add it
@@ -4573,7 +4605,8 @@ module HDLRuby::Low
4573
4605
  # Yes so it is also a left value if it is a sub ref.
4574
4606
  if parent.respond_to?(:ref) then
4575
4607
  # It might nor be a sub ref.
4576
- return parent.ref == self
4608
+ # return parent.ref == self
4609
+ return parent.ref.eql?(self)
4577
4610
  else
4578
4611
  # It is necessarily a sub ref (case of RefConcat for now).
4579
4612
  return true
@@ -4581,7 +4614,8 @@ module HDLRuby::Low
4581
4614
  end
4582
4615
  # No, therefore maybe it is directly a left value.
4583
4616
  return (parent.is_a?(Transmit) || parent.is_a?(Connection)) &&
4584
- parent.left == self
4617
+ # parent.left == self
4618
+ parent.left.eql?(self)
4585
4619
  end
4586
4620
 
4587
4621
  # Tells if the expression is a right value.
@@ -4655,12 +4689,16 @@ module HDLRuby::Low
4655
4689
  # Creates a new value typed +type+ and containing +content+.
4656
4690
  def initialize(type,content)
4657
4691
  super(type)
4658
- unless content then
4692
+ if content.nil? then
4659
4693
  # Handle the nil content case.
4660
4694
  unless type.eql?(Void) then
4661
4695
  raise AnyError, "A value with nil content must have the Void type."
4662
4696
  end
4663
4697
  @content = content
4698
+ elsif content.is_a?(FalseClass) then
4699
+ @content = 0
4700
+ elsif content.is_a?(TrueClass) then
4701
+ @content = 1
4664
4702
  else
4665
4703
  # Checks and set the content: Ruby Numeric and HDLRuby
4666
4704
  # BitString are supported. Strings or equivalent are
@@ -4697,8 +4735,8 @@ module HDLRuby::Low
4697
4735
 
4698
4736
  # Comparison for hash: structural comparison.
4699
4737
  def eql?(obj)
4700
- # General comparison.
4701
- return false unless super(obj)
4738
+ # # General comparison.
4739
+ # return false unless super(obj)
4702
4740
  # Specific comparison.
4703
4741
  return false unless obj.is_a?(Value)
4704
4742
  return false unless @content.eql?(obj.content)
@@ -5097,7 +5135,7 @@ module HDLRuby::Low
5097
5135
 
5098
5136
 
5099
5137
  ##
5100
- # Describes a section operation (generalization of the ternary operator).
5138
+ # Describes a selection operation (generalization of the ternary operator).
5101
5139
  #
5102
5140
  # NOTE: choice is using the value of +select+ as an index.
5103
5141
  class Select < Operation
@@ -5263,6 +5301,7 @@ module HDLRuby::Low
5263
5301
  # def initialize(expressions = [])
5264
5302
  def initialize(type,expressions = [])
5265
5303
  super(type)
5304
+ # puts "Building concat=#{self} with direction=#{type.direction}\n"
5266
5305
  # Initialize the array of expressions that are concatenated.
5267
5306
  @expressions = []
5268
5307
  # Check and add the expressions.
@@ -709,6 +709,10 @@ module HDLRuby::Low
709
709
  # Tells if the behavior is timed or not.
710
710
  res << " " * (level+1)*3
711
711
  res << "behavior->timed = #{time ? 1 : 0};\n"
712
+
713
+ # Set the active time to 0.
714
+ res << " " * (level+1)*3
715
+ res << "behavior->active_time = 0;\n"
712
716
 
713
717
  # Is it a clocked behavior?
714
718
  events = self.each_event.to_a
@@ -858,6 +862,7 @@ module HDLRuby::Low
858
862
  # +level+ is the hierachical level of the object.
859
863
  # def to_c(level = 0)
860
864
  def to_c(res,level = 0)
865
+
861
866
  # puts "Signal.to_c with name: #{Low2C.obj_name(self)}"
862
867
  # Declare the global variable holding the signal.
863
868
  res << "SignalI "
@@ -2546,6 +2551,7 @@ module HDLRuby::Low
2546
2551
  # Generates the C text for the equivalent HDLRuby code.
2547
2552
  # +level+ is the hierachical level of the object.
2548
2553
  def to_c(res,level = 0)
2554
+ # puts "to_c fo concat=#{self} with type=#{self.type} and direction=#{self.type.direction}"
2549
2555
  # Save the value pool state.
2550
2556
  res << (" " * (level*3)) << "PV;\n"
2551
2557
  # Gather the content to concat.
@@ -2556,6 +2562,7 @@ module HDLRuby::Low
2556
2562
  end
2557
2563
  # Compute the resulting concatenation.
2558
2564
  res << (" " * ((level+1)*3))
2565
+ # puts "self.type.direction=#{self.type.direction}\n"
2559
2566
  res << "sconcat(#{expressions.size},"
2560
2567
  res << (self.type.direction == :little ? "1" : "0")
2561
2568
  res << ");\n"
@@ -222,7 +222,7 @@ module HDLRuby::Low
222
222
  end
223
223
 
224
224
  # Deletes all the connections.
225
- def delete_all_conncetions!
225
+ def delete_all_connections!
226
226
  @connections.each { |cnx| cnx.parent = nil }
227
227
  @connections = []
228
228
  end
@@ -147,7 +147,8 @@ module HDLRuby::Low
147
147
  cnxs = self.each_connection.to_a
148
148
  # Remove them from the scope.
149
149
  # cnxs.each { |cnx| self.delete_connection!(cnx) }
150
- cnxs.delete_all_connections!
150
+ # cnxs.delete_all_connections!
151
+ self.delete_all_connections!
151
152
  # Return the connections.
152
153
  return cnxs
153
154
  end