HDLRuby 2.11.11 → 2.11.12

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 (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +55 -18
  3. data/ext/hruby_sim/hruby_rcsim_build.c +27 -0
  4. data/ext/hruby_sim/hruby_sim.h +3 -0
  5. data/ext/hruby_sim/hruby_sim_core.c +17 -5
  6. data/ext/hruby_sim/hruby_sim_stack_calc.c +1 -1
  7. data/ext/hruby_sim/hruby_sim_tree_calc.c +8 -1
  8. data/ext/hruby_sim/hruby_sim_vcd.c +24 -7
  9. data/ext/hruby_sim/hruby_sim_vizualize.c +9 -1
  10. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +3 -1
  11. data/lib/HDLRuby/hdr_samples/counter_dff_bench.rb +3 -1
  12. data/lib/HDLRuby/hdr_samples/huge_rom.rb +1 -1
  13. data/lib/HDLRuby/hdr_samples/mei8.rb +11 -11
  14. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +11 -11
  15. data/lib/HDLRuby/hdr_samples/neg_arith_bench.rb +4 -4
  16. data/lib/HDLRuby/hdr_samples/rom_nest.rb +1 -1
  17. data/lib/HDLRuby/hdr_samples/ruby_fir_hw.rb +4 -4
  18. data/lib/HDLRuby/hdr_samples/struct.rb +44 -10
  19. data/lib/HDLRuby/hdr_samples/with_bram.rb +45 -0
  20. data/lib/HDLRuby/hdr_samples/with_casts.rb +3 -3
  21. data/lib/HDLRuby/hdr_samples/with_concat.rb +6 -6
  22. data/lib/HDLRuby/hdr_samples/with_connector_memory.rb +2 -2
  23. data/lib/HDLRuby/hdr_samples/with_def.rb +10 -3
  24. data/lib/HDLRuby/hdr_samples/with_define_operator.rb +44 -0
  25. data/lib/HDLRuby/hdr_samples/with_fixpoint.rb +12 -12
  26. data/lib/HDLRuby/hdr_samples/with_init.rb +3 -3
  27. data/lib/HDLRuby/hdr_samples/with_leftright.rb +21 -0
  28. data/lib/HDLRuby/hdr_samples/with_reduce.rb +13 -13
  29. data/lib/HDLRuby/hdr_samples/with_ref_array.rb +6 -6
  30. data/lib/HDLRuby/hdr_samples/with_subsums.rb +3 -3
  31. data/lib/HDLRuby/hdr_samples/with_terminate.rb +3 -3
  32. data/lib/HDLRuby/hdr_samples/with_to_a.rb +10 -10
  33. data/lib/HDLRuby/hdr_samples/with_values.rb +3 -3
  34. data/lib/HDLRuby/hdrcc.rb +14 -1
  35. data/lib/HDLRuby/hruby_bstr.rb +10 -5
  36. data/lib/HDLRuby/hruby_high.rb +114 -27
  37. data/lib/HDLRuby/hruby_low.rb +187 -16
  38. data/lib/HDLRuby/hruby_low2c.rb +71 -11
  39. data/lib/HDLRuby/hruby_low2vhd.rb +2 -1
  40. data/lib/HDLRuby/hruby_low_fix_types.rb +1 -0
  41. data/lib/HDLRuby/hruby_low_mutable.rb +30 -1
  42. data/lib/HDLRuby/hruby_low_resolve.rb +15 -2
  43. data/lib/HDLRuby/hruby_low_without_concat.rb +28 -8
  44. data/lib/HDLRuby/hruby_low_without_parinseq.rb +14 -4
  45. data/lib/HDLRuby/hruby_low_without_select.rb +2 -2
  46. data/lib/HDLRuby/hruby_low_without_subsignals.rb +279 -0
  47. data/lib/HDLRuby/hruby_rcsim.rb +80 -71
  48. data/lib/HDLRuby/hruby_rsim.rb +132 -7
  49. data/lib/HDLRuby/hruby_rsim_vcd.rb +99 -27
  50. data/lib/HDLRuby/hruby_values.rb +35 -31
  51. data/lib/HDLRuby/std/bram.rb +22 -0
  52. data/lib/HDLRuby/std/fixpoint.rb +2 -2
  53. data/lib/HDLRuby/std/fsm.rb +20 -3
  54. data/lib/HDLRuby/std/function_generator.rb +2 -2
  55. data/lib/HDLRuby/version.rb +1 -1
  56. metadata +7 -3
  57. data/lib/HDLRuby/hdr_samples/sumprod.rb +0 -29
@@ -66,7 +66,6 @@ module HDLRuby::High
66
66
  @sig_active.each do |sig|
67
67
  next if (sig.c_value.eql?(sig.f_value))
68
68
  # next if (sig.c_value.to_vstr == sig.f_value.to_vstr)
69
- # puts "sig.c_value: #{sig.c_value.to_vstr}, sig.f_value=#{sig.f_value.to_vstr}"
70
69
  sig.each_anyedge { |beh| @sig_exec << beh }
71
70
  if (sig.c_value.zero?) then
72
71
  # puts "sig.c_value=#{sig.c_value.content}"
@@ -108,6 +107,8 @@ module HDLRuby::High
108
107
  HDLRuby.show "#{Time.now}#{show_mem}"
109
108
  # Merge the included.
110
109
  self.merge_included!
110
+ # Process par in seq.
111
+ self.par_in_seq2seq!
111
112
  # Initializes the time.
112
113
  @time = 0
113
114
  # Initializes the time and signals execution buffers.
@@ -131,6 +132,9 @@ module HDLRuby::High
131
132
  self.init_untimeds
132
133
  # puts "End of init_untimed."
133
134
 
135
+ # Maybe there is nothing to execute.
136
+ return if @total_timed_behaviors == 0
137
+
134
138
  # Is there more than one timed behavior.
135
139
  if @total_timed_behaviors <= 1 then
136
140
  # No, no need of multithreading.
@@ -490,6 +494,12 @@ module HDLRuby::High
490
494
 
491
495
  ## Initialize the simulation for +systemT+
492
496
  def init_sim(systemT)
497
+ # Recurse on the sub signals if any.
498
+ if self.each_signal.any? then
499
+ self.each_signal {|sig| sig.init_sim(systemT) }
500
+ return
501
+ end
502
+ # No sub signal, really initialize the current signal.
493
503
  if self.value then
494
504
  @c_value = self.value.execute(:par).to_value
495
505
  @f_value = @c_value.to_value
@@ -506,18 +516,27 @@ module HDLRuby::High
506
516
 
507
517
  ## Adds behavior +beh+ activated on a positive edge of the signal.
508
518
  def add_posedge(beh)
519
+ # Recurse on the sub signals.
520
+ self.each_signal {|sig| sig.add_posedge(beh) }
521
+ # Apply on current signal.
509
522
  @posedge_behaviors ||= []
510
523
  @posedge_behaviors << beh
511
524
  end
512
525
 
513
526
  ## Adds behavior +beh+ activated on a negative edge of the signal.
514
527
  def add_negedge(beh)
528
+ # Recurse on the sub signals.
529
+ self.each_signal {|sig| sig.add_negedge(beh) }
530
+ # Apply on current signal.
515
531
  @negedge_behaviors ||= []
516
532
  @negedge_behaviors << beh
517
533
  end
518
534
 
519
535
  ## Adds behavior +beh+ activated on a any edge of the signal.
520
536
  def add_anyedge(beh)
537
+ # Recurse on the sub signals.
538
+ self.each_signal {|sig| sig.add_anyedge(beh) }
539
+ # Apply on current signal.
521
540
  @anyedge_behaviors ||= []
522
541
  @anyedge_behaviors << beh
523
542
  end
@@ -543,9 +562,9 @@ module HDLRuby::High
543
562
 
544
563
  ## Execute the expression.
545
564
  def execute(mode)
546
- # puts "Executing signal=#{self.fullname}"
547
- # return mode == :par ? self.c_value : self.f_value
565
+ # puts "Executing signal=#{self.fullname} in mode=#{mode} with c_value=#{self.c_value} and f_value=#{self.f_value}"
548
566
  return @mode == :seq ? self.f_value : self.c_value
567
+ # return @mode == :seq || mode == :seq ? self.f_value : self.c_value
549
568
  end
550
569
 
551
570
  ## Assigns +value+ the the reference.
@@ -649,10 +668,12 @@ module HDLRuby::High
649
668
  ## Initialize the simulation for system +systemT+.
650
669
  def init_sim(systemT)
651
670
  self.left.init_sim(systemT)
671
+ self.right.init_sim(systemT)
652
672
  end
653
673
 
654
674
  ## Executes the statement.
655
675
  def execute(mode)
676
+ # puts "execute Transmit in mode=#{mode} for left=#{self.left.object.name}"
656
677
  self.left.assign(mode,self.right.execute(mode))
657
678
  end
658
679
  end
@@ -670,6 +691,7 @@ module HDLRuby::High
670
691
 
671
692
  ## Executes the statement.
672
693
  def execute(mode)
694
+ # puts "execute hif with mode=#{mode}"
673
695
  # Check the main condition.
674
696
  if !(self.condition.execute(mode).zero?) then
675
697
  self.yes.execute(mode)
@@ -848,6 +870,7 @@ module HDLRuby::High
848
870
 
849
871
  ## Executes the statement.
850
872
  def execute(mode)
873
+ # puts "execute block of mode=#{self.mode}"
851
874
  self.each_statement { |stmnt| stmnt.execute(self.mode) }
852
875
  end
853
876
 
@@ -858,6 +881,27 @@ module HDLRuby::High
858
881
  end
859
882
  end
860
883
 
884
+ class If
885
+ ## Returns the name of the signal with its hierarchy.
886
+ def fullname
887
+ return self.parent.fullname
888
+ end
889
+ end
890
+
891
+ class When
892
+ ## Returns the name of the signal with its hierarchy.
893
+ def fullname
894
+ return self.parent.fullname
895
+ end
896
+ end
897
+
898
+ class Case
899
+ ## Returns the name of the signal with its hierarchy.
900
+ def fullname
901
+ return self.parent.fullname
902
+ end
903
+ end
904
+
861
905
  # Describes a timed block.
862
906
  #
863
907
  # NOTE:
@@ -889,8 +933,9 @@ module HDLRuby::High
889
933
  def init_sim(systemT)
890
934
  # Add the connection to the list of untimed objets.
891
935
  systemT.add_untimed(self)
892
- # Recurse on the left.
936
+ # Recurse on the left and right.
893
937
  self.left.init_sim(systemT)
938
+ self.right.init_sim(systemT)
894
939
  # Process the sensitivity list.
895
940
  # Is it a clocked behavior?
896
941
  events = []
@@ -914,7 +959,7 @@ module HDLRuby::High
914
959
 
915
960
  ## Executes the statement.
916
961
  def execute(mode)
917
- # puts "connection = #{self}" if self.left.is_a?(RefObject) && self.left.object.name.to_s.include?("xnor")
962
+ # puts "connection left=#{left} right=#{right}"
918
963
  self.left.assign(mode,self.right.execute(mode))
919
964
  end
920
965
  end
@@ -926,6 +971,11 @@ module HDLRuby::High
926
971
  #
927
972
  # NOTE: this is an abstract class which is not to be used directly.
928
973
  class Expression
974
+ ## Initialize the simulation for system +systemT+.
975
+ def init_sim(systemT)
976
+ # By default: do nothing.
977
+ end
978
+
929
979
  ## Executes the expression in +mode+ (:blocking or :nonblocking)
930
980
  # NOTE: to be overrided.
931
981
  def execute(mode)
@@ -937,6 +987,11 @@ module HDLRuby::High
937
987
  ##
938
988
  # Describes a value.
939
989
  class Value
990
+ ## Initialize the simulation for system +systemT+.
991
+ def init_sim(systemT)
992
+ # Nothing to do.
993
+ end
994
+
940
995
  # include Vprocess
941
996
 
942
997
  ## Executes the expression.
@@ -949,10 +1004,16 @@ module HDLRuby::High
949
1004
  ##
950
1005
  # Describes a cast.
951
1006
  class Cast
1007
+ ## Initialize the simulation for system +systemT+.
1008
+ def init_sim(systemT)
1009
+ # Recurse on the child.
1010
+ self.child.init_sim(systemT)
1011
+ end
1012
+
952
1013
  ## Executes the expression.
953
1014
  def execute(mode)
954
- # Recurse on the child.
955
- # res = tocast.execute(mode)
1015
+ # puts "child=#{self.child}"
1016
+ # puts "child object=#{self.child.object}(#{self.child.object.name})" if self.child.is_a?(RefObject)
956
1017
  # Shall we reverse the content of a concat.
957
1018
  if self.child.is_a?(Concat) &&
958
1019
  self.type.direction != self.child.type.direction then
@@ -961,6 +1022,7 @@ module HDLRuby::High
961
1022
  else
962
1023
  res = self.child.execute(mode)
963
1024
  end
1025
+ # puts "res=#{res}"
964
1026
  # Cast it.
965
1027
  res = res.cast(self.type,true)
966
1028
  # Returns the result.
@@ -981,6 +1043,12 @@ module HDLRuby::High
981
1043
  ##
982
1044
  # Describes an unary operation.
983
1045
  class Unary
1046
+ ## Initialize the simulation for system +systemT+.
1047
+ def init_sim(systemT)
1048
+ # Recurse on the child.
1049
+ self.child.init_sim(systemT)
1050
+ end
1051
+
984
1052
  ## Execute the expression.
985
1053
  def execute(mode)
986
1054
  # puts "Unary with operator=#{self.operator}"
@@ -996,6 +1064,13 @@ module HDLRuby::High
996
1064
  ##
997
1065
  # Describes an binary operation.
998
1066
  class Binary
1067
+ ## Initialize the simulation for system +systemT+.
1068
+ def init_sim(systemT)
1069
+ # Recurse on the children.
1070
+ self.left.init_sim(systemT)
1071
+ self.right.init_sim(systemT)
1072
+ end
1073
+
999
1074
  ## Execute the expression.
1000
1075
  def execute(mode)
1001
1076
  # Recurse on the children.
@@ -1012,6 +1087,13 @@ module HDLRuby::High
1012
1087
  #
1013
1088
  # NOTE: choice is using the value of +select+ as an index.
1014
1089
  class Select
1090
+ ## Initialize the simulation for system +systemT+.
1091
+ def init_sim(systemT)
1092
+ # Recurse on the children.
1093
+ self.select.init_sim(systemT)
1094
+ self.each_choice { |choice| choice.init_sim(systemT) }
1095
+ end
1096
+
1015
1097
  ## Execute the expression.
1016
1098
  def execute(mode)
1017
1099
  unless @mask then
@@ -1033,6 +1115,12 @@ module HDLRuby::High
1033
1115
  ##
1034
1116
  # Describes a concatenation expression.
1035
1117
  class Concat
1118
+ ## Initialize the simulation for system +systemT+.
1119
+ def init_sim(systemT)
1120
+ # Recurse on the children.
1121
+ self.each_expression { |expr| expr.init_sim(systemT) }
1122
+ end
1123
+
1036
1124
  ## Execute the expression.
1037
1125
  def execute(mode, reverse=false)
1038
1126
  # Recurse on the children.
@@ -1218,7 +1306,44 @@ module HDLRuby::High
1218
1306
  class RefObject
1219
1307
  ## Initialize the simulation for system +systemT+.
1220
1308
  def init_sim(systemT)
1309
+ # puts "init_sim for RefObject=#{self}"
1221
1310
  @sim = systemT
1311
+
1312
+ # Modify the exectute and assign methods if the object has
1313
+ # sub signals (for faster execution).
1314
+ if self.object.each_signal.any? then
1315
+ ## Execute the expression.
1316
+ self.define_singleton_method(:execute) do |mode|
1317
+ # Recurse on the children.
1318
+ iter = self.object.each_signal
1319
+ iter = iter.reverse_each unless self.object.type.direction == :big
1320
+ tmpe = iter.map {|sig| sig.execute(mode) }
1321
+ # Concatenate the result.
1322
+ # return tmpe.reduce(:concat)
1323
+ return Vprocess.concat(*tmpe)
1324
+ end
1325
+ ## Assigns +value+ the the reference.
1326
+ self.define_singleton_method(:assign) do |mode,value|
1327
+ # puts "RefObject #{self} assign with object=#{self.object}"
1328
+ # Flatten the value type.
1329
+ value.type = [value.type.width].to_type
1330
+ pos = 0
1331
+ width = 0
1332
+ # Recurse on the children.
1333
+ iter = self.object.each_signal
1334
+ iter = iter.reverse_each unless self.object.type.direction == :big
1335
+ iter.each do |sig|
1336
+ width = sig.type.width
1337
+ sig.assign(mode,value[(pos+width-1).to_expr..pos.to_expr])
1338
+ # Tell the signal changed.
1339
+ if !(sig.c_value.eql?(sig.f_value)) then
1340
+ @sim.add_sig_active(sig)
1341
+ end
1342
+ # Prepare for the next reference.
1343
+ pos += width
1344
+ end
1345
+ end
1346
+ end
1222
1347
  end
1223
1348
 
1224
1349
  ## Execute the expression.
@@ -94,9 +94,10 @@ module HDLRuby::High
94
94
 
95
95
  ## Gets the VCD variables with their long name.
96
96
  def get_vars_with_fullname(vars_with_fullname = {})
97
- # Adds the signals of the interface of the system.
97
+ # Recurse on the signals.
98
98
  self.each_signal do |sig|
99
- vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
99
+ sig.get_vars_with_fullname(vars_with_fullname)
100
+ # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
100
101
  end
101
102
  # Recurse on the scope.
102
103
  return self.scope.get_vars_with_fullname(vars_with_fullname)
@@ -104,9 +105,13 @@ module HDLRuby::High
104
105
 
105
106
  ## Gets the VCD variables with their id string.
106
107
  def get_vars_with_idstr(vars_with_idstr = {})
107
- # Adds the signals of the interface of the system.
108
+ # # Adds the signals of the interface of the system.
109
+ # self.each_signal do |sig|
110
+ # vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig)
111
+ # end
112
+ # Recurse on the signals.
108
113
  self.each_signal do |sig|
109
- vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig)
114
+ sig.get_vars_with_idstr(vars_with_idstr)
110
115
  end
111
116
  # Recurse on the scope.
112
117
  return self.scope.get_vars_with_idstr(vars_with_idstr)
@@ -119,11 +124,11 @@ module HDLRuby::High
119
124
  vcdout << "$scope module #{HDLRuby::High.vcd_name(self.name)} $end\n"
120
125
  # Shows the interface signals.
121
126
  self.each_signal do |sig|
122
- # puts "showing signal #{HDLRuby::High.vcd_name(sig.fullname)}"
123
- vcdout << "$var wire #{sig.type.width} "
124
- # vcdout << "#{HDLRuby::High.vcd_name(sig.fullname)} "
125
- vcdout << "#{HDLRuby::High.vcd_idstr(sig)} "
126
- vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n"
127
+ sig.show_hierarchy(vcdout)
128
+ # # puts "showing signal #{HDLRuby::High.vcd_name(sig.fullname)}"
129
+ # vcdout << "$var wire #{sig.type.width} "
130
+ # vcdout << "#{HDLRuby::High.vcd_idstr(sig)} "
131
+ # vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n"
127
132
  end
128
133
  # Recurse on the scope.
129
134
  self.scope.show_hierarchy(vcdout)
@@ -170,11 +175,12 @@ module HDLRuby::High
170
175
  end
171
176
  # Shows the inner signals.
172
177
  self.each_inner do |sig|
173
- # puts "showing inner signal #{HDLRuby::High.vcd_name(sig.fullname)}"
174
- vcdout << "$var wire #{sig.type.width} "
175
- # vcdout << "#{HDLRuby::High.vcd_name(sig.fullname)} "
176
- vcdout << "#{HDLRuby::High.vcd_idstr(sig)} "
177
- vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n"
178
+ sig.show_hierarchy(vcdout)
179
+ # # puts "showing inner signal #{HDLRuby::High.vcd_name(sig.fullname)}"
180
+ # vcdout << "$var wire #{sig.type.width} "
181
+ # # vcdout << "#{HDLRuby::High.vcd_name(sig.fullname)} "
182
+ # vcdout << "#{HDLRuby::High.vcd_idstr(sig)} "
183
+ # vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n"
178
184
  end
179
185
  # Recurse on the behaviors' blocks
180
186
  self.each_behavior do |beh|
@@ -196,9 +202,14 @@ module HDLRuby::High
196
202
 
197
203
  ## Gets the VCD variables with their long name.
198
204
  def get_vars_with_fullname(vars_with_fullname = {})
199
- # Adds the inner signals.
205
+ # # Adds the inner signals.
206
+ # self.each_inner do |sig|
207
+ # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
208
+ # end
209
+ # Recurse on the inner signals.
200
210
  self.each_inner do |sig|
201
- vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
211
+ sig.get_vars_with_fullname(vars_with_fullname)
212
+ # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
202
213
  end
203
214
  # Recurse on the behaviors' blocks
204
215
  self.each_behavior do |beh|
@@ -217,9 +228,13 @@ module HDLRuby::High
217
228
 
218
229
  ## Gets the VCD variables with their id string.
219
230
  def get_vars_with_idstr(vars_with_idstr = {})
220
- # Adds the inner signals.
231
+ # # Adds the inner signals.
232
+ # self.each_inner do |sig|
233
+ # vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig)
234
+ # end
235
+ # Recurse on the inner signals.
221
236
  self.each_inner do |sig|
222
- vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig)
237
+ sig.get_vars_with_idstr(vars_with_idstr)
223
238
  end
224
239
  # Recurse on the behaviors' blocks
225
240
  self.each_behavior do |beh|
@@ -237,6 +252,53 @@ module HDLRuby::High
237
252
  end
238
253
  end
239
254
 
255
+ ##
256
+ # Enhance the signals class with VCD support.
257
+ module SimSignal
258
+ ## Shows the hierarchy of the variables.
259
+ def show_hierarchy(vcdout)
260
+ # puts "show_hierarcy for signal=#{self.name}"
261
+ if self.each_signal.any? then
262
+ # The signal is hierarchical, recurse on the sub signals.
263
+ vcdout << "$scope module #{HDLRuby::High.vcd_name(self.name)} $end\n"
264
+ self.each_signal { |sig| sig.show_hierarchy(vcdout) }
265
+ vcdout << "$upscope $end\n"
266
+ else
267
+ # This is a signal to show.
268
+ vcdout << "$var wire #{self.type.width} "
269
+ vcdout << "#{HDLRuby::High.vcd_idstr(self)} "
270
+ vcdout << "#{HDLRuby::High.vcd_name(self.name)} $end\n"
271
+ end
272
+ end
273
+
274
+ ## Gets the VCD variables with their long name.
275
+ def get_vars_with_fullname(vars_with_fullname = {})
276
+ if self.each_signal.any? then
277
+ # There are sub signals, recurse on them.
278
+ self.each_signal do |sig|
279
+ sig.get_vars_with_fullname(vars_with_fullname)
280
+ end
281
+ else
282
+ # No add the current signal.
283
+ vars_with_fullname[self] = HDLRuby::High.vcd_name(self.fullname)
284
+ end
285
+ return vars_with_full_name
286
+ end
287
+
288
+ ## Gets the VCD variables with their id string.
289
+ def get_vars_with_idstr(vars_with_idstr = {})
290
+ if self.each_signal.any? then
291
+ # There are sub signals, recurse on them.
292
+ self.each_signal do |sig|
293
+ sig.get_vars_with_idstr(vars_with_idstr)
294
+ end
295
+ else
296
+ # No add the current signal.
297
+ vars_with_idstr[self] = HDLRuby::High.vcd_idstr(self)
298
+ end
299
+ return vars_with_idstr
300
+ end
301
+ end
240
302
 
241
303
  ##
242
304
  # Enhance the Transmit class with VCD support.
@@ -329,11 +391,12 @@ module HDLRuby::High
329
391
  end
330
392
  # Shows the inner signals.
331
393
  self.each_inner do |sig|
332
- # puts "showing inner signal #{HDLRuby::High.vcd_name(sig.fullname)}"
333
- vcdout << "$var wire #{sig.type.width} "
334
- # vcdout << "#{HDLRuby::High.vcd_name(sig.fullname)} "
335
- vcdout << "#{HDLRuby::High.vcd_idstr(sig)} "
336
- vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n"
394
+ sig.show_hierarchy(vcdout)
395
+ # # puts "showing inner signal #{HDLRuby::High.vcd_name(sig.fullname)}"
396
+ # vcdout << "$var wire #{sig.type.width} "
397
+ # # vcdout << "#{HDLRuby::High.vcd_name(sig.fullname)} "
398
+ # vcdout << "#{HDLRuby::High.vcd_idstr(sig)} "
399
+ # vcdout << "#{HDLRuby::High.vcd_name(sig.name)} $end\n"
337
400
  end
338
401
  # Recurse on the statements
339
402
  self.each_statement do |stmnt|
@@ -347,9 +410,14 @@ module HDLRuby::High
347
410
 
348
411
  ## Gets the VCD variables with their long name.
349
412
  def get_vars_with_fullname(vars_with_fullname = {})
350
- # Adds the inner signals.
413
+ # # Adds the inner signals.
414
+ # self.each_inner do |sig|
415
+ # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
416
+ # end
417
+ # Recurse on the inner signals.
351
418
  self.each_inner do |sig|
352
- vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
419
+ sig.get_vars_with_fullname(vars_with_fullname)
420
+ # vars_with_fullname[sig] = HDLRuby::High.vcd_name(sig.fullname)
353
421
  end
354
422
  # Recurse on the statements.
355
423
  self.each_statement do |stmnt|
@@ -360,9 +428,13 @@ module HDLRuby::High
360
428
 
361
429
  ## Gets the VCD variables with their id string.
362
430
  def get_vars_with_idstr(vars_with_idstr = {})
363
- # Adds the inner signals.
431
+ # # Adds the inner signals.
432
+ # self.each_inner do |sig|
433
+ # vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig)
434
+ # end
435
+ # Recurse on the inner signals.
364
436
  self.each_inner do |sig|
365
- vars_with_idstr[sig] = HDLRuby::High.vcd_idstr(sig)
437
+ sif.get_vars_with_idstr(vars_with_idstr)
366
438
  end
367
439
  # Recurse on the statements.
368
440
  self.each_statement do |stmnt|
@@ -13,6 +13,9 @@ module HDLRuby
13
13
 
14
14
  # Truncs integer +val+ to +width+
15
15
  def trunc(val,width)
16
+ if val.is_a?(BitString) then
17
+ return val[(width-1)..0]
18
+ end
16
19
  if val.bit_length > width then
17
20
  if val >= 0 then
18
21
  # return val & (2**width-1)
@@ -38,8 +41,9 @@ module HDLRuby
38
41
  unless val.to_value? then
39
42
  # Not computable, use the former method that generates
40
43
  # HDLRuby code.
41
- return self.send(orig_operator(op),value)
44
+ return self.send(orig_operator(op),val)
42
45
  end
46
+ val = val.to_value unless val.is_a?(Value)
43
47
  # Handle Numeric op BitString case.
44
48
  if self.content.is_a?(Numeric) && val.content.is_a?(BitString)
45
49
  if val.content.specified? then
@@ -80,27 +84,29 @@ module HDLRuby
80
84
  return self.send(orig_operator(op),val)
81
85
  end
82
86
  # Process left.
83
- # unless left.is_a?(Numeric) || left.is_a?(BitString) then
84
- # left = left.to_value.content
85
- # end
86
- left = left.content
87
- if left.is_a?(BitString) && !left.specified? then
88
- return self.class.new(self.type.base,
89
- BitString::UNKNOWN.clone)
87
+ if left.is_a?(Value) then
88
+ left = left.content
89
+ if left.is_a?(BitString) && !left.specified? then
90
+ return self.class.new(self.type.base,
91
+ BitString::UNKNOWN.clone)
92
+ end
93
+ # left = left.to_i
94
+ left = self.trunc(left.to_i,val.first.type.width)
95
+ else
96
+ left = left.to_i
90
97
  end
91
- # left = left.to_i
92
- left = self.trunc(left.to_i,val.first.type.width)
93
98
  # Process right.
94
- # unless right.is_a?(Numeric) || right.is_a?(BitString) then
95
- # right = right.to_value.content
96
- # end
97
- right = right.content
98
- if right.is_a?(BitString) && !right.specified? then
99
- return self.class.new(self.type.base,
100
- BitString::UNKNOWN.clone)
99
+ if right.is_a?(Value) then
100
+ right = right.content
101
+ if right.is_a?(BitString) && !right.specified? then
102
+ return self.class.new(self.type.base,
103
+ BitString::UNKNOWN.clone)
104
+ end
105
+ # right = right.to_i
106
+ right = self.trunc(right.to_i,val.last.type.width)
107
+ else
108
+ right = right.to_i
101
109
  end
102
- # right = right.to_i
103
- right = self.trunc(right.to_i,val.last.type.width)
104
110
  # Generate the resulting type.
105
111
  res_type = self.type.base[(left-right+1).abs]
106
112
  # Generate the resulting value.
@@ -124,18 +130,16 @@ module HDLRuby
124
130
  return self.send(orig_operator(op),val)
125
131
  end
126
132
  # Process val.
127
- index = val.content
128
- if index.is_a?(BitString) && !index.specified? then
129
- return self.class.new(self.type.base,
130
- BitString::UNKNOWN.clone)
133
+ if val.is_a?(Value) then
134
+ index = val.content
135
+ if index.is_a?(BitString) && !index.specified? then
136
+ return self.class.new(self.type.base,
137
+ BitString::UNKNOWN.clone)
138
+ end
139
+ index = self.trunc(index.to_i,val.type.width)
140
+ else
141
+ index = val.to_i
131
142
  end
132
- index = self.trunc(index.to_i,val.type.width)
133
- # index = index.to_i
134
- # if index >= self.type.size then
135
- # # puts "index=#{index}"
136
- # index %= self.type.size
137
- # # puts "now index=#{index}"
138
- # end
139
143
  # Generate the resulting type.
140
144
  res_type = self.type.base
141
145
  # Generate the resulting value.
@@ -308,7 +312,7 @@ module HDLRuby
308
312
  break if count == width
309
313
  end
310
314
  if count < width then
311
- res_content.concat(res_content[-1] * (width-count))
315
+ res_content.concat([res_content[-1]] * (width-count))
312
316
  end
313
317
  else
314
318
  width.times do |p|
@@ -0,0 +1,22 @@
1
+ module HDLRuby::High::Std
2
+
3
+ # Describe a RAM compatibile with BRAM of FPGAs.
4
+ # - 'widthA': address bit width
5
+ # - 'widthD': data bit width
6
+ system :bram do |widthA, widthD|
7
+ input :clk, :rwb
8
+ [widthA].input :addr
9
+ [widthD].input :din
10
+ [widthD].output :dout
11
+
12
+ # puts "widthA=#{widthA} widthD=#{widthD}"
13
+
14
+ bit[widthD][-2**widthA].inner mem: [ :"_b#{"0"*widthD}".to_value ] * 2**widthA
15
+
16
+ par(clk.negedge) do
17
+ hif(rwb == 1) { mem[addr] <= din }
18
+ dout <= mem[addr]
19
+ end
20
+ end
21
+
22
+ end
@@ -55,14 +55,14 @@ module HDLRuby::High::Std
55
55
  if (typ.signed?) then
56
56
  (left.as(signed[isize+fsize*2])*right) >> fsize
57
57
  else
58
- (left.as([isize+fsize*2])*right) >> fsize
58
+ (left.as(bit[isize+fsize*2])*right) >> fsize
59
59
  end
60
60
  end
61
61
  typ.define_operator(:/) do |left,right|
62
62
  if (typ.signed?) then
63
63
  (left.as(signed[isize+fsize*2]) << fsize) / right
64
64
  else
65
- (left.as([isize+fsize*2]) << fsize) / right
65
+ (left.as(bit[isize+fsize*2]) << fsize) / right
66
66
  end
67
67
  end
68
68
  # Define the removal of the point.