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.
- checksums.yaml +4 -4
- data/lib/HDLRuby/drivers/xcd.rb +79 -0
- data/lib/HDLRuby/drivers/xcd/dummy.xcd +4 -0
- data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
- data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
- data/lib/HDLRuby/hdr_samples/dff_properties.rb +19 -0
- data/lib/HDLRuby/hdr_samples/dff_unit.rb +54 -0
- data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
- data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/music.rb +79 -0
- data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
- data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
- data/lib/HDLRuby/hdr_samples/seqpar_bench.rb +59 -0
- data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
- data/lib/HDLRuby/hdrcc.rb +140 -24
- data/lib/HDLRuby/hruby_decorator.rb +250 -0
- data/lib/HDLRuby/hruby_high.rb +468 -91
- data/lib/HDLRuby/hruby_low.rb +913 -45
- data/lib/HDLRuby/hruby_low2c.rb +189 -168
- data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
- data/lib/HDLRuby/hruby_low2high.rb +331 -549
- data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
- data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
- data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
- data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
- data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
- data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
- data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
- data/lib/HDLRuby/hruby_low_without_parinseq.rb +151 -0
- data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
- data/lib/HDLRuby/hruby_tools.rb +11 -1
- data/lib/HDLRuby/hruby_verilog.rb +1602 -1629
- data/lib/HDLRuby/sim/hruby_sim.h +25 -2
- data/lib/HDLRuby/sim/hruby_sim_calc.c +63 -6
- data/lib/HDLRuby/sim/hruby_sim_vcd.c +5 -1
- data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
- data/lib/HDLRuby/std/fixpoint.rb +9 -0
- data/lib/HDLRuby/std/function_generator.rb +139 -0
- data/lib/HDLRuby/std/hruby_unit.rb +75 -0
- data/lib/HDLRuby/template_expander.rb +61 -0
- data/lib/HDLRuby/version.rb +1 -1
- metadata +22 -5
data/lib/HDLRuby/hruby_low.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require "HDLRuby/hruby_bstr"
|
2
2
|
require "HDLRuby/hruby_error"
|
3
|
+
require "HDLRuby/hruby_decorator"
|
3
4
|
require 'forwardable'
|
4
5
|
|
5
6
|
|
@@ -34,6 +35,9 @@ module HDLRuby::Low
|
|
34
35
|
alias_method :each, :each_value
|
35
36
|
end
|
36
37
|
|
38
|
+
|
39
|
+
Hdecorator = HDLRuby::Hdecorator
|
40
|
+
|
37
41
|
##
|
38
42
|
# Gives parent definition and access properties to an hardware object.
|
39
43
|
module Hparent
|
@@ -62,6 +66,7 @@ module HDLRuby::Low
|
|
62
66
|
end
|
63
67
|
|
64
68
|
|
69
|
+
|
65
70
|
##
|
66
71
|
# Describes a system type.
|
67
72
|
#
|
@@ -113,6 +118,9 @@ module HDLRuby::Low
|
|
113
118
|
end
|
114
119
|
end
|
115
120
|
|
121
|
+
# Add decorator capability (modifies intialize to put after).
|
122
|
+
include Hdecorator
|
123
|
+
|
116
124
|
# Comparison for hash: structural comparison.
|
117
125
|
def eql?(obj)
|
118
126
|
return false unless obj.is_a?(SystemT)
|
@@ -376,8 +384,28 @@ module HDLRuby::Low
|
|
376
384
|
# end
|
377
385
|
# signal
|
378
386
|
# end
|
387
|
+
|
388
|
+
# Iterates over each object deeply.
|
389
|
+
#
|
390
|
+
# Returns an enumerator if no ruby block is given.
|
391
|
+
def each_deep(&ruby_block)
|
392
|
+
# No ruby block? Return an enumerator.
|
393
|
+
return to_enum(:each_deep) unless ruby_block
|
394
|
+
# A ruby block? First apply it to current.
|
395
|
+
ruby_block.call(self)
|
396
|
+
# Then apply on each signal.
|
397
|
+
self.each_signal do |signal|
|
398
|
+
signal.each_deep(&ruby_block)
|
399
|
+
end
|
400
|
+
# Then apply on each scope.
|
401
|
+
self.each_scope do |scope|
|
402
|
+
scope.each_deep(&ruby_block)
|
403
|
+
end
|
404
|
+
end
|
379
405
|
|
380
406
|
# Iterates over the systemT deeply if any.
|
407
|
+
#
|
408
|
+
# Returns an enumerator if no ruby block is given.
|
381
409
|
def each_systemT_deep(&ruby_block)
|
382
410
|
# No ruby block? Return an enumerator.
|
383
411
|
return to_enum(:each_systemT_deep) unless ruby_block
|
@@ -427,6 +455,9 @@ module HDLRuby::Low
|
|
427
455
|
@behaviors = []
|
428
456
|
end
|
429
457
|
|
458
|
+
# Add decorator capability (modifies intialize to put after).
|
459
|
+
include Hdecorator
|
460
|
+
|
430
461
|
# Comparison for hash: structural comparison.
|
431
462
|
def eql?(obj)
|
432
463
|
return false unless obj.is_a?(Scope)
|
@@ -1117,6 +1148,50 @@ module HDLRuby::Low
|
|
1117
1148
|
# systemI.each_sensitive_deep(&ruby_block)
|
1118
1149
|
# end
|
1119
1150
|
# end
|
1151
|
+
|
1152
|
+
# Iterates over each object deeply.
|
1153
|
+
#
|
1154
|
+
# Returns an enumerator if no ruby block is given.
|
1155
|
+
def each_deep(&ruby_block)
|
1156
|
+
# No ruby block? Return an enumerator.
|
1157
|
+
return to_enum(:each_deep) unless ruby_block
|
1158
|
+
# A ruby block? First apply it to current.
|
1159
|
+
ruby_block.call(self)
|
1160
|
+
# The apply on each type.
|
1161
|
+
self.each_type do |type|
|
1162
|
+
type.each_deep(&ruby_block)
|
1163
|
+
end
|
1164
|
+
# Then apply on each systemT.
|
1165
|
+
self.each_systemT do |systemT|
|
1166
|
+
systemT.each_deep(&ruby_block)
|
1167
|
+
end
|
1168
|
+
# Then apply on each scope.
|
1169
|
+
self.each_scope do |scope|
|
1170
|
+
scope.each_deep(&ruby_block)
|
1171
|
+
end
|
1172
|
+
# Then apply on each inner signal.
|
1173
|
+
self.each_inner do |inner|
|
1174
|
+
inner.each_deep(&ruby_block)
|
1175
|
+
end
|
1176
|
+
# Then apply on each systemI.
|
1177
|
+
self.each_systemI do |systemI|
|
1178
|
+
systemI.each_deep(&ruby_block)
|
1179
|
+
end
|
1180
|
+
# Then apply on each code.
|
1181
|
+
self.each_code do |code|
|
1182
|
+
code.each_deep(&ruby_block)
|
1183
|
+
end
|
1184
|
+
# Then apply on each connection.
|
1185
|
+
self.each_connection do |connection|
|
1186
|
+
connection.each_deep(&ruby_block)
|
1187
|
+
end
|
1188
|
+
# Then apply on each behavior.
|
1189
|
+
self.each_behavior do |behavior|
|
1190
|
+
behavior.each_deep(&ruby_block)
|
1191
|
+
end
|
1192
|
+
end
|
1193
|
+
|
1194
|
+
|
1120
1195
|
|
1121
1196
|
# Gets the top scope, i.e. the first scope of the current system.
|
1122
1197
|
def top_scope
|
@@ -1146,6 +1221,9 @@ module HDLRuby::Low
|
|
1146
1221
|
@name = name.to_sym
|
1147
1222
|
end
|
1148
1223
|
|
1224
|
+
# Add decorator capability (modifies intialize to put after).
|
1225
|
+
include Hdecorator
|
1226
|
+
|
1149
1227
|
# Comparison for hash: structural comparison.
|
1150
1228
|
def eql?(obj)
|
1151
1229
|
return false unless obj.is_a?(Type)
|
@@ -1239,6 +1317,11 @@ module HDLRuby::Low
|
|
1239
1317
|
return false
|
1240
1318
|
end
|
1241
1319
|
|
1320
|
+
# Tells if the type is hierarchical.
|
1321
|
+
def hierarchical?
|
1322
|
+
return self.base? || self.types?
|
1323
|
+
end
|
1324
|
+
|
1242
1325
|
# Tell if +type+ is equivalent to current type.
|
1243
1326
|
#
|
1244
1327
|
# NOTE: type can be compatible while not being equivalent, please
|
@@ -1256,6 +1339,7 @@ module HDLRuby::Low
|
|
1256
1339
|
ruby_block.call(self)
|
1257
1340
|
# And that's all by default.
|
1258
1341
|
end
|
1342
|
+
alias_method :each_deep, :each_type_deep
|
1259
1343
|
|
1260
1344
|
# Converts to a bit vector.
|
1261
1345
|
def to_vector
|
@@ -1280,10 +1364,6 @@ module HDLRuby::Low
|
|
1280
1364
|
# The void type.
|
1281
1365
|
class << (Void = Type.new(:void) )
|
1282
1366
|
include LLeaf
|
1283
|
-
# # Get the base type, actually self for leaf types.
|
1284
|
-
# def base
|
1285
|
-
# self
|
1286
|
-
# end
|
1287
1367
|
end
|
1288
1368
|
|
1289
1369
|
##
|
@@ -1386,6 +1466,11 @@ module HDLRuby::Low
|
|
1386
1466
|
# end
|
1387
1467
|
end
|
1388
1468
|
|
1469
|
+
##
|
1470
|
+
# The void type.
|
1471
|
+
class << (StringT = Type.new(:string) )
|
1472
|
+
include LLeaf
|
1473
|
+
end
|
1389
1474
|
|
1390
1475
|
|
1391
1476
|
##
|
@@ -1394,9 +1479,6 @@ module HDLRuby::Low
|
|
1394
1479
|
# NOTE: type definition are actually type with a name refering to another
|
1395
1480
|
# type (and equivalent to it).
|
1396
1481
|
class TypeDef < Type
|
1397
|
-
# Moved to constructor
|
1398
|
-
# extend Forwardable
|
1399
|
-
|
1400
1482
|
# The definition of the type.
|
1401
1483
|
attr_reader :def
|
1402
1484
|
|
@@ -1452,15 +1534,8 @@ module HDLRuby::Low
|
|
1452
1534
|
@def.each_type_deep(&ruby_block)
|
1453
1535
|
end
|
1454
1536
|
|
1455
|
-
|
1456
|
-
|
1457
|
-
# def_delegators :@def,
|
1458
|
-
# :signed?, :unsigned?, :fixed?, :float?, :leaf?,
|
1459
|
-
# :width, :range?, :range, :base?, :base, :types?,
|
1460
|
-
# :get_all_types, :get_type, :each, :each_type,
|
1461
|
-
# :regular?,
|
1462
|
-
# :each_name,
|
1463
|
-
# :equivalent?
|
1537
|
+
alias_method :each_deep, :each_type_deep
|
1538
|
+
|
1464
1539
|
end
|
1465
1540
|
|
1466
1541
|
|
@@ -1601,6 +1676,8 @@ module HDLRuby::Low
|
|
1601
1676
|
# And recurse on the base.
|
1602
1677
|
@base.each_type_deep(&ruby_block)
|
1603
1678
|
end
|
1679
|
+
|
1680
|
+
alias_method :each_deep, :each_type_deep
|
1604
1681
|
end
|
1605
1682
|
|
1606
1683
|
|
@@ -1756,6 +1833,8 @@ module HDLRuby::Low
|
|
1756
1833
|
@types.each { |type| type.each_type_deep(&ruby_block) }
|
1757
1834
|
end
|
1758
1835
|
|
1836
|
+
alias_method :each_deep, :each_type_deep
|
1837
|
+
|
1759
1838
|
# Tell if the tuple is regular, i.e., all its sub types are equivalent.
|
1760
1839
|
#
|
1761
1840
|
# NOTE: empty tuples are assumed not to be regular.
|
@@ -1927,6 +2006,8 @@ module HDLRuby::Low
|
|
1927
2006
|
@types.each_value { |type| type.each_type_deep(&ruby_block) }
|
1928
2007
|
end
|
1929
2008
|
|
2009
|
+
alias_method :each_deep, :each_type_deep
|
2010
|
+
|
1930
2011
|
# Gets the bitwidth of the type, nil for undefined.
|
1931
2012
|
#
|
1932
2013
|
# NOTE: must be redefined for specific types.
|
@@ -2012,6 +2093,9 @@ module HDLRuby::Low
|
|
2012
2093
|
# @block = block
|
2013
2094
|
end
|
2014
2095
|
|
2096
|
+
# Add decorator capability (modifies intialize to put after).
|
2097
|
+
include Hdecorator
|
2098
|
+
|
2015
2099
|
# Sets the block if not already set.
|
2016
2100
|
def block=(block)
|
2017
2101
|
# Check the block.
|
@@ -2134,6 +2218,22 @@ module HDLRuby::Low
|
|
2134
2218
|
@block.reverse_each_statement(&ruby_block)
|
2135
2219
|
end
|
2136
2220
|
|
2221
|
+
# Iterates over each object deeply.
|
2222
|
+
#
|
2223
|
+
# Returns an enumerator if no ruby block is given.
|
2224
|
+
def each_deep(&ruby_block)
|
2225
|
+
# No ruby block? Return an enumerator.
|
2226
|
+
return to_enum(:each_deep) unless ruby_block
|
2227
|
+
# A ruby block? First apply it to current.
|
2228
|
+
ruby_block.call(self)
|
2229
|
+
# Then apply on each event.
|
2230
|
+
self.each_event do |event|
|
2231
|
+
event.each_deep(&ruby_block)
|
2232
|
+
end
|
2233
|
+
# Then apply on the block.
|
2234
|
+
self.block.each_deep(&ruby_block)
|
2235
|
+
end
|
2236
|
+
|
2137
2237
|
# Returns the last statement.
|
2138
2238
|
def last_statement
|
2139
2239
|
@block.last_statement
|
@@ -2217,6 +2317,9 @@ module HDLRuby::Low
|
|
2217
2317
|
ref.parent = self
|
2218
2318
|
end
|
2219
2319
|
|
2320
|
+
# Add decorator capability (modifies intialize to put after).
|
2321
|
+
include Hdecorator
|
2322
|
+
|
2220
2323
|
# Comparison for hash: structural comparison.
|
2221
2324
|
def eql?(obj)
|
2222
2325
|
return false unless obj.is_a?(Event)
|
@@ -2236,6 +2339,20 @@ module HDLRuby::Low
|
|
2236
2339
|
def on_edge?
|
2237
2340
|
return (@type == :posedge or @type == :negedge)
|
2238
2341
|
end
|
2342
|
+
|
2343
|
+
# Iterates over each object deeply.
|
2344
|
+
#
|
2345
|
+
# Returns an enumerator if no ruby block is given.
|
2346
|
+
def each_deep(&ruby_block)
|
2347
|
+
# No ruby block? Return an enumerator.
|
2348
|
+
return to_enum(:each_deep) unless ruby_block
|
2349
|
+
# A ruby block? First apply it to current.
|
2350
|
+
ruby_block.call(self)
|
2351
|
+
# Then apply on the type.
|
2352
|
+
self.type.each_deep(&ruby_block)
|
2353
|
+
# Then apply on the reference.
|
2354
|
+
self.ref.each_deep(&ruby_block)
|
2355
|
+
end
|
2239
2356
|
end
|
2240
2357
|
|
2241
2358
|
|
@@ -2278,6 +2395,29 @@ module HDLRuby::Low
|
|
2278
2395
|
end
|
2279
2396
|
end
|
2280
2397
|
|
2398
|
+
# Tells if the signal is immutable (cannot be written.)
|
2399
|
+
def immutable?
|
2400
|
+
# By default, signals are not immutable.
|
2401
|
+
false
|
2402
|
+
end
|
2403
|
+
|
2404
|
+
# Add decorator capability (modifies intialize to put after).
|
2405
|
+
include Hdecorator
|
2406
|
+
|
2407
|
+
# Iterates over each object deeply.
|
2408
|
+
#
|
2409
|
+
# Returns an enumerator if no ruby block is given.
|
2410
|
+
def each_deep(&ruby_block)
|
2411
|
+
# No ruby block? Return an enumerator.
|
2412
|
+
return to_enum(:each_deep) unless ruby_block
|
2413
|
+
# A ruby block? First apply it to current.
|
2414
|
+
ruby_block.call(self)
|
2415
|
+
# Then apply on the type.
|
2416
|
+
self.type.each_deep(&ruby_block)
|
2417
|
+
# Then apply on the value.
|
2418
|
+
self.value.each_deep(&ruby_block) if self.value
|
2419
|
+
end
|
2420
|
+
|
2281
2421
|
# Comparison for hash: structural comparison.
|
2282
2422
|
def eql?(obj)
|
2283
2423
|
return false unless obj.is_a?(SignalI)
|
@@ -2305,6 +2445,11 @@ module HDLRuby::Low
|
|
2305
2445
|
##
|
2306
2446
|
# Describes a constant signal.
|
2307
2447
|
class SignalC < SignalI
|
2448
|
+
# Tells if the signal is immutable (cannot be written.)
|
2449
|
+
def immutable?
|
2450
|
+
# Constant signals are immutable.
|
2451
|
+
true
|
2452
|
+
end
|
2308
2453
|
end
|
2309
2454
|
|
2310
2455
|
##
|
@@ -2341,6 +2486,22 @@ module HDLRuby::Low
|
|
2341
2486
|
@systemTs = [ @systemT ]
|
2342
2487
|
end
|
2343
2488
|
|
2489
|
+
# Add decorator capability (modifies intialize to put after).
|
2490
|
+
include Hdecorator
|
2491
|
+
|
2492
|
+
# Iterates over each object deeply.
|
2493
|
+
#
|
2494
|
+
# Returns an enumerator if no ruby block is given.
|
2495
|
+
def each_deep(&ruby_block)
|
2496
|
+
# No ruby block? Return an enumerator.
|
2497
|
+
return to_enum(:each_deep) unless ruby_block
|
2498
|
+
# A ruby block? First apply it to current.
|
2499
|
+
ruby_block.call(self)
|
2500
|
+
|
2501
|
+
# Do not recurse on the systemTs since necesarily processed
|
2502
|
+
# before!
|
2503
|
+
end
|
2504
|
+
|
2344
2505
|
# Comparison for hash: structural comparison.
|
2345
2506
|
def eql?(obj)
|
2346
2507
|
return false unless obj.is_a?(SystemI)
|
@@ -2457,6 +2618,9 @@ module HDLRuby::Low
|
|
2457
2618
|
lumps.each { |lump| self.add_lump(lump) }
|
2458
2619
|
end
|
2459
2620
|
|
2621
|
+
# Add decorator capability (modifies intialize to put after).
|
2622
|
+
include Hdecorator
|
2623
|
+
|
2460
2624
|
# Adds a +lump+ of code, it is ment to become an expression or
|
2461
2625
|
# some text.
|
2462
2626
|
def add_lump(lump)
|
@@ -2476,6 +2640,16 @@ module HDLRuby::Low
|
|
2476
2640
|
# A ruby block? Apply it on each lump.
|
2477
2641
|
@lumps.each(&ruby_block)
|
2478
2642
|
end
|
2643
|
+
|
2644
|
+
# Iterates over each object deeply.
|
2645
|
+
#
|
2646
|
+
# Returns an enumerator if no ruby block is given.
|
2647
|
+
def each_deep(&ruby_block)
|
2648
|
+
# No ruby block? Return an enumerator.
|
2649
|
+
return to_enum(:each_deep) unless ruby_block
|
2650
|
+
# A ruby block? First apply it to current.
|
2651
|
+
ruby_block.call(self)
|
2652
|
+
end
|
2479
2653
|
end
|
2480
2654
|
|
2481
2655
|
|
@@ -2493,6 +2667,9 @@ module HDLRuby::Low
|
|
2493
2667
|
@chunks = HashName.new
|
2494
2668
|
end
|
2495
2669
|
|
2670
|
+
# Add decorator capability (modifies intialize to put after).
|
2671
|
+
include Hdecorator
|
2672
|
+
|
2496
2673
|
# Adds a +chunk+ to the sensitivity list.
|
2497
2674
|
def add_chunk(chunk)
|
2498
2675
|
# Check and add the chunk.
|
@@ -2555,6 +2732,24 @@ module HDLRuby::Low
|
|
2555
2732
|
return false
|
2556
2733
|
end
|
2557
2734
|
|
2735
|
+
# Iterates over each object deeply.
|
2736
|
+
#
|
2737
|
+
# Returns an enumerator if no ruby block is given.
|
2738
|
+
def each_deep(&ruby_block)
|
2739
|
+
# No ruby block? Return an enumerator.
|
2740
|
+
return to_enum(:each_deep) unless ruby_block
|
2741
|
+
# A ruby block? First apply it to current.
|
2742
|
+
ruby_block.call(self)
|
2743
|
+
# Then apply on each chunk.
|
2744
|
+
self.each_chunk do |chunk|
|
2745
|
+
chunk.each_deep(&ruby_block)
|
2746
|
+
end
|
2747
|
+
# Then apply on each event.
|
2748
|
+
self.each_event do |event|
|
2749
|
+
event.each_deep(&ruby_block)
|
2750
|
+
end
|
2751
|
+
end
|
2752
|
+
|
2558
2753
|
# Comparison for hash: structural comparison.
|
2559
2754
|
def eql?(obj)
|
2560
2755
|
return false unless obj.is_a?(Code)
|
@@ -2584,6 +2779,7 @@ module HDLRuby::Low
|
|
2584
2779
|
# NOTE: this is an abstract class which is not to be used directly.
|
2585
2780
|
class Statement
|
2586
2781
|
include Hparent
|
2782
|
+
include Hdecorator
|
2587
2783
|
|
2588
2784
|
# Clones (deeply)
|
2589
2785
|
def clone
|
@@ -2591,6 +2787,14 @@ module HDLRuby::Low
|
|
2591
2787
|
"Internal error: clone is not defined for class: #{self.class}"
|
2592
2788
|
end
|
2593
2789
|
|
2790
|
+
# Iterates over each object deeply.
|
2791
|
+
#
|
2792
|
+
# Returns an enumerator if no ruby block is given.
|
2793
|
+
def each_deep(&ruby_block)
|
2794
|
+
raise AnyError,
|
2795
|
+
"Internal error: each_deep is not defined for class: #{self.class}"
|
2796
|
+
end
|
2797
|
+
|
2594
2798
|
# Comparison for hash: structural comparison.
|
2595
2799
|
def eql?(obj)
|
2596
2800
|
raise AnyError,
|
@@ -2603,6 +2807,15 @@ module HDLRuby::Low
|
|
2603
2807
|
"Internal error: hash is not defined for class: #{self.class}"
|
2604
2808
|
end
|
2605
2809
|
|
2810
|
+
# Iterates over each sub statement if any.
|
2811
|
+
#
|
2812
|
+
# Returns an enumerator if no ruby block is given.
|
2813
|
+
def each_statement(&ruby_block)
|
2814
|
+
# No ruby statement? Return an enumerator.
|
2815
|
+
return to_enum(:each_statement) unless ruby_block
|
2816
|
+
# By default: nothing to do.
|
2817
|
+
end
|
2818
|
+
|
2606
2819
|
# Get the block of the statement.
|
2607
2820
|
def block
|
2608
2821
|
if self.is_a?(Block)
|
@@ -2692,6 +2905,7 @@ module HDLRuby::Low
|
|
2692
2905
|
raise AnyError,
|
2693
2906
|
"Invalid class for a reference (left value): #{left.class}"
|
2694
2907
|
end
|
2908
|
+
super()
|
2695
2909
|
@left = left
|
2696
2910
|
# and set its parent.
|
2697
2911
|
left.parent = self
|
@@ -2704,6 +2918,20 @@ module HDLRuby::Low
|
|
2704
2918
|
right.parent = self
|
2705
2919
|
end
|
2706
2920
|
|
2921
|
+
# Iterates over each object deeply.
|
2922
|
+
#
|
2923
|
+
# Returns an enumerator if no ruby block is given.
|
2924
|
+
def each_deep(&ruby_block)
|
2925
|
+
# No ruby block? Return an enumerator.
|
2926
|
+
return to_enum(:each_deep) unless ruby_block
|
2927
|
+
# A ruby block? First apply it to current.
|
2928
|
+
ruby_block.call(self)
|
2929
|
+
# Then apply on the left.
|
2930
|
+
self.left.each_deep(&ruby_block)
|
2931
|
+
# Then apply on the right.
|
2932
|
+
self.right.each_deep(&ruby_block)
|
2933
|
+
end
|
2934
|
+
|
2707
2935
|
# Comparison for hash: structural comparison.
|
2708
2936
|
def eql?(obj)
|
2709
2937
|
return false unless obj.is_a?(Transmit)
|
@@ -2793,6 +3021,7 @@ module HDLRuby::Low
|
|
2793
3021
|
raise AnyError,
|
2794
3022
|
"Invalid class for a condition: #{condition.class}"
|
2795
3023
|
end
|
3024
|
+
super()
|
2796
3025
|
@condition = condition
|
2797
3026
|
# And set its parent.
|
2798
3027
|
condition.parent = self
|
@@ -2815,6 +3044,27 @@ module HDLRuby::Low
|
|
2815
3044
|
@noifs = []
|
2816
3045
|
end
|
2817
3046
|
|
3047
|
+
# Iterates over each object deeply.
|
3048
|
+
#
|
3049
|
+
# Returns an enumerator if no ruby block is given.
|
3050
|
+
def each_deep(&ruby_block)
|
3051
|
+
# No ruby block? Return an enumerator.
|
3052
|
+
return to_enum(:each_deep) unless ruby_block
|
3053
|
+
# A ruby block? First apply it to current.
|
3054
|
+
ruby_block.call(self)
|
3055
|
+
# Then apply on the condition.
|
3056
|
+
self.condition.each_deep(&ruby_block)
|
3057
|
+
# Then apply on the yes.
|
3058
|
+
self.yes.each_deep(&ruby_block)
|
3059
|
+
# The apply on the no.
|
3060
|
+
self.no.each_deep(&ruby_block)
|
3061
|
+
# Then apply on the alternate ifs.
|
3062
|
+
self.each_noif do |cond,stmnt|
|
3063
|
+
cond.each_deep(&ruby_block)
|
3064
|
+
stmnt.each_deep(&ruby_block)
|
3065
|
+
end
|
3066
|
+
end
|
3067
|
+
|
2818
3068
|
# Comparison for hash: structural comparison.
|
2819
3069
|
def eql?(obj)
|
2820
3070
|
return false unless obj.is_a?(If)
|
@@ -2878,7 +3128,24 @@ module HDLRuby::Low
|
|
2878
3128
|
end
|
2879
3129
|
end
|
2880
3130
|
|
3131
|
+
# Iterates over each sub statement if any.
|
3132
|
+
#
|
3133
|
+
# Returns an enumerator if no ruby block is given.
|
3134
|
+
def each_statement(&ruby_block)
|
3135
|
+
# No ruby block? Return an enumerator.
|
3136
|
+
return to_enum(:each_statement) unless ruby_block
|
3137
|
+
# A ruby block?
|
3138
|
+
# Appy it on the statement children.
|
3139
|
+
ruby_block.call(@yes)
|
3140
|
+
self.each_noif do |next_cond,next_yes|
|
3141
|
+
ruby_block.call(next_yes)
|
3142
|
+
end
|
3143
|
+
ruby_block.call(@no) if @no
|
3144
|
+
end
|
3145
|
+
|
2881
3146
|
# Iterates over the children (including the condition).
|
3147
|
+
#
|
3148
|
+
# Returns an enumerator if no ruby block is given.
|
2882
3149
|
def each_node(&ruby_block)
|
2883
3150
|
# No ruby block? Return an enumerator.
|
2884
3151
|
return to_enum(:each_node) unless ruby_block
|
@@ -3000,6 +3267,23 @@ module HDLRuby::Low
|
|
3000
3267
|
match.parent = statement.parent = self
|
3001
3268
|
end
|
3002
3269
|
|
3270
|
+
# Add decorator capability (modifies intialize to put after).
|
3271
|
+
include Hdecorator
|
3272
|
+
|
3273
|
+
# Iterates over each object deeply.
|
3274
|
+
#
|
3275
|
+
# Returns an enumerator if no ruby block is given.
|
3276
|
+
def each_deep(&ruby_block)
|
3277
|
+
# No ruby block? Return an enumerator.
|
3278
|
+
return to_enum(:each_deep) unless ruby_block
|
3279
|
+
# A ruby block? First apply it to current.
|
3280
|
+
ruby_block.call(self)
|
3281
|
+
# Then apply on the match.
|
3282
|
+
self.match.each_deep(&ruby_block)
|
3283
|
+
# Then apply on the statement.
|
3284
|
+
self.statement.each_deep(&ruby_block)
|
3285
|
+
end
|
3286
|
+
|
3003
3287
|
# Comparison for hash: structural comparison.
|
3004
3288
|
def eql?(obj)
|
3005
3289
|
return false unless obj.is_a?(When)
|
@@ -3018,6 +3302,17 @@ module HDLRuby::Low
|
|
3018
3302
|
return When.new(@match.clone,@statement.clone)
|
3019
3303
|
end
|
3020
3304
|
|
3305
|
+
# Iterates over each sub statement if any.
|
3306
|
+
#
|
3307
|
+
# Returns an enumerator if no ruby block is given.
|
3308
|
+
def each_statement(&ruby_block)
|
3309
|
+
# No ruby block? Return an enumerator.
|
3310
|
+
return to_enum(:each_statement) unless ruby_block
|
3311
|
+
# A ruby block?
|
3312
|
+
# Appy it on the statement child.
|
3313
|
+
ruby_block.call(@statement)
|
3314
|
+
end
|
3315
|
+
|
3021
3316
|
# Iterates over the sub blocks.
|
3022
3317
|
def each_block(&ruby_block)
|
3023
3318
|
# No ruby block? Return an enumerator.
|
@@ -3068,7 +3363,8 @@ module HDLRuby::Low
|
|
3068
3363
|
|
3069
3364
|
# Gets the top block, i.e. the first block of the current behavior.
|
3070
3365
|
def top_block
|
3071
|
-
return self.parent.is_a?(Behavior) ? self : self.parent.top_block
|
3366
|
+
# return self.parent.is_a?(Behavior) ? self : self.parent.top_block
|
3367
|
+
return self.parent.top_block
|
3072
3368
|
end
|
3073
3369
|
|
3074
3370
|
# Tell if the statement includes a signal whose name is one of +names+.
|
@@ -3096,6 +3392,7 @@ module HDLRuby::Low
|
|
3096
3392
|
unless value.is_a?(Expression)
|
3097
3393
|
raise AnyError, "Invalid class for a value: #{value.class}"
|
3098
3394
|
end
|
3395
|
+
super()
|
3099
3396
|
@value = value
|
3100
3397
|
# And set its parent.
|
3101
3398
|
value.parent = self
|
@@ -3106,6 +3403,22 @@ module HDLRuby::Low
|
|
3106
3403
|
whens.each { |w| self.add_when(w) }
|
3107
3404
|
end
|
3108
3405
|
|
3406
|
+
# Iterates over each object deeply.
|
3407
|
+
#
|
3408
|
+
# Returns an enumerator if no ruby block is given.
|
3409
|
+
def each_deep(&ruby_block)
|
3410
|
+
# No ruby block? Return an enumerator.
|
3411
|
+
return to_enum(:each_deep) unless ruby_block
|
3412
|
+
# A ruby block? First apply it to current.
|
3413
|
+
ruby_block.call(self)
|
3414
|
+
# Then apply on the value.
|
3415
|
+
self.value.each_deep(&ruby_block)
|
3416
|
+
# Then apply on the whens.
|
3417
|
+
self.each_when do |w|
|
3418
|
+
w.each_deep(&ruby_block)
|
3419
|
+
end
|
3420
|
+
end
|
3421
|
+
|
3109
3422
|
# Comparison for hash: structural comparison.
|
3110
3423
|
def eql?(obj)
|
3111
3424
|
return false unless obj.is_a?(Case)
|
@@ -3155,6 +3468,19 @@ module HDLRuby::Low
|
|
3155
3468
|
@default
|
3156
3469
|
end
|
3157
3470
|
|
3471
|
+
# Iterates over each sub statement if any.
|
3472
|
+
#
|
3473
|
+
# Returns an enumerator if no ruby block is given.
|
3474
|
+
def each_statement(&ruby_block)
|
3475
|
+
# No ruby block? Return an enumerator.
|
3476
|
+
return to_enum(:each_statement) unless ruby_block
|
3477
|
+
# A ruby block?
|
3478
|
+
# Apply on each when.
|
3479
|
+
@whens.each { |w| w.each_statement(&ruby_block) }
|
3480
|
+
# And on the default if any.
|
3481
|
+
ruby_block.call(@default) if @default
|
3482
|
+
end
|
3483
|
+
|
3158
3484
|
# Iterates over the match cases.
|
3159
3485
|
#
|
3160
3486
|
# Returns an enumerator if no ruby block is given.
|
@@ -3266,6 +3592,21 @@ module HDLRuby::Low
|
|
3266
3592
|
@unit = unit.to_sym
|
3267
3593
|
end
|
3268
3594
|
|
3595
|
+
# Add decorator capability (modifies intialize to put after).
|
3596
|
+
include Hdecorator
|
3597
|
+
|
3598
|
+
# Iterates over each object deeply.
|
3599
|
+
#
|
3600
|
+
# Returns an enumerator if no ruby block is given.
|
3601
|
+
def each_deep(&ruby_block)
|
3602
|
+
# No ruby block? Return an enumerator.
|
3603
|
+
return to_enum(:each_deep) unless ruby_block
|
3604
|
+
# A ruby block? First apply it to current.
|
3605
|
+
ruby_block.call(self)
|
3606
|
+
# Then apply on the value.
|
3607
|
+
self.value.each_deep(&ruby_block)
|
3608
|
+
end
|
3609
|
+
|
3269
3610
|
# Comparison for hash: structural comparison.
|
3270
3611
|
def eql?(obj)
|
3271
3612
|
return false unless obj.is_a?(Delay)
|
@@ -3286,6 +3627,122 @@ module HDLRuby::Low
|
|
3286
3627
|
end
|
3287
3628
|
|
3288
3629
|
|
3630
|
+
##
|
3631
|
+
# Describes a print statement: not synthesizable!
|
3632
|
+
class Print < Statement
|
3633
|
+
|
3634
|
+
# Creates a new statement for printing +args+.
|
3635
|
+
def initialize(*args)
|
3636
|
+
super()
|
3637
|
+
# Process the arguments.
|
3638
|
+
@args = args.map do |arg|
|
3639
|
+
arg.parent = self
|
3640
|
+
arg
|
3641
|
+
end
|
3642
|
+
end
|
3643
|
+
|
3644
|
+
# Comparison for hash: structural comparison.
|
3645
|
+
def eql?(obj)
|
3646
|
+
return false unless obj.is_a?(Print)
|
3647
|
+
return false if @args.each.zip(obj.each_arg).any? do |a0,a1|
|
3648
|
+
!a0.eql?(a1)
|
3649
|
+
end
|
3650
|
+
return true
|
3651
|
+
end
|
3652
|
+
|
3653
|
+
# Iterates over each argument.
|
3654
|
+
#
|
3655
|
+
# Returns an enumerator if no ruby block is given.
|
3656
|
+
def each_arg(&ruby_block)
|
3657
|
+
# No ruby block? Return an enumerator.
|
3658
|
+
return to_enum(:each_arg) unless ruby_block
|
3659
|
+
# A ruby block? First apply it to each argument.
|
3660
|
+
@args.each(&ruby_block)
|
3661
|
+
end
|
3662
|
+
|
3663
|
+
# Iterates over each object deeply.
|
3664
|
+
#
|
3665
|
+
# Returns an enumerator if no ruby block is given.
|
3666
|
+
def each_deep(&ruby_block)
|
3667
|
+
# No ruby block? Return an enumerator.
|
3668
|
+
return to_enum(:each_deep) unless ruby_block
|
3669
|
+
# A ruby block? First apply it to current.
|
3670
|
+
ruby_block.call(self)
|
3671
|
+
# Then apply on the arguments.
|
3672
|
+
self.each_arg(&ruby_block)
|
3673
|
+
end
|
3674
|
+
|
3675
|
+
# Hash function.
|
3676
|
+
def hash
|
3677
|
+
return @args.hash
|
3678
|
+
end
|
3679
|
+
|
3680
|
+
# Clones the TimeWait (deeply)
|
3681
|
+
def clone
|
3682
|
+
return Print.new(*@args.map { |arg| arg.clone })
|
3683
|
+
end
|
3684
|
+
|
3685
|
+
# Iterates over the expression children if any.
|
3686
|
+
def each_node(&ruby_block)
|
3687
|
+
# No ruby block? Return an enumerator.
|
3688
|
+
return to_enum(:each_node) unless ruby_block
|
3689
|
+
# A ruby block?
|
3690
|
+
# Apply it on each argument.
|
3691
|
+
@args.each(&ruby_block)
|
3692
|
+
end
|
3693
|
+
|
3694
|
+
# Iterates over the nodes deeply if any.
|
3695
|
+
def each_node_deep(&ruby_block)
|
3696
|
+
# No ruby block? Return an enumerator.
|
3697
|
+
return to_enum(:each_node_deep) unless ruby_block
|
3698
|
+
# A ruby block? First apply it to current.
|
3699
|
+
ruby_block.call(self)
|
3700
|
+
# And apply it on each argument.
|
3701
|
+
@args.each(&ruby_block)
|
3702
|
+
end
|
3703
|
+
|
3704
|
+
# Iterates over the sub blocks.
|
3705
|
+
def each_block(&ruby_block)
|
3706
|
+
# No ruby block? Return an enumerator.
|
3707
|
+
return to_enum(:each_block) unless ruby_block
|
3708
|
+
# A ruby block?
|
3709
|
+
# Recurse on each argument.
|
3710
|
+
@args.each do |arg|
|
3711
|
+
arg.each_block(&ruby_block) if arg.respond_to?(:each_block)
|
3712
|
+
end
|
3713
|
+
end
|
3714
|
+
|
3715
|
+
# Iterates over all the blocks contained in the current block.
|
3716
|
+
def each_block_deep(&ruby_block)
|
3717
|
+
# No ruby block? Return an enumerator.
|
3718
|
+
return to_enum(:each_block_deep) unless ruby_block
|
3719
|
+
# A ruby block?
|
3720
|
+
# Recurse on each argument.
|
3721
|
+
@args.each do |arg|
|
3722
|
+
if arg.respond_to?(:each_block_deep) then
|
3723
|
+
arg.each_block_deep(&ruby_block)
|
3724
|
+
end
|
3725
|
+
end
|
3726
|
+
end
|
3727
|
+
|
3728
|
+
# Iterates over all the statements contained in the current block.
|
3729
|
+
def each_statement_deep(&ruby_block)
|
3730
|
+
# No ruby block? Return an enumerator.
|
3731
|
+
return to_enum(:each_statement_deep) unless ruby_block
|
3732
|
+
# A ruby block?
|
3733
|
+
# Apply it on self.
|
3734
|
+
ruby_block.call(self)
|
3735
|
+
# Recurse on each argument.
|
3736
|
+
@args.each do |arg|
|
3737
|
+
if arg.respond_to?(:each_statement_deep) then
|
3738
|
+
arg.each_statement_deep(&ruby_block)
|
3739
|
+
end
|
3740
|
+
end
|
3741
|
+
end
|
3742
|
+
|
3743
|
+
end
|
3744
|
+
|
3745
|
+
|
3289
3746
|
##
|
3290
3747
|
# Describes a wait statement: not synthesizable!
|
3291
3748
|
class TimeWait < Statement
|
@@ -3298,6 +3755,7 @@ module HDLRuby::Low
|
|
3298
3755
|
unless delay.is_a?(Delay)
|
3299
3756
|
raise AnyError, "Invalid class for a delay: #{delay.class}."
|
3300
3757
|
end
|
3758
|
+
super()
|
3301
3759
|
@delay = delay
|
3302
3760
|
# And set its parent.
|
3303
3761
|
delay.parent = self
|
@@ -3310,6 +3768,18 @@ module HDLRuby::Low
|
|
3310
3768
|
return true
|
3311
3769
|
end
|
3312
3770
|
|
3771
|
+
# Iterates over each object deeply.
|
3772
|
+
#
|
3773
|
+
# Returns an enumerator if no ruby block is given.
|
3774
|
+
def each_deep(&ruby_block)
|
3775
|
+
# No ruby block? Return an enumerator.
|
3776
|
+
return to_enum(:each_deep) unless ruby_block
|
3777
|
+
# A ruby block? First apply it to current.
|
3778
|
+
ruby_block.call(self)
|
3779
|
+
# Then apply on the delay.
|
3780
|
+
self.delay.each_deep(&ruby_block)
|
3781
|
+
end
|
3782
|
+
|
3313
3783
|
# Hash function.
|
3314
3784
|
def hash
|
3315
3785
|
return [@delay].hash
|
@@ -3381,6 +3851,7 @@ module HDLRuby::Low
|
|
3381
3851
|
raise AnyError,
|
3382
3852
|
"Invalid class for a statement: #{statement.class}."
|
3383
3853
|
end
|
3854
|
+
super()
|
3384
3855
|
@statement = statement
|
3385
3856
|
# And set its parent.
|
3386
3857
|
statement.parent = self
|
@@ -3394,6 +3865,20 @@ module HDLRuby::Low
|
|
3394
3865
|
delay.parent = self
|
3395
3866
|
end
|
3396
3867
|
|
3868
|
+
# Iterates over each object deeply.
|
3869
|
+
#
|
3870
|
+
# Returns an enumerator if no ruby block is given.
|
3871
|
+
def each_deep(&ruby_block)
|
3872
|
+
# No ruby block? Return an enumerator.
|
3873
|
+
return to_enum(:each_deep) unless ruby_block
|
3874
|
+
# A ruby block? First apply it to current.
|
3875
|
+
ruby_block.call(self)
|
3876
|
+
# Then apply on the statement.
|
3877
|
+
self.statement.each_deep(&ruby_block)
|
3878
|
+
# Then apply on the delay.
|
3879
|
+
self.delay.each_deep(&ruby_block)
|
3880
|
+
end
|
3881
|
+
|
3397
3882
|
# Comparison for hash: structural comparison.
|
3398
3883
|
def eql?(obj)
|
3399
3884
|
return false unless obj.is_a?(TimeRepeat)
|
@@ -3473,6 +3958,7 @@ module HDLRuby::Low
|
|
3473
3958
|
|
3474
3959
|
# Creates a new +mode+ sort of block with possible +name+.
|
3475
3960
|
def initialize(mode, name = :"")
|
3961
|
+
super()
|
3476
3962
|
# puts "new block with mode=#{mode} and name=#{name}"
|
3477
3963
|
# Check and set the type.
|
3478
3964
|
@mode = mode.to_sym
|
@@ -3485,6 +3971,24 @@ module HDLRuby::Low
|
|
3485
3971
|
@statements = []
|
3486
3972
|
end
|
3487
3973
|
|
3974
|
+
# Iterates over each object deeply.
|
3975
|
+
#
|
3976
|
+
# Returns an enumerator if no ruby block is given.
|
3977
|
+
def each_deep(&ruby_block)
|
3978
|
+
# No ruby block? Return an enumerator.
|
3979
|
+
return to_enum(:each_deep) unless ruby_block
|
3980
|
+
# A ruby block? First apply it to current.
|
3981
|
+
ruby_block.call(self)
|
3982
|
+
# Then apply on the inners.
|
3983
|
+
self.each_inner do |inner|
|
3984
|
+
inner.each_deep(&ruby_block)
|
3985
|
+
end
|
3986
|
+
# Then apply on the statements.
|
3987
|
+
self.each_statement do |stmnt|
|
3988
|
+
stmnt.each_deep(&ruby_block)
|
3989
|
+
end
|
3990
|
+
end
|
3991
|
+
|
3488
3992
|
# Comparison for hash: structural comparison.
|
3489
3993
|
def eql?(obj)
|
3490
3994
|
return false unless obj.is_a?(Block)
|
@@ -3535,7 +4039,6 @@ module HDLRuby::Low
|
|
3535
4039
|
# No ruby block? Return an enumerator.
|
3536
4040
|
return to_enum(:each_inner) unless ruby_block
|
3537
4041
|
# A ruby block? Apply it on each inner signal instance.
|
3538
|
-
# @inners.each_value(&ruby_block)
|
3539
4042
|
@inners.each(&ruby_block)
|
3540
4043
|
end
|
3541
4044
|
alias_method :each_signal, :each_inner
|
@@ -3626,17 +4129,6 @@ module HDLRuby::Low
|
|
3626
4129
|
def last_statement
|
3627
4130
|
return @statements[-1]
|
3628
4131
|
end
|
3629
|
-
|
3630
|
-
# # Deletes +statement+.
|
3631
|
-
# def delete_statement(statement)
|
3632
|
-
# if @statements.include?(statement) then
|
3633
|
-
# # Statement is present, delete it.
|
3634
|
-
# @statements.delete(statement)
|
3635
|
-
# # And remove its parent.
|
3636
|
-
# statement.parent = nil
|
3637
|
-
# end
|
3638
|
-
# statement
|
3639
|
-
# end
|
3640
4132
|
|
3641
4133
|
# Iterates over the sub blocks.
|
3642
4134
|
def each_block(&ruby_block)
|
@@ -3810,6 +4302,9 @@ module HDLRuby::Low
|
|
3810
4302
|
end
|
3811
4303
|
end
|
3812
4304
|
|
4305
|
+
# Add decorator capability (modifies intialize to put after).
|
4306
|
+
include Hdecorator
|
4307
|
+
|
3813
4308
|
# Comparison for hash: structural comparison.
|
3814
4309
|
def eql?(obj)
|
3815
4310
|
return false unless obj.is_a?(Expression)
|
@@ -3845,6 +4340,11 @@ module HDLRuby::Low
|
|
3845
4340
|
return !self.leftvalue?
|
3846
4341
|
end
|
3847
4342
|
|
4343
|
+
# Tells if the expression is immutable (cannot be written.)
|
4344
|
+
def immutable?
|
4345
|
+
false
|
4346
|
+
end
|
4347
|
+
|
3848
4348
|
# Iterates over the expression children if any.
|
3849
4349
|
def each_node(&ruby_block)
|
3850
4350
|
# By default: no child.
|
@@ -3900,29 +4400,50 @@ module HDLRuby::Low
|
|
3900
4400
|
# Describes a value.
|
3901
4401
|
class Value < Expression
|
3902
4402
|
|
3903
|
-
# Moved to Expression
|
3904
|
-
# # The type of value.
|
3905
|
-
# attr_reader :type
|
3906
|
-
|
3907
4403
|
# The content of the value.
|
3908
4404
|
attr_reader :content
|
3909
4405
|
|
3910
4406
|
# Creates a new value typed +type+ and containing +content+.
|
3911
4407
|
def initialize(type,content)
|
3912
|
-
# Moved to Expression.
|
3913
|
-
# # Check and set the type.
|
3914
|
-
# if type.is_a?(Type) then
|
3915
|
-
# @type = type
|
3916
|
-
# else
|
3917
|
-
# raise AnyError, "Invalid class for a type: #{type.class}."
|
3918
|
-
# end
|
3919
4408
|
super(type)
|
3920
|
-
|
3921
|
-
|
3922
|
-
|
3923
|
-
|
4409
|
+
unless content then
|
4410
|
+
# Handle the nil content case.
|
4411
|
+
unless type.eql?(Void) then
|
4412
|
+
raise AnyError, "A value with nil content must have the Void type."
|
4413
|
+
end
|
4414
|
+
@content = content
|
4415
|
+
else
|
4416
|
+
# Checks and set the content: Ruby Numeric and HDLRuby
|
4417
|
+
# BitString are supported. Strings or equivalent are
|
4418
|
+
# converted to BitString.
|
4419
|
+
unless content.is_a?(Numeric) or
|
4420
|
+
content.is_a?(HDLRuby::BitString)
|
4421
|
+
content = HDLRuby::BitString.new(content.to_s)
|
4422
|
+
end
|
4423
|
+
@content = content
|
4424
|
+
end
|
4425
|
+
end
|
4426
|
+
|
4427
|
+
# Tells if the expression is immutable (cannot be written.)
|
4428
|
+
def immutable?
|
4429
|
+
# Values are always immutable.
|
4430
|
+
true
|
4431
|
+
end
|
4432
|
+
|
4433
|
+
# Iterates over each object deeply.
|
4434
|
+
#
|
4435
|
+
# Returns an enumerator if no ruby block is given.
|
4436
|
+
def each_deep(&ruby_block)
|
4437
|
+
# No ruby block? Return an enumerator.
|
4438
|
+
return to_enum(:each_deep) unless ruby_block
|
4439
|
+
# A ruby block? First apply it to current.
|
4440
|
+
ruby_block.call(self)
|
4441
|
+
# Then apply on the type.
|
4442
|
+
self.type.each_deep(&ruby_block)
|
4443
|
+
# Then apply on the content if possible.
|
4444
|
+
if self.content.respond_to?(:each_deep) then
|
4445
|
+
self.content.each_deep(&ruby_block)
|
3924
4446
|
end
|
3925
|
-
@content = content
|
3926
4447
|
end
|
3927
4448
|
|
3928
4449
|
# Comparison for hash: structural comparison.
|
@@ -3975,6 +4496,7 @@ module HDLRuby::Low
|
|
3975
4496
|
end
|
3976
4497
|
end
|
3977
4498
|
|
4499
|
+
|
3978
4500
|
##
|
3979
4501
|
# Describes a cast.
|
3980
4502
|
class Cast < Expression
|
@@ -3994,6 +4516,26 @@ module HDLRuby::Low
|
|
3994
4516
|
child.parent = self
|
3995
4517
|
end
|
3996
4518
|
|
4519
|
+
# Tells if the expression is immutable (cannot be written.)
|
4520
|
+
def immutable?
|
4521
|
+
# Immutable if the child is immutable.
|
4522
|
+
return child.immutable?
|
4523
|
+
end
|
4524
|
+
|
4525
|
+
# Iterates over each object deeply.
|
4526
|
+
#
|
4527
|
+
# Returns an enumerator if no ruby block is given.
|
4528
|
+
def each_deep(&ruby_block)
|
4529
|
+
# No ruby block? Return an enumerator.
|
4530
|
+
return to_enum(:each_deep) unless ruby_block
|
4531
|
+
# A ruby block? First apply it to current.
|
4532
|
+
ruby_block.call(self)
|
4533
|
+
# Then apply on the type.
|
4534
|
+
self.type.each_deep(&ruby_block)
|
4535
|
+
# Then apply on the child.
|
4536
|
+
self.child.each_deep(&ruby_block)
|
4537
|
+
end
|
4538
|
+
|
3997
4539
|
# Comparison for hash: structural comparison.
|
3998
4540
|
def eql?(obj)
|
3999
4541
|
# General comparison.
|
@@ -4110,6 +4652,26 @@ module HDLRuby::Low
|
|
4110
4652
|
child.parent = self
|
4111
4653
|
end
|
4112
4654
|
|
4655
|
+
# Tells if the expression is immutable (cannot be written.)
|
4656
|
+
def immutable?
|
4657
|
+
# Immutable if the child is immutable.
|
4658
|
+
return child.immutable?
|
4659
|
+
end
|
4660
|
+
|
4661
|
+
# Iterates over each object deeply.
|
4662
|
+
#
|
4663
|
+
# Returns an enumerator if no ruby block is given.
|
4664
|
+
def each_deep(&ruby_block)
|
4665
|
+
# No ruby block? Return an enumerator.
|
4666
|
+
return to_enum(:each_deep) unless ruby_block
|
4667
|
+
# A ruby block? First apply it to current.
|
4668
|
+
ruby_block.call(self)
|
4669
|
+
# Then apply on the type.
|
4670
|
+
self.type.each_deep(&ruby_block)
|
4671
|
+
# Then apply on the child.
|
4672
|
+
self.child.each_deep(&ruby_block)
|
4673
|
+
end
|
4674
|
+
|
4113
4675
|
# Comparison for hash: structural comparison.
|
4114
4676
|
def eql?(obj)
|
4115
4677
|
# General comparison.
|
@@ -4198,6 +4760,28 @@ module HDLRuby::Low
|
|
4198
4760
|
left.parent = right.parent = self
|
4199
4761
|
end
|
4200
4762
|
|
4763
|
+
# Tells if the expression is immutable (cannot be written.)
|
4764
|
+
def immutable?
|
4765
|
+
# Immutable if both children are immutable.
|
4766
|
+
return left.immutable? && right.immutable?
|
4767
|
+
end
|
4768
|
+
|
4769
|
+
# Iterates over each object deeply.
|
4770
|
+
#
|
4771
|
+
# Returns an enumerator if no ruby block is given.
|
4772
|
+
def each_deep(&ruby_block)
|
4773
|
+
# No ruby block? Return an enumerator.
|
4774
|
+
return to_enum(:each_deep) unless ruby_block
|
4775
|
+
# A ruby block? First apply it to current.
|
4776
|
+
ruby_block.call(self)
|
4777
|
+
# Then apply on the type.
|
4778
|
+
self.type.each_deep(&ruby_block)
|
4779
|
+
# Then apply on the left.
|
4780
|
+
self.left.each_deep(&ruby_block)
|
4781
|
+
# Then apply on the right.
|
4782
|
+
self.right.each_deep(&ruby_block)
|
4783
|
+
end
|
4784
|
+
|
4201
4785
|
# Comparison for hash: structural comparison.
|
4202
4786
|
def eql?(obj)
|
4203
4787
|
# General comparison.
|
@@ -4293,6 +4877,33 @@ module HDLRuby::Low
|
|
4293
4877
|
end
|
4294
4878
|
end
|
4295
4879
|
|
4880
|
+
# Tells if the expression is immutable (cannot be written.)
|
4881
|
+
def immutable?
|
4882
|
+
# Immutable if children are all immutable.
|
4883
|
+
return self.select.constant &&
|
4884
|
+
self.each_choice.reduce(true) do |r,c|
|
4885
|
+
r && c.immutable?
|
4886
|
+
end
|
4887
|
+
end
|
4888
|
+
|
4889
|
+
# Iterates over each object deeply.
|
4890
|
+
#
|
4891
|
+
# Returns an enumerator if no ruby block is given.
|
4892
|
+
def each_deep(&ruby_block)
|
4893
|
+
# No ruby block? Return an enumerator.
|
4894
|
+
return to_enum(:each_deep) unless ruby_block
|
4895
|
+
# A ruby block? First apply it to current.
|
4896
|
+
ruby_block.call(self)
|
4897
|
+
# Then apply on the type.
|
4898
|
+
self.type.each_deep(&ruby_block)
|
4899
|
+
# Then apply on the select.
|
4900
|
+
self.select.each_deep(&ruby_block)
|
4901
|
+
# Then apply on the choices.
|
4902
|
+
self.each_choice do |choice|
|
4903
|
+
choice.each_deep(&ruby_block)
|
4904
|
+
end
|
4905
|
+
end
|
4906
|
+
|
4296
4907
|
# Comparison for hash: structural comparison.
|
4297
4908
|
def eql?(obj)
|
4298
4909
|
# General comparison.
|
@@ -4409,6 +5020,30 @@ module HDLRuby::Low
|
|
4409
5020
|
expressions.each { |expression| self.add_expression(expression) }
|
4410
5021
|
end
|
4411
5022
|
|
5023
|
+
# Tells if the expression is immutable (cannot be written.)
|
5024
|
+
def immutable?
|
5025
|
+
# Immutable if children are all immutable.
|
5026
|
+
return self.each_expression.reduce(true) do |r,c|
|
5027
|
+
r && c.immutable?
|
5028
|
+
end
|
5029
|
+
end
|
5030
|
+
|
5031
|
+
# Iterates over each object deeply.
|
5032
|
+
#
|
5033
|
+
# Returns an enumerator if no ruby block is given.
|
5034
|
+
def each_deep(&ruby_block)
|
5035
|
+
# No ruby block? Return an enumerator.
|
5036
|
+
return to_enum(:each_deep) unless ruby_block
|
5037
|
+
# A ruby block? First apply it to current.
|
5038
|
+
ruby_block.call(self)
|
5039
|
+
# Then apply on the type.
|
5040
|
+
self.type.each_deep(&ruby_block)
|
5041
|
+
# Then apply on the expressions.
|
5042
|
+
self.each_expression do |expr|
|
5043
|
+
expr.each_deep(&ruby_block)
|
5044
|
+
end
|
5045
|
+
end
|
5046
|
+
|
4412
5047
|
# Comparison for hash: structural comparison.
|
4413
5048
|
def eql?(obj)
|
4414
5049
|
# General comparison.
|
@@ -4556,6 +5191,30 @@ module HDLRuby::Low
|
|
4556
5191
|
refs.each { |ref| ref.parent = self }
|
4557
5192
|
end
|
4558
5193
|
|
5194
|
+
# Tells if the expression is immutable (cannot be written.)
|
5195
|
+
def immutable?
|
5196
|
+
# Immutable if children are all immutable.
|
5197
|
+
return self.each_ref.reduce(true) do |r,c|
|
5198
|
+
r && c.immutable?
|
5199
|
+
end
|
5200
|
+
end
|
5201
|
+
|
5202
|
+
# Iterates over each object deeply.
|
5203
|
+
#
|
5204
|
+
# Returns an enumerator if no ruby block is given.
|
5205
|
+
def each_deep(&ruby_block)
|
5206
|
+
# No ruby block? Return an enumerator.
|
5207
|
+
return to_enum(:each_deep) unless ruby_block
|
5208
|
+
# A ruby block? First apply it to current.
|
5209
|
+
ruby_block.call(self)
|
5210
|
+
# Then apply on the type.
|
5211
|
+
self.type.each_deep(&ruby_block)
|
5212
|
+
# Then apply on the sub references.
|
5213
|
+
self.each_ref do |ref|
|
5214
|
+
ref.each_deep(&ruby_block)
|
5215
|
+
end
|
5216
|
+
end
|
5217
|
+
|
4559
5218
|
# Comparison for hash: structural comparison.
|
4560
5219
|
def eql?(obj)
|
4561
5220
|
# General comparison.
|
@@ -4657,6 +5316,30 @@ module HDLRuby::Low
|
|
4657
5316
|
index.parent = self
|
4658
5317
|
end
|
4659
5318
|
|
5319
|
+
# Tells if the expression is immutable (cannot be written.)
|
5320
|
+
def immutable?
|
5321
|
+
# Immutable if the ref is immutable.
|
5322
|
+
return self.ref.immutable?
|
5323
|
+
end
|
5324
|
+
|
5325
|
+
# Iterates over each object deeply.
|
5326
|
+
#
|
5327
|
+
# Returns an enumerator if no ruby block is given.
|
5328
|
+
def each_deep(&ruby_block)
|
5329
|
+
# No ruby block? Return an enumerator.
|
5330
|
+
return to_enum(:each_deep) unless ruby_block
|
5331
|
+
# A ruby block? First apply it to current.
|
5332
|
+
ruby_block.call(self)
|
5333
|
+
# Then apply on the type.
|
5334
|
+
self.type.each_deep(&ruby_block)
|
5335
|
+
# Then apply on the reference.
|
5336
|
+
self.ref.each_deep(&ruby_block)
|
5337
|
+
# Then apply on the index if possible.
|
5338
|
+
if self.index.respond_to?(:each_deep) then
|
5339
|
+
self.index.each_deep(&ruby_block)
|
5340
|
+
end
|
5341
|
+
end
|
5342
|
+
|
4660
5343
|
# Comparison for hash: structural comparison.
|
4661
5344
|
def eql?(obj)
|
4662
5345
|
# General comparison.
|
@@ -4752,6 +5435,33 @@ module HDLRuby::Low
|
|
4752
5435
|
first.parent = last.parent = self
|
4753
5436
|
end
|
4754
5437
|
|
5438
|
+
# Tells if the expression is immutable (cannot be written.)
|
5439
|
+
def immutable?
|
5440
|
+
# Immutable if the ref is immutable.
|
5441
|
+
return self.ref.immutable?
|
5442
|
+
end
|
5443
|
+
|
5444
|
+
# Iterates over each object deeply.
|
5445
|
+
#
|
5446
|
+
# Returns an enumerator if no ruby block is given.
|
5447
|
+
def each_deep(&ruby_block)
|
5448
|
+
# No ruby block? Return an enumerator.
|
5449
|
+
return to_enum(:each_deep) unless ruby_block
|
5450
|
+
# A ruby block? First apply it to current.
|
5451
|
+
ruby_block.call(self)
|
5452
|
+
# Then apply on the type.
|
5453
|
+
self.type.each_deep(&ruby_block)
|
5454
|
+
# Then apply on the reference.
|
5455
|
+
self.ref.each_deep(&ruby_block)
|
5456
|
+
# Then apply on the range if possible.
|
5457
|
+
if self.range.first.respond_to?(:each_deep) then
|
5458
|
+
self.range.first.each_deep(&ruby_block)
|
5459
|
+
end
|
5460
|
+
if self.range.last.respond_to?(:each_deep) then
|
5461
|
+
self.range.last.each_deep(&ruby_block)
|
5462
|
+
end
|
5463
|
+
end
|
5464
|
+
|
4755
5465
|
# Comparison for hash: structural comparison.
|
4756
5466
|
#
|
4757
5467
|
# NOTE: ranges are assumed to be flattened (a range of range is
|
@@ -4843,6 +5553,20 @@ module HDLRuby::Low
|
|
4843
5553
|
@name = name.to_sym
|
4844
5554
|
end
|
4845
5555
|
|
5556
|
+
# Iterates over each object deeply.
|
5557
|
+
#
|
5558
|
+
# Returns an enumerator if no ruby block is given.
|
5559
|
+
def each_deep(&ruby_block)
|
5560
|
+
# No ruby block? Return an enumerator.
|
5561
|
+
return to_enum(:each_deep) unless ruby_block
|
5562
|
+
# A ruby block? First apply it to current.
|
5563
|
+
ruby_block.call(self)
|
5564
|
+
# Then apply on the type.
|
5565
|
+
self.type.each_deep(&ruby_block)
|
5566
|
+
# Then apply on the reference.
|
5567
|
+
self.ref.each_deep(&ruby_block)
|
5568
|
+
end
|
5569
|
+
|
4846
5570
|
# Get the full name of the reference, i.e. including the sub ref
|
4847
5571
|
# names if any.
|
4848
5572
|
def full_name
|
@@ -4918,6 +5642,19 @@ module HDLRuby::Low
|
|
4918
5642
|
#
|
4919
5643
|
# This is the current system.
|
4920
5644
|
class RefThis < Ref
|
5645
|
+
|
5646
|
+
# Iterates over each object deeply.
|
5647
|
+
#
|
5648
|
+
# Returns an enumerator if no ruby block is given.
|
5649
|
+
def each_deep(&ruby_block)
|
5650
|
+
# No ruby block? Return an enumerator.
|
5651
|
+
return to_enum(:each_deep) unless ruby_block
|
5652
|
+
# A ruby block? First apply it to current.
|
5653
|
+
ruby_block.call(self)
|
5654
|
+
# Then apply on the type.
|
5655
|
+
self.type.each_deep(&ruby_block)
|
5656
|
+
end
|
5657
|
+
|
4921
5658
|
# Clones this.
|
4922
5659
|
def clone
|
4923
5660
|
return RefThis.new
|
@@ -4933,4 +5670,135 @@ module HDLRuby::Low
|
|
4933
5670
|
return super
|
4934
5671
|
end
|
4935
5672
|
end
|
5673
|
+
|
5674
|
+
|
5675
|
+
|
5676
|
+
##
|
5677
|
+
# Describes a string.
|
5678
|
+
#
|
5679
|
+
# NOTE: This is not synthesizable!
|
5680
|
+
class StringE < Expression
|
5681
|
+
|
5682
|
+
attr_reader :content
|
5683
|
+
|
5684
|
+
# Creates a new string whose content is +str+ and is modified using
|
5685
|
+
# the objects of +args+.
|
5686
|
+
def initialize(content,*args)
|
5687
|
+
super(StringT)
|
5688
|
+
# Checks and set the content.
|
5689
|
+
@content = content.to_s
|
5690
|
+
# Process the arguments.
|
5691
|
+
@args = args.map do |arg|
|
5692
|
+
arg.parent = self
|
5693
|
+
arg
|
5694
|
+
end
|
5695
|
+
end
|
5696
|
+
|
5697
|
+
# Tells if the expression is immutable (cannot be written.)
|
5698
|
+
def immutable?
|
5699
|
+
# String objects are always immutable.
|
5700
|
+
true
|
5701
|
+
end
|
5702
|
+
|
5703
|
+
# Comparison for hash: structural comparison.
|
5704
|
+
def eql?(obj)
|
5705
|
+
return false unless obj.is_a?(StringE)
|
5706
|
+
return false unless @content.eql?(obj.content)
|
5707
|
+
return false if @args.each.zip(obj.each_arg).any? do |a0,a1|
|
5708
|
+
!a0.eql?(a1)
|
5709
|
+
end
|
5710
|
+
return true
|
5711
|
+
end
|
5712
|
+
|
5713
|
+
# Iterates over each argument.
|
5714
|
+
#
|
5715
|
+
# Returns an enumerator if no ruby block is given.
|
5716
|
+
def each_arg(&ruby_block)
|
5717
|
+
# No ruby block? Return an enumerator.
|
5718
|
+
return to_enum(:each_arg) unless ruby_block
|
5719
|
+
# A ruby block? First apply it to each argument.
|
5720
|
+
@args.each(&ruby_block)
|
5721
|
+
end
|
5722
|
+
|
5723
|
+
# Iterates over each object deeply.
|
5724
|
+
#
|
5725
|
+
# Returns an enumerator if no ruby block is given.
|
5726
|
+
def each_deep(&ruby_block)
|
5727
|
+
# No ruby block? Return an enumerator.
|
5728
|
+
return to_enum(:each_deep) unless ruby_block
|
5729
|
+
# A ruby block? First apply it to current.
|
5730
|
+
ruby_block.call(self)
|
5731
|
+
# Then apply on the arguments.
|
5732
|
+
self.each_arg(&ruby_block)
|
5733
|
+
end
|
5734
|
+
|
5735
|
+
# Hash function.
|
5736
|
+
def hash
|
5737
|
+
return @args.hash
|
5738
|
+
end
|
5739
|
+
|
5740
|
+
# Clones the string.
|
5741
|
+
def clone
|
5742
|
+
return StringE.new(@content.clone,*@args.map {|arg| arg.clone})
|
5743
|
+
end
|
5744
|
+
|
5745
|
+
# Iterates over the expression children if any.
|
5746
|
+
def each_node(&ruby_block)
|
5747
|
+
# No ruby block? Return an enumerator.
|
5748
|
+
return to_enum(:each_node) unless ruby_block
|
5749
|
+
# A ruby block?
|
5750
|
+
# Apply it on each argument.
|
5751
|
+
@args.each(&ruby_block)
|
5752
|
+
end
|
5753
|
+
|
5754
|
+
# Iterates over the nodes deeply if any.
|
5755
|
+
def each_node_deep(&ruby_block)
|
5756
|
+
# No ruby block? Return an enumerator.
|
5757
|
+
return to_enum(:each_node_deep) unless ruby_block
|
5758
|
+
# A ruby block? First apply it to current.
|
5759
|
+
ruby_block.call(self)
|
5760
|
+
# And apply it on each argument.
|
5761
|
+
@args.each(&ruby_block)
|
5762
|
+
end
|
5763
|
+
|
5764
|
+
# Iterates over the sub blocks.
|
5765
|
+
def each_block(&ruby_block)
|
5766
|
+
# No ruby block? Return an enumerator.
|
5767
|
+
return to_enum(:each_block) unless ruby_block
|
5768
|
+
# A ruby block?
|
5769
|
+
# Recurse on each argument.
|
5770
|
+
@args.each do |arg|
|
5771
|
+
arg.each_block(&ruby_block) if arg.respond_to?(:each_block)
|
5772
|
+
end
|
5773
|
+
end
|
5774
|
+
|
5775
|
+
# Iterates over all the blocks contained in the current block.
|
5776
|
+
def each_block_deep(&ruby_block)
|
5777
|
+
# No ruby block? Return an enumerator.
|
5778
|
+
return to_enum(:each_block_deep) unless ruby_block
|
5779
|
+
# A ruby block?
|
5780
|
+
# Recurse on each argument.
|
5781
|
+
@args.each do |arg|
|
5782
|
+
if arg.respond_to?(:each_block_deep) then
|
5783
|
+
arg.each_block_deep(&ruby_block)
|
5784
|
+
end
|
5785
|
+
end
|
5786
|
+
end
|
5787
|
+
|
5788
|
+
# Iterates over all the statements contained in the current block.
|
5789
|
+
def each_statement_deep(&ruby_block)
|
5790
|
+
# No ruby block? Return an enumerator.
|
5791
|
+
return to_enum(:each_statement_deep) unless ruby_block
|
5792
|
+
# A ruby block?
|
5793
|
+
# Apply it on self.
|
5794
|
+
ruby_block.call(self)
|
5795
|
+
# Recurse on each argument.
|
5796
|
+
@args.each do |arg|
|
5797
|
+
if arg.respond_to?(:each_statement_deep) then
|
5798
|
+
arg.each_statement_deep(&ruby_block)
|
5799
|
+
end
|
5800
|
+
end
|
5801
|
+
end
|
5802
|
+
|
5803
|
+
end
|
4936
5804
|
end
|