HDLRuby 3.0.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/HDLRuby.gemspec +1 -0
  3. data/README.md +149 -79
  4. data/ext/hruby_sim/hruby_rcsim_build.c +2 -0
  5. data/ext/hruby_sim/hruby_sim_calc.c +33 -6
  6. data/ext/hruby_sim/hruby_sim_tree_calc.c +111 -22
  7. data/lib/HDLRuby/hdr_samples/comparison_bench.rb +2 -2
  8. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +2 -1
  9. data/lib/HDLRuby/hdr_samples/counter_bench.rb +1 -1
  10. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +8 -7
  11. data/lib/HDLRuby/hdr_samples/dff_properties.rb +2 -0
  12. data/lib/HDLRuby/hdr_samples/enum_as_param.rb +52 -0
  13. data/lib/HDLRuby/hdr_samples/linear_test.rb +2 -0
  14. data/lib/HDLRuby/hdr_samples/logic_bench.rb +6 -0
  15. data/lib/HDLRuby/hdr_samples/mei8.rb +6 -6
  16. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +6 -6
  17. data/lib/HDLRuby/hdr_samples/memory_test.rb +2 -0
  18. data/lib/HDLRuby/hdr_samples/named_sub.rb +9 -5
  19. data/lib/HDLRuby/hdr_samples/ram.rb +7 -6
  20. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +2 -0
  21. data/lib/HDLRuby/hdr_samples/struct.rb +15 -3
  22. data/lib/HDLRuby/hdr_samples/with_bram.rb +1 -1
  23. data/lib/HDLRuby/hdr_samples/with_bram_frame_stack.rb +1 -1
  24. data/lib/HDLRuby/hdr_samples/with_bram_stack.rb +1 -1
  25. data/lib/HDLRuby/hdr_samples/with_channel.rb +2 -0
  26. data/lib/HDLRuby/hdr_samples/with_channel_other.rb +2 -0
  27. data/lib/HDLRuby/hdr_samples/with_class.rb +3 -1
  28. data/lib/HDLRuby/hdr_samples/with_connector.rb +2 -0
  29. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -0
  30. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +6 -0
  31. data/lib/HDLRuby/hdr_samples/with_fixpoint_adv.rb +73 -0
  32. data/lib/HDLRuby/hdr_samples/with_leftright.rb +1 -1
  33. data/lib/HDLRuby/hdr_samples/with_ref_expr.rb +30 -0
  34. data/lib/HDLRuby/hdr_samples/with_sequencer.rb +49 -37
  35. data/lib/HDLRuby/hdr_samples/with_sequencer_channel.rb +58 -0
  36. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +113 -69
  37. data/lib/HDLRuby/hdr_samples/with_sequencer_enumerator.rb +28 -14
  38. data/lib/HDLRuby/hdr_samples/with_sequencer_func.rb +63 -0
  39. data/lib/HDLRuby/hdr_samples/with_sequencer_sync.rb +2 -1
  40. data/lib/HDLRuby/hdrcc.rb +13 -1
  41. data/lib/HDLRuby/hruby_high.rb +105 -31
  42. data/lib/HDLRuby/hruby_low.rb +127 -3
  43. data/lib/HDLRuby/hruby_low2programs.rb +47 -0
  44. data/lib/HDLRuby/hruby_low_resolve.rb +3 -2
  45. data/lib/HDLRuby/hruby_low_without_namespace.rb +133 -5
  46. data/lib/HDLRuby/hruby_low_without_subsignals.rb +51 -12
  47. data/lib/HDLRuby/hruby_rcsim.rb +24 -1
  48. data/lib/HDLRuby/hruby_serializer.rb +2 -1
  49. data/lib/HDLRuby/hruby_types.rb +5 -5
  50. data/lib/HDLRuby/hruby_values.rb +7 -7
  51. data/lib/HDLRuby/hruby_verilog.rb +193 -35
  52. data/lib/HDLRuby/hruby_verilog_name.rb +35 -42
  53. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  54. data/lib/HDLRuby/std/fsm.rb +10 -1
  55. data/lib/HDLRuby/std/function_generator.rb +1 -1
  56. data/lib/HDLRuby/std/linear.rb +7 -7
  57. data/lib/HDLRuby/std/sequencer.rb +538 -60
  58. data/lib/HDLRuby/std/sequencer_channel.rb +90 -0
  59. data/lib/HDLRuby/std/sequencer_func.rb +546 -0
  60. data/lib/HDLRuby/std/std.rb +2 -0
  61. data/lib/HDLRuby/version.rb +1 -1
  62. data/tuto/tutorial_sw.md +267 -61
  63. metadata +25 -4
  64. data/lib/HDLRuby/hdr_samples/with_register_stack.rb +0 -150
@@ -122,10 +122,17 @@ module HDLRuby::Low
122
122
  # Extract the connections of the sub scopes.
123
123
  cnxs = self.each_scope.map(&:extract_connections!).flatten
124
124
  # Reinsert them to self.
125
- cnxs.each { |beh| self.add_connection(beh) }
125
+ cnxs.each { |cnx| self.add_connection(cnx) }
126
+
127
+ # The fix the RefName using sub scopes since their target have
128
+ # been deplaced to current scope and renamed.
129
+ self_scopes = self.each_scope.to_a
130
+ self.each_behavior { |beh| beh.fix_scope_refnames!(self_scopes) }
131
+ self.each_connection { |cnx| cnx.fix_scope_refnames!(self_scopes) }
126
132
 
127
133
  # Now can delete the sub scopes since they are empty.
128
- self.each_scope.to_a.each { |scope| self.delete_scope!(scope) }
134
+ # self.each_scope.to_a.each { |scope| self.delete_scope!(scope) }
135
+ self_scopes.each { |scope| self.delete_scope!(scope) }
129
136
  end
130
137
 
131
138
  # Extract the behaviors from the scope and returns them into an array.
@@ -219,9 +226,10 @@ module HDLRuby::Low
219
226
  # in the internals.
220
227
  def replace_names_subs!(former,nname)
221
228
  # puts "replace_names_subs! for #{self} with former=#{former} and nname=#{nname}"
222
- self.each_type do |type|
223
- type.replace_names!(former,nname)
224
- end
229
+ # No need?
230
+ # self.each_type do |type|
231
+ # type.replace_names!(former,nname)
232
+ # end
225
233
  self.each_systemT do |systemT|
226
234
  systemT.replace_names!(former,nname)
227
235
  end
@@ -460,6 +468,13 @@ module HDLRuby::Low
460
468
  # Recurse on the block.
461
469
  self.block.replace_names!(former,nname)
462
470
  end
471
+
472
+ # Fix the references names using scopes given in +scopes + list (they
473
+ # are marked to be deleted).
474
+ def fix_scope_refnames!(scopes)
475
+ self.block.fix_scope_refnames!(scopes)
476
+ return self
477
+ end
463
478
  end
464
479
 
465
480
 
@@ -498,6 +513,34 @@ module HDLRuby::Low
498
513
  node.break_types!(types)
499
514
  end
500
515
  end
516
+
517
+ # Fix the references names using scopes given in +scopes + list (they
518
+ # are marked to be deleted).
519
+ def fix_scope_refnames!(scopes)
520
+ # By default, does nothing.
521
+ return self
522
+ end
523
+ end
524
+
525
+
526
+ class Transmit
527
+ # Fix the references names using scopes given in +scopes + list (they
528
+ # are marked to be deleted).
529
+ def fix_scope_refnames!(scopes)
530
+ self.set_left!(self.left.fix_scope_refnames!(scopes))
531
+ self.set_right!(self.right.fix_scope_refnames!(scopes))
532
+ return self
533
+ end
534
+ end
535
+
536
+ class Connection
537
+ # Fix the references names using scopes given in +scopes + list (they
538
+ # are marked to be deleted).
539
+ def fix_scope_refnames!(scopes)
540
+ self.set_left!(self.left.fix_scope_refnames!(scopes))
541
+ self.set_right!(self.right.fix_scope_refnames!(scopes))
542
+ return self
543
+ end
501
544
  end
502
545
 
503
546
 
@@ -527,6 +570,16 @@ module HDLRuby::Low
527
570
  end
528
571
  end
529
572
  end
573
+
574
+ # Fix the references names using scopes given in +scopes + list (they
575
+ # are marked to be deleted).
576
+ def fix_scope_refnames!(scopes)
577
+ # By default: recurse.
578
+ self.map_nodes! do |node|
579
+ node.fix_scope_refnames!(scopes)
580
+ end
581
+ return self
582
+ end
530
583
  end
531
584
 
532
585
 
@@ -578,6 +631,24 @@ module HDLRuby::Low
578
631
  # Recurse on the no if any.
579
632
  self.no.replace_names!(former,nname) if self.no
580
633
  end
634
+
635
+ # Fix the references names using scopes given in +scopes + list (they
636
+ # are marked to be deleted).
637
+ def fix_scope_refnames!(scopes)
638
+ # Fix the condition.
639
+ self.set_condition!(self.condition.fix_scope_refnames!(scopes))
640
+ # Recurse on the yes.
641
+ self.yes.fix_scope_refnames!(scopes)
642
+ # Recurse on the alternate ifs.
643
+ self.map_noifs! do |cond,stmnt|
644
+ cond = cond.fix_scope_refnames!(scopes)
645
+ stmnt = stmnt.fix_scope_refnames!(scopes)
646
+ [cond,stmnt]
647
+ end
648
+ # Recruse on the no if any.
649
+ self.no.fix_scope_refnames!(scopes) if self.no
650
+ return self
651
+ end
581
652
  end
582
653
 
583
654
 
@@ -618,6 +689,16 @@ module HDLRuby::Low
618
689
  end
619
690
  end
620
691
  end
692
+
693
+ # Fix the references names using scopes given in +scopes + list (they
694
+ # are marked to be deleted).
695
+ def fix_scope_refnames!(scopes)
696
+ # Fix the match.
697
+ self.set_match!(self.match.fix_scope_refnames!(scopes))
698
+ # Recurse on the statement.
699
+ self.statement.fix_scope_refnames!(scopes)
700
+ return self
701
+ end
621
702
  end
622
703
 
623
704
 
@@ -655,6 +736,18 @@ module HDLRuby::Low
655
736
  # Recurse on the default.
656
737
  self.default.replace_names!(former,nname) if self.default
657
738
  end
739
+
740
+ # Fix the references names using scopes given in +scopes + list (they
741
+ # are marked to be deleted).
742
+ def fix_scope_refnames!(scopes)
743
+ # Fix the value.
744
+ self.set_value!(self.value.fix_scope_refnames!(scopes))
745
+ # Recurse on the whens.
746
+ self.each_when {|w| w.fix_scope_refnames!(scopes) }
747
+ # Recurse on the default.
748
+ self.default.fix_scope_refnames!(scopes) if self.default
749
+ return self
750
+ end
658
751
  end
659
752
 
660
753
 
@@ -681,6 +774,14 @@ module HDLRuby::Low
681
774
  # Recurse on the statement.
682
775
  self.statement.replace_names!(former,nname)
683
776
  end
777
+
778
+ # Fix the references names using scopes given in +scopes + list (they
779
+ # are marked to be deleted).
780
+ def fix_scope_refnames!(scopes)
781
+ # Recurse on the statement.
782
+ self.statement.fix_scope_refnames!(scopes)
783
+ return self
784
+ end
684
785
  end
685
786
 
686
787
 
@@ -738,6 +839,33 @@ module HDLRuby::Low
738
839
  # Recurse on the sub scopes and behaviors.
739
840
  replace_names_subs!(former,nname)
740
841
  end
842
+
843
+ # Fix the references names using scopes given in +scopes + list (they
844
+ # are marked to be deleted).
845
+ def fix_scope_refnames!(scopes)
846
+ self.each_statement {|stmnt| stmnt.fix_scope_refnames!(scopes) }
847
+ return self
848
+ end
849
+ end
850
+
851
+
852
+ class RefName
853
+ include ForceName
854
+
855
+ # Fix the references names using scopes given in +scopes + list (they
856
+ # are marked to be deleted).
857
+ def fix_scope_refnames!(scopes)
858
+ return self unless self.ref.is_a?(RefName)
859
+ # puts "fix_scope_refnames! with self.name=#{name} and self.ref=#{self.ref}"
860
+ # Recurse on the ref.
861
+ self.set_ref!(self.ref.fix_scope_refnames!(scopes))
862
+ # Rename and curt the subref if referening to one of the scopes.
863
+ if scopes.find {|scope| scope.name == self.ref.name } then
864
+ self.ref.extend_name!(self)
865
+ self.set_ref!(RefThis.new)
866
+ end
867
+ return self
868
+ end
741
869
  end
742
870
 
743
871
  end
@@ -18,10 +18,24 @@ module HDLRuby::Low
18
18
  ## Extends the SystemT class with functionality for decomposing the
19
19
  # hierachical signals in the statements.
20
20
 
21
+ # # Decompose the hierarchical signals in the statements.
22
+ # def signal2subs!
23
+ # self.scope.signal2subs!
24
+ # end
25
+
21
26
  # Decompose the hierarchical signals in the statements.
22
- def signal2subs!
27
+ # If +decompose_vec2d+ is true then also decompose 2 dimension vectors
28
+ # (e.g., for Verilog HDL that does not support handling such signals
29
+ # as usual expressions).
30
+ def signal2subs!(decompose_vec2d = false)
31
+ @@decompose_vec2d = decompose_vec2d == true
23
32
  self.scope.signal2subs!
24
33
  end
34
+
35
+ ## Tell if 2d vector signals must be decomposed too.
36
+ def self.decompose_vec2d?
37
+ @@decompose_vec2d
38
+ end
25
39
  end
26
40
 
27
41
 
@@ -229,17 +243,41 @@ module HDLRuby::Low
229
243
  # Flatten a reference to a list of reference to leaf signals
230
244
  # from signal +sig+ and add to result to +subrefs+
231
245
  def flatten_to(sig,subrefs)
232
- # puts "flatten_to with sig name=#{sig.name}"
233
- # Work on the sub signals if any.
234
- sig.each_signal do |sub|
235
- # Create a reference for the sub.
236
- subref = RefName.new(sub.type,self.clone,sub.name)
237
- # Recruse on it.
238
- subref.flatten_to(sub,subrefs)
239
- # Was it a leaf?
240
- unless sub.each_signal.any? then
241
- # Yes, add its new ref to the list of subs.
242
- subrefs << subref
246
+ # Shall we decompose 2d vectors, and is the current signal
247
+ # for one of them?
248
+ if SystemT.decompose_vec2d? and sig.type.is_a?(TypeVector) and
249
+ sig.type.base.is_a?(TypeVector) then
250
+ # Is the reference used other than for a memory access?
251
+ unless self.parent.is_a?(RefIndex) then
252
+ # Yes, do the decomposition.
253
+ # Selects the direction.
254
+ rng = sig.type.range
255
+ if rng.first > rng.last then
256
+ itr = (rng.last..rng.first).each
257
+ else
258
+ itr = rng.reverse_each
259
+ end
260
+ # Iterate on each element.
261
+ itr.each do |i|
262
+ # Create a reference fo the sub.
263
+ subref = RefIndex.new(sig.type.base,self.clone,
264
+ Value.new(TypeUnsigned.new(:""),i))
265
+ # Add it.
266
+ subrefs << subref
267
+ end
268
+ end
269
+ else
270
+ # Work on the sub signals if any.
271
+ sig.each_signal do |sub|
272
+ # Create a reference for the sub.
273
+ subref = RefName.new(sub.type,self.clone,sub.name)
274
+ # Recurse on it.
275
+ subref.flatten_to(sub,subrefs)
276
+ # Was it a leaf?
277
+ unless sub.each_signal.any? then
278
+ # Yes, add its new ref to the list of subs.
279
+ subrefs << subref
280
+ end
243
281
  end
244
282
  end
245
283
  end
@@ -255,6 +293,7 @@ module HDLRuby::Low
255
293
  # Decompose the hierarchical signals in the statements.
256
294
  def signal2subs!
257
295
  # puts "signal2subs! for RefName: #{self.name}"
296
+ return self if self.type == void # Not a singal anyway.
258
297
  # Decompose it to a list of reference to each leaf sub signal.
259
298
  subrefs = []
260
299
  self.flatten_to(self.resolve,subrefs)
@@ -1000,7 +1000,30 @@ module HDLRuby::High
1000
1000
 
1001
1001
  class RefName
1002
1002
  ## Extends the RefName class for hybrid Ruby-C simulation.
1003
- # Should not be used with rcsim.
1003
+ # Converted to RefRange.
1004
+
1005
+ # Generate the C description of the reference range (not ref name!).
1006
+ def to_rcsim
1007
+ # Convert the base to a bit vector.
1008
+ type_base = Bit[self.ref.type.width]
1009
+ # self.ref.parent = nil
1010
+ # bit_base = Cast.new(type_base,self.ref)
1011
+ bit_base = RCSim.rcsim_make_cast(type_base.to_rcsim,self.ref.to_rcsim)
1012
+ # Compute range in bits of the field.
1013
+ last = 0
1014
+ self.ref.type.each.detect do |name,typ|
1015
+ last += typ.width
1016
+ name == self.name
1017
+ end
1018
+ first = last-self.type.width
1019
+ last -= 1
1020
+ # puts "name=#{self.name} first=#{first} last=#{last}"
1021
+ type_int = Bit[type_base.width.width]
1022
+ return RCSim.rcsim_make_refRange(self.type.to_rcsim,
1023
+ Value.new(type_int,last).to_rcsim,
1024
+ Value.new(type_int,first).to_rcsim,
1025
+ bit_base)
1026
+ end
1004
1027
  end
1005
1028
 
1006
1029
 
@@ -23,7 +23,8 @@ module HDLRuby
23
23
  Low::TypeSigned, Low::TypeUnsigned, Low::TypeFloat,
24
24
  Low::TypeTuple, Low::TypeStruct,
25
25
  Low::Behavior, Low::TimeBehavior,
26
- Low::Event, Low::Block, Low::TimeBlock, Low::Code,
26
+ Low::Event, Low::Block, Low::TimeBlock,
27
+ Low::Program, Low::Code,
27
28
  Low::SignalI, Low::SignalC,
28
29
  Low::SystemI, Low::Connection,
29
30
  Low::Transmit, Low::If, Low::Case, Low::When, Low::Cast,
@@ -42,13 +42,13 @@ module HDLRuby
42
42
  elsif type.float? then
43
43
  return type
44
44
  elsif self.signed? then
45
- return self
45
+ if type.signed? then
46
+ return self.width >= type.width ? self : type
47
+ else
48
+ return self
49
+ end
46
50
  elsif type.signed? then
47
51
  return type
48
- elsif self.unsigned? then
49
- return self
50
- elsif type.unsigned? then
51
- return type
52
52
  elsif self.width >= type.width then
53
53
  return self
54
54
  else
@@ -253,6 +253,7 @@ module HDLRuby
253
253
  # Cast to +type+.
254
254
  # NOTE: nodir tells if the direction is to be ignored.
255
255
  def cast(type,nodir = false)
256
+ # puts "cast with content=#{self.content} type.signed=#{type.signed?} type.width=#{type.width}"
256
257
  # Handle the direction.
257
258
  if !nodir && type.direction != self.type.direction then
258
259
  if self.content.is_a?(Numeric) then
@@ -281,19 +282,18 @@ module HDLRuby
281
282
  res_content.positive!
282
283
  end
283
284
  end
284
- if type.signed && res_content.is_a?(Numeric) && res_content >= (1 << (type.width-1)) then
285
+ if type.signed? && res_content.is_a?(Numeric) && res_content >= (1 << (type.width-1)) then
285
286
  res_content = (-1 << type.width) + res_content
286
287
  end
287
- # # truncs to the right size if necessary.
288
- # if res_content.is_a?(BitString) then
289
- # res_content.trunc!(type.width)
290
- # else
291
- # res_content = self.trunc(res_content,type.width)
292
- # end
293
288
  # Generate the resulting value.
289
+ # puts "res_content=#{res_content}"
294
290
  return self.class.new(type,res_content)
295
291
  end
296
292
 
293
+ def as(typ)
294
+ return self.cast(typ)
295
+ end
296
+
297
297
  # Concat the content of +vals+.
298
298
  def self.concat(*vals)
299
299
  # Compute the resulting type.