HDLRuby 2.6.5 → 2.6.16
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 +4 -4
- data/lib/HDLRuby/hdr_samples/comparison_bench.rb +40 -0
- data/lib/HDLRuby/hdr_samples/neg_arith_bench.rb +11 -0
- data/lib/HDLRuby/hdr_samples/type_minmax_bench.rb +37 -0
- data/lib/HDLRuby/hdr_samples/with_to_array.rb +29 -0
- data/lib/HDLRuby/hdrcc.rb +49 -24
- data/lib/HDLRuby/hruby_high.rb +136 -117
- data/lib/HDLRuby/hruby_low.rb +58 -27
- data/lib/HDLRuby/hruby_low2c.rb +3 -1
- data/lib/HDLRuby/hruby_low_resolve.rb +24 -0
- data/lib/HDLRuby/hruby_verilog.rb +5 -5
- data/lib/HDLRuby/hruby_verilog_name.rb +50 -32
- data/lib/HDLRuby/sim/hruby_sim.h +16 -2
- data/lib/HDLRuby/sim/hruby_sim_calc.c +293 -18
- data/lib/HDLRuby/std/function_generator.rb +9 -7
- data/lib/HDLRuby/version.rb +1 -1
- metadata +5 -2
data/lib/HDLRuby/hruby_low.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require "HDLRuby/hruby_bstr"
|
2
2
|
require "HDLRuby/hruby_error"
|
3
|
-
require "HDLRuby/hruby_decorator"
|
3
|
+
# require "HDLRuby/hruby_decorator"
|
4
4
|
require 'forwardable'
|
5
5
|
|
6
6
|
|
@@ -36,7 +36,7 @@ module HDLRuby::Low
|
|
36
36
|
end
|
37
37
|
|
38
38
|
|
39
|
-
Hdecorator = HDLRuby::Hdecorator
|
39
|
+
# Hdecorator = HDLRuby::Hdecorator
|
40
40
|
|
41
41
|
##
|
42
42
|
# Gives parent definition and access properties to an hardware object.
|
@@ -118,8 +118,8 @@ module HDLRuby::Low
|
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
-
# Add decorator capability (modifies intialize to put after).
|
122
|
-
include Hdecorator
|
121
|
+
# # Add decorator capability (modifies intialize to put after).
|
122
|
+
# include Hdecorator
|
123
123
|
|
124
124
|
# Comparison for hash: structural comparison.
|
125
125
|
def eql?(obj)
|
@@ -455,8 +455,8 @@ module HDLRuby::Low
|
|
455
455
|
@behaviors = []
|
456
456
|
end
|
457
457
|
|
458
|
-
# Add decorator capability (modifies intialize to put after).
|
459
|
-
include Hdecorator
|
458
|
+
# # Add decorator capability (modifies intialize to put after).
|
459
|
+
# include Hdecorator
|
460
460
|
|
461
461
|
# Comparison for hash: structural comparison.
|
462
462
|
def eql?(obj)
|
@@ -1221,8 +1221,8 @@ module HDLRuby::Low
|
|
1221
1221
|
@name = name.to_sym
|
1222
1222
|
end
|
1223
1223
|
|
1224
|
-
# Add decorator capability (modifies intialize to put after).
|
1225
|
-
include Hdecorator
|
1224
|
+
# # Add decorator capability (modifies intialize to put after).
|
1225
|
+
# include Hdecorator
|
1226
1226
|
|
1227
1227
|
# Comparison for hash: structural comparison.
|
1228
1228
|
def eql?(obj)
|
@@ -1276,6 +1276,18 @@ module HDLRuby::Low
|
|
1276
1276
|
end
|
1277
1277
|
end
|
1278
1278
|
|
1279
|
+
# Gets the type max value if any.
|
1280
|
+
# Default: not defined.
|
1281
|
+
def max
|
1282
|
+
raise AnyError, "No max value for type #{self}"
|
1283
|
+
end
|
1284
|
+
|
1285
|
+
# Gets the type min value if any.
|
1286
|
+
# Default: not defined.
|
1287
|
+
def min
|
1288
|
+
raise AnyError, "No min value for type #{self}"
|
1289
|
+
end
|
1290
|
+
|
1279
1291
|
# Get the direction of the type, little or big endian.
|
1280
1292
|
def direction
|
1281
1293
|
# By default, little endian.
|
@@ -1617,6 +1629,25 @@ module HDLRuby::Low
|
|
1617
1629
|
return @base.width * ((first-last).abs + 1)
|
1618
1630
|
end
|
1619
1631
|
|
1632
|
+
# Gets the type max value if any.
|
1633
|
+
def max
|
1634
|
+
if (self.signed?) then
|
1635
|
+
return (2**(self.width-1))-1
|
1636
|
+
else
|
1637
|
+
return (2**(self.width))-1
|
1638
|
+
end
|
1639
|
+
end
|
1640
|
+
|
1641
|
+
# Gets the type min value if any.
|
1642
|
+
# Default: not defined.
|
1643
|
+
def min
|
1644
|
+
if (self.signed?) then
|
1645
|
+
return -(2**(self.width-1))
|
1646
|
+
else
|
1647
|
+
return 0
|
1648
|
+
end
|
1649
|
+
end
|
1650
|
+
|
1620
1651
|
# Get the direction of the type, little or big endian.
|
1621
1652
|
def direction
|
1622
1653
|
return @range.first < @range.last ? :big : :little
|
@@ -2093,8 +2124,8 @@ module HDLRuby::Low
|
|
2093
2124
|
# @block = block
|
2094
2125
|
end
|
2095
2126
|
|
2096
|
-
# Add decorator capability (modifies intialize to put after).
|
2097
|
-
include Hdecorator
|
2127
|
+
# # Add decorator capability (modifies intialize to put after).
|
2128
|
+
# include Hdecorator
|
2098
2129
|
|
2099
2130
|
# Sets the block if not already set.
|
2100
2131
|
def block=(block)
|
@@ -2317,8 +2348,8 @@ module HDLRuby::Low
|
|
2317
2348
|
ref.parent = self
|
2318
2349
|
end
|
2319
2350
|
|
2320
|
-
# Add decorator capability (modifies intialize to put after).
|
2321
|
-
include Hdecorator
|
2351
|
+
# # Add decorator capability (modifies intialize to put after).
|
2352
|
+
# include Hdecorator
|
2322
2353
|
|
2323
2354
|
# Comparison for hash: structural comparison.
|
2324
2355
|
def eql?(obj)
|
@@ -2401,8 +2432,8 @@ module HDLRuby::Low
|
|
2401
2432
|
false
|
2402
2433
|
end
|
2403
2434
|
|
2404
|
-
# Add decorator capability (modifies intialize to put after).
|
2405
|
-
include Hdecorator
|
2435
|
+
# # Add decorator capability (modifies intialize to put after).
|
2436
|
+
# include Hdecorator
|
2406
2437
|
|
2407
2438
|
# Iterates over each object deeply.
|
2408
2439
|
#
|
@@ -2486,8 +2517,8 @@ module HDLRuby::Low
|
|
2486
2517
|
@systemTs = [ @systemT ]
|
2487
2518
|
end
|
2488
2519
|
|
2489
|
-
# Add decorator capability (modifies intialize to put after).
|
2490
|
-
include Hdecorator
|
2520
|
+
# # Add decorator capability (modifies intialize to put after).
|
2521
|
+
# include Hdecorator
|
2491
2522
|
|
2492
2523
|
# Iterates over each object deeply.
|
2493
2524
|
#
|
@@ -2618,8 +2649,8 @@ module HDLRuby::Low
|
|
2618
2649
|
lumps.each { |lump| self.add_lump(lump) }
|
2619
2650
|
end
|
2620
2651
|
|
2621
|
-
# Add decorator capability (modifies intialize to put after).
|
2622
|
-
include Hdecorator
|
2652
|
+
# # Add decorator capability (modifies intialize to put after).
|
2653
|
+
# include Hdecorator
|
2623
2654
|
|
2624
2655
|
# Adds a +lump+ of code, it is ment to become an expression or
|
2625
2656
|
# some text.
|
@@ -2667,8 +2698,8 @@ module HDLRuby::Low
|
|
2667
2698
|
@chunks = HashName.new
|
2668
2699
|
end
|
2669
2700
|
|
2670
|
-
# Add decorator capability (modifies intialize to put after).
|
2671
|
-
include Hdecorator
|
2701
|
+
# # Add decorator capability (modifies intialize to put after).
|
2702
|
+
# include Hdecorator
|
2672
2703
|
|
2673
2704
|
# Adds a +chunk+ to the sensitivity list.
|
2674
2705
|
def add_chunk(chunk)
|
@@ -2779,7 +2810,7 @@ module HDLRuby::Low
|
|
2779
2810
|
# NOTE: this is an abstract class which is not to be used directly.
|
2780
2811
|
class Statement
|
2781
2812
|
include Hparent
|
2782
|
-
include Hdecorator
|
2813
|
+
# include Hdecorator
|
2783
2814
|
|
2784
2815
|
# Clones (deeply)
|
2785
2816
|
def clone
|
@@ -3267,8 +3298,8 @@ module HDLRuby::Low
|
|
3267
3298
|
match.parent = statement.parent = self
|
3268
3299
|
end
|
3269
3300
|
|
3270
|
-
# Add decorator capability (modifies intialize to put after).
|
3271
|
-
include Hdecorator
|
3301
|
+
# # Add decorator capability (modifies intialize to put after).
|
3302
|
+
# include Hdecorator
|
3272
3303
|
|
3273
3304
|
# Iterates over each object deeply.
|
3274
3305
|
#
|
@@ -3592,8 +3623,8 @@ module HDLRuby::Low
|
|
3592
3623
|
@unit = unit.to_sym
|
3593
3624
|
end
|
3594
3625
|
|
3595
|
-
# Add decorator capability (modifies intialize to put after).
|
3596
|
-
include Hdecorator
|
3626
|
+
# # Add decorator capability (modifies intialize to put after).
|
3627
|
+
# include Hdecorator
|
3597
3628
|
|
3598
3629
|
# Iterates over each object deeply.
|
3599
3630
|
#
|
@@ -4302,8 +4333,8 @@ module HDLRuby::Low
|
|
4302
4333
|
end
|
4303
4334
|
end
|
4304
4335
|
|
4305
|
-
# Add decorator capability (modifies intialize to put after).
|
4306
|
-
include Hdecorator
|
4336
|
+
# # Add decorator capability (modifies intialize to put after).
|
4337
|
+
# include Hdecorator
|
4307
4338
|
|
4308
4339
|
# Comparison for hash: structural comparison.
|
4309
4340
|
def eql?(obj)
|
data/lib/HDLRuby/hruby_low2c.rb
CHANGED
@@ -1570,7 +1570,9 @@ module HDLRuby::Low
|
|
1570
1570
|
# puts "content=#{self.content} str=#{str}"
|
1571
1571
|
end
|
1572
1572
|
# Is it a fully defined number?
|
1573
|
-
|
1573
|
+
# NOTE: bignum values are not supported by the simulation engine
|
1574
|
+
# yet, therefore numeric values are limited to 64 max.
|
1575
|
+
if str =~ /^[01]+$/ && str.length <= 64 then
|
1574
1576
|
# Yes, generate a numeral value.
|
1575
1577
|
res << " " * (level+1)*3
|
1576
1578
|
res << "static unsigned long long data[] = { "
|
@@ -165,6 +165,30 @@ module HDLRuby::Low
|
|
165
165
|
return false
|
166
166
|
end
|
167
167
|
|
168
|
+
## Gets the systemI the reference comes from if any.
|
169
|
+
def get_systemI
|
170
|
+
# Look for the owner from the name hierarchy.
|
171
|
+
if self.ref.is_a?(RefName) then
|
172
|
+
# Look in the parent hierachy for the sub reference name.
|
173
|
+
parent = self.parent
|
174
|
+
# puts "self.ref.name=#{self.ref.name}"
|
175
|
+
while parent
|
176
|
+
# puts "parent=#{parent}"
|
177
|
+
if parent.respond_to?(:get_by_name) then
|
178
|
+
found = parent.get_by_name(self.ref.name)
|
179
|
+
# puts "found is a :#{found.class}"
|
180
|
+
return found if found.is_a?(SystemI)
|
181
|
+
end
|
182
|
+
parent = parent.parent
|
183
|
+
end
|
184
|
+
# Not found, look further in the reference hierarchy.
|
185
|
+
return self.ref.get_systemI
|
186
|
+
end
|
187
|
+
# Not from a systemI.
|
188
|
+
# puts "Not from systemI for #{self.name}"
|
189
|
+
return nil
|
190
|
+
end
|
191
|
+
|
168
192
|
|
169
193
|
## Resolves the name of the reference and return the
|
170
194
|
# corresponding object.
|
@@ -134,7 +134,7 @@ module HDLRuby::Low
|
|
134
134
|
if self.name && !self.name.empty? then
|
135
135
|
vname = name_to_verilog(self.name)
|
136
136
|
code << " : #{vname}"
|
137
|
-
self.properties[:verilog_name] = vname
|
137
|
+
# self.properties[:verilog_name] = vname
|
138
138
|
end
|
139
139
|
code << "\n" if block.each_inner.any?
|
140
140
|
# Declaration of "inner" part within "always".
|
@@ -1371,7 +1371,7 @@ module HDLRuby::Low
|
|
1371
1371
|
# Converts the system to Verilog code using +renamer+ for producing Verilog-compatible names.
|
1372
1372
|
def to_verilog
|
1373
1373
|
vname = name_to_verilog(self.name)
|
1374
|
-
self.properties[:verilog_name] = vname
|
1374
|
+
# self.properties[:verilog_name] = vname
|
1375
1375
|
return "#{vname}"
|
1376
1376
|
end
|
1377
1377
|
|
@@ -1677,7 +1677,7 @@ module HDLRuby::Low
|
|
1677
1677
|
def to_verilog
|
1678
1678
|
# Convert unusable characters and return them.
|
1679
1679
|
vname = name_to_verilog(self.name)
|
1680
|
-
self.properties[:verilog_name] = vname
|
1680
|
+
# self.properties[:verilog_name] = vname
|
1681
1681
|
return "#{vname}"
|
1682
1682
|
end
|
1683
1683
|
end
|
@@ -1842,7 +1842,7 @@ module HDLRuby::Low
|
|
1842
1842
|
code = "`timescale 1ps/1ps\n\n"
|
1843
1843
|
|
1844
1844
|
vname = name_to_verilog(self.name)
|
1845
|
-
self.properties[:verilog_name] = vname
|
1845
|
+
# self.properties[:verilog_name] = vname
|
1846
1846
|
# Output the module name.
|
1847
1847
|
code << "module #{vname}("
|
1848
1848
|
|
@@ -2007,7 +2007,7 @@ module HDLRuby::Low
|
|
2007
2007
|
systemT = systemI.systemT
|
2008
2008
|
code << name_to_verilog(systemT.name) << " "
|
2009
2009
|
vname = name_to_verilog(systemI.name)
|
2010
|
-
systemI.properties[:verilog_name] = vname
|
2010
|
+
# systemI.properties[:verilog_name] = vname
|
2011
2011
|
code << vname << "("
|
2012
2012
|
# Its ports connections
|
2013
2013
|
# Inputs
|
@@ -10,41 +10,59 @@ module HDLRuby::Verilog
|
|
10
10
|
|
11
11
|
# Since it is possible to use $ and numbers other than the beginning of the character string, it is divided.
|
12
12
|
def name_to_verilog(name)
|
13
|
-
ref = "" # For storing the converted character.
|
14
|
-
name = name.to_s # Ensure name is a string
|
15
|
-
|
16
|
-
if (name[0] =~ /[a-zA-Z]/) then
|
17
|
-
|
18
|
-
|
19
|
-
elsif (name[0] == "_") then
|
20
|
-
|
21
|
-
# If it does not satisfy the above, it is another character.
|
22
|
-
# In that case, convert it to UTF-8 and convert it to a usable character string.
|
23
|
-
else
|
24
|
-
|
13
|
+
# ref = "" # For storing the converted character.
|
14
|
+
# name = name.to_s # Ensure name is a string
|
15
|
+
#
|
16
|
+
# if (name[0] =~ /[a-zA-Z]/) then
|
17
|
+
# ref << name[0]
|
18
|
+
# # _ To convert it to __.
|
19
|
+
# elsif (name[0] == "_") then
|
20
|
+
# ref << "__"
|
21
|
+
# # If it does not satisfy the above, it is another character.
|
22
|
+
# # In that case, convert it to UTF-8 and convert it to a usable character string.
|
23
|
+
# else
|
24
|
+
# l = name[0].bytes.map{|v| v.to_s(16)}.join # Conversion to UTF-8 hexadecimal number.
|
25
25
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
26
|
+
# ref << "_" + l.rjust(6,"0") # Add an underscore indicating conversion.
|
27
|
+
# # The remainder of 6 digits is filled with 0.
|
28
|
+
# end
|
29
|
+
#
|
30
|
+
# name[1..-1].each_char do |c|
|
31
|
+
# # Confirmation of characters in array.
|
32
|
+
# # If it is a-zA-Z 0 - 9, it is added to ref as it is.
|
33
|
+
# if (c =~ /[a-zA-Z0-9]|\$/) then
|
34
|
+
# ref << c
|
35
|
+
# # _ To convert it to __.
|
36
|
+
# elsif (c == "_") then
|
37
|
+
# ref << "__"
|
38
|
+
# # If it does not satisfy the above, it is another character.
|
39
|
+
# # In that case, convert it to UTF-8 and convert it to a usable character string.
|
40
|
+
# else
|
41
|
+
# l = c.bytes.map{|v| v.to_s(16)}.join # Conversion to UTF-8 hexadecimal number.
|
42
|
+
#
|
43
|
+
# ref << "_" + l.rjust(6,"0") # Add an underscore indicating conversion.
|
44
|
+
# # The remainder of 6 digits is filled with 0.
|
45
|
+
# end
|
46
|
+
# end
|
47
|
+
# return ref
|
48
|
+
|
29
49
|
|
30
|
-
|
31
|
-
#
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# The remainder of 6 digits is filled with 0.
|
50
|
+
name = name.to_s
|
51
|
+
# Convert special characters.
|
52
|
+
name = name.each_char.map do |c|
|
53
|
+
if c=~ /[a-z0-9]/ then
|
54
|
+
c
|
55
|
+
elsif c == "_" then
|
56
|
+
"__"
|
57
|
+
else
|
58
|
+
"_" + c.ord.to_s
|
59
|
+
end
|
60
|
+
end.join
|
61
|
+
# First character: only letter is possible.
|
62
|
+
unless name[0] =~ /[a-z_]/ then
|
63
|
+
name = "_" + name
|
45
64
|
end
|
46
|
-
|
47
|
-
return ref
|
65
|
+
return name
|
48
66
|
end
|
49
67
|
|
50
68
|
#puts ref
|
data/lib/HDLRuby/sim/hruby_sim.h
CHANGED
@@ -219,6 +219,13 @@ Value shift_right_value(Value src0, Value src1, Value dst);
|
|
219
219
|
* @return dst */
|
220
220
|
extern Value equal_value(Value src0, Value src1, Value dst);
|
221
221
|
|
222
|
+
/** Computes the greater comparision of two values.
|
223
|
+
* @param src0 the first source value of the comparison
|
224
|
+
* @param src1 the second source value of the comparison
|
225
|
+
* @param dst the destination value
|
226
|
+
* @return dst */
|
227
|
+
extern Value greater_value(Value src0, Value src1, Value dst);
|
228
|
+
|
222
229
|
/** Computes the lesser comparision of two values.
|
223
230
|
* @param src0 the first source value of the comparison
|
224
231
|
* @param src1 the second source value of the comparison
|
@@ -226,12 +233,19 @@ extern Value equal_value(Value src0, Value src1, Value dst);
|
|
226
233
|
* @return dst */
|
227
234
|
extern Value lesser_value(Value src0, Value src1, Value dst);
|
228
235
|
|
229
|
-
/** Computes the greater comparision of two values.
|
236
|
+
/** Computes the greater or equal comparision of two values.
|
230
237
|
* @param src0 the first source value of the comparison
|
231
238
|
* @param src1 the second source value of the comparison
|
232
239
|
* @param dst the destination value
|
233
240
|
* @return dst */
|
234
|
-
extern Value
|
241
|
+
extern Value greater_equal_value(Value src0, Value src1, Value dst);
|
242
|
+
|
243
|
+
/** Computes the lesser or equal comparision of two values.
|
244
|
+
* @param src0 the first source value of the comparison
|
245
|
+
* @param src1 the second source value of the comparison
|
246
|
+
* @param dst the destination value
|
247
|
+
* @return dst */
|
248
|
+
extern Value lesser_equal_value(Value src0, Value src1, Value dst);
|
235
249
|
|
236
250
|
/** Selects a value depending on a condition.
|
237
251
|
* @param cond the condition to use for selecting a value
|