HDLRuby 3.9.5 → 3.9.7
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/README.md +182 -9
- data/ext/hruby_sim/hruby_rcsim_build.c +23 -0
- data/ext/hruby_sim/hruby_sim.h +29 -1
- data/ext/hruby_sim/hruby_sim_calc.c +141 -18
- data/ext/hruby_sim/hruby_sim_tree_calc.c +37 -0
- data/lib/HDLRuby/hdr_samples/case_bench.rb +1 -1
- data/lib/HDLRuby/hdr_samples/logic_bench.rb +12 -12
- data/lib/HDLRuby/hdr_samples/with_assign_to_slice.rb +19 -0
- data/lib/HDLRuby/hdr_samples/with_auto_connect.rb +40 -0
- data/lib/HDLRuby/hdr_samples/with_casez.rb +35 -0
- data/lib/HDLRuby/hdr_samples/with_expr_decoder.rb +38 -0
- data/lib/HDLRuby/hdr_samples/with_expr_hif.rb +34 -0
- data/lib/HDLRuby/hdr_samples/with_hbreak.rb +42 -0
- data/lib/HDLRuby/hdr_samples/with_henumerable.rb +1 -1
- data/lib/HDLRuby/hdr_samples/with_values.rb +3 -0
- data/lib/HDLRuby/hruby_high.rb +237 -15
- data/lib/HDLRuby/hruby_low.rb +50 -46
- data/lib/HDLRuby/hruby_rcsim.rb +7 -2
- data/lib/HDLRuby/hruby_verilog.rb +17 -6
- data/lib/HDLRuby/std/decoder.rb +77 -2
- data/lib/HDLRuby/std/hruby_enum.rb +103 -0
- data/lib/HDLRuby/verilog_hruby.rb +30 -0
- data/lib/HDLRuby/verilog_parser.rb +1 -1
- data/lib/HDLRuby/version.rb +1 -1
- metadata +8 -2
data/lib/HDLRuby/hruby_high.rb
CHANGED
|
@@ -777,7 +777,6 @@ module HDLRuby::High
|
|
|
777
777
|
# registered in the namespace stack, and one for creating an
|
|
778
778
|
# array of instances being registered in the Array class.
|
|
779
779
|
def make_instantiater(name,klass,&ruby_block)
|
|
780
|
-
# puts "make_instantiater with name=#{name}"
|
|
781
780
|
# Set the instanciater.
|
|
782
781
|
@instance_procs = [ ruby_block ]
|
|
783
782
|
# Set the target instantiation class.
|
|
@@ -794,7 +793,8 @@ module HDLRuby::High
|
|
|
794
793
|
# If no arguments, return the system as is
|
|
795
794
|
return obj if args.empty?
|
|
796
795
|
# Are there any generic arguments?
|
|
797
|
-
if ruby_block.arity > 0 then
|
|
796
|
+
if ruby_block.arity > 0 or args.size > 1 or args[0].is_a?(Hash) then
|
|
797
|
+
# if ruby_block.parameters.size > 0 then
|
|
798
798
|
# Yes, must specialize the system with the arguments.
|
|
799
799
|
# If arguments, create a new system specialized with them
|
|
800
800
|
return SystemT.new(:"") { include(obj,*args) }
|
|
@@ -1431,11 +1431,20 @@ module HDLRuby::High
|
|
|
1431
1431
|
# NOTE:
|
|
1432
1432
|
# * the else part is defined through the helse method.
|
|
1433
1433
|
# * a behavior is created to enclose the hif.
|
|
1434
|
-
def hif(condition, mode = nil, &ruby_block)
|
|
1434
|
+
def hif(condition, mode = nil, other = nil, &ruby_block)
|
|
1435
|
+
if mode and !mode.is_a?(Symbol) then
|
|
1436
|
+
if ruby_block then
|
|
1437
|
+
raise AnyError, "Error: expression hif with a block."
|
|
1438
|
+
end
|
|
1439
|
+
# Expression hif case: 'mode' is interpreted as the
|
|
1440
|
+
# expression of the condition is true, 'other'if it is false.
|
|
1441
|
+
return EIfMaker.new(condition,mode,other)
|
|
1442
|
+
end
|
|
1435
1443
|
return if self.metaif(condition,&ruby_block)
|
|
1436
1444
|
# Ensure there is a block.
|
|
1437
1445
|
ruby_block = proc {} unless block_given?
|
|
1438
|
-
self.par do
|
|
1446
|
+
# self.par do
|
|
1447
|
+
self.seq do # Seq for combinatorial is good practice
|
|
1439
1448
|
hif(condition,mode,&ruby_block)
|
|
1440
1449
|
end
|
|
1441
1450
|
end
|
|
@@ -1491,11 +1500,40 @@ module HDLRuby::High
|
|
|
1491
1500
|
# * a new behavior is created to enclose the hcase.
|
|
1492
1501
|
def hcase(value)
|
|
1493
1502
|
return if self.metacase(value)
|
|
1494
|
-
self.par do
|
|
1503
|
+
# self.par do
|
|
1504
|
+
self.seq do # Seq for combinatorial is good practice
|
|
1495
1505
|
hcase(value)
|
|
1496
1506
|
end
|
|
1497
1507
|
end
|
|
1498
1508
|
|
|
1509
|
+
# Creates a new case statement taking z was wildcard with a +value+ used for deciding which
|
|
1510
|
+
# block to execute.
|
|
1511
|
+
#
|
|
1512
|
+
# NOTE:
|
|
1513
|
+
# * the when part is defined through the hwhen method.
|
|
1514
|
+
# * a new behavior is created to enclose the hcase.
|
|
1515
|
+
def hcasez(value)
|
|
1516
|
+
return if self.metacase(value)
|
|
1517
|
+
# self.par do
|
|
1518
|
+
self.seq do # Seq for combinatorial is good practice
|
|
1519
|
+
hcasez(value)
|
|
1520
|
+
end
|
|
1521
|
+
end
|
|
1522
|
+
|
|
1523
|
+
# Creates a new case statement taking z as wildcards with a +value+ used for deciding which
|
|
1524
|
+
# block to execute.
|
|
1525
|
+
#
|
|
1526
|
+
# NOTE:
|
|
1527
|
+
# * the when part is defined through the hwhen method.
|
|
1528
|
+
# * a new behavior is created to enclose the hcase.
|
|
1529
|
+
def hcasez(value)
|
|
1530
|
+
return if self.metacase(value)
|
|
1531
|
+
# self.par do
|
|
1532
|
+
self.seq do # Seq for combinatorial is good practice
|
|
1533
|
+
hcasez(value)
|
|
1534
|
+
end
|
|
1535
|
+
end
|
|
1536
|
+
|
|
1499
1537
|
# Sets the block of a case structure executed when the +match+ is met
|
|
1500
1538
|
# to the block in +mode+ generated by the execution of +ruby_block+.
|
|
1501
1539
|
#
|
|
@@ -2337,6 +2375,7 @@ module HDLRuby::High
|
|
|
2337
2375
|
end
|
|
2338
2376
|
define_singleton_method(name.to_sym) do |*args|
|
|
2339
2377
|
if (args.size < ruby_block.arity) then
|
|
2378
|
+
# if (args.size < ruby_block.parameters.size) then
|
|
2340
2379
|
# Not enough arguments get generic type as is.
|
|
2341
2380
|
type
|
|
2342
2381
|
else
|
|
@@ -2350,6 +2389,7 @@ module HDLRuby::High
|
|
|
2350
2389
|
else
|
|
2351
2390
|
define_method(name.to_sym) do |*args|
|
|
2352
2391
|
if (args.size < ruby_block.arity) then
|
|
2392
|
+
# if (args.size < ruby_block.parameters.size) then
|
|
2353
2393
|
# Not enough arguments, get generic type as is.
|
|
2354
2394
|
type
|
|
2355
2395
|
else
|
|
@@ -2368,7 +2408,7 @@ module HDLRuby::High
|
|
|
2368
2408
|
def system(name = :"", *includes, &ruby_block)
|
|
2369
2409
|
# Ensure there is a block.
|
|
2370
2410
|
ruby_block = proc {} unless block_given?
|
|
2371
|
-
# print "system ruby_block=#{ruby_block}\n"
|
|
2411
|
+
# print "system name=#{name} ruby_block=#{ruby_block}\n"
|
|
2372
2412
|
# Creates the resulting system.
|
|
2373
2413
|
return SystemT.new(name,*includes,&ruby_block)
|
|
2374
2414
|
end
|
|
@@ -2523,6 +2563,9 @@ module HDLRuby::High
|
|
|
2523
2563
|
connects.each do |key,value|
|
|
2524
2564
|
# Gets the signal corresponding to connect.
|
|
2525
2565
|
signal = self.systemT.get_signal_with_included(key)
|
|
2566
|
+
unless signal then
|
|
2567
|
+
raise AnyError, "Invalid parameter: #{key}"
|
|
2568
|
+
end
|
|
2526
2569
|
# Check if it is an output.
|
|
2527
2570
|
isout = self.systemT.get_output_with_included(key)
|
|
2528
2571
|
# Convert it to a reference.
|
|
@@ -2565,6 +2608,32 @@ module HDLRuby::High
|
|
|
2565
2608
|
end
|
|
2566
2609
|
end
|
|
2567
2610
|
end
|
|
2611
|
+
return self
|
|
2612
|
+
end
|
|
2613
|
+
|
|
2614
|
+
# Auto connects signals of the system instance.
|
|
2615
|
+
#
|
|
2616
|
+
# NOTE: the connections are looked for automatically by name in
|
|
2617
|
+
# the system the instance is placed.
|
|
2618
|
+
def auto_connect
|
|
2619
|
+
# Gather the names of the signals to connect.
|
|
2620
|
+
names = self.systemT.each_signal_with_included.map do |sig|
|
|
2621
|
+
sig.name
|
|
2622
|
+
end
|
|
2623
|
+
# Look for the right signals in the current context.
|
|
2624
|
+
signals = []
|
|
2625
|
+
High.top_user.instance_eval do
|
|
2626
|
+
names.dup.each_with_index do |name,i|
|
|
2627
|
+
begin
|
|
2628
|
+
signals << send(name)
|
|
2629
|
+
rescue NotDefinedError => e
|
|
2630
|
+
# Signal not found so no connection.
|
|
2631
|
+
names.delete(name)
|
|
2632
|
+
end
|
|
2633
|
+
end
|
|
2634
|
+
end
|
|
2635
|
+
# Do the connection.
|
|
2636
|
+
self.call(names.zip(signals).to_h)
|
|
2568
2637
|
end
|
|
2569
2638
|
|
|
2570
2639
|
# Gets an exported element (signal or system instance) by +name+.
|
|
@@ -2826,7 +2895,7 @@ module HDLRuby::High
|
|
|
2826
2895
|
obj = self
|
|
2827
2896
|
::HDLRuby::High.cur_block.delete_statement!(obj)
|
|
2828
2897
|
# Handles the metaprogramming.
|
|
2829
|
-
return obj if self.metaif(condition
|
|
2898
|
+
return obj if self.metaif(condition) { add_statement(obj) }
|
|
2830
2899
|
# Creates the if statement.
|
|
2831
2900
|
stmnt = If.new(condition) { add_statement(obj) }
|
|
2832
2901
|
# Add it to the current block.
|
|
@@ -2935,9 +3004,11 @@ module HDLRuby::High
|
|
|
2935
3004
|
|
|
2936
3005
|
# Creates a new case statement with a +value+ that decides which
|
|
2937
3006
|
# block to execute.
|
|
2938
|
-
|
|
3007
|
+
# +mode+ is the mode the case should run in. For now there are
|
|
3008
|
+
# only two possiblities: normal case :"", and casez :casez
|
|
3009
|
+
def initialize(value, mode = :"")
|
|
2939
3010
|
# Create the yes block.
|
|
2940
|
-
super(value.to_expr)
|
|
3011
|
+
super(value.to_expr, mode)
|
|
2941
3012
|
end
|
|
2942
3013
|
|
|
2943
3014
|
# Sets the block executed in +mode+ when the value matches +match+.
|
|
@@ -2969,7 +3040,7 @@ module HDLRuby::High
|
|
|
2969
3040
|
# Converts the case to HDLRuby::Low.
|
|
2970
3041
|
def to_low
|
|
2971
3042
|
# Create the low level case.
|
|
2972
|
-
caseL = HDLRuby::Low::Case.new(@value.to_low)
|
|
3043
|
+
caseL = HDLRuby::Low::Case.new(@value.to_low,@mode)
|
|
2973
3044
|
# # For debugging: set the source high object
|
|
2974
3045
|
# caseL.properties[:low2high] = self.hdr_id
|
|
2975
3046
|
# self.properties[:high2low] = caseL
|
|
@@ -3056,6 +3127,66 @@ module HDLRuby::High
|
|
|
3056
3127
|
|
|
3057
3128
|
|
|
3058
3129
|
|
|
3130
|
+
##
|
|
3131
|
+
# Class for building multiplexers from expression ifs.
|
|
3132
|
+
#
|
|
3133
|
+
# Note: expression if does not exist in HDLRuby, this is a syntactic
|
|
3134
|
+
# sugar.
|
|
3135
|
+
class EIfMaker
|
|
3136
|
+
# Create a new multiplexer generator from if expression with
|
|
3137
|
+
# +cond+ as boolean selection, +texpr+ the expression to use if
|
|
3138
|
+
# +cond+ is true +fexpr+ the expression to use if false.
|
|
3139
|
+
# Note: +fexpr+ can be false, it it is the case, the call operator
|
|
3140
|
+
# has to be used to give it.
|
|
3141
|
+
def initialize(cond,texpr,fexpr = nil)
|
|
3142
|
+
@cond = cond
|
|
3143
|
+
@texpr = texpr
|
|
3144
|
+
@fexpr = fexpr
|
|
3145
|
+
end
|
|
3146
|
+
|
|
3147
|
+
# Replace the expression (fexpr) to use if the condition is false.
|
|
3148
|
+
# If +epxr1+ is given, create an expression whose condition is expr0
|
|
3149
|
+
# otherwise, use expression as fexpr.
|
|
3150
|
+
def call(expr0,expr1 = nil,expr2 = nil)
|
|
3151
|
+
if @fexpr then
|
|
3152
|
+
if @fexpr.is_a?(EIfMaker) then
|
|
3153
|
+
# Complete the fexpr.
|
|
3154
|
+
@fexpr = @fexpr.call(expr0,expr1,expr2)
|
|
3155
|
+
else
|
|
3156
|
+
raise AnyError, "The expression to use if the condition is false is already set."
|
|
3157
|
+
end
|
|
3158
|
+
elsif expr1 then
|
|
3159
|
+
@fexpr = EIfMaker.new(expr0,expr1,expr2)
|
|
3160
|
+
else
|
|
3161
|
+
@fexpr = expr0
|
|
3162
|
+
end
|
|
3163
|
+
return self
|
|
3164
|
+
end
|
|
3165
|
+
|
|
3166
|
+
# Convert the expression if to an expression mux.
|
|
3167
|
+
def to_expr
|
|
3168
|
+
return HDLRuby::High.top_user.mux(@cond.to_expr == 0, @texpr.to_expr, @fexpr.to_expr)
|
|
3169
|
+
end
|
|
3170
|
+
|
|
3171
|
+
[:"-@",:"+@",:"~", :abs,
|
|
3172
|
+
:boolean, :bit, :signed, :unsigned].each do |operator|
|
|
3173
|
+
define_method(operator) do
|
|
3174
|
+
self.to_expr.send(operator)
|
|
3175
|
+
end
|
|
3176
|
+
end
|
|
3177
|
+
|
|
3178
|
+
[:"+",:"-",:"*",:"/",:"%",:"**",
|
|
3179
|
+
:"&",:"|",:"^",
|
|
3180
|
+
:"<<",:">>",# :ls,:rs,:lr,:rr, # ls, rs lr and rr are treated separately
|
|
3181
|
+
:"==",:"!=",:"<",:">",:"<=",:">="].each do |operator|
|
|
3182
|
+
define_method(operator) do |expr|
|
|
3183
|
+
self.to_expr.send(operator,expr)
|
|
3184
|
+
end
|
|
3185
|
+
end
|
|
3186
|
+
|
|
3187
|
+
end
|
|
3188
|
+
|
|
3189
|
+
|
|
3059
3190
|
##
|
|
3060
3191
|
# Module giving high-level expression properties
|
|
3061
3192
|
module HExpression
|
|
@@ -3185,12 +3316,12 @@ module HDLRuby::High
|
|
|
3185
3316
|
|
|
3186
3317
|
# Extends on the left to +n+ bits filling with +v+ bit values.
|
|
3187
3318
|
def ljust(n,v)
|
|
3188
|
-
|
|
3319
|
+
return [(v.to_s * (n-self.width)).to_value, self].to_expr
|
|
3189
3320
|
end
|
|
3190
3321
|
|
|
3191
3322
|
# Extends on the right to +n+ bits filling with +v+ bit values.
|
|
3192
3323
|
def rjust(n,v)
|
|
3193
|
-
|
|
3324
|
+
return [self, (v.to_s * (n-self.width)).to_value].to_expr
|
|
3194
3325
|
end
|
|
3195
3326
|
|
|
3196
3327
|
# Extends on the left to +n+ bits filling with 0.
|
|
@@ -3200,7 +3331,8 @@ module HDLRuby::High
|
|
|
3200
3331
|
|
|
3201
3332
|
# Extends on the left to +n+ bits preserving the signe.
|
|
3202
3333
|
def sext(n)
|
|
3203
|
-
return self.ljust(self[-1])
|
|
3334
|
+
# return self.ljust(n,self[-1])
|
|
3335
|
+
return self.as(HDLRuby::High.top_user.signed[self.type.width]).as(HDLRuby::High.top_user.signed[n])
|
|
3204
3336
|
end
|
|
3205
3337
|
|
|
3206
3338
|
# # Match the type with +typ+:
|
|
@@ -3741,6 +3873,9 @@ module HDLRuby::High
|
|
|
3741
3873
|
# Creates a new reference from a +base+ reference and named +object+.
|
|
3742
3874
|
def initialize(base,object)
|
|
3743
3875
|
# puts "New RefObjet with base=#{base}, object=#{object}"
|
|
3876
|
+
unless object
|
|
3877
|
+
raise AnyError, "Empty object for reference."
|
|
3878
|
+
end
|
|
3744
3879
|
if object.respond_to?(:type) then
|
|
3745
3880
|
# Typed object, so typed reference.
|
|
3746
3881
|
super(object.type)
|
|
@@ -4574,7 +4709,15 @@ module HDLRuby::High
|
|
|
4574
4709
|
#
|
|
4575
4710
|
# NOTE: the else part is defined through the helse method.
|
|
4576
4711
|
# def hif(condition, mode = nil, &ruby_block)
|
|
4577
|
-
def hif(condition, mode = self.mode, &ruby_block)
|
|
4712
|
+
def hif(condition, mode = self.mode, other = nil, &ruby_block)
|
|
4713
|
+
if mode and !mode.is_a?(Symbol) then
|
|
4714
|
+
if ruby_block then
|
|
4715
|
+
raise AnyError, "Error: expression hif with a block."
|
|
4716
|
+
end
|
|
4717
|
+
# Expression hif case: 'mode' is interpreted as the
|
|
4718
|
+
# expression of the condition is true, 'other'if it is false.
|
|
4719
|
+
return EIfMaker.new(condition,mode,other)
|
|
4720
|
+
end
|
|
4578
4721
|
return if self.metaif(condition,&ruby_block)
|
|
4579
4722
|
# Ensure there is a block.
|
|
4580
4723
|
ruby_block = proc {} unless block_given?
|
|
@@ -4636,6 +4779,16 @@ module HDLRuby::High
|
|
|
4636
4779
|
self.add_statement(Case.new(value))
|
|
4637
4780
|
end
|
|
4638
4781
|
|
|
4782
|
+
# Creates a new case statement taking z as wildcard with a +value+ used for deciding which
|
|
4783
|
+
# block to execute.
|
|
4784
|
+
#
|
|
4785
|
+
# NOTE: the when part is defined through the hwhen method.
|
|
4786
|
+
def hcasez(value)
|
|
4787
|
+
return if self.metacase(value)
|
|
4788
|
+
# Creates the case statement.
|
|
4789
|
+
self.add_statement(Case.new(value, :casez))
|
|
4790
|
+
end
|
|
4791
|
+
|
|
4639
4792
|
# Sets the block of a case structure executed when the +match+ is met
|
|
4640
4793
|
# to the block in +mode+ generated by the execution of +ruby_block+.
|
|
4641
4794
|
#
|
|
@@ -5247,6 +5400,7 @@ module HDLRuby::High
|
|
|
5247
5400
|
class ::Float
|
|
5248
5401
|
# Converts to a new high-level expression.
|
|
5249
5402
|
def to_expr
|
|
5403
|
+
raise "Float not supported yet."
|
|
5250
5404
|
return Value.new(Real,self)
|
|
5251
5405
|
end
|
|
5252
5406
|
|
|
@@ -5256,6 +5410,13 @@ module HDLRuby::High
|
|
|
5256
5410
|
end
|
|
5257
5411
|
end
|
|
5258
5412
|
|
|
5413
|
+
# Extends the NilClass to act as an empty statement.
|
|
5414
|
+
class ::NilClass
|
|
5415
|
+
# Does nothing.
|
|
5416
|
+
def hif(*args)
|
|
5417
|
+
end
|
|
5418
|
+
end
|
|
5419
|
+
|
|
5259
5420
|
# Extends the String class for computing conversion to expression.
|
|
5260
5421
|
class ::String
|
|
5261
5422
|
# # Converts to a new high-level expression.
|
|
@@ -5399,6 +5560,38 @@ module HDLRuby::High
|
|
|
5399
5560
|
expr
|
|
5400
5561
|
end
|
|
5401
5562
|
|
|
5563
|
+
# Casts to +typ+.
|
|
5564
|
+
def as(typ)
|
|
5565
|
+
return self.to_expr.as(typ)
|
|
5566
|
+
end
|
|
5567
|
+
|
|
5568
|
+
# Converts to a bit vector.
|
|
5569
|
+
def to_bit
|
|
5570
|
+
return self.to_expr.to_bit
|
|
5571
|
+
end
|
|
5572
|
+
|
|
5573
|
+
# Casts to an unsigned bit vector type.
|
|
5574
|
+
def to_unsigned
|
|
5575
|
+
return self.to_bit.to_unsigned
|
|
5576
|
+
end
|
|
5577
|
+
|
|
5578
|
+
# Casts to a signed bit vector type.
|
|
5579
|
+
def to_signed
|
|
5580
|
+
return self.to_bit_to_signed
|
|
5581
|
+
end
|
|
5582
|
+
|
|
5583
|
+
# Extends on the left to +n+ bits filling with 0.
|
|
5584
|
+
def zext(n)
|
|
5585
|
+
return self.to_bit.zext(n)
|
|
5586
|
+
end
|
|
5587
|
+
|
|
5588
|
+
# Extends on the left to +n+ bits preserving the signe.
|
|
5589
|
+
def sext(n)
|
|
5590
|
+
return self.to_bit.sext(n)
|
|
5591
|
+
end
|
|
5592
|
+
|
|
5593
|
+
# Add the methods of HExpression
|
|
5594
|
+
|
|
5402
5595
|
# Converts to a new high-level reference.
|
|
5403
5596
|
def to_ref
|
|
5404
5597
|
expr = RefConcat.new(TypeTuple.new(:"",:little,*self.map do |elem|
|
|
@@ -5467,6 +5660,17 @@ module HDLRuby::High
|
|
|
5467
5660
|
end
|
|
5468
5661
|
end
|
|
5469
5662
|
|
|
5663
|
+
# Creates a hcase statement taking z as wildcard executing +ruby_block+ on the element of
|
|
5664
|
+
# the array selected by +value+
|
|
5665
|
+
def hcasez(value,&ruby_block)
|
|
5666
|
+
# Ensure there is a block.
|
|
5667
|
+
ruby_block = proc {} unless block_given?
|
|
5668
|
+
High.cur_block.hcasez(value)
|
|
5669
|
+
self.each.with_index do |elem,i|
|
|
5670
|
+
High.cur_block.hwhen(i) { ruby_block.call(elem) }
|
|
5671
|
+
end
|
|
5672
|
+
end
|
|
5673
|
+
|
|
5470
5674
|
# Moved to HArrow.
|
|
5471
5675
|
# # Add support of the left arrow operator.
|
|
5472
5676
|
# def <=(expr)
|
|
@@ -5537,7 +5741,8 @@ module HDLRuby::High
|
|
|
5537
5741
|
# Get and check the type
|
|
5538
5742
|
# type = str[0]
|
|
5539
5743
|
type = str[1]
|
|
5540
|
-
if ["0", "1", "
|
|
5744
|
+
if ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
|
5745
|
+
"z", "Z", "o", "d", "h"].include?(type) then
|
|
5541
5746
|
# Default binary
|
|
5542
5747
|
type = "b"
|
|
5543
5748
|
else
|
|
@@ -5639,6 +5844,9 @@ module HDLRuby::High
|
|
|
5639
5844
|
# Unknown type
|
|
5640
5845
|
return nil
|
|
5641
5846
|
end
|
|
5847
|
+
# Extends by duplicating the upper bit if the width is too
|
|
5848
|
+
# large.
|
|
5849
|
+
value = value.rjust(width,value[0])
|
|
5642
5850
|
# puts "type.width=#{type.width}, value=#{value}"
|
|
5643
5851
|
# Create and return the value.
|
|
5644
5852
|
return Value.new(type,value)
|
|
@@ -5792,6 +6000,20 @@ def self.configure_high
|
|
|
5792
6000
|
end
|
|
5793
6001
|
|
|
5794
6002
|
|
|
6003
|
+
|
|
6004
|
+
## Handling the properties that can be added to HDLRuby objects.
|
|
6005
|
+
|
|
6006
|
+
## Add to object +obj+, property +prop+.
|
|
6007
|
+
def self.add_property(obj,prop)
|
|
6008
|
+
HDLRuby::Low.add_property(obj,prop)
|
|
6009
|
+
end
|
|
6010
|
+
|
|
6011
|
+
## Iterate on the properties of object +obj+.
|
|
6012
|
+
def self.each_property(obj,&ruby_block)
|
|
6013
|
+
HDLRuby::Low.each_property(obj,&ruby_block)
|
|
6014
|
+
end
|
|
6015
|
+
|
|
6016
|
+
|
|
5795
6017
|
end
|
|
5796
6018
|
|
|
5797
6019
|
|
data/lib/HDLRuby/hruby_low.rb
CHANGED
|
@@ -36,8 +36,6 @@ module HDLRuby::Low
|
|
|
36
36
|
end
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
# Hdecorator = HDLRuby::Hdecorator
|
|
40
|
-
|
|
41
39
|
##
|
|
42
40
|
# Gives parent definition and access properties to an hardware object.
|
|
43
41
|
module Hparent
|
|
@@ -162,9 +160,6 @@ module HDLRuby::Low
|
|
|
162
160
|
end
|
|
163
161
|
end
|
|
164
162
|
|
|
165
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
166
|
-
# include Hdecorator
|
|
167
|
-
|
|
168
163
|
# Comparison for hash: structural comparison.
|
|
169
164
|
def eql?(obj)
|
|
170
165
|
return false unless obj.is_a?(SystemT)
|
|
@@ -529,9 +524,6 @@ module HDLRuby::Low
|
|
|
529
524
|
@behaviors = []
|
|
530
525
|
end
|
|
531
526
|
|
|
532
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
533
|
-
# include Hdecorator
|
|
534
|
-
|
|
535
527
|
# Comparison for hash: structural comparison.
|
|
536
528
|
def eql?(obj)
|
|
537
529
|
return false unless obj.is_a?(Scope)
|
|
@@ -1293,8 +1285,11 @@ module HDLRuby::Low
|
|
|
1293
1285
|
@name = name.to_sym
|
|
1294
1286
|
end
|
|
1295
1287
|
|
|
1296
|
-
#
|
|
1297
|
-
#
|
|
1288
|
+
# Converts the system to HDLRuby::Low.
|
|
1289
|
+
# Here already low.
|
|
1290
|
+
def to_low
|
|
1291
|
+
return self
|
|
1292
|
+
end
|
|
1298
1293
|
|
|
1299
1294
|
# Comparison for hash: structural comparison.
|
|
1300
1295
|
def eql?(obj)
|
|
@@ -1989,6 +1984,11 @@ module HDLRuby::Low
|
|
|
1989
1984
|
return true
|
|
1990
1985
|
end
|
|
1991
1986
|
|
|
1987
|
+
# Gets thebitwidth
|
|
1988
|
+
def width
|
|
1989
|
+
return self.reduce(0) {|sum,elem| sum + elem.width }
|
|
1990
|
+
end
|
|
1991
|
+
|
|
1992
1992
|
# Hash function.
|
|
1993
1993
|
def hash
|
|
1994
1994
|
return [super,@types].hash
|
|
@@ -2330,9 +2330,6 @@ module HDLRuby::Low
|
|
|
2330
2330
|
# @block = block
|
|
2331
2331
|
end
|
|
2332
2332
|
|
|
2333
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
2334
|
-
# include Hdecorator
|
|
2335
|
-
|
|
2336
2333
|
# Sets the block if not already set.
|
|
2337
2334
|
def block=(block)
|
|
2338
2335
|
# Check the block.
|
|
@@ -2561,9 +2558,6 @@ module HDLRuby::Low
|
|
|
2561
2558
|
ref.parent = self
|
|
2562
2559
|
end
|
|
2563
2560
|
|
|
2564
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
2565
|
-
# include Hdecorator
|
|
2566
|
-
|
|
2567
2561
|
# Comparison for hash: structural comparison.
|
|
2568
2562
|
def eql?(obj)
|
|
2569
2563
|
return false unless obj.is_a?(Event)
|
|
@@ -2698,9 +2692,6 @@ module HDLRuby::Low
|
|
|
2698
2692
|
@signals.each(&ruby_block) if @signals
|
|
2699
2693
|
end
|
|
2700
2694
|
|
|
2701
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
2702
|
-
# include Hdecorator
|
|
2703
|
-
|
|
2704
2695
|
# Iterates over each object deeply.
|
|
2705
2696
|
#
|
|
2706
2697
|
# Returns an enumerator if no ruby block is given.
|
|
@@ -2783,9 +2774,6 @@ module HDLRuby::Low
|
|
|
2783
2774
|
@systemTs = [ @systemT ]
|
|
2784
2775
|
end
|
|
2785
2776
|
|
|
2786
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
2787
|
-
# include Hdecorator
|
|
2788
|
-
|
|
2789
2777
|
# Iterates over each object deeply.
|
|
2790
2778
|
#
|
|
2791
2779
|
# Returns an enumerator if no ruby block is given.
|
|
@@ -2919,9 +2907,6 @@ module HDLRuby::Low
|
|
|
2919
2907
|
lumps.each { |lump| self.add_lump(lump) }
|
|
2920
2908
|
end
|
|
2921
2909
|
|
|
2922
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
2923
|
-
# include Hdecorator
|
|
2924
|
-
|
|
2925
2910
|
# Adds a +lump+ of code, it is ment to become an expression or
|
|
2926
2911
|
# some text.
|
|
2927
2912
|
def add_lump(lump)
|
|
@@ -3101,9 +3086,6 @@ module HDLRuby::Low
|
|
|
3101
3086
|
@chunks = HashName.new
|
|
3102
3087
|
end
|
|
3103
3088
|
|
|
3104
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
3105
|
-
# include Hdecorator
|
|
3106
|
-
|
|
3107
3089
|
# Adds a +chunk+ to the sensitivity list.
|
|
3108
3090
|
def add_chunk(chunk)
|
|
3109
3091
|
# Check and add the chunk.
|
|
@@ -3212,7 +3194,6 @@ module HDLRuby::Low
|
|
|
3212
3194
|
# NOTE: this is an abstract class which is not to be used directly.
|
|
3213
3195
|
class Statement
|
|
3214
3196
|
include Hparent
|
|
3215
|
-
# include Hdecorator
|
|
3216
3197
|
|
|
3217
3198
|
# Clones (deeply)
|
|
3218
3199
|
def clone
|
|
@@ -3700,9 +3681,6 @@ module HDLRuby::Low
|
|
|
3700
3681
|
match.parent = statement.parent = self
|
|
3701
3682
|
end
|
|
3702
3683
|
|
|
3703
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
3704
|
-
# include Hdecorator
|
|
3705
|
-
|
|
3706
3684
|
# Iterates over each object deeply.
|
|
3707
3685
|
#
|
|
3708
3686
|
# Returns an enumerator if no ruby block is given.
|
|
@@ -3818,15 +3796,18 @@ module HDLRuby::Low
|
|
|
3818
3796
|
attr_reader :default
|
|
3819
3797
|
|
|
3820
3798
|
# Creates a new case statement whose excution flow is decided from
|
|
3821
|
-
# +value+ with a possible cases given in +whens+ and +default
|
|
3822
|
-
#
|
|
3823
|
-
|
|
3799
|
+
# +value+ with a possible cases given in +whens+ and +default+
|
|
3800
|
+
# (can be set later)
|
|
3801
|
+
# +mode+ is the mode the case should run in. For now there are two
|
|
3802
|
+
# possible modes: normal case :"", and in a mode where z are taken as wildcards :casez.
|
|
3803
|
+
def initialize(value, mode = :"", default = nil, whens = [])
|
|
3824
3804
|
# Check and set the value.
|
|
3825
3805
|
unless value.is_a?(Expression)
|
|
3826
3806
|
raise AnyError, "Invalid class for a value: #{value.class}"
|
|
3827
3807
|
end
|
|
3828
3808
|
super()
|
|
3829
3809
|
@value = value
|
|
3810
|
+
@mode = mode.to_sym
|
|
3830
3811
|
# And set its parent.
|
|
3831
3812
|
value.parent = self
|
|
3832
3813
|
# Checks and set the default case if any.
|
|
@@ -3994,7 +3975,7 @@ module HDLRuby::Low
|
|
|
3994
3975
|
# Clone the default if any.
|
|
3995
3976
|
default = @default ? @default.clone : nil
|
|
3996
3977
|
# Clone the case.
|
|
3997
|
-
return Case.new(@value.clone,default,(@whens.map do |w|
|
|
3978
|
+
return Case.new(@value.clone,@mode,default,(@whens.map do |w|
|
|
3998
3979
|
w.clone
|
|
3999
3980
|
end) )
|
|
4000
3981
|
end
|
|
@@ -4025,9 +4006,6 @@ module HDLRuby::Low
|
|
|
4025
4006
|
@unit = unit.to_sym
|
|
4026
4007
|
end
|
|
4027
4008
|
|
|
4028
|
-
# # Add decorator capability (modifies intialize to put after).
|
|
4029
|
-
# include Hdecorator
|
|
4030
|
-
|
|
4031
4009
|
# Iterates over each object deeply.
|
|
4032
4010
|
#
|
|
4033
4011
|
# Returns an enumerator if no ruby block is given.
|
|
@@ -4918,8 +4896,10 @@ module HDLRuby::Low
|
|
|
4918
4896
|
end
|
|
4919
4897
|
end
|
|
4920
4898
|
|
|
4921
|
-
#
|
|
4922
|
-
|
|
4899
|
+
# Gets the bit width of the expression.
|
|
4900
|
+
def width
|
|
4901
|
+
return @type.width
|
|
4902
|
+
end
|
|
4923
4903
|
|
|
4924
4904
|
# Comparison for hash: structural comparison.
|
|
4925
4905
|
def eql?(obj)
|
|
@@ -5023,6 +5003,7 @@ module HDLRuby::Low
|
|
|
5023
5003
|
|
|
5024
5004
|
# Creates a new value typed +type+ and containing +content+.
|
|
5025
5005
|
def initialize(type,content)
|
|
5006
|
+
# puts "New value with content=#{content} (content.class=#{content.class})"
|
|
5026
5007
|
super(type)
|
|
5027
5008
|
if content.nil? then
|
|
5028
5009
|
# Handle the nil content case.
|
|
@@ -5041,7 +5022,11 @@ module HDLRuby::Low
|
|
|
5041
5022
|
unless content.is_a?(Numeric) or
|
|
5042
5023
|
content.is_a?(HDLRuby::BitString)
|
|
5043
5024
|
# content = HDLRuby::BitString.new(content.to_s)
|
|
5044
|
-
|
|
5025
|
+
if content.is_a?(Array) then
|
|
5026
|
+
content = content.map(&:to_s).join
|
|
5027
|
+
else
|
|
5028
|
+
content = content.to_s
|
|
5029
|
+
end
|
|
5045
5030
|
if self.type.unsigned? && content[0] != "0" then
|
|
5046
5031
|
# content = "0" + content.rjust(self.type.width,content[0])
|
|
5047
5032
|
if content[0] == "1" then
|
|
@@ -5108,10 +5093,10 @@ module HDLRuby::Low
|
|
|
5108
5093
|
return self.content <=> value
|
|
5109
5094
|
end
|
|
5110
5095
|
|
|
5111
|
-
# Gets the bit width of the value.
|
|
5112
|
-
def width
|
|
5113
|
-
|
|
5114
|
-
end
|
|
5096
|
+
# # Gets the bit width of the value.
|
|
5097
|
+
# def width
|
|
5098
|
+
# return @type.width
|
|
5099
|
+
# end
|
|
5115
5100
|
|
|
5116
5101
|
# Tells if the value is even.
|
|
5117
5102
|
def even?
|
|
@@ -6449,4 +6434,23 @@ module HDLRuby::Low
|
|
|
6449
6434
|
end
|
|
6450
6435
|
|
|
6451
6436
|
end
|
|
6437
|
+
|
|
6438
|
+
|
|
6439
|
+
## Handling the properties that can be added to HDLRuby objects.
|
|
6440
|
+
|
|
6441
|
+
Properties = Hash.new
|
|
6442
|
+
|
|
6443
|
+
## Add to object +obj+, property +prop+.
|
|
6444
|
+
def self.add_property(obj,prop)
|
|
6445
|
+
Properties[obj] ||= Set.new
|
|
6446
|
+
Properties[obj] << prop
|
|
6447
|
+
obj
|
|
6448
|
+
end
|
|
6449
|
+
|
|
6450
|
+
## Iterate on the properties of object +obj+.
|
|
6451
|
+
def self.each_property(obj,&ruby_block)
|
|
6452
|
+
Properties[obj].each(&ruby_block)
|
|
6453
|
+
end
|
|
6454
|
+
|
|
6455
|
+
|
|
6452
6456
|
end
|
data/lib/HDLRuby/hruby_rcsim.rb
CHANGED
|
@@ -719,8 +719,13 @@ module HDLRuby::High
|
|
|
719
719
|
# Generate the C description of the hardware case.
|
|
720
720
|
def to_rcsim
|
|
721
721
|
# Create the hardware case C object.
|
|
722
|
-
@
|
|
723
|
-
|
|
722
|
+
if(@mode == :casez) then
|
|
723
|
+
@rcstatement = RCSim.rcsim_make_hcasez(self.value.to_rcsim,
|
|
724
|
+
self.default ? self.default.to_rcsim : nil)
|
|
725
|
+
else
|
|
726
|
+
@rcstatement = RCSim.rcsim_make_hcase(self.value.to_rcsim,
|
|
727
|
+
self.default ? self.default.to_rcsim : nil)
|
|
728
|
+
end
|
|
724
729
|
|
|
725
730
|
# Add the hardware whens.
|
|
726
731
|
rcsim_matches = self.each_when.map {|wh| wh.match.to_rcsim }
|