HDLRuby 2.4.27 → 2.6.2

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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/lib/HDLRuby/drivers/xcd.rb +79 -0
  3. data/lib/HDLRuby/drivers/xcd/dummy.xcd +4 -0
  4. data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
  5. data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
  6. data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
  7. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
  8. data/lib/HDLRuby/hdr_samples/dff_properties.rb +19 -0
  9. data/lib/HDLRuby/hdr_samples/dff_unit.rb +54 -0
  10. data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
  11. data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
  12. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  13. data/lib/HDLRuby/hdr_samples/music.rb +79 -0
  14. data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
  15. data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
  16. data/lib/HDLRuby/hdr_samples/seqpar_bench.rb +59 -0
  17. data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
  18. data/lib/HDLRuby/hdrcc.rb +140 -24
  19. data/lib/HDLRuby/hruby_decorator.rb +250 -0
  20. data/lib/HDLRuby/hruby_high.rb +468 -91
  21. data/lib/HDLRuby/hruby_low.rb +913 -45
  22. data/lib/HDLRuby/hruby_low2c.rb +189 -168
  23. data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
  24. data/lib/HDLRuby/hruby_low2high.rb +331 -549
  25. data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
  26. data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
  27. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
  28. data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
  29. data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
  30. data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
  31. data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
  32. data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
  33. data/lib/HDLRuby/hruby_low_without_parinseq.rb +151 -0
  34. data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
  35. data/lib/HDLRuby/hruby_tools.rb +11 -1
  36. data/lib/HDLRuby/hruby_verilog.rb +1602 -1629
  37. data/lib/HDLRuby/sim/hruby_sim.h +25 -2
  38. data/lib/HDLRuby/sim/hruby_sim_calc.c +63 -6
  39. data/lib/HDLRuby/sim/hruby_sim_vcd.c +5 -1
  40. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
  41. data/lib/HDLRuby/std/fixpoint.rb +9 -0
  42. data/lib/HDLRuby/std/function_generator.rb +139 -0
  43. data/lib/HDLRuby/std/hruby_unit.rb +75 -0
  44. data/lib/HDLRuby/template_expander.rb +61 -0
  45. data/lib/HDLRuby/version.rb +1 -1
  46. metadata +22 -5
@@ -50,6 +50,15 @@ module HDLRuby::Low
50
50
  @@alliance = mode ? true : false
51
51
  end
52
52
 
53
+
54
+ ## Converts string +str+ to a VHDL-compatible string.
55
+ def self.vhdl_string(str)
56
+ str = str.gsub(/\n/,"\\n")
57
+ str.gsub!(/\t/,"\\t")
58
+ return str
59
+ end
60
+
61
+
53
62
  ## Generates the pakage requirement for an entity.
54
63
  # +spaces+ are the spaces to put before each line.
55
64
  def self.packages(spaces)
@@ -523,7 +532,8 @@ module HDLRuby::Low
523
532
  if inner.value.is_a?(Concat) then
524
533
  # Concat are to be given the expected type of the
525
534
  # elements for casting them equally.
526
- res << " := " << inner.value.to_vhdl(inner.type.base,level)
535
+ # res << " := " << inner.value.to_vhdl(inner.type.base,level)
536
+ res << " := " << inner.value.to_vhdl(level,inner.type.base)
527
537
  else
528
538
  res << " := " << inner.value.to_vhdl(level)
529
539
  end
@@ -901,6 +911,20 @@ module HDLRuby::Low
901
911
  Low2VHDL.to_type(self.left.type,self.right) + ";\n"
902
912
  end
903
913
  end
914
+
915
+ ## Extends the Print class with generation of HDLRuby::High text.
916
+ class Print
917
+
918
+ # Generates the text of the equivalent HDLRuby::High code.
919
+ # +vars+ is the list of the variables and
920
+ # +level+ is the hierachical level of the object.
921
+ def to_vhdl(vars,level = 0)
922
+ # Generate a report statement.
923
+ return " " * (level*3) + "report " + self.each_arg.map do |arg|
924
+ arg.to_vhdl
925
+ end.join(" & ") + ";\n"
926
+ end
927
+ end
904
928
 
905
929
  ## Extends the If class with generation of HDLRuby::High text.
906
930
  class If
@@ -1347,7 +1371,8 @@ module HDLRuby::Low
1347
1371
  # Generates the text of the equivalent HDLRuby::High code.
1348
1372
  # +type+ is the expected type of the content.
1349
1373
  # +level+ is the hierachical level of the object.
1350
- def to_vhdl(type,level = 0)
1374
+ # def to_vhdl(type,level = 0)
1375
+ def to_vhdl(level = 0, type = self.type)
1351
1376
  raise "Invalid class for a type: #{type.class}" unless type.is_a?(Type)
1352
1377
  # The resulting string.
1353
1378
  res = ""
@@ -1487,6 +1512,18 @@ module HDLRuby::Low
1487
1512
  # Nothing to generate.
1488
1513
  end
1489
1514
 
1515
+ ## Extends the StringE class with generation of HDLRuby::High text.
1516
+ class StringE
1517
+
1518
+ # Generates the text of the equivalent HDLRuby::High code.
1519
+ # +level+ is the hierachical level of the object.
1520
+ def to_vhdl(level = 0, std_logic = false)
1521
+ # Generate a report statement.
1522
+ return "\"#{Low2VHDL.vhdl_string(self.content)}\"" +
1523
+ self.each_arg.map { |arg| arg.to_vhdl }.join(" & ")
1524
+ end
1525
+ end
1526
+
1490
1527
  ## Extends the Numeric class with generation of HDLRuby::High text.
1491
1528
  class ::Numeric
1492
1529
 
@@ -61,6 +61,20 @@ module HDLRuby::Low
61
61
  return self
62
62
  end
63
63
  end
64
+
65
+
66
+ ## Extends the Print class with functionality for converting booleans
67
+ # in assignments to select operators.
68
+ class Print
69
+
70
+ # Converts booleans in assignments to select operators.
71
+ def boolean_in_assign2select!
72
+ # Apply on the arguments.
73
+ self.map_args! { |arg| arg.boolean_in_assign2select }
74
+ return self
75
+ end
76
+ end
77
+
64
78
 
65
79
  ## Extends the If class with functionality for converting booleans
66
80
  # in assignments to select operators.
@@ -315,4 +329,19 @@ module HDLRuby::Low
315
329
  return self.clone
316
330
  end
317
331
  end
332
+
333
+
334
+ ## Extends the StringE class with functionality for converting booleans
335
+ # in assignments to select operators.
336
+ class StringE
337
+
338
+ # Converts booleans in assignments to select operators.
339
+ def boolean_in_assign2select
340
+ # Apply on the content.
341
+ # Apply on the arguments.
342
+ return StringE.new(self.content.clone,*self.each_arg.map do |arg|
343
+ arg.boolean_in_assign2select
344
+ end)
345
+ end
346
+ end
318
347
  end
@@ -62,6 +62,20 @@ module HDLRuby::Low
62
62
  return self
63
63
  end
64
64
  end
65
+
66
+
67
+ ## Extends the Print class with functionality for extracting
68
+ # expressions from cast.
69
+ class Print
70
+
71
+ # Extracts the expressions from the casts.
72
+ def casts_without_expression!
73
+ # Apply on the arguments.
74
+ self.map_args!(&:casts_without_expression)
75
+ return self
76
+ end
77
+ end
78
+
65
79
 
66
80
  ## Extends the If class with functionality for extracting
67
81
  # expressions from cast.
@@ -323,4 +337,17 @@ module HDLRuby::Low
323
337
  return self.clone
324
338
  end
325
339
  end
340
+
341
+
342
+ ## Extends the StringE class with functionality for extracting
343
+ # expressions from cast.
344
+ class StringE
345
+
346
+ # Extracts the expressions from the casts.
347
+ def casts_without_expression
348
+ return StringE.new(self.content,
349
+ *self.each_arg.map(&:cast_without_expression))
350
+ return self
351
+ end
352
+ end
326
353
  end
@@ -89,6 +89,20 @@ module HDLRuby::Low
89
89
 
90
90
  end
91
91
 
92
+
93
+ ## Extends the Print class with fixing of types and constants.
94
+ class Print
95
+ # Explicit the types conversions in the statement.
96
+ def explicit_types!
97
+ # Recurse on the arguments.
98
+ self.map_args!(&:explicit_types)
99
+ return self
100
+ end
101
+
102
+ end
103
+
104
+
105
+
92
106
 
93
107
  ## Extends the If class with fixing of types and constants.
94
108
  class If
@@ -438,4 +452,15 @@ module HDLRuby::Low
438
452
  end
439
453
 
440
454
 
455
+ ## Extends the stringE class with fixing of types and constants.
456
+ class StringE
457
+ # Explicit the types conversions in the concat where
458
+ # +type+ is the expected type of the condition if any.
459
+ def explicit_types(type = nil)
460
+ return StringE.new(self.content,
461
+ *self.each_arg.map(&:explicit_types))
462
+ end
463
+ end
464
+
465
+
441
466
  end
@@ -626,6 +626,64 @@ module HDLRuby::Low
626
626
  end
627
627
 
628
628
 
629
+ ##
630
+ # Decribes a print statement.
631
+ class Print
632
+
633
+ # Maps on the arguments.
634
+ def map_args!(&ruby_block)
635
+ @args.map! do |arg|
636
+ arg = ruby_block.call(arg)
637
+ arg.parent = self unless arg.parent
638
+ arg
639
+ end
640
+ end
641
+
642
+ alias_method :map_nodes!, :map_args!
643
+
644
+ # Delete an arg.
645
+ def delete_arg!(arg)
646
+ if @args.include?(arg) then
647
+ # The arg is present, delete it.
648
+ @args.delete(arg)
649
+ # And remove its parent.
650
+ arg.parent = nil
651
+ end
652
+ arg
653
+ end
654
+
655
+ # Replaces sub arguments using +node2rep+ table indicating the
656
+ # node to replace and the corresponding replacement.
657
+ # Returns the actually replaced nodes and their corresponding
658
+ # replacement.
659
+ #
660
+ # NOTE: the replacement is duplicated.
661
+ def replace_args!(node2rep)
662
+ # First recurse on the children.
663
+ res = {}
664
+ self.each_node do |node|
665
+ res.merge!(node.replace_args!(node2rep))
666
+ end
667
+ # Is there a replacement of on a sub node?
668
+ self.map_nodes! do |sub|
669
+ rep = node2rep[sub]
670
+ if rep then
671
+ # Yes, do it.
672
+ rep = rep.clone
673
+ node = sub
674
+ # node.set_parent!(nil)
675
+ # And register the replacement.
676
+ res[node] = rep
677
+ rep
678
+ else
679
+ sub
680
+ end
681
+ end
682
+ return res
683
+ end
684
+ end
685
+
686
+
629
687
  ##
630
688
  # Describes an if statement.
631
689
  class If
@@ -1093,6 +1151,18 @@ module HDLRuby::Low
1093
1151
  stmnt.parent = self
1094
1152
  end
1095
1153
 
1154
+ # Replaces statement +org+ by statement +stmnt+.
1155
+ #
1156
+ # NOTE: does nothing if +org+ is not present.
1157
+ def replace_statement!(org,stmnt)
1158
+ # Checks the statement.
1159
+ unless stmnt.is_a?(Statement)
1160
+ raise AnyError, "Invalid type for a statement: #{stmnt.class}"
1161
+ end
1162
+ idx = @statements.index(org)
1163
+ @statements[idx] = stmnt if idx
1164
+ end
1165
+
1096
1166
  # Maps on the statements.
1097
1167
  def map_statements!(&ruby_block)
1098
1168
  @statements.map! do |stmnt|
@@ -84,6 +84,20 @@ module HDLRuby::Low
84
84
  end
85
85
 
86
86
 
87
+ ##
88
+ # Extends RefIndex with the capability of finding the object it
89
+ # refered to.
90
+ class Ref
91
+ ## Resolves the name of the reference (if any) and return the
92
+ # corresponding object.
93
+ # NOTE: return nil if could not resolve.
94
+ def resolve
95
+ # By default cannot resolve.
96
+ return nil
97
+ end
98
+ end
99
+
100
+
87
101
  ##
88
102
  # Extends RefIndex with the capability of finding the object it
89
103
  # refered to.
@@ -93,6 +107,13 @@ module HDLRuby::Low
93
107
  def from_systemI?
94
108
  return self.ref.from_systemI?
95
109
  end
110
+
111
+ ## Resolves the name of the reference (if any) and return the
112
+ # corresponding object.
113
+ # NOTE: return nil if could not resolve.
114
+ def resolve
115
+ return self.ref.resolve
116
+ end
96
117
  end
97
118
 
98
119
 
@@ -105,6 +126,13 @@ module HDLRuby::Low
105
126
  def from_systemI?
106
127
  return self.ref.from_systemI?
107
128
  end
129
+
130
+ ## Resolves the name of the reference (if any) and return the
131
+ # corresponding object.
132
+ # NOTE: return nil if could not resolve.
133
+ def resolve
134
+ return self.ref.resolve
135
+ end
108
136
  end
109
137
 
110
138
 
@@ -42,7 +42,8 @@ module HDLRuby::Low
42
42
  right_r = right.resolve if right.respond_to?(:resolve)
43
43
  # puts "right_r=#{right_r.name}" if right_r
44
44
  # puts "right_r.parent=#{right_r.parent.name}" if right_r && right_r.parent
45
- if right.is_a?(Value) then
45
+ # if right.is_a?(Value) then
46
+ if right.immutable? then
46
47
  # Right is value, the new transmit is to add
47
48
  # to the timed block.
48
49
  timed_blk.add_statement(
@@ -108,13 +109,15 @@ module HDLRuby::Low
108
109
  # end
109
110
  # Both or neither input/output, make a behavior
110
111
  # for each.
111
- if (left.is_a?(Ref)) then
112
+ if (left.is_a?(Ref) &&
113
+ !(left_r && left_r.immutable?)) then
112
114
  blk = Block.new(:par)
113
115
  blk.add_statement(
114
116
  Transmit.new(left.clone,right.clone))
115
117
  scope.add_behavior(Behavior.new(blk))
116
118
  end
117
- if (right.is_a?(Ref)) then
119
+ if (right.is_a?(Ref) &&
120
+ !(right_r && right_r.immutable?)) then
118
121
  blk = Block.new(:par)
119
122
  blk.add_statement(
120
123
  Transmit.new(right.clone,left.clone))
@@ -617,10 +617,13 @@ module HDLRuby::Low
617
617
  #
618
618
  # NOTE: do not recurse into the sub scopes or behaviors!
619
619
  def extract_declares!
620
- # Recurse on the whens.
621
- return self.each_when.map(&:extract_declares!)
622
- # Recurse on the default if any.
623
- self.default.extract_declares! if self.default
620
+ # # Recurse on the whens.
621
+ # return self.each_when.map(&:extract_declares!)
622
+ # # Recurse on the default if any.
623
+ # self.default.extract_declares! if self.default
624
+ res = self.each_when.map(&:extract_declares!)
625
+ res += self.default.extract_declares! if self.default
626
+ return res
624
627
  end
625
628
 
626
629
  # Replaces recursively +former+ name by +nname+ until it is redeclared.
@@ -0,0 +1,151 @@
1
+ require 'HDLRuby'
2
+ require 'HDLRuby/hruby_tools'
3
+ require 'HDLRuby/hruby_low_mutable'
4
+
5
+
6
+ module HDLRuby::Low
7
+
8
+
9
+ ##
10
+ # Converts par blocks within seq blocks to seq blocks.
11
+ # For matching the executing model of Verilog.
12
+ #
13
+ ########################################################################
14
+
15
+
16
+ ## Extends the SystemT class with functionality for converting par blocks
17
+ # within seq blocks to seq blocks.
18
+ class SystemT
19
+
20
+ # Converts par blocks within seq blocks to seq blocks.
21
+ def par_in_seq2seq!
22
+ self.scope.par_in_seq2seq!
23
+ end
24
+ end
25
+
26
+ ## Extends the Scope class with functionality for breaking assingments
27
+ # to concats.
28
+ class Scope
29
+ # Converts par blocks within seq blocks to seq blocks.
30
+ def par_in_seq2seq!
31
+ # Recruse on the sub scopes.
32
+ self.each_scope(&:par_in_seq2seq!)
33
+ # Recurse on the block.
34
+ self.each_behavior do |behavior|
35
+ behavior.block.par_in_seq2seq!
36
+ end
37
+ end
38
+ end
39
+
40
+
41
+ ## Extends the Statement class with functionality for breaking assingments
42
+ # to concats.
43
+ class Statement
44
+ # Converts par blocks within seq blocks to seq blocks.
45
+ def par_in_seq2seq!
46
+ # By default nothing to do.
47
+ return self
48
+ end
49
+
50
+ # Convert the block to seq.
51
+ def to_seq!
52
+ # By default nothing to do.
53
+ return self
54
+ end
55
+ end
56
+
57
+
58
+ ## Extends the If class with functionality for breaking assingments
59
+ # to concats.
60
+ class If
61
+ # Converts par blocks within seq blocks to seq blocks.
62
+ def par_in_seq2seq!
63
+ self.yes.par_in_seq2seq!
64
+ self.each_noif do |cond,blk|
65
+ blk.par_in_seq2seq!
66
+ end
67
+ self.no.par_in_seq2seq! if self.no
68
+ end
69
+
70
+ # Convert the block to seq.
71
+ def to_seq!
72
+ self.to_seq!
73
+ self.each_noif do |cond,blk|
74
+ blk.to_seq!
75
+ end
76
+ self.no.to_seq! if self.no
77
+ end
78
+ end
79
+
80
+
81
+ ## Extends the Case class with functionality for breaking assingments
82
+ # to concats.
83
+ class Case
84
+ # Converts par blocks within seq blocks to seq blocks.
85
+ def par_in_seq2seq!
86
+ self.each_when do |w|
87
+ w.statement.par_in_seq2seq!
88
+ end
89
+ self.default.par_in_seq2seq! if self.default
90
+ end
91
+
92
+ # Convert the block to seq.
93
+ def to_seq!
94
+ self.each_when do |w|
95
+ w.statement.to_seq!
96
+ end
97
+ self.default.to_seq! if self.default
98
+ end
99
+ end
100
+
101
+
102
+ ## Extends the Block class with functionality for breaking assingments
103
+ # to concats.
104
+ class Block
105
+ # Converts par blocks within seq blocks to seq blocks.
106
+ def par_in_seq2seq!
107
+ # Recurse on the sub blocks.
108
+ self.each_statement(&:par_in_seq2seq!)
109
+ # Is the current block a seq block?
110
+ if self.mode == :seq then
111
+ # Yes, convert its inner par blocks to seq blocks.
112
+ self.each_statement do |statement|
113
+ if (statement.is_a?(Block)) then
114
+ statement.to_seq! if statement.mode == :par
115
+ end
116
+ end
117
+ end
118
+ return self
119
+ end
120
+
121
+ # Convert the block to seq.
122
+ def to_seq!
123
+ if self.mode == :par then
124
+ # Need to convert.
125
+ # First recurse on the sub blocks.
126
+ self.each_statement(&:to_seq!)
127
+ # Now replace each left value by a new signal for
128
+ # differed assingment in seq.
129
+ differeds = []
130
+ self.each_statement do |statement|
131
+ left = statement.left
132
+ if statement.is_a?(Transmit) then
133
+ sig = SignalI.new(HDLRuby.uniq_name,left.type)
134
+ self.add_inner(sig)
135
+ diff = RefName.new(left.type,RefThis.new,sig.name)
136
+ differeds << [left,diff]
137
+ statement.set_left!(diff)
138
+ end
139
+ end
140
+ # Adds the differed assignments.
141
+ differeds.each do |left,diff|
142
+ self.add_statement(Transmit.new(left.clone,diff.clone))
143
+ end
144
+ # Change the mode.
145
+ self.set_mode!(:seq)
146
+ end
147
+ return self
148
+ end
149
+ end
150
+
151
+ end