HDLRuby 2.4.22 → 2.4.25

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bd32be1a749a209488dea4e2d6d05c8c90a2a181ce48575288e33dc65c25ff02
4
- data.tar.gz: fc615ba447dc1fe712b2620f39d4f6fbbc1a5a698efa2c38b0ca4f075dc5a53f
3
+ metadata.gz: 4d049304b2681a96575ee9e398827724e0262404e973b8c73f830176ec94dffa
4
+ data.tar.gz: '0472118ef46e7bff7df577fb19dd66396da8a65bc5f9f442967346f4b640ed80'
5
5
  SHA512:
6
- metadata.gz: 6b81a944107060ac2844260d83d90cac747decf72b3facf9fa06bb4453267679de12dbbc72c08a3016701a304ef1c1941b7689358e125cd00d1112f028e302cb
7
- data.tar.gz: 369b9864dc3504ab0536c6e3a1df19b70cda921f46c1680bfdf7b78087348f93864285dada62e52db9ab105b15510cb98c1054bfd870d01ee13913e3d5216d4e
6
+ metadata.gz: 291dd1ed58fd73a420fc9681a6a64e3cb96ff6667164a98d85bb164723b83e3e5d285ff65a495f3f5f6705423b7ae879f0577386227483b0bd9b5254782774c6
7
+ data.tar.gz: a9f88a800878ed07c5e3a56bd0a70e3bd7c329a39e5576a36c044c14535d6104f7906444467d4c1f3a27c518da9fc14364ba5c6e02bdd437c5b0dba12fac4268
@@ -61,5 +61,6 @@ system :fix_test do
61
61
  !10.ns
62
62
  c <= a * b
63
63
  !10.ns
64
+ c <= (a+b) * b
64
65
  end
65
66
  end
@@ -19,6 +19,7 @@ require 'HDLRuby/hruby_low_with_port'
19
19
  require 'HDLRuby/hruby_low_with_var'
20
20
  require 'HDLRuby/hruby_low_without_concat'
21
21
  require 'HDLRuby/hruby_low_without_connection'
22
+ require 'HDLRuby/hruby_low_casts_without_expression'
22
23
  require 'HDLRuby/hruby_low_cleanup'
23
24
 
24
25
  require 'HDLRuby/hruby_verilog.rb'
@@ -577,6 +578,7 @@ elsif $options[:verilog] then
577
578
  # top_system = $top_system
578
579
  # Make description compatible with verilog generation.
579
580
  $top_system.each_systemT_deep do |systemT|
581
+ systemT.casts_without_expression!
580
582
  systemT.to_upper_space!
581
583
  systemT.to_global_systemTs!
582
584
  # systemT.break_types!
@@ -0,0 +1,326 @@
1
+ require 'HDLRuby'
2
+ require 'HDLRuby/hruby_tools'
3
+ require 'HDLRuby/hruby_low_mutable'
4
+ require 'HDLRuby/hruby_low_with_bool'
5
+
6
+
7
+ module HDLRuby::Low
8
+
9
+
10
+ ##
11
+ # Replace expressions in cast operators with variables.
12
+ # Use for generating Verilog code generation since bit extension cannot
13
+ # be performed on expression but only on signals.
14
+ #
15
+ ########################################################################
16
+
17
+
18
+ ## Extends the SystemT class with functionality for extracting
19
+ # expressions from cast.
20
+ class SystemT
21
+
22
+ # Extracts the expressions from the casts.
23
+ def casts_without_expression!
24
+ self.scope.casts_without_expression!
25
+ return self
26
+ end
27
+
28
+ end
29
+
30
+
31
+ ## Extends the Scope class with functionality for extracting
32
+ # expressions from cast.
33
+ class Scope
34
+
35
+ # Extracts the expressions from the casts.
36
+ def casts_without_expression!
37
+ # Recurse on the sub scopes.
38
+ self.each_scope(&:casts_without_expression!)
39
+
40
+ # Apply on the connections.
41
+ self.each_connection(&:casts_without_expression!)
42
+
43
+ # Apply on the behaviors.
44
+ self.each_behavior do |behavior|
45
+ behavior.block.casts_without_expression!
46
+ end
47
+ return self
48
+ end
49
+ end
50
+
51
+
52
+ ## Extends the Transmit class with functionality for extracting
53
+ # expressions from cast.
54
+ class Transmit
55
+
56
+ # Extracts the expressions from the casts.
57
+ def casts_without_expression!
58
+ # Apply on the left value.
59
+ self.set_left!(self.left.casts_without_expression)
60
+ # Apply on the right value.
61
+ self.set_right!(self.right.casts_without_expression)
62
+ return self
63
+ end
64
+ end
65
+
66
+ ## Extends the If class with functionality for extracting
67
+ # expressions from cast.
68
+ class If
69
+
70
+ # Extracts the expressions from the casts.
71
+ def casts_without_expression!
72
+ # Apply on the condition.
73
+ self.set_condition!(self.condition.casts_without_expression)
74
+ # Apply on the yes.
75
+ self.yes.casts_without_expression!
76
+ # Apply on the noifs.
77
+ @noifs.map! do |cond,stmnt|
78
+ [cond.casts_without_expression,stmnt.casts_without_expression!]
79
+ end
80
+ # Apply on the no if any.
81
+ self.no.casts_without_expression! if self.no
82
+ return self
83
+ end
84
+ end
85
+
86
+ ## Extends the When class with functionality for extracting
87
+ # expressions from cast.
88
+ class When
89
+
90
+ # Extracts the expressions from the casts.
91
+ def casts_without_expression!
92
+ # Apply on the match.
93
+ self.set_match!(self.match.casts_without_expression)
94
+ # Apply on the statement.
95
+ self.statement.casts_without_expression!
96
+ return self
97
+ end
98
+ end
99
+
100
+
101
+ ## Extends the Case class with functionality for extracting
102
+ # expressions from cast.
103
+ class Case
104
+
105
+ # Extracts the expressions from the casts.
106
+ def casts_without_expression!
107
+ # No need to apply on the value!
108
+ # Apply on the value.
109
+ self.set_value!(self.value.casts_without_expression)
110
+ # Apply on the whens.
111
+ self.each_when(&:casts_without_expression!)
112
+ # Apply on the default if any.
113
+ self.default.casts_without_expression! if self.default
114
+ return self
115
+ end
116
+ end
117
+
118
+
119
+ ## Extends the TimeWait class with functionality for extracting
120
+ # expressions from cast.
121
+ class TimeWait
122
+ # Extracts the expressions from the casts.
123
+ def casts_without_expression!
124
+ # Nothing to do.
125
+ return self
126
+ end
127
+ end
128
+
129
+ ## Extends the TimeRepeat class with functionality for extracting
130
+ # expressions from cast.
131
+ class TimeRepeat
132
+ # Extracts the expressions from the casts.
133
+ def casts_without_expression!
134
+ # Simply recurse on the stamtement.
135
+ self.statement.casts_without_expression!
136
+ return self
137
+ end
138
+ end
139
+
140
+
141
+ ## Extends the Block class with functionality for extracting
142
+ # expressions from cast.
143
+ class Block
144
+
145
+ # Extracts the expressions from the casts.
146
+ def casts_without_expression!
147
+ # Apply on each statement.
148
+ self.each_statement(&:casts_without_expression!)
149
+ return self
150
+ end
151
+ end
152
+
153
+
154
+ ## Extends the Value class with functionality for extracting
155
+ # expressions from cast.
156
+ class Value
157
+ # Extracts the expressions from the casts.
158
+ def casts_without_expression
159
+ # Simple clones.
160
+ return self.clone
161
+ end
162
+ end
163
+
164
+
165
+ ## Extends the Cast class with functionality for extracting
166
+ # expressions from cast.
167
+ class Cast
168
+ # Extracts the expressions from the casts.
169
+ def casts_without_expression
170
+ # Recurse on the child.
171
+ nchild = self.child.casts_without_expression
172
+ # Process the cast.
173
+ unless (nchild.is_a?(Ref)) then
174
+ # Need to extract the child.
175
+ # Create signal holding the child.
176
+ stmnt = self.statement
177
+ if (stmnt.is_a?(Connection)) then
178
+ # Specific case of connections: need to build
179
+ # a new block.
180
+ scop = stmnt.parent
181
+ scop.delete_connection!(stmnt)
182
+ stmnt = Transmit.new(stmnt.left.clone, stmnt.right.clone)
183
+ blk = Block.new(:seq)
184
+ scop.add_behavior(Behavior.new(blk))
185
+ blk.add_statement(stmnt)
186
+ else
187
+ blk = stmnt.block
188
+ end
189
+ name = HDLRuby.uniq_name
190
+ typ = nchild.type
191
+ sig = blk.add_inner(SignalI.new(name,typ))
192
+ # Add a statement assigning the child to the new signal.
193
+ nref = RefName.new(typ,RefThis.new,name)
194
+ nstmnt = Transmit.new(nref,nchild)
195
+ idx = blk.each_statement.find_index(stmnt)
196
+ blk.insert_statement!(idx,nstmnt)
197
+ # Replace the child by a reference to the created
198
+ # signal.
199
+ nchild = nref.clone
200
+ end
201
+ return Cast.new(self.type,nchild)
202
+ end
203
+ end
204
+
205
+ ## Extends the Unary class with functionality for extracting
206
+ # expressions from cast.
207
+ class Unary
208
+
209
+ # Extracts the expressions from the casts.
210
+ def casts_without_expression
211
+ # Recurse on the sub node.
212
+ return Unary.new(self.type,self.operator,
213
+ self.child.casts_without_expression)
214
+ return self
215
+ end
216
+ end
217
+
218
+
219
+ ## Extends the Binary class with functionality for extracting
220
+ # expressions from cast.
221
+ class Binary
222
+
223
+ # Extracts the expressions from the casts.
224
+ def casts_without_expression
225
+ # Recurse on the sub nodes.
226
+ return Binary.new(self.type,self.operator,
227
+ self.left.casts_without_expression,
228
+ self.right.casts_without_expression)
229
+ end
230
+ end
231
+
232
+
233
+
234
+ ## Extends the Select class with functionality for extracting
235
+ # expressions from cast.
236
+ class Select
237
+
238
+ # Extracts the expressions from the casts.
239
+ def casts_without_expression
240
+ # Recurse on the sub node.
241
+ return Select.new(self.type,"?",
242
+ self.select.casts_without_expression,
243
+ *self.each_choice.map do |choice|
244
+ choice.casts_without_expression
245
+ end )
246
+ return self
247
+ end
248
+ end
249
+
250
+
251
+ ## Extends the Concat class with functionality for converting booleans
252
+ # in assignments to select operators.
253
+ class Concat
254
+ # Extracts the expressions from the casts.
255
+ def casts_without_expression
256
+ # Recurse on the sub expressions.
257
+ return Concat.new(self.type,self.each_expression.map do |expr|
258
+ expr.casts_without_expression
259
+ end )
260
+ end
261
+ end
262
+
263
+
264
+ ## Extends the RefConcat class with functionality for converting booleans
265
+ # in assignments to select operators.
266
+ class RefConcat
267
+ # Extracts the expressions from the casts.
268
+ def casts_without_expression
269
+ # Recurse on the sub references.
270
+ return RefConcat.new(self.type,self.each_expression.map do |expr|
271
+ expr.casts_without_expression
272
+ end )
273
+ end
274
+ end
275
+
276
+
277
+ ## Extends the RefIndex class with functionality for converting booleans
278
+ # in assignments to select operators.
279
+ class RefIndex
280
+ # Extracts the expressions from the casts.
281
+ def casts_without_expression
282
+ # Recurse on the sub references.
283
+ return RefIndex.new(self.type,
284
+ self.ref.casts_without_expression,
285
+ self.index.casts_without_expression)
286
+ end
287
+ end
288
+
289
+
290
+ ## Extends the RefRange class with functionality for converting booleans
291
+ # in assignments to select operators.
292
+ class RefRange
293
+ # Extracts the expressions from the casts.
294
+ def casts_without_expression
295
+ # Recurse on the sub references.
296
+ return RefRange.new(self.type,
297
+ self.ref.casts_without_expression,
298
+ self.range.first.casts_without_expression ..
299
+ self.range.last.casts_without_expression)
300
+ end
301
+ end
302
+
303
+
304
+ ## Extends the RefName class with functionality for converting booleans
305
+ # in assignments to select operators.
306
+ class RefName
307
+ # Extracts the expressions from the casts.
308
+ def casts_without_expression
309
+ # Recurse on the sub references.
310
+ return RefName.new(self.type,
311
+ self.ref.casts_without_expression,
312
+ self.name)
313
+ end
314
+ end
315
+
316
+
317
+ ## Extends the RefThis class with functionality for converting booleans
318
+ # in assignments to select operators.
319
+ class RefThis
320
+ # Extracts the expressions from the casts.
321
+ def casts_without_expression
322
+ # Simply clone.
323
+ return self.clone
324
+ end
325
+ end
326
+ end
@@ -460,7 +460,10 @@ class Block
460
460
  $fm.fm_par["#{tmt.left.to_verilog}"] = tmt.right
461
461
  end
462
462
  new_block.add_statement(tmt.clone)
463
- end
463
+ end
464
+ else
465
+ # Other statements are simply added as is.
466
+ new_block.add_statement(statement.clone)
464
467
  end
465
468
  end
466
469
 
@@ -1603,7 +1606,7 @@ end
1603
1606
  class Unary
1604
1607
  # Converts the system to Verilog code.
1605
1608
  def to_verilog
1606
- return "#{self.operator}#{self.child.to_verilog}"
1609
+ return "#{self.operator[0]}#{self.child.to_verilog}"
1607
1610
  end
1608
1611
  end
1609
1612
 
@@ -1614,10 +1617,37 @@ class Cast
1614
1617
  # by traditional verilog.
1615
1618
  def to_verilog
1616
1619
  # return "#{self.type.to_verilog}'(#{self.child.to_verilog})"
1620
+ if self.child.is_a?(Value) then
1621
+ return self.child.to_verilog
1622
+ end
1623
+ # Get the type widths, used for computing extensions or truncations.
1624
+ cw = self.child.type.width
1625
+ sw = self.type.width
1617
1626
  if self.type.signed? then
1618
- return "$signed(#{self.child.to_verilog})"
1627
+ # return "$signed(#{self.child.to_verilog})"
1628
+ if (sw>cw) then
1629
+ # Need to sign extend.
1630
+ return "$signed({{#{sw-cw}{#{self.child.to_verilog}[#{cw-1}]}}," +
1631
+ "#{self.child.to_verilog}})"
1632
+ elsif (sw<cw) then
1633
+ # Need to truncate
1634
+ return "$signed(#{self.child.to_verilog}[#{sw-1}:0])"
1635
+ else
1636
+ # Only enforce signed.
1637
+ return "$signed(#{self.child.to_verilog})"
1638
+ end
1619
1639
  else
1620
- return "$unsigned(#{self.child.to_verilog})"
1640
+ # return "$unsigned(#{self.child.to_verilog})"
1641
+ if (sw>cw) then
1642
+ # Need to extend.
1643
+ return "$unsigned({{#{sw-cw}{1'b0}},#{self.child.to_verilog}})"
1644
+ elsif (sw<cw) then
1645
+ # Need to truncate
1646
+ return "$unsigned(#{self.child.to_verilog}[#{sw-1}:0])"
1647
+ else
1648
+ # Only enforce signed.
1649
+ return "$unsigned(#{self.child.to_verilog})"
1650
+ end
1621
1651
  end
1622
1652
  end
1623
1653
  end
@@ -1675,15 +1705,15 @@ class Delay
1675
1705
  def to_verilog
1676
1706
  time = self.value.to_s
1677
1707
  if(self.unit.to_s == "ps") then
1678
- return "##{time}"
1708
+ return "##{time};"
1679
1709
  elsif(self.unit.to_s == "ns")
1680
- return "##{time}000"
1710
+ return "##{time}000;"
1681
1711
  elsif(self.unit.to_s == "us")
1682
- return "##{time}000000"
1712
+ return "##{time}000000;"
1683
1713
  elsif(self.unit.to_s == "ms")
1684
- return "##{time}000000000"
1714
+ return "##{time}000000000;"
1685
1715
  elsif(self.unit.to_s == "s")
1686
- return "##{time}000000000000"
1716
+ return "##{time}000000000000;"
1687
1717
  end
1688
1718
  end
1689
1719
  end
@@ -1,3 +1,3 @@
1
1
  module HDLRuby
2
- VERSION = "2.4.22"
2
+ VERSION = "2.4.25"
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.4.22
4
+ version: 2.4.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lovic Gauthier
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-01 00:00:00.000000000 Z
11
+ date: 2021-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -207,6 +207,7 @@ files:
207
207
  - lib/HDLRuby/hruby_low2sym.rb
208
208
  - lib/HDLRuby/hruby_low2vhd.rb
209
209
  - lib/HDLRuby/hruby_low_bool2select.rb
210
+ - lib/HDLRuby/hruby_low_casts_without_expression.rb
210
211
  - lib/HDLRuby/hruby_low_cleanup.rb
211
212
  - lib/HDLRuby/hruby_low_fix_types.rb
212
213
  - lib/HDLRuby/hruby_low_mutable.rb