HDLRuby 2.11.5 → 2.11.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,35 @@
1
+ require "HDLRuby/hruby_rsim"
2
+
3
+ ##
4
+ # Library for enhancing the Ruby simulator with VCD support
5
+ #
6
+ ########################################################################
7
+ module HDLRuby::High
8
+
9
+ ##
10
+ # Enhance the system type class with VCD support.
11
+ class SystemT
12
+
13
+ ## Initializes the displayer for generating a vcd on +vcdout+
14
+ def show_init(vcdout)
15
+ end
16
+
17
+ ## Displays the time.
18
+ def show_time
19
+ end
20
+
21
+ ## Displays the value of signal +sig+.
22
+ def show_signal(sig)
23
+ end
24
+
25
+ ## Displays value +val+.
26
+ # NOTE: for now displays on the standard output and NOT the vcd.
27
+ def show_value(val)
28
+ end
29
+
30
+ ## Displays string +str+.
31
+ def show_string(str)
32
+ end
33
+ end
34
+
35
+ end
@@ -440,7 +440,7 @@ module HDLRuby::High
440
440
  w.statement.show_hierarchy(vcdout)
441
441
  end
442
442
  # Recurse on the default if any.
443
- self.default.show_hierarchy(vcdout)
443
+ self.default.show_hierarchy(vcdout) if self.default
444
444
  end
445
445
 
446
446
  ## Gets the VCD variables with their long name.
@@ -450,7 +450,7 @@ module HDLRuby::High
450
450
  w.statement.get_vars_with_fullname(vars_with_fullname)
451
451
  end
452
452
  # Recurse on the default if any.
453
- self.default.get_vars_with_fullname(vars_with_fullname)
453
+ self.default.get_vars_with_fullname(vars_with_fullname) if self.default
454
454
  return vars_with_fullname
455
455
  end
456
456
 
@@ -461,7 +461,7 @@ module HDLRuby::High
461
461
  w.statement.get_vars_with_idstr(vars_with_idstr)
462
462
  end
463
463
  # Recurse on the default if any.
464
- self.default.get_vars_with_idstr(vars_with_idstr)
464
+ self.default.get_vars_with_idstr(vars_with_idstr) if self.default
465
465
  return vars_with_idstr
466
466
  end
467
467
  end
@@ -34,7 +34,6 @@ module HDLRuby
34
34
  :==, :!=, :<, :>, :<=, :>=, :<=> ].
35
35
  each do |op|
36
36
  define_method(op) do |val|
37
- # puts "op=#{op} value=#{value}"
38
37
  # Ensures val is computable.
39
38
  unless val.to_value? then
40
39
  # Not computable, use the former method that generates
@@ -45,6 +44,7 @@ module HDLRuby
45
44
  if self.content.is_a?(Numeric) && val.content.is_a?(BitString)
46
45
  if val.content.specified? then
47
46
  res_content = self.content.send(op,val.content.to_i)
47
+ # puts "op=#{op} self.content=#{self.content} val.content=#{val.content.to_i} res_content=#{res_content}"
48
48
  else
49
49
  res_content =
50
50
  BitString.new(self.content).send(op,val.content)
@@ -52,7 +52,7 @@ module HDLRuby
52
52
  else
53
53
  # Generate the resulting content.
54
54
  res_content = self.content.send(op,val.content)
55
- # puts "op=#{op} self.content=#{self.content} (#{self.content.class}) val.content=#{val.content} (#{val.content.class}) res_content=#{res_content} (#{res_content.class})"
55
+ # puts "op=#{op} self.content=#{self.content} (#{self.content.to_i}) val.content=#{val.content} (#{val.content.to_i}) res_content=#{res_content} (#{res_content.class})" if op == :^
56
56
  end
57
57
  res_type = self.type.resolve(val.type)
58
58
  # # Adjust the result content size.
@@ -374,6 +374,23 @@ module HDLRuby
374
374
  return other,self.content
375
375
  end
376
376
 
377
+ # Hash-map comparison of values.
378
+ # Also use in simulation engines to know if a signal changed.
379
+ def eql?(val)
380
+ if self.content.is_a?(Numeric) then
381
+ return self.content == val if val.is_a?(Numeric)
382
+ return self.content == val.content if val.content.is_a?(Numeric)
383
+ return false unless val.content.specified?
384
+ return self.content == val.content.to_i
385
+ else
386
+ return self.content.to_i == val if val.is_a?(Numeric)
387
+ return self.content.eql?(val.content) unless val.content.is_a?(Numeric)
388
+ return false if self.content.specified?
389
+ return self.content.to_i == val.content
390
+ end
391
+ end
392
+
393
+
377
394
  # Tell if the value is zero.
378
395
  def zero?
379
396
  return false unless @content
@@ -1524,7 +1524,14 @@ module HDLRuby::Low
1524
1524
  # Converts the system to Verilog code.
1525
1525
  def to_verilog
1526
1526
  # Outputs the first and second choices (choice (0) and choice (1)).
1527
- return "#{self.select.to_verilog} == 1 #{self.operator} #{self.get_choice(0).to_verilog} : #{self.get_choice(1).to_verilog}"
1527
+ # return "#{self.select.to_verilog} == 1 #{self.operator} #{self.get_choice(0).to_verilog} : #{self.get_choice(1).to_verilog}"
1528
+ res = ""
1529
+ sels = self.select.to_verilog
1530
+ @choices[0..-2].each_with_index do |choice,i|
1531
+ res << "#{sels} == #{i} ? #{choice.to_verilog} : "
1532
+ end
1533
+ res << @choices[-1].to_verilog
1534
+ return res
1528
1535
  end
1529
1536
  end
1530
1537
 
@@ -1534,18 +1541,36 @@ module HDLRuby::Low
1534
1541
  # Converts the system to Verilog code.
1535
1542
  # If it is bit, it is b, and if it is int, it is represented by d. (Example: 4'b0000, 32'd1)
1536
1543
  def to_verilog(unknown = nil)
1537
- if self.type.base.name.to_s == "bit"
1538
- return "#{self.type.range.first + 1}'b#{self.content.to_verilog}"
1539
- elsif self.type.name.to_s == "integer"
1540
- str = self.content.to_verilog
1541
- if str[0] == "-" then
1542
- # Negative value.
1543
- return "-#{self.type.range.first + 1}'d#{str[1..-1]}"
1544
+ # if self.type.base.name.to_s == "bit"
1545
+ # if self.type.unsigned? then
1546
+ # # return "#{self.type.range.first + 1}'b#{self.content.to_verilog}"
1547
+ # return "#{self.type.width}'b#{self.content.to_verilog}"
1548
+ # elsif self.type.name.to_s == "integer"
1549
+ # str = self.content.to_verilog
1550
+ # if str[0] == "-" then
1551
+ # # Negative value.
1552
+ # return "-#{self.type.range.first + 1}'d#{str[1..-1]}"
1553
+ # else
1554
+ # return "#{self.type.range.first + 1}'d#{str}"
1555
+ # end
1556
+ # end
1557
+ # return "#{self.type.range.first + 1}'b#{self.content.to_verilog}"
1558
+ if self.content.is_a?(Numeric) then
1559
+ if self.content < 0 then
1560
+ # str = (2**self.type.width + self.content).to_s(2)
1561
+ str = self.content.to_s(2)
1562
+ str = "0" * (self.type.width-str.length+1) + str[1..-1]
1563
+ return "-#{self.type.width}'b#{str}"
1544
1564
  else
1545
- return "#{self.type.range.first + 1}'d#{str}"
1565
+ str = self.content.to_s(2)
1566
+ str = "0" * (self.type.width-str.length) + str
1567
+ return "#{self.type.width}'b#{str}"
1546
1568
  end
1569
+ # return "#{self.type.width}'b#{str}"
1570
+ else
1571
+ str = self.content.to_verilog
1572
+ return "#{str.length}'b#{str}"
1547
1573
  end
1548
- return "#{self.type.range.first + 1}'b#{self.content.to_verilog}"
1549
1574
  end
1550
1575
  # How to use when simply obtaining the width
1551
1576
  def to_getrange
@@ -1602,7 +1627,6 @@ module HDLRuby::Low
1602
1627
 
1603
1628
  result = " " * spc # Indented based on space_count.
1604
1629
 
1605
- result = ""
1606
1630
  result << "case(#{self.value.to_verilog})\n"
1607
1631
 
1608
1632
  # n the case statement, each branch is partitioned by when. Process each time when.
@@ -1611,18 +1635,19 @@ module HDLRuby::Low
1611
1635
  result << " " * (spc+3) + "#{whens.match.to_verilog}: "
1612
1636
 
1613
1637
  if whens.statement.each_statement.count >= 1 then
1614
- result << whens.statement.to_verilog(spc+3)
1638
+ result << whens.statement.to_verilog(spc+3) << "\n"
1615
1639
  else
1616
- result << "\n"
1640
+ result << ";\n"
1617
1641
  end
1618
1642
  end
1619
1643
  if self.default then
1644
+ result << " " * (spc+3) + "default: "
1620
1645
  if self.default.each_statement.count >= 1 then
1621
1646
  result << self.default.each_statement.map do |stmnt|
1622
1647
  stmnt.to_verilog(spc+3)
1623
- end.join("\n")
1648
+ end.join("\n") << "\n"
1624
1649
  else
1625
- result << "\n"
1650
+ result << ";\n"
1626
1651
  end
1627
1652
  end
1628
1653
  result << " " * spc + "endcase\n" # Conclusion.
@@ -2032,6 +2057,9 @@ module HDLRuby::Low
2032
2057
  # Generate content code.
2033
2058
  codeC = ""
2034
2059
 
2060
+ # Arrays to initialize.
2061
+ arrays_to_init = []
2062
+
2035
2063
  # Declare "inner".
2036
2064
  self.each_inner do |inner|
2037
2065
  if HDLRuby::Low::VERILOG_REGS.include?(inner.to_verilog) then
@@ -2050,8 +2078,14 @@ module HDLRuby::Low
2050
2078
  codeC << " #{inner.type.to_verilog}#{inner.to_verilog}"
2051
2079
  end
2052
2080
  if inner.value then
2053
- # There is an initial value.
2054
- codeC << " = #{inner.value.to_verilog}"
2081
+ val = inner.value
2082
+ val = val.child while val.is_a?(Cast)
2083
+ if val.is_a?(Concat) then
2084
+ arrays_to_init << [inner,val]
2085
+ else
2086
+ # There is an initial value.
2087
+ codeC << " = #{inner.value.to_verilog}"
2088
+ end
2055
2089
  end
2056
2090
  codeC << ";\n"
2057
2091
  end
@@ -2192,6 +2226,22 @@ module HDLRuby::Low
2192
2226
 
2193
2227
  end
2194
2228
 
2229
+ # Generate the code for the initialization of the arrays.
2230
+ if arrays_to_init.any? then
2231
+ codeC << " initial begin\n"
2232
+ arrays_to_init.each do |(sig,val)|
2233
+ val.each_expression.with_index do |expr,i|
2234
+ # Initialization, therefore maybe no cast required...
2235
+ # if sig.value.is_a?(Cast) then
2236
+ # expr = Cast.new(sig.value.type,expr.clone)
2237
+ # end
2238
+ codeC << " ";
2239
+ codeC << "#{sig.to_verilog}[#{i}]=#{expr.to_verilog};\n"
2240
+ end
2241
+ end
2242
+ codeC << " end\n"
2243
+ end
2244
+
2195
2245
  # Conclusion.
2196
2246
  codeC << "\nendmodule"
2197
2247
 
@@ -120,10 +120,10 @@ module HDLRuby::High::Std
120
120
 
121
121
  # Enters the current system
122
122
  HDLRuby::High.cur_system.open do
123
- sub do
123
+ # sub do
124
124
  HDLRuby::High.space_push(namespace)
125
125
  # Execute the instantiation block
126
- return_value =HDLRuby::High.top_user.instance_exec(&ruby_block)
126
+ return_value = HDLRuby::High.top_user.instance_exec(&ruby_block)
127
127
 
128
128
  # Expands the extra state processing so that al all the
129
129
  # parts of the state machine are in par (clear synthesis).
@@ -311,7 +311,7 @@ module HDLRuby::High::Std
311
311
  end
312
312
 
313
313
  HDLRuby::High.space_pop
314
- end
314
+ # end
315
315
  end
316
316
 
317
317
  return return_value
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.11.5"
2
+ VERSION = "2.11.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: HDLRuby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.11.5
4
+ version: 2.11.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-14 00:00:00.000000000 Z
11
+ date: 2022-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,6 +70,7 @@ files:
70
70
  - ext/hruby_sim/hruby_sim_calc.c
71
71
  - ext/hruby_sim/hruby_sim_core.c
72
72
  - ext/hruby_sim/hruby_sim_list.c
73
+ - ext/hruby_sim/hruby_sim_mute.c
73
74
  - ext/hruby_sim/hruby_sim_stack_calc.c
74
75
  - ext/hruby_sim/hruby_sim_stack_calc.c.sav
75
76
  - ext/hruby_sim/hruby_sim_tree_calc.c
@@ -96,11 +97,13 @@ files:
96
97
  - lib/HDLRuby/hdr_samples/addsub.rb
97
98
  - lib/HDLRuby/hdr_samples/addsubz.rb
98
99
  - lib/HDLRuby/hdr_samples/alu.rb
100
+ - lib/HDLRuby/hdr_samples/arith_bench.rb
99
101
  - lib/HDLRuby/hdr_samples/bstr_bench.rb
100
102
  - lib/HDLRuby/hdr_samples/calculator.rb
101
103
  - lib/HDLRuby/hdr_samples/case_bench.rb
102
104
  - lib/HDLRuby/hdr_samples/comparison_bench.rb
103
105
  - lib/HDLRuby/hdr_samples/constant_in_function.rb
106
+ - lib/HDLRuby/hdr_samples/constant_prop_bench.rb
104
107
  - lib/HDLRuby/hdr_samples/counter_bench.rb
105
108
  - lib/HDLRuby/hdr_samples/counter_dff_bench.rb
106
109
  - lib/HDLRuby/hdr_samples/dff.rb
@@ -286,6 +289,7 @@ files:
286
289
  - lib/HDLRuby/hruby_low_without_select.rb
287
290
  - lib/HDLRuby/hruby_rcsim.rb
288
291
  - lib/HDLRuby/hruby_rsim.rb
292
+ - lib/HDLRuby/hruby_rsim_mute.rb
289
293
  - lib/HDLRuby/hruby_rsim_vcd.rb
290
294
  - lib/HDLRuby/hruby_serializer.rb
291
295
  - lib/HDLRuby/hruby_tools.rb