HDLRuby 2.3.7 → 2.4.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,13 +32,17 @@ module HDLRuby
32
32
  # and negative when "1".
33
33
  # * when not present it is assumed to be within str.
34
34
  def initialize(str,sign = nil)
35
+ # puts "str=#{str}"
35
36
  # Maybe str is an numeric.
36
37
  if str.is_a?(Numeric) then
37
38
  # Yes, convert it to a binary string.
38
- str = str.to_s(2)
39
+ num = str
40
+ str = num.to_s(2)
39
41
  # And fix the sign.
40
42
  if str[0] == "-" then
41
- str = str[1..-1]
43
+ # str = str[1..-1]
44
+ str = (2**str.size+num).to_s(2)
45
+ puts "str=#{str}"
42
46
  sign = "-"
43
47
  else
44
48
  sign = "+"
@@ -71,6 +75,7 @@ module HDLRuby
71
75
  end.reverse.join
72
76
  end
73
77
  @str += str.to_s.downcase
78
+ # puts "@str=#{@str}"
74
79
  unless @str.match(/^[0-1zx]+$/) then
75
80
  raise "Invalid value for creating a bit string: #{str}"
76
81
  end
@@ -2791,6 +2791,14 @@ module HDLRuby::High
2791
2791
  return RefObject.new(@base,@object)
2792
2792
  end
2793
2793
 
2794
+ # Comparison for hash: structural comparison.
2795
+ def eql?(obj)
2796
+ return false unless obj.is_a?(RefObject)
2797
+ return false unless @base.eql?(obj.base)
2798
+ return false unless @object.eql?(obj.object)
2799
+ return true
2800
+ end
2801
+
2794
2802
  # Converts the name reference to a HDLRuby::Low::RefName.
2795
2803
  def to_low
2796
2804
  # return HDLRuby::Low::RefName.new(@base.to_ref.to_low,@object.name)
@@ -1978,14 +1978,6 @@ module HDLRuby::Low
1978
1978
 
1979
1979
  include Hparent
1980
1980
 
1981
- # # Creates a new behavior.
1982
- # def initialize
1983
- # # Initialize the sensitivity list.
1984
- # @events = []
1985
- # # Initialize the block list.
1986
- # @blocks = []
1987
- # end
1988
-
1989
1981
  # The block executed by the behavior.
1990
1982
  attr_reader :block
1991
1983
 
@@ -2074,6 +2066,11 @@ module HDLRuby::Low
2074
2066
  return !@events.empty?
2075
2067
  end
2076
2068
 
2069
+ # Tells if it is activated on one of +events+.
2070
+ def on_event?(*events)
2071
+ @events.any? { |ev0| events.any? { |ev1| ev0.eql?(ev1) } }
2072
+ end
2073
+
2077
2074
  # Tells if there is a positive or negative edge event.
2078
2075
  def on_edge?
2079
2076
  @events.each do |event|
@@ -2619,6 +2616,15 @@ module HDLRuby::Low
2619
2616
  end
2620
2617
  end
2621
2618
 
2619
+ # Gets the behavior the statement is in.
2620
+ def behavior
2621
+ if self.parent.is_a?(Behavior) then
2622
+ return self.parent
2623
+ else
2624
+ return self.parent.behavior
2625
+ end
2626
+ end
2627
+
2622
2628
  # Gets the top block, i.e. the first block of the current behavior.
2623
2629
  def top_block
2624
2630
  return self.parent.is_a?(Behavior) ? self : self.parent.top_block
@@ -2633,6 +2639,11 @@ module HDLRuby::Low
2633
2639
  def parent_system
2634
2640
  return self.top_scope.parent
2635
2641
  end
2642
+
2643
+ # Tell if the statement includes a signal whose name is one of +names+.
2644
+ def use_name?(*names)
2645
+ # By default, nothing to do.
2646
+ end
2636
2647
  end
2637
2648
 
2638
2649
 
@@ -2747,6 +2758,11 @@ module HDLRuby::Low
2747
2758
  # A ruby block?
2748
2759
  # Nothing to do.
2749
2760
  end
2761
+
2762
+ # Tell if the statement includes a signal whose name is one of +names+.
2763
+ def use_name?(*names)
2764
+ return @left.use_name?(*names) || @right.use_name?(*names)
2765
+ end
2750
2766
  end
2751
2767
 
2752
2768
 
@@ -2925,6 +2941,12 @@ module HDLRuby::Low
2925
2941
  @no.each_block_deep(&ruby_block) if @no
2926
2942
  end
2927
2943
 
2944
+ # Tell if the statement includes a signal whose name is one of +names+.
2945
+ # NOTE: for the if check only the condition.
2946
+ def use_name?(*names)
2947
+ return @condition.use_name?(*name)
2948
+ end
2949
+
2928
2950
  # Clones the If (deeply)
2929
2951
  def clone
2930
2952
  # Duplicate the if.
@@ -3038,6 +3060,12 @@ module HDLRuby::Low
3038
3060
  def top_block
3039
3061
  return self.parent.is_a?(Behavior) ? self : self.parent.top_block
3040
3062
  end
3063
+
3064
+ # Tell if the statement includes a signal whose name is one of +names+.
3065
+ # NOTE: for the when check only the match.
3066
+ def use_name?(*names)
3067
+ return @match.use_name?(*name)
3068
+ end
3041
3069
  end
3042
3070
 
3043
3071
 
@@ -3186,6 +3214,12 @@ module HDLRuby::Low
3186
3214
  @default.each_statement_deep(&ruby_block) if @default
3187
3215
  end
3188
3216
 
3217
+ # Tell if the statement includes a signal whose name is one of +names+.
3218
+ # NOTE: for the case check only the value.
3219
+ def use_name?(*names)
3220
+ return @value.use_name?(*name)
3221
+ end
3222
+
3189
3223
  # Clones the Case (deeply)
3190
3224
  def clone
3191
3225
  # Clone the default if any.
@@ -3838,6 +3872,12 @@ module HDLRuby::Low
3838
3872
  end
3839
3873
  end
3840
3874
 
3875
+ # Tell if the expression includes a signal whose name is one of +names+.
3876
+ def use_name?(*names)
3877
+ # By default nothing.
3878
+ return false
3879
+ end
3880
+
3841
3881
  # Clones the expression (deeply)
3842
3882
  def clone
3843
3883
  raise AnyError,
@@ -3991,6 +4031,12 @@ module HDLRuby::Low
3991
4031
  @child.each_ref_deep(&ruby_block)
3992
4032
  end
3993
4033
 
4034
+ # Tell if the expression includes a signal whose name is one of +names+.
4035
+ def use_name?(*names)
4036
+ # Recurse on the child.
4037
+ return @child.use_name?(*names)
4038
+ end
4039
+
3994
4040
  # Clones the value (deeply)
3995
4041
  def clone
3996
4042
  return Cast.new(@type,@child.clone)
@@ -4101,6 +4147,12 @@ module HDLRuby::Low
4101
4147
  @child.each_ref_deep(&ruby_block)
4102
4148
  end
4103
4149
 
4150
+ # Tell if the expression includes a signal whose name is one of +names+.
4151
+ def use_name?(*names)
4152
+ # Recurse on the child.
4153
+ return @child.use_name?(*names)
4154
+ end
4155
+
4104
4156
  # Clones the unary operator (deeply)
4105
4157
  def clone
4106
4158
  return Unary.new(@type,self.operator,@child.clone)
@@ -4187,6 +4239,12 @@ module HDLRuby::Low
4187
4239
  @right.each_ref_deep(&ruby_block)
4188
4240
  end
4189
4241
 
4242
+ # Tell if the expression includes a signal whose name is one of +names+.
4243
+ def use_name?(*names)
4244
+ # Recurse on the left and the right.
4245
+ return @left.use_name?(*names) || @right.use_name?(*names)
4246
+ end
4247
+
4190
4248
  # Clones the binary operator (deeply)
4191
4249
  def clone
4192
4250
  return Binary.new(@type, self.operator,
@@ -4311,6 +4369,14 @@ module HDLRuby::Low
4311
4369
  end
4312
4370
  end
4313
4371
 
4372
+ # Tell if the expression includes a signal whose name is one of +names+.
4373
+ def use_name?(*names)
4374
+ # Recurse on the select.
4375
+ return true if @select.use_name?(*names)
4376
+ # Recurse on the choices.
4377
+ return @choices.any? { |choice| choice.use_name?(*names) }
4378
+ end
4379
+
4314
4380
  # Clones the select (deeply)
4315
4381
  def clone
4316
4382
  return Select.new(@type, self.operator, @select.clone,
@@ -4390,6 +4456,12 @@ module HDLRuby::Low
4390
4456
  end
4391
4457
  end
4392
4458
 
4459
+ # Tell if the expression includes a signal whose name is one of +names+.
4460
+ def use_name?(*names)
4461
+ # Recurse on the expressions.
4462
+ return @expressions.any? { |expr| expr.use_name?(*names) }
4463
+ end
4464
+
4393
4465
  # Clones the concatenated expression (deeply)
4394
4466
  def clone
4395
4467
  return Concat.new(@type,
@@ -4532,6 +4604,12 @@ module HDLRuby::Low
4532
4604
  end
4533
4605
  end
4534
4606
 
4607
+ # Tell if the expression includes a signal whose name is one of +names+.
4608
+ def use_name?(*names)
4609
+ # Recurse on the references.
4610
+ return @refs.any? { |expr| expr.use_name?(*names) }
4611
+ end
4612
+
4535
4613
  # Clones the concatenated references (deeply)
4536
4614
  def clone
4537
4615
  return RefConcat.new(@type, @refs.map { |ref| ref.clone } )
@@ -4615,6 +4693,12 @@ module HDLRuby::Low
4615
4693
  @ref.each_node_deep(&ruby_block)
4616
4694
  end
4617
4695
 
4696
+ # Tell if the expression includes a signal whose name is one of +names+.
4697
+ def use_name?(*names)
4698
+ # Recurse on the index and the reference.
4699
+ return @index.use_name?(names) || @ref.use_name?(*names)
4700
+ end
4701
+
4618
4702
  # Clones the indexed references (deeply)
4619
4703
  def clone
4620
4704
  return RefIndex.new(@type, @ref.clone, @index.clone)
@@ -4710,6 +4794,13 @@ module HDLRuby::Low
4710
4794
  @ref.each_node_deep(&ruby_block)
4711
4795
  end
4712
4796
 
4797
+ # Tell if the expression includes a signal whose name is one of +names+.
4798
+ def use_name?(*names)
4799
+ # Recurse on the range and the reference.
4800
+ return @range.first.use_name?(names) ||
4801
+ @range.last.use_name?(names) || @ref.use_name?(*names)
4802
+ end
4803
+
4713
4804
  # Clones the range references (deeply)
4714
4805
  def clone
4715
4806
  return RefRange.new(@type, @ref.clone,
@@ -4797,6 +4888,14 @@ module HDLRuby::Low
4797
4888
  @ref.each_node_deep(&ruby_block)
4798
4889
  end
4799
4890
 
4891
+ # Tell if the expression includes a signal whose name is one of +names+.
4892
+ def use_name?(*names)
4893
+ # Is the named used here?
4894
+ return true if names.include?(@name)
4895
+ # No, recurse the reference.
4896
+ return @ref.use_name?(*names)
4897
+ end
4898
+
4800
4899
  # Clones the name references (deeply)
4801
4900
  def clone
4802
4901
  return RefName.new(@type, @ref.clone, @name)
@@ -106,13 +106,15 @@ module HDLRuby::Low
106
106
 
107
107
  ## Generates the main for making the objects of +objs+ and
108
108
  # for starting the simulation and including the files from +hnames+
109
- def self.main(top,objs,hnames)
109
+ def self.main(name,init_visualizer,top,objs,hnames)
110
110
  res = Low2C.includes(*hnames)
111
111
  res << "int main(int argc, char* argv[]) {\n"
112
112
  # Build the objects.
113
113
  objs.each { |obj| res << " #{Low2C.make_name(obj)}();\n" }
114
+ # Sets the top systemT.
115
+ res << " top_system = #{Low2C.obj_name(top)};\n"
114
116
  # Starts the simulation.
115
- res << " hruby_sim_core(-1);\n"
117
+ res<< " hruby_sim_core(\"#{name}\",#{init_visualizer},-1);\n"
116
118
  # Close the main.
117
119
  res << "}\n"
118
120
  return res
@@ -1329,6 +1331,10 @@ module HDLRuby::Low
1329
1331
  res << "block->owner = NULL;\n"
1330
1332
  end
1331
1333
 
1334
+ # The name
1335
+ res << " " * (level+1)*3
1336
+ res << "block->name = \"#{self.name}\";\n"
1337
+
1332
1338
  # Add the inner signals declaration.
1333
1339
  res << " " * (level+1)*3
1334
1340
  res << "block->num_inners = #{self.each_inner.to_a.size};\n"
@@ -1439,8 +1445,18 @@ module HDLRuby::Low
1439
1445
  str = self.content.is_a?(BitString) ?
1440
1446
  self.content.to_s : self.content.to_s(2).rjust(32,"0")
1441
1447
  else
1442
- sign = self.content>=0 ? "0" : "1"
1443
- str = self.content.abs.to_s(2).rjust(width,sign).upcase
1448
+ # sign = self.content>=0 ? "0" : "1"
1449
+ # str = self.content.abs.to_s(2).rjust(width,sign).upcase
1450
+ if self.content >= 0 then
1451
+ str = self.content.to_s(2).rjust(width,"0").upcase
1452
+ else
1453
+ # Compute the extension to the next multiple
1454
+ # of int_width
1455
+ ext_width = (((width-1) / Low2C.int_width)+1)*Low2C.int_width
1456
+ # Convert the string.
1457
+ str = (2**ext_width+self.content).to_s(2).upcase
1458
+ end
1459
+ # puts "content=#{self.content} str=#{str}"
1444
1460
  end
1445
1461
  # Is it a fully defined number?
1446
1462
  if str =~ /^[01]+$/ then
@@ -1453,13 +1469,14 @@ module HDLRuby::Low
1453
1469
  res << " };\n"
1454
1470
  # Create the value.
1455
1471
  res << " " * (level+1)*3
1456
- # puts "str=#{str} type width=#{self.type.width}"
1472
+ # puts "str=#{str} type width=#{self.type.width} signed? #{type.signed?}"
1457
1473
  res << "return make_set_value(#{self.type.to_c(level+1)},1," +
1458
1474
  "data);\n"
1459
1475
  else
1460
1476
  # No, generate a bit string value.
1461
1477
  res << " " * (level+1)*3
1462
- res << "static unsigned char data[] = \"#{str}\";\n"
1478
+ # res << "static unsigned char data[] = \"#{str}\";\n"
1479
+ res << "static unsigned char data[] = \"#{str.reverse}\";\n"
1463
1480
  # Create the value.
1464
1481
  res << " " * (level+1)*3
1465
1482
  res << "return make_set_value(#{self.type.to_c(level+1)},0," +
@@ -1612,7 +1629,9 @@ module HDLRuby::Low
1612
1629
  # return "equal_value(#{self.left.to_c(level)}," +
1613
1630
  # "#{self.right.to_c(level)})"
1614
1631
  # when :!= then
1615
- # return "not_equal_value(#{self.left.to_c(level)}," +
1632
+ # # return "not_equal_value(#{self.left.to_c(level)}," +
1633
+ # # "#{self.right.to_c(level)})"
1634
+ # return "xor_value(#{self.left.to_c(level)}," +
1616
1635
  # "#{self.right.to_c(level)})"
1617
1636
  # when :> then
1618
1637
  # return "greater_value(#{self.left.to_c(level)}," +
@@ -1681,9 +1700,12 @@ module HDLRuby::Low
1681
1700
  when :rr then
1682
1701
  res += "dst = rotate_right_value(src0,src1,dst);\n"
1683
1702
  when :== then
1684
- res += "dst = equal_value(src0,src1,dst);\n"
1703
+ res += "dst = equal_value(src0,src1,dst);\n" +
1704
+ "dst = reduce_or_value(dst,dst);"
1685
1705
  when :!= then
1686
- res += "dst = not_equal_value(src0,src1,dst);\n"
1706
+ # res += "dst = not_equal_value(src0,src1,dst);\n"
1707
+ res += "dst = xor_value(src0,src1,dst);\n" +
1708
+ "dst = reduce_or_value(dst,dst);"
1687
1709
  when :> then
1688
1710
  res += "dst = greater_value(src0,src1,dst);\n"
1689
1711
  when :< then
@@ -156,7 +156,7 @@ module HDLRuby::Low
156
156
  end
157
157
  end
158
158
 
159
- # Deletes an type.
159
+ # Deletes a type.
160
160
  def delete_type!(type)
161
161
  if @types.key?(type.name) then
162
162
  # The type is present, delete it.
@@ -167,7 +167,7 @@ module HDLRuby::Low
167
167
  type
168
168
  end
169
169
 
170
- # Deletes an systemT.
170
+ # Deletes a systemT.
171
171
  def delete_systemT!(systemT)
172
172
  if @systemTs.key?(systemT.name) then
173
173
  # The systemT is present, delete it.
@@ -230,6 +230,33 @@ module HDLRuby::Low
230
230
  behavior.parent = nil
231
231
  end
232
232
  end
233
+
234
+ # Deletes the elements related to one of +names+: either they have
235
+ # one of the names or they use an element with these names.
236
+ # NOTE: only delete actual instantiated elements, types or
237
+ # systemTs are left as is.
238
+ def delete_related!(*names)
239
+ # Delete the sub scopes whose name are in names.
240
+ @scopes.delete_if { |scope| names.include?(scope.name) }
241
+ # Delete the inner signals whose name are in names.
242
+ @inners.delete_if { |sig| names.include?(sig.name) }
243
+ # Delete the connections that contain signals whose name are
244
+ # in names.
245
+ @connections.delete_if { |connection| connection.use_name?(*names) }
246
+ # Delete the behaviors whose block name or events' name are in
247
+ # names.
248
+ @behaviors.delete_if do |behavior|
249
+ names.include?(behavior.block.name) or
250
+ behavior.each_event.include? do |event|
251
+ event.ref.use_name?(*names)
252
+ end
253
+ end
254
+
255
+ # Recurse on the sub scopes.
256
+ @scopes.each { |scope| scope.delete_related!(names) }
257
+ # Recurse on the behaviors.
258
+ @behaviors.each { |behavior| behavior.block.delete_related!(names) }
259
+ end
233
260
  end
234
261
 
235
262
 
@@ -514,6 +541,14 @@ module HDLRuby::Low
514
541
  # By default: nothing to do.
515
542
  return {}
516
543
  end
544
+
545
+ # Deletes the elements related to one of +names+: either they have
546
+ # one of the names or they use an element with these names.
547
+ # NOTE: only delete actual instantiated elements, types or
548
+ # systemTs are left as is.
549
+ def delete_related!(*names)
550
+ # Nothing to do by default.
551
+ end
517
552
  end
518
553
 
519
554
 
@@ -694,6 +729,21 @@ module HDLRuby::Low
694
729
 
695
730
  return res
696
731
  end
732
+
733
+ # Deletes the elements related to one of +names+: either they have
734
+ # one of the names or they use an element with these names.
735
+ # NOTE: only delete actual instantiated elements, types or
736
+ # systemTs are left as is.
737
+ def delete_related!(*names)
738
+ # Delete the noifs if their condition uses one of names.
739
+ @noifs.delete_if { |noif| noif[0].use_names?(names) }
740
+ # Recurse on the yes.
741
+ @yes.delete_related!(*names)
742
+ # Recurse on the no.
743
+ @no.delete_related!(*names)
744
+ # Recruse one the no ifs statements.
745
+ @noifs.each { |noif| noif[1].delete_related!(*names) }
746
+ end
697
747
  end
698
748
 
699
749
  ##
@@ -758,6 +808,15 @@ module HDLRuby::Low
758
808
 
759
809
  return res
760
810
  end
811
+
812
+ # Deletes the elements related to one of +names+: either they have
813
+ # one of the names or they use an element with these names.
814
+ # NOTE: only delete actual instantiated elements, types or
815
+ # systemTs are left as is.
816
+ def delete_related!(*names)
817
+ # Recurse on the statement.
818
+ @statement.delete_related!(*names)
819
+ end
761
820
  end
762
821
 
763
822
 
@@ -833,6 +892,18 @@ module HDLRuby::Low
833
892
 
834
893
  return res
835
894
  end
895
+
896
+ # Deletes the elements related to one of +names+: either they have
897
+ # one of the names or they use an element with these names.
898
+ # NOTE: only delete actual instantiated elements, types or
899
+ # systemTs are left as is.
900
+ def delete_related!(*names)
901
+ # Delete the whens whose match contains a signal whoses name is
902
+ # in names.
903
+ @whens.delete_if { |w| w.match.use_name?(*names) }
904
+ # Recurse on the whens.
905
+ @whens.each { |w| w.delete_related!(*names) }
906
+ end
836
907
  end
837
908
 
838
909
 
@@ -1091,8 +1162,25 @@ module HDLRuby::Low
1091
1162
  end
1092
1163
  end
1093
1164
  end
1165
+
1166
+ # Deletes the elements related to one of +names+: either they have
1167
+ # one of the names or they use an element with these names.
1168
+ # NOTE: only delete actual instantiated elements, types or
1169
+ # systemTs are left as is.
1170
+ def delete_related!(*names)
1171
+ # Delete the inner signals whose name are in names.
1172
+ @inners.delete_if { |sig| names.include?(sig.name) }
1173
+ # Recurse on the statements.
1174
+ @statements.each do |statement|
1175
+ statement.delete_related!(*names)
1176
+ end
1177
+ # Delete the statements that contain signals whose name are
1178
+ # in names.
1179
+ @statements.delete_if { |statement| statement.use_name?(*names) }
1180
+ end
1094
1181
  end
1095
1182
 
1183
+
1096
1184
  # Describes a timed block.
1097
1185
  #
1098
1186
  # NOTE: