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
@@ -38,7 +38,7 @@ module HDLRuby::High
38
38
  # puts "eigen_extend for #{self} class=#{self.class}"
39
39
  obj.singleton_methods.each do |name|
40
40
  next if name == :yaml_tag # Do not know why we need to skip
41
- # puts "name=#{name}"
41
+ puts "name=#{name}"
42
42
  self.define_singleton_method(name, &obj.singleton_method(name))
43
43
  end
44
44
  end
@@ -87,10 +87,11 @@ module HDLRuby::High
87
87
  raise AnyError,
88
88
  "Resevered name #{name} cannot be overridden."
89
89
  end
90
- if self.respond_to?(name) then
91
- raise AnyError,
92
- "Symbol #{name} is already defined."
93
- end
90
+ # Deactivated: overriding is now accepted.
91
+ # if self.respond_to?(name) then
92
+ # raise AnyError,
93
+ # "Symbol #{name} is already defined."
94
+ # end
94
95
  define_singleton_method(name,&ruby_block)
95
96
  end
96
97
  end
@@ -669,7 +670,6 @@ module HDLRuby::High
669
670
  # Fill the public namespace
670
671
  space = self.public_namespace
671
672
  # Interface signals
672
- # puts "i_name=#{i_name} @to_includes=#{@to_includes.size}"
673
673
  self.each_signal do |signal|
674
674
  # puts "signal=#{signal.name}"
675
675
  space.send(:define_singleton_method,signal.name) do
@@ -825,8 +825,20 @@ module HDLRuby::High
825
825
 
826
826
  include Hmux
827
827
 
828
+
829
+ # Merge the included systems interface in current system.
830
+ # NOTE: incompatible with further to_low transformation.
831
+ def merge_included!
832
+ # puts "merge_included! for system=#{self.name}"
833
+ # Recurse on the system instances.
834
+ self.scope.merge_included!
835
+ # Merge for current system.
836
+ self.scope.merge_included(self)
837
+ end
838
+
839
+
828
840
  # Fills the interface of a low level system.
829
- def fill_interface(systemTlow)
841
+ def fill_interface_low(systemTlow)
830
842
  # Adds its input signals.
831
843
  self.each_input { |input| systemTlow.add_input(input.to_low) }
832
844
  # Adds its output signals.
@@ -835,7 +847,7 @@ module HDLRuby::High
835
847
  self.each_inout { |inout| systemTlow.add_inout(inout.to_low) }
836
848
  # Adds the interface of its included systems.
837
849
  self.scope.each_included do |included|
838
- included.fill_interface(systemTlow)
850
+ included.fill_interface_low(systemTlow)
839
851
  end
840
852
  end
841
853
 
@@ -844,7 +856,7 @@ module HDLRuby::High
844
856
  # NOTE: name conflicts are treated in the current NameStack state.
845
857
  def fill_low(systemTlow)
846
858
  # Fills the interface
847
- self.fill_interface(systemTlow)
859
+ self.fill_interface_low(systemTlow)
848
860
  end
849
861
 
850
862
  # Converts the system to HDLRuby::Low and set its +name+.
@@ -1181,6 +1193,8 @@ module HDLRuby::High
1181
1193
 
1182
1194
  # Declares a sub scope with possible +name+ and built from +ruby_block+.
1183
1195
  def sub(name = :"", &ruby_block)
1196
+ # Ensure there is a block.
1197
+ ruby_block = proc {} unless block_given?
1184
1198
  # Creates the new scope.
1185
1199
  # scope = Scope.new(name,&ruby_block)
1186
1200
  scope = Scope.new(name)
@@ -1197,6 +1211,8 @@ module HDLRuby::High
1197
1211
  # Declares a high-level sequential behavior activated on a list of
1198
1212
  # +events+, and built by executing +ruby_block+.
1199
1213
  def seq(*events, &ruby_block)
1214
+ # Ensure there is a block.
1215
+ ruby_block = proc {} unless block_given?
1200
1216
  # Preprocess the events.
1201
1217
  events.map! do |event|
1202
1218
  event.respond_to?(:to_event) ? event.to_event : event
@@ -1208,6 +1224,8 @@ module HDLRuby::High
1208
1224
  # Declares a high-level parallel behavior activated on a list of
1209
1225
  # +events+, and built by executing +ruby_block+.
1210
1226
  def par(*events, &ruby_block)
1227
+ # Ensure there is a block.
1228
+ ruby_block = proc {} unless block_given?
1211
1229
  # Preprocess the events.
1212
1230
  events.map! do |event|
1213
1231
  event.respond_to?(:to_event) ? event.to_event : event
@@ -1219,6 +1237,8 @@ module HDLRuby::High
1219
1237
  # Declares a high-level timed behavior built by executing +ruby_block+.
1220
1238
  # By default, timed behavior are sequential.
1221
1239
  def timed(&ruby_block)
1240
+ # Ensure there is a block.
1241
+ ruby_block = proc {} unless block_given?
1222
1242
  # Create and add the resulting behavior.
1223
1243
  self.add_behavior(TimeBehavior.new(:seq,&ruby_block))
1224
1244
  end
@@ -1232,6 +1252,8 @@ module HDLRuby::High
1232
1252
  # * the else part is defined through the helse method.
1233
1253
  # * a behavior is created to enclose the hif.
1234
1254
  def hif(condition, mode = nil, &ruby_block)
1255
+ # Ensure there is a block.
1256
+ ruby_block = proc {} unless block_given?
1235
1257
  self.par do
1236
1258
  hif(condition,mode,&ruby_block)
1237
1259
  end
@@ -1244,6 +1266,8 @@ module HDLRuby::High
1244
1266
  #
1245
1267
  # NOTE: added to the hif of the last behavior.
1246
1268
  def helse(mode = nil, &ruby_block)
1269
+ # Ensure there is a block.
1270
+ ruby_block = proc {} unless block_given?
1247
1271
  # There is a ruby_block: the helse is assumed to be with
1248
1272
  # the last statement of the last behavior.
1249
1273
  statement = self.last_behavior.last_statement
@@ -1258,6 +1282,8 @@ module HDLRuby::High
1258
1282
  # with a +condition+ that when met lead
1259
1283
  # to the execution of the block in +mode+ generated by the +ruby_block+.
1260
1284
  def helsif(condition, mode = nil, &ruby_block)
1285
+ # Ensure there is a block.
1286
+ ruby_block = proc {} unless block_given?
1261
1287
  # There is a ruby_block: the helse is assumed to be with
1262
1288
  # the last statement of the last behavior.
1263
1289
  statement = self.last_behavior.last_statement
@@ -1285,6 +1311,8 @@ module HDLRuby::High
1285
1311
  #
1286
1312
  # Can only be used once.
1287
1313
  def hwhen(match, mode = nil, &ruby_block)
1314
+ # Ensure there is a block.
1315
+ ruby_block = proc {} unless block_given?
1288
1316
  # There is a ruby_block: the helse is assumed to be with
1289
1317
  # the last statement of the last behavior.
1290
1318
  statement = @behaviors.last.last_statement
@@ -1364,6 +1392,72 @@ module HDLRuby::High
1364
1392
 
1365
1393
  include Hmux
1366
1394
 
1395
+
1396
+
1397
+ # Merge the included systems interface in +systemT+
1398
+ # NOTE: incompatible with further to_low transformation.
1399
+ def merge_included(systemT)
1400
+ # Recurse on the sub.
1401
+ self.each_scope {|scope| scope.merge_included(systemT) }
1402
+ # Include for current scope.
1403
+ self.each_included do |included|
1404
+ included.merge_included!
1405
+ # Adds its interface signals.
1406
+ included.each_input do |input|
1407
+ input.no_parent!
1408
+ systemT.add_input(input)
1409
+ end
1410
+ included.each_output do |output|
1411
+ output.no_parent!
1412
+ systemT.add_output(output)
1413
+ end
1414
+ included.each_inout do |inout|
1415
+ inout.no_parent!
1416
+ systemT.add_inout(inout)
1417
+ end
1418
+ # Adds its behaviors.
1419
+ included.scope.each_behavior do |beh|
1420
+ beh.no_parent!
1421
+ systemT.scope.add_behavior(beh)
1422
+ end
1423
+ # Adds its connections.
1424
+ included.scope.each_connection do |cx|
1425
+ cx.no_parent!
1426
+ systemT.scope.add_connection(cx)
1427
+ end
1428
+ # Adds its sytem instances.
1429
+ included.scope.each_systemI do |sys|
1430
+ sys.no_parent!
1431
+ systemT.scope.add_systemI(sys)
1432
+ end
1433
+ # Adds its code.
1434
+ included.scope.each_code do |code|
1435
+ code.no_parent!
1436
+ systemT.scope.add_code(code)
1437
+ end
1438
+ # Adds its subscopes.
1439
+ included.scope.each_scope do |scope|
1440
+ scope.no_parent!
1441
+ systemT.scope.add_scope(scope)
1442
+ end
1443
+ # Add its inner signals.
1444
+ included.scope.each_inner do |inner|
1445
+ inner.no_parent!
1446
+ systemT.scope.add_inner(inner)
1447
+ end
1448
+ end
1449
+ end
1450
+
1451
+ # Merge the included systems interface in system instances.
1452
+ # NOTE: incompatible with further to_low transformation.
1453
+ def merge_included!
1454
+ # Recurse on the sub.
1455
+ self.each_scope {|scope| scope.merge_included! }
1456
+ # Merge in the system instances.
1457
+ self.each_systemI {|systemI| systemI.systemT.merge_included! }
1458
+ end
1459
+
1460
+
1367
1461
  # Fills a low level scope with self's contents.
1368
1462
  #
1369
1463
  # NOTE: name conflicts are treated in the current NameStack state.
@@ -1607,6 +1701,8 @@ module HDLRuby::High
1607
1701
 
1608
1702
  # Redefinition of +operator+.
1609
1703
  def define_operator(operator,&ruby_block)
1704
+ # Ensure there is a block.
1705
+ ruby_block = proc {} unless block_given?
1610
1706
  # Register the operator as overloaded.
1611
1707
  @overloads ||= {}
1612
1708
  @overloads[operator] = ruby_block
@@ -2003,6 +2099,8 @@ module HDLRuby::High
2003
2099
  # Declares a high-level generic type named +name+, and using +ruby_block+
2004
2100
  # for construction.
2005
2101
  def typedef(name, &ruby_block)
2102
+ # Ensure there is a block.
2103
+ ruby_block = proc {} unless block_given?
2006
2104
  type = TypeGen.new(name,&ruby_block)
2007
2105
  if HDLRuby::High.in_system? then
2008
2106
  # Must be inside a scope.
@@ -2038,6 +2136,8 @@ module HDLRuby::High
2038
2136
  # Declares a high-level system type named +name+, with +includes+ mixins
2039
2137
  # system types and using +ruby_block+ for instantiating.
2040
2138
  def system(name = :"", *includes, &ruby_block)
2139
+ # Ensure there is a block.
2140
+ ruby_block = proc {} unless block_given?
2041
2141
  # print "system ruby_block=#{ruby_block}\n"
2042
2142
  # Creates the resulting system.
2043
2143
  return SystemT.new(name,*includes,&ruby_block)
@@ -2049,6 +2149,8 @@ module HDLRuby::High
2049
2149
  # NOTE: this is for generating directly an instance without declaring
2050
2150
  # it system type.
2051
2151
  def instance(name, *includes, &ruby_block)
2152
+ # Ensure there is a block.
2153
+ ruby_block = proc {} unless block_given?
2052
2154
  # Creates the system type.
2053
2155
  systemT = system(:"",*includes,&ruby_block)
2054
2156
  # Instantiate it with +name+.
@@ -2061,6 +2163,8 @@ module HDLRuby::High
2061
2163
  #
2062
2164
  # NOTE: a function is a short-cut for a method that creates a scope.
2063
2165
  def function(name, &ruby_block)
2166
+ # Ensure there is a block.
2167
+ ruby_block = proc {} unless block_given?
2064
2168
  if HDLRuby::High.in_system? then
2065
2169
  define_singleton_method(name.to_sym) do |*args,&other_block|
2066
2170
  # sub do
@@ -2168,8 +2272,6 @@ module HDLRuby::High
2168
2272
  else
2169
2273
  # No, perform a connection is order of declaration
2170
2274
  connects.each.with_index do |csig,i|
2171
- csig = csig.to_expr
2172
- # puts "csig=#{csig} i=#{i}"
2173
2275
  # puts "systemT inputs=#{systemT.each_input.to_a.size}"
2174
2276
  # Gets i-est signal to connect
2175
2277
  ssig = self.systemT.get_interface_with_included(i)
@@ -2181,8 +2283,10 @@ module HDLRuby::High
2181
2283
  # Make the connection.
2182
2284
  if isout then
2183
2285
  csig <= ssig
2286
+ # csig.to_ref <= ssig
2184
2287
  else
2185
2288
  ssig <= csig
2289
+ # ssig <= csig.to_expr
2186
2290
  end
2187
2291
  end
2188
2292
  end
@@ -2199,6 +2303,8 @@ module HDLRuby::High
2199
2303
  # NOTE: actually executes +ruby_block+ in the context of the
2200
2304
  # systemT.
2201
2305
  def open(&ruby_block)
2306
+ # Ensure there is a block.
2307
+ ruby_block = proc {} unless block_given?
2202
2308
  # Extend the eigen system.
2203
2309
  @systemT.run(&ruby_block)
2204
2310
  # Update the methods.
@@ -2260,7 +2366,15 @@ module HDLRuby::High
2260
2366
  # system type.
2261
2367
  def method_missing(m, *args, &ruby_block)
2262
2368
  # print "method_missing in class=#{self.class} with m=#{m}\n"
2263
- self.public_namespace.send(m,*args,&ruby_block)
2369
+ # Maybe its a signal reference.
2370
+ signal = self.systemT.get_signal_with_included(m)
2371
+ if signal then
2372
+ # Yes, create the reference.
2373
+ return RefObject.new(self.to_ref,signal)
2374
+ else
2375
+ # No try elsewhere
2376
+ self.public_namespace.send(m,*args,&ruby_block)
2377
+ end
2264
2378
  end
2265
2379
 
2266
2380
 
@@ -2395,6 +2509,8 @@ module HDLRuby::High
2395
2509
  #
2396
2510
  # Can only be used once.
2397
2511
  def helse(mode = nil, &ruby_block)
2512
+ # Ensure there is a block.
2513
+ ruby_block = proc {} unless block_given?
2398
2514
  # If there is a no block, it is an error.
2399
2515
  raise AnyError, "Cannot have two helse for a single if statement." if self.no
2400
2516
  # Create the no block if required
@@ -2409,6 +2525,8 @@ module HDLRuby::High
2409
2525
  #
2410
2526
  # Can only be used if the no-block is not set yet.
2411
2527
  def helsif(next_cond, mode = nil, &ruby_block)
2528
+ # Ensure there is a block.
2529
+ ruby_block = proc {} unless block_given?
2412
2530
  # If there is a no block, it is an error.
2413
2531
  raise AnyError, "Cannot have an helsif after an helse." if self.no
2414
2532
  # Create the noif block if required
@@ -2477,6 +2595,8 @@ module HDLRuby::High
2477
2595
  #
2478
2596
  # Can only be used once for the given +match+.
2479
2597
  def hwhen(match, mode = nil, &ruby_block)
2598
+ # Ensure there is a block.
2599
+ ruby_block = proc {} unless block_given?
2480
2600
  # Create the nu block if required
2481
2601
  when_block = High.make_block(mode,&ruby_block)
2482
2602
  # Adds the case.
@@ -2488,6 +2608,8 @@ module HDLRuby::High
2488
2608
  #
2489
2609
  # Can only be used once.
2490
2610
  def helse(mode = nil, &ruby_block)
2611
+ # Ensure there is a block.
2612
+ ruby_block = proc {} unless block_given?
2491
2613
  # Create the nu block if required
2492
2614
  default_block = High.make_block(mode,&ruby_block)
2493
2615
  # Sets the default block.
@@ -2731,30 +2853,39 @@ module HDLRuby::High
2731
2853
  return self.ljust(self[-1])
2732
2854
  end
2733
2855
 
2734
- # Match the type with +typ+:
2735
- # - Recurse on the sub expr if hierachical type, raising an arror
2736
- # if the expression is not hierarchical.
2737
- # - Directly cast otherwise.
2856
+ # # Match the type with +typ+:
2857
+ # # - Recurse on the sub expr if hierachical type, raising an error
2858
+ # # if the expression is not hierarchical.
2859
+ # # - Directly cast otherwise.
2860
+ # def match_type(typ)
2861
+ # # Has the type sub types?
2862
+ # if typ.types? then
2863
+ # unless self.is_a?(Concat) then
2864
+ # raise AnyError,
2865
+ # "Invalid class for assignment to hierarchical: #{self.class}."
2866
+ # end
2867
+ # return Concat.new(typ,
2868
+ # self.each_expression.zip(typ.each_type).map do |e,t|
2869
+ # e.match_type(t)
2870
+ # end)
2871
+ # elsif typ.vector? && typ.base.hierarchical? then
2872
+ # unless self.is_a?(Concat) then
2873
+ # raise AnyError,
2874
+ # "Invalid class for assignment to hierarchical: #{self.class}."
2875
+ # end
2876
+ # return Concat.new(typ,
2877
+ # self.each_expression.map do |e|
2878
+ # e.match_type(typ.base)
2879
+ # end)
2880
+ # else
2881
+ # return self.as(typ)
2882
+ # end
2883
+ # end
2884
+
2885
+ # Match the type with +typ+: cast if different type.
2738
2886
  def match_type(typ)
2739
- # Has the type sub types?
2740
- if typ.types? then
2741
- unless self.is_a?(Concat) then
2742
- raise AnyError,
2743
- "Invalid class for assignment to hierarchical: #{self.class}."
2744
- end
2745
- return Concat.new(typ,
2746
- self.each_expression.zip(typ.each_type).map do |e,t|
2747
- e.match_type(t)
2748
- end)
2749
- elsif typ.vector? && typ.base.hierarchical? then
2750
- unless self.is_a?(Concat) then
2751
- raise AnyError,
2752
- "Invalid class for assignment to hierarchical: #{self.class}."
2753
- end
2754
- return Concat.new(typ,
2755
- self.each_expression.map do |e|
2756
- e.match_type(typ.base)
2757
- end)
2887
+ if self.type.eql?(typ) then
2888
+ return self
2758
2889
  else
2759
2890
  return self.as(typ)
2760
2891
  end
@@ -2831,54 +2962,58 @@ module HDLRuby::High
2831
2962
  define_method(orig_operator(operator),&meth)
2832
2963
  end
2833
2964
 
2834
- # Creates an access to elements of range +rng+ of the signal.
2835
- #
2836
- # NOTE: +rng+ can be a single expression in which case it is an index.
2837
- def [](rng)
2838
- if rng.is_a?(::Range) then
2839
- first = rng.first
2840
- if (first.is_a?(::Integer)) then
2841
- first = self.type.size+first if first < 0
2842
- end
2843
- last = rng.last
2844
- if (last.is_a?(::Integer)) then
2845
- last = self.type.size+last if last < 0
2846
- end
2847
- rng = first..last
2848
- end
2849
- if rng.is_a?(::Integer) && rng < 0 then
2850
- rng = self.type.size+rng
2851
- end
2852
- if rng.respond_to?(:to_expr) then
2853
- # Number range: convert it to an expression.
2854
- rng = rng.to_expr
2855
- end
2856
- if rng.is_a?(HDLRuby::Low::Expression) then
2857
- # Index case
2858
- return RefIndex.new(self.type.base,self.to_expr,rng)
2859
- else
2860
- # Range case, ensure it is made among expression.
2861
- first = rng.first.to_expr
2862
- last = rng.last.to_expr
2863
- # Abd create the reference.
2864
- return RefRange.new(self.type.slice(first..last),
2865
- self.to_expr,first..last)
2866
- end
2867
- end
2868
2965
 
2869
- # Converts to a select operator using current expression as
2870
- # condition for one of the +choices+.
2871
- #
2872
- # NOTE: +choices+ can either be a list of arguments or an array.
2873
- # If +choices+ has only two entries
2874
- # (and it is not a hash), +value+ will be converted to a boolean.
2875
- def mux(*choices)
2876
- # Process the choices.
2877
- choices = choices.flatten(1) if choices.size == 1
2878
- choices.map! { |choice| choice.to_expr }
2879
- # Generate the select expression.
2880
- return Select.new(choices[0].type,"?",self.to_expr,*choices)
2881
- end
2966
+ # Creates an access to elements of range +rng+ of the signal.
2967
+ #
2968
+ # NOTE: +rng+ can be a single expression in which case it is an index.
2969
+ def [](rng)
2970
+ if rng.is_a?(::Range) then
2971
+ first = rng.first
2972
+ if (first.is_a?(::Integer)) then
2973
+ first = self.type.size+first if first < 0
2974
+ end
2975
+ last = rng.last
2976
+ if (last.is_a?(::Integer)) then
2977
+ last = self.type.size+last if last < 0
2978
+ end
2979
+ rng = first..last
2980
+ end
2981
+ if rng.is_a?(::Integer) && rng < 0 then
2982
+ rng = self.type.size+rng
2983
+ end
2984
+ if rng.respond_to?(:to_expr) then
2985
+ # Number range: convert it to an expression.
2986
+ rng = rng.to_expr
2987
+ end
2988
+ if rng.is_a?(HDLRuby::Low::Expression) then
2989
+ # Index case
2990
+ return RefIndex.new(self.type.base,self.to_expr,rng)
2991
+ else
2992
+ # Range case, ensure it is made among expression.
2993
+ first = rng.first.to_expr
2994
+ last = rng.last.to_expr
2995
+ # Abd create the reference.
2996
+ return RefRange.new(self.type.slice(first..last),
2997
+ self.to_expr,first..last)
2998
+ end
2999
+ end
3000
+
3001
+ # And save it so that it can still be accessed if overidden.
3002
+ alias_method orig_operator(:[]), :[]
3003
+
3004
+ # Converts to a select operator using current expression as
3005
+ # condition for one of the +choices+.
3006
+ #
3007
+ # NOTE: +choices+ can either be a list of arguments or an array.
3008
+ # If +choices+ has only two entries
3009
+ # (and it is not a hash), +value+ will be converted to a boolean.
3010
+ def mux(*choices)
3011
+ # Process the choices.
3012
+ choices = choices.flatten(1) if choices.size == 1
3013
+ choices.map! { |choice| choice.to_expr }
3014
+ # Generate the select expression.
3015
+ return Select.new(choices[0].type,"?",self.to_expr,*choices)
3016
+ end
2882
3017
 
2883
3018
 
2884
3019
 
@@ -2922,19 +3057,25 @@ module HDLRuby::High
2922
3057
  #
2923
3058
  # NOTE: it is converted afterward to an expression if required.
2924
3059
  def <=(expr)
3060
+ # Generate a ref from self for the left of the transmit.
3061
+ left = self.to_ref
2925
3062
  # Cast expr to self if required.
2926
- expr = expr.to_expr.match_type(self.type)
3063
+ expr = expr.to_expr.match_type(left.type)
3064
+ # Ensure expr is an expression.
3065
+ expr = expr.to_expr
3066
+ # Cast it to left if necessary.
3067
+ expr = expr.as(left.type) unless expr.type.eql?(left.type)
2927
3068
  # Generate the transmit.
2928
3069
  if High.top_user.is_a?(HDLRuby::Low::Block) then
2929
3070
  # We are in a block, so generate and add a Transmit.
2930
3071
  High.top_user.
2931
- # add_statement(Transmit.new(self.to_ref,expr.to_expr))
2932
- add_statement(Transmit.new(self.to_ref,expr))
3072
+ # add_statement(Transmit.new(self.to_ref,expr))
3073
+ add_statement(Transmit.new(left,expr))
2933
3074
  else
2934
3075
  # We are in a system type, so generate and add a Connection.
2935
3076
  High.top_user.
2936
- # add_connection(Connection.new(self.to_ref,expr.to_expr))
2937
- add_connection(Connection.new(self.to_ref,expr))
3077
+ # add_connection(Connection.new(self.to_ref,expr))
3078
+ add_connection(Connection.new(left,expr))
2938
3079
  end
2939
3080
  end
2940
3081
  end
@@ -3185,7 +3326,7 @@ module HDLRuby::High
3185
3326
 
3186
3327
  # Creates a new reference from a +base+ reference and named +object+.
3187
3328
  def initialize(base,object)
3188
- # puts "New RefObjet with base=#{base}, object=#{object.name}"
3329
+ # puts "New RefObjet with base=#{base}, object=#{object}"
3189
3330
  if object.respond_to?(:type) then
3190
3331
  # Typed object, so typed reference.
3191
3332
  super(object.type)
@@ -3202,6 +3343,11 @@ module HDLRuby::High
3202
3343
  @object = object
3203
3344
  end
3204
3345
 
3346
+ # Clones.
3347
+ def clone
3348
+ return RefObject.new(self.base.clone,self.object)
3349
+ end
3350
+
3205
3351
  # Tell if the expression is constant.
3206
3352
  def constant?
3207
3353
  return self.base.constant?
@@ -3351,6 +3497,11 @@ module HDLRuby::High
3351
3497
  High = HDLRuby::High
3352
3498
  include HRef
3353
3499
 
3500
+ # Clones.
3501
+ def clone
3502
+ return RefThis.new
3503
+ end
3504
+
3354
3505
  # Converts to a new reference.
3355
3506
  def to_ref
3356
3507
  return RefThis.new
@@ -3859,11 +4010,15 @@ module HDLRuby::High
3859
4010
  # Creates a new block with the current mode with possible +name+ and
3860
4011
  # built from +ruby_block+.
3861
4012
  def sub(name = :"", &ruby_block)
4013
+ # Ensure there is a block.
4014
+ ruby_block = proc {} unless block_given?
3862
4015
  self.add_block(self.mode,name,&ruby_block)
3863
4016
  end
3864
4017
 
3865
4018
  # Adds statements at the top of the block.
3866
4019
  def unshift(&ruby_block)
4020
+ # Ensure there is a block.
4021
+ ruby_block = proc {} unless block_given?
3867
4022
  # Create a sub block for the statements.
3868
4023
  block = High.make_block(self.mode,:"",&ruby_block)
3869
4024
  # Unshifts it.
@@ -3908,6 +4063,8 @@ module HDLRuby::High
3908
4063
  #
3909
4064
  # NOTE: the else part is defined through the helse method.
3910
4065
  def hif(condition, mode = nil, &ruby_block)
4066
+ # Ensure there is a block.
4067
+ ruby_block = proc {} unless block_given?
3911
4068
  # Creates the if statement.
3912
4069
  self.add_statement(If.new(condition,mode,&ruby_block))
3913
4070
  end
@@ -3917,6 +4074,8 @@ module HDLRuby::High
3917
4074
  #
3918
4075
  # Can only be used once.
3919
4076
  def helse(mode = nil, &ruby_block)
4077
+ # Ensure there is a block.
4078
+ ruby_block = proc {} unless block_given?
3920
4079
  # There is a ruby_block: the helse is assumed to be with
3921
4080
  # the hif in the same block.
3922
4081
  # Completes the hif or the hcase statement.
@@ -3931,6 +4090,8 @@ module HDLRuby::High
3931
4090
  # with a +condition+ that when met lead
3932
4091
  # to the execution of the block in +mode+ generated by the +ruby_block+.
3933
4092
  def helsif(condition, mode = nil, &ruby_block)
4093
+ # Ensure there is a block.
4094
+ ruby_block = proc {} unless block_given?
3934
4095
  # There is a ruby_block: the helse is assumed to be with
3935
4096
  # the hif in the same block.
3936
4097
  # Completes the hif statement.
@@ -3958,6 +4119,8 @@ module HDLRuby::High
3958
4119
  #
3959
4120
  # Can only be used once.
3960
4121
  def hwhen(match, mode = nil, &ruby_block)
4122
+ # Ensure there is a block.
4123
+ ruby_block = proc {} unless block_given?
3961
4124
  # There is a ruby_block: the helse is assumed to be with
3962
4125
  # the hif in the same block.
3963
4126
  # Completes the hcase statement.
@@ -4073,6 +4236,8 @@ module HDLRuby::High
4073
4236
  # Adds a loop until +delay+ statement in the block in +mode+ whose
4074
4237
  # loop content is built using +ruby_block+.
4075
4238
  def repeat(delay, mode = nil, &ruby_block)
4239
+ # Ensure there is a block.
4240
+ ruby_block = proc {} unless block_given?
4076
4241
  # Build the content block.
4077
4242
  content = High.make_block(mode,&ruby_block)
4078
4243
  # Create and add the statement.
@@ -4539,13 +4704,19 @@ module HDLRuby::High
4539
4704
  # # Use it to create the new value.
4540
4705
  # return Value.new(Bit[bstr.width],self)
4541
4706
  # end
4707
+
4708
+ # Tell if the expression can be converted to a value.
4709
+ def to_value?
4710
+ return true
4711
+ end
4542
4712
 
4543
4713
  # Converts to a new high-level value.
4544
4714
  def to_value
4545
4715
  # Convert the string to a bit string.
4546
4716
  bstr = BitString.new(self)
4547
4717
  # Use it to create the new value.
4548
- return Value.new(Bit[bstr.width],self)
4718
+ # return Value.new(Bit[bstr.width],bstr)
4719
+ return Value.new(Bit[self.length],bstr)
4549
4720
  end
4550
4721
 
4551
4722
  # Convert to a new high-level string expression
@@ -4659,9 +4830,6 @@ module HDLRuby::High
4659
4830
 
4660
4831
  # Converts to a new high-level expression.
4661
4832
  def to_expr
4662
- # expr = Concat.new(TypeTuple.new(:"",:little,*self.map do |elem|
4663
- # elem.to_expr.type
4664
- # end))
4665
4833
  elems = self.map {|elem| elem.to_expr }
4666
4834
  typ= TypeTuple.new(:"",:little)
4667
4835
  elems.each {|elem| typ.add_type(elem.type) }
@@ -4672,7 +4840,6 @@ module HDLRuby::High
4672
4840
 
4673
4841
  # Converts to a new high-level reference.
4674
4842
  def to_ref
4675
- # expr = RefConcat.new
4676
4843
  expr = RefConcat.new(TypeTuple.new(:"",:little,*self.map do |elem|
4677
4844
  elem.to_ref.type
4678
4845
  end))
@@ -4731,16 +4898,19 @@ module HDLRuby::High
4731
4898
  # Creates a hcase statement executing +ruby_block+ on the element of
4732
4899
  # the array selected by +value+
4733
4900
  def hcase(value,&ruby_block)
4901
+ # Ensure there is a block.
4902
+ ruby_block = proc {} unless block_given?
4734
4903
  High.cur_block.hcase(value)
4735
4904
  self.each.with_index do |elem,i|
4736
4905
  High.cur_block.hwhen(i) { ruby_block.call(elem) }
4737
4906
  end
4738
4907
  end
4739
4908
 
4740
- # Add support of the left arrow operator.
4741
- def <=(expr)
4742
- self.to_expr <= expr
4743
- end
4909
+ # Moved to HArrow.
4910
+ # # Add support of the left arrow operator.
4911
+ # def <=(expr)
4912
+ # self.to_expr <= expr
4913
+ # end
4744
4914
 
4745
4915
  # Array construction shortcuts
4746
4916