HDLRuby 2.5.1 → 2.6.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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/comparison_bench.rb +40 -0
- data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
- data/lib/HDLRuby/hdr_samples/dff_unit.rb +3 -3
- 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/multi_timed_bench.rb +54 -0
- 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/type_minmax_bench.rb +37 -0
- data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
- data/lib/HDLRuby/hdr_samples/with_to_array.rb +29 -0
- data/lib/HDLRuby/hdrcc.rb +69 -9
- data/lib/HDLRuby/hruby_decorator.rb +3 -1
- data/lib/HDLRuby/hruby_high.rb +220 -29
- data/lib/HDLRuby/hruby_low.rb +433 -45
- data/lib/HDLRuby/hruby_low2c.rb +122 -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_select.rb +13 -0
- data/lib/HDLRuby/hruby_tools.rb +11 -1
- data/lib/HDLRuby/hruby_verilog.rb +1572 -1723
- data/lib/HDLRuby/sim/hruby_sim.h +45 -5
- data/lib/HDLRuby/sim/hruby_sim_calc.c +192 -20
- data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
- data/lib/HDLRuby/sim/hruby_sim_vcd.c +7 -3
- 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/version.rb +1 -1
- metadata +18 -6
- data/lib/HDLRuby/hruby_unit.rb +0 -43
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
def connect8(i0,i1,i2,i3,i4,i5,i6,i7,
|
3
|
+
o0,o1,o2,o3,o4,o5,o6,o7)
|
4
|
+
o0 <= i0
|
5
|
+
o1 <= i1
|
6
|
+
o2 <= i2
|
7
|
+
o3 <= i3
|
8
|
+
o4 <= i4
|
9
|
+
o5 <= i5
|
10
|
+
o6 <= i6
|
11
|
+
o7 <= i7
|
12
|
+
end
|
13
|
+
|
14
|
+
# A benchmark for testing the conversion to ruby array of expressions.
|
15
|
+
system :with_to_bench do
|
16
|
+
[8].inner :val
|
17
|
+
inner :b0,:b1,:b2,:b3,:b4,:b5,:b6,:b7
|
18
|
+
|
19
|
+
connect8(*val,b0,b1,b2,b3,b4,b5,b6,b7)
|
20
|
+
|
21
|
+
timed do
|
22
|
+
val <= _01101010
|
23
|
+
!10.ns
|
24
|
+
val <= _01011010
|
25
|
+
!10.ns
|
26
|
+
val <= _00001111
|
27
|
+
!10.ns
|
28
|
+
end
|
29
|
+
end
|
data/lib/HDLRuby/hdrcc.rb
CHANGED
@@ -5,7 +5,7 @@ require 'tempfile'
|
|
5
5
|
require 'HDLRuby'
|
6
6
|
require 'HDLRuby/hruby_check.rb'
|
7
7
|
# require 'ripper'
|
8
|
-
require 'HDLRuby/
|
8
|
+
require 'HDLRuby/hruby_low2hdr'
|
9
9
|
require 'HDLRuby/hruby_low2c'
|
10
10
|
require 'HDLRuby/hruby_low2vhd'
|
11
11
|
require 'HDLRuby/hruby_low_fix_types'
|
@@ -252,6 +252,20 @@ module HDLRuby
|
|
252
252
|
|
253
253
|
end
|
254
254
|
|
255
|
+
# Locate an executable from cmd.
|
256
|
+
def which(cmd)
|
257
|
+
# Get the possible exetensions (for windows case).
|
258
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
259
|
+
# Look for the command within the executable paths.
|
260
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
261
|
+
exts.each do |ext|
|
262
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
263
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
nil
|
267
|
+
end
|
268
|
+
|
255
269
|
|
256
270
|
|
257
271
|
if __FILE__ == $0 then
|
@@ -337,9 +351,12 @@ $optparse = OptionParser.new do |opts|
|
|
337
351
|
opts.on("-D", "--debug","Set the HDLRuby debug mode") do |d|
|
338
352
|
$options[:debug] = d
|
339
353
|
end
|
340
|
-
opts.on("-T","--test","Compile the unit tests
|
354
|
+
opts.on("-T","--test t0,t1,t2","Compile the unit tests named t0,t1,...") do |t|
|
341
355
|
$options[:test] = t
|
342
356
|
end
|
357
|
+
opts.on("--testall","Compile all the available unit tests.") do |t|
|
358
|
+
$options[:testall] = t
|
359
|
+
end
|
343
360
|
opts.on("-t", "--top system", "Specify the top system to process") do|t|
|
344
361
|
$options[:top] = t
|
345
362
|
end
|
@@ -350,6 +367,10 @@ $optparse = OptionParser.new do |opts|
|
|
350
367
|
$options[:dump] = v
|
351
368
|
$options[:multiple] = v
|
352
369
|
end
|
370
|
+
opts.on("--version", "Shows the version of HDLRuby.") do |v|
|
371
|
+
puts VERSION
|
372
|
+
exit
|
373
|
+
end
|
353
374
|
# opts.on_tail("-h", "--help", "Show this message") do
|
354
375
|
opts.on("-h", "--help", "Show this message") do
|
355
376
|
puts opts
|
@@ -400,14 +421,23 @@ if $input == nil then
|
|
400
421
|
exit
|
401
422
|
end
|
402
423
|
|
403
|
-
if ($options[:test]) then
|
424
|
+
if ($options[:test] || $options[:testall]) then
|
404
425
|
$top = "__test__"
|
426
|
+
tests = $options[:test]
|
427
|
+
if tests then
|
428
|
+
tests = tests.to_s.split(",")
|
429
|
+
tests.map! {|test| ":\"#{test}\"" }
|
430
|
+
tests = ", #{tests.join(",")}"
|
431
|
+
else
|
432
|
+
tests = ""
|
433
|
+
end
|
405
434
|
# Generate the unit test file.
|
406
435
|
$test_file = Tempfile.new('tester.rb',Dir.getwd)
|
407
|
-
$test_file.write("require 'hruby_unit.rb'\nrequire_relative '#{$input}'\n\n" +
|
408
|
-
|
436
|
+
$test_file.write("require 'std/hruby_unit.rb'\nrequire_relative '#{$input}'\n\n" +
|
437
|
+
"HDLRuby::Unit.test(:\"#{$top}\"#{tests})\n")
|
409
438
|
# $test_file.rewind
|
410
439
|
# puts $test_file.read
|
440
|
+
# exit
|
411
441
|
$test_file.rewind
|
412
442
|
# It is the new input file.
|
413
443
|
$input = $test_file
|
@@ -425,7 +455,7 @@ if $output then
|
|
425
455
|
$output = File.open($output,"w")
|
426
456
|
end
|
427
457
|
else
|
428
|
-
if $
|
458
|
+
if $options[:multiple] then
|
429
459
|
raise "Need a target directory in multiple files generation mode."
|
430
460
|
end
|
431
461
|
$output = $stdout
|
@@ -463,6 +493,24 @@ end
|
|
463
493
|
# Get the top systemT.
|
464
494
|
$top_system = $top_instance.to_low.systemT
|
465
495
|
|
496
|
+
|
497
|
+
# Apply the pre drivers if any.
|
498
|
+
Hdecorator.each_with_property(:pre_driver) do |obj, value|
|
499
|
+
unless value.is_a?(Array) && value.size == 2 then
|
500
|
+
raise "pre_driver requires a driver file name command name."
|
501
|
+
end
|
502
|
+
# Load the driver.
|
503
|
+
require_relative(value[0].to_s)
|
504
|
+
# Ensure obj is the low version.
|
505
|
+
if obj.properties.key?(:high2low) then
|
506
|
+
# obj is high, get the corresponding low.
|
507
|
+
obj = obj.properties[:high2low][0]
|
508
|
+
end
|
509
|
+
# Execute it.
|
510
|
+
send(value[1].to_sym,obj,*value[2..-1])
|
511
|
+
end
|
512
|
+
|
513
|
+
|
466
514
|
# Gather the non-HDLRuby code.
|
467
515
|
$non_hdlruby = []
|
468
516
|
$top_system.each_systemT_deep do |systemT|
|
@@ -504,7 +552,7 @@ elsif $options[:hdr] then
|
|
504
552
|
# $output << systemT.to_high
|
505
553
|
# end
|
506
554
|
# $output << $top_instance.to_low.systemT.to_high
|
507
|
-
$output << $top_system.
|
555
|
+
$output << $top_system.to_hdr
|
508
556
|
elsif $options[:clang] then
|
509
557
|
# top_system = $top_instance.to_low.systemT
|
510
558
|
# top_system = $top_system
|
@@ -589,6 +637,7 @@ elsif $options[:clang] then
|
|
589
637
|
name = $output + "/" +
|
590
638
|
HDLRuby::Low::Low2C.c_name(systemT.name) +
|
591
639
|
".c"
|
640
|
+
# puts "for systemT=#{systemT.name} generating: #{name}"
|
592
641
|
# Open the file for current systemT
|
593
642
|
outfile = File.open(name,"w")
|
594
643
|
# Generate the C code in to.
|
@@ -621,8 +670,19 @@ elsif $options[:clang] then
|
|
621
670
|
end
|
622
671
|
end
|
623
672
|
Dir.chdir($output)
|
624
|
-
#
|
625
|
-
|
673
|
+
# Find the compiler.
|
674
|
+
cc_cmd = which('cc')
|
675
|
+
unless cc_cmd then
|
676
|
+
cc_cmd = which('gcc')
|
677
|
+
end
|
678
|
+
unless cc_cmd then
|
679
|
+
raise "Could not find any compiler, please compile by hand as follows:\n" +
|
680
|
+
" In folder #{$output} execute:\n" +
|
681
|
+
" <my compiler> -o hruby_simulator *.c -lpthread\n" +
|
682
|
+
" Then execute:\n hruby_simulator"
|
683
|
+
end
|
684
|
+
# Use it.
|
685
|
+
Kernel.system("#{cc_cmd} -o3 -o hruby_simulator *.c -lpthread")
|
626
686
|
Kernel.system("./hruby_simulator")
|
627
687
|
end
|
628
688
|
elsif $options[:verilog] then
|
@@ -46,11 +46,13 @@ module HDLRuby
|
|
46
46
|
# Iterate over all the id with their object.
|
47
47
|
#
|
48
48
|
# Returns an enumerator if no ruby block is given.
|
49
|
+
#
|
50
|
+
# NOTE: converts the hash to an array to allow on-the-fly modification.
|
49
51
|
def self.each(&ruby_block)
|
50
52
|
# No ruby block? Return an enumerator.
|
51
53
|
return to_enum(:each) unless ruby_block
|
52
54
|
# A ruby block? Apply it on each object.
|
53
|
-
@@id_map.each(&ruby_block)
|
55
|
+
@@id_map.to_a.each(&ruby_block)
|
54
56
|
end
|
55
57
|
|
56
58
|
# The decorator also need to add properties to the HDLRuby objects.
|
data/lib/HDLRuby/hruby_high.rb
CHANGED
@@ -609,7 +609,8 @@ module HDLRuby::High
|
|
609
609
|
# possible arguments +args+.
|
610
610
|
def instantiate(i_name,*args)
|
611
611
|
# Create the eigen type.
|
612
|
-
eigen = self.expand(High.names_create(i_name.to_s + ":T"), *args)
|
612
|
+
# eigen = self.expand(High.names_create(i_name.to_s + ":T"), *args)
|
613
|
+
eigen = self.expand(HDLRuby.uniq_name(i_name.to_s + ":T"), *args)
|
613
614
|
|
614
615
|
# Create the instance and sets its eigen system to +eigen+.
|
615
616
|
instance = @instance_class.new(i_name,eigen)
|
@@ -620,8 +621,8 @@ module HDLRuby::High
|
|
620
621
|
# Extend the instance.
|
621
622
|
instance.eigen_extend(@singleton_instanceO)
|
622
623
|
# puts "instance scope= #{instance.systemT.scope}"
|
623
|
-
# Add the instance.
|
624
|
-
High.top_user.send(:add_systemI,instance)
|
624
|
+
# Add the instance if instantiating within another system.
|
625
|
+
High.top_user.send(:add_systemI,instance) if High.top_user
|
625
626
|
|
626
627
|
# Execute the post instantiation tasks.
|
627
628
|
eigen.each_on_instance { |task| task.(instance) }
|
@@ -758,10 +759,13 @@ module HDLRuby::High
|
|
758
759
|
"Cannot convert a system without a name to HDLRuby::Low."
|
759
760
|
end
|
760
761
|
# Create the resulting low system type.
|
761
|
-
systemTL = HDLRuby::Low::SystemT.new(High.names_create(name),
|
762
|
+
# systemTL = HDLRuby::Low::SystemT.new(High.names_create(name),
|
763
|
+
systemTL = HDLRuby::Low::SystemT.new(HDLRuby.uniq_name(name),
|
762
764
|
self.scope.to_low)
|
765
|
+
# puts "New low from system #{self.name}: #{systemTL.name}"
|
763
766
|
# For debugging: set the source high object
|
764
767
|
systemTL.properties[:low2high] = self.hdr_id
|
768
|
+
self.properties[:high2low] = systemTL
|
765
769
|
|
766
770
|
# Fills the interface of the new system
|
767
771
|
# from the included systems.
|
@@ -936,8 +940,19 @@ module HDLRuby::High
|
|
936
940
|
# Set the namespace for buidling the scope.
|
937
941
|
High.space_push(@namespace)
|
938
942
|
# Build the scope.
|
939
|
-
@return_value = High.top_user.instance_eval(&ruby_block)
|
943
|
+
# @return_value = High.top_user.instance_eval(&ruby_block)
|
944
|
+
res = High.top_user.instance_eval(&ruby_block)
|
940
945
|
High.space_pop
|
946
|
+
# Now gain access to the result within the sub scope.
|
947
|
+
if (res.is_a?(HRef)) then
|
948
|
+
@return_value = res.type.inner(HDLRuby.uniq_name)
|
949
|
+
High.space_push(@namespace)
|
950
|
+
@return_value <= res
|
951
|
+
High.space_pop
|
952
|
+
else
|
953
|
+
@return_value = res
|
954
|
+
end
|
955
|
+
# This will be the return value.
|
941
956
|
@return_value
|
942
957
|
end
|
943
958
|
|
@@ -1298,6 +1313,7 @@ module HDLRuby::High
|
|
1298
1313
|
scopeL = HDLRuby::Low::Scope.new(self.name)
|
1299
1314
|
# For debugging: set the source high object
|
1300
1315
|
scopeL.properties[:low2high] = self.hdr_id
|
1316
|
+
self.properties[:high2low] = scopeL
|
1301
1317
|
|
1302
1318
|
# Push the private namespace for the low generation.
|
1303
1319
|
High.space_push(@namespace)
|
@@ -1531,6 +1547,7 @@ module HDLRuby::High
|
|
1531
1547
|
typeL = HDLRuby::Low::Type.new(name)
|
1532
1548
|
# For debugging: set the source high object
|
1533
1549
|
typeL.properties[:low2high] = self.hdr_id
|
1550
|
+
self.properties[:high2low] = typeL
|
1534
1551
|
return typeL
|
1535
1552
|
end
|
1536
1553
|
end
|
@@ -1616,6 +1633,18 @@ module HDLRuby::High
|
|
1616
1633
|
include HbasicType
|
1617
1634
|
end
|
1618
1635
|
|
1636
|
+
# The string type
|
1637
|
+
StringT = define_type(:string)
|
1638
|
+
class << StringT
|
1639
|
+
# Converts the type to HDLRuby::Low.
|
1640
|
+
def to_low
|
1641
|
+
return Low::StringT
|
1642
|
+
end
|
1643
|
+
|
1644
|
+
include HbasicType
|
1645
|
+
end
|
1646
|
+
|
1647
|
+
|
1619
1648
|
# # The infer type.
|
1620
1649
|
# # Unspecified, but automatically infered when connected.
|
1621
1650
|
# Infer = define_type(:infer)
|
@@ -1672,6 +1701,7 @@ module HDLRuby::High
|
|
1672
1701
|
typeDefL = HDLRuby::Low::TypeDef.new(name,self.def.to_low)
|
1673
1702
|
# For debugging: set the source high object
|
1674
1703
|
typeDefL.properties[:low2high] = self.hdr_id
|
1704
|
+
self.properties[:high2low] = typeDefL
|
1675
1705
|
return typeDefL
|
1676
1706
|
end
|
1677
1707
|
end
|
@@ -1724,6 +1754,7 @@ module HDLRuby::High
|
|
1724
1754
|
typeDefL = HDLRuby::Low::TypeDef.new(name,self.def.to_low)
|
1725
1755
|
# For debugging: set the source high object
|
1726
1756
|
typeDefL.properties[:low2high] = self.hdr_id
|
1757
|
+
self.properties[:high2low] = typeDefL
|
1727
1758
|
return typeDefL
|
1728
1759
|
end
|
1729
1760
|
end
|
@@ -1741,6 +1772,7 @@ module HDLRuby::High
|
|
1741
1772
|
self.range.to_low)
|
1742
1773
|
# For debugging: set the source high object
|
1743
1774
|
typeVectorL.properties[:low2high] = self.hdr_id
|
1775
|
+
self.properties[:high2low] = typeVectorL
|
1744
1776
|
return typeVectorL
|
1745
1777
|
end
|
1746
1778
|
end
|
@@ -1820,6 +1852,7 @@ module HDLRuby::High
|
|
1820
1852
|
*@types.map { |type| type.to_low } )
|
1821
1853
|
# For debugging: set the source high object
|
1822
1854
|
typeTupleL.properties[:low2high] = self.hdr_id
|
1855
|
+
self.properties[:high2low] = typeTupleL
|
1823
1856
|
return typeTupleL
|
1824
1857
|
end
|
1825
1858
|
end
|
@@ -1840,6 +1873,7 @@ module HDLRuby::High
|
|
1840
1873
|
@types.map { |name,type| [name,type.to_low] } )
|
1841
1874
|
# For debugging: set the source high object
|
1842
1875
|
typeStructL.properties[:low2high] = self.hdr_id
|
1876
|
+
self.properties[:high2low] = typeStructL
|
1843
1877
|
return typeStructL
|
1844
1878
|
end
|
1845
1879
|
end
|
@@ -2007,7 +2041,8 @@ module HDLRuby::High
|
|
2007
2041
|
else
|
2008
2042
|
# No, perform a connection is order of declaration
|
2009
2043
|
connects.each.with_index do |csig,i|
|
2010
|
-
|
2044
|
+
csig = csig.to_expr
|
2045
|
+
# puts "csig=#{csig} i=#{i}"
|
2011
2046
|
# puts "systemT inputs=#{systemT.each_input.to_a.size}"
|
2012
2047
|
# Gets i-est signal to connect
|
2013
2048
|
ssig = self.systemT.get_interface_with_included(i)
|
@@ -2078,6 +2113,7 @@ module HDLRuby::High
|
|
2078
2113
|
systemTL)
|
2079
2114
|
# For debugging: set the source high object
|
2080
2115
|
systemIL.properties[:low2high] = self.hdr_id
|
2116
|
+
self.properties[:high2low] = systemIL
|
2081
2117
|
# Adds the other systemTs.
|
2082
2118
|
self.each_systemT do |systemT|
|
2083
2119
|
systemIL.add_systemT(systemT.to_low) unless systemT == self.systemT
|
@@ -2105,6 +2141,7 @@ module HDLRuby::High
|
|
2105
2141
|
end)
|
2106
2142
|
# For debugging: set the source high object
|
2107
2143
|
chunkL.properties[:low2high] = self.hdr_id
|
2144
|
+
self.properties[:high2low] = chunkL
|
2108
2145
|
return chunkL
|
2109
2146
|
end
|
2110
2147
|
end
|
@@ -2118,6 +2155,7 @@ module HDLRuby::High
|
|
2118
2155
|
codeL = HDLRuby::Low::Code.new
|
2119
2156
|
# For debugging: set the source high object
|
2120
2157
|
codeL.properties[:low2high] = self.hdr_id
|
2158
|
+
self.properties[:high2low] = codeL
|
2121
2159
|
# Add the low-level events.
|
2122
2160
|
self.each_event { |event| codeL.add_event(event.to_low) }
|
2123
2161
|
# Add the low-level code chunks.
|
@@ -2211,6 +2249,7 @@ module HDLRuby::High
|
|
2211
2249
|
self.each_noif {|cond,block| ifL.add_noif(cond.to_low,block.to_low)}
|
2212
2250
|
# For debugging: set the source high object
|
2213
2251
|
ifL.properties[:low2high] = self.hdr_id
|
2252
|
+
self.properties[:high2low] = ifL
|
2214
2253
|
return ifL
|
2215
2254
|
end
|
2216
2255
|
end
|
@@ -2235,6 +2274,7 @@ module HDLRuby::High
|
|
2235
2274
|
self.statement.to_low)
|
2236
2275
|
# For debugging: set the source high object
|
2237
2276
|
whenL.properties[:low2high] = self.hdr_id
|
2277
|
+
self.properties[:high2low] = whenL
|
2238
2278
|
return whenL
|
2239
2279
|
end
|
2240
2280
|
end
|
@@ -2282,6 +2322,7 @@ module HDLRuby::High
|
|
2282
2322
|
caseL = HDLRuby::Low::Case.new(@value.to_low)
|
2283
2323
|
# For debugging: set the source high object
|
2284
2324
|
caseL.properties[:low2high] = self.hdr_id
|
2325
|
+
self.properties[:high2low] = caseL
|
2285
2326
|
# Add each when case.
|
2286
2327
|
self.each_when do |w|
|
2287
2328
|
caseL.add_when(w.to_low)
|
@@ -2312,6 +2353,7 @@ module HDLRuby::High
|
|
2312
2353
|
delayL = HDLRuby::Low::Delay.new(self.value, self.unit)
|
2313
2354
|
# For debugging: set the source high object
|
2314
2355
|
delayL.properties[:low2high] = self.hdr_id
|
2356
|
+
self.properties[:high2low] = delayL
|
2315
2357
|
return delayL
|
2316
2358
|
end
|
2317
2359
|
end
|
@@ -2327,6 +2369,7 @@ module HDLRuby::High
|
|
2327
2369
|
timeWaitL = HDLRuby::Low::TimeWait.new(self.delay.to_low)
|
2328
2370
|
# For debugging: set the source high object
|
2329
2371
|
timeWaitL.properties[:low2high] = self.hdr_id
|
2372
|
+
self.properties[:high2low] = timeWaitL
|
2330
2373
|
return timeWaitL
|
2331
2374
|
end
|
2332
2375
|
end
|
@@ -2345,6 +2388,7 @@ module HDLRuby::High
|
|
2345
2388
|
self.delay.to_low)
|
2346
2389
|
# For debugging: set the source high object
|
2347
2390
|
timeRepeatL.properties[:low2high] = self.hdr_id
|
2391
|
+
self.properties[:high2low] = timeRepeatL
|
2348
2392
|
return timeRepeatL
|
2349
2393
|
end
|
2350
2394
|
end
|
@@ -2493,6 +2537,35 @@ module HDLRuby::High
|
|
2493
2537
|
return self.ljust(self[-1])
|
2494
2538
|
end
|
2495
2539
|
|
2540
|
+
# Match the type with +typ+:
|
2541
|
+
# - Recurse on the sub expr if hierachical type, raising an arror
|
2542
|
+
# if the expression is not hierarchical.
|
2543
|
+
# - Directly cast otherwise.
|
2544
|
+
def match_type(typ)
|
2545
|
+
# Has the type sub types?
|
2546
|
+
if typ.types? then
|
2547
|
+
unless self.is_a?(Concat) then
|
2548
|
+
raise AnyError,
|
2549
|
+
"Invalid class for assignment to hierarchical: #{self.class}."
|
2550
|
+
end
|
2551
|
+
return Concat.new(typ,
|
2552
|
+
self.each_expression.zip(typ.each_type).map do |e,t|
|
2553
|
+
e.match_type(t)
|
2554
|
+
end)
|
2555
|
+
elsif typ.vector? && typ.base.hierarchical? then
|
2556
|
+
unless self.is_a?(Concat) then
|
2557
|
+
raise AnyError,
|
2558
|
+
"Invalid class for assignment to hierarchical: #{self.class}."
|
2559
|
+
end
|
2560
|
+
return Concat.new(typ,
|
2561
|
+
self.each_expression.map do |e|
|
2562
|
+
e.match_type(typ.base)
|
2563
|
+
end)
|
2564
|
+
else
|
2565
|
+
return self.as(typ)
|
2566
|
+
end
|
2567
|
+
end
|
2568
|
+
|
2496
2569
|
# Gets the origin method for operation +op+.
|
2497
2570
|
def self.orig_operator(op)
|
2498
2571
|
return (op.to_s + "_orig").to_sym
|
@@ -2585,7 +2658,6 @@ module HDLRuby::High
|
|
2585
2658
|
end
|
2586
2659
|
end
|
2587
2660
|
|
2588
|
-
|
2589
2661
|
# Converts to a select operator using current expression as
|
2590
2662
|
# condition for one of the +choices+.
|
2591
2663
|
#
|
@@ -2601,6 +2673,7 @@ module HDLRuby::High
|
|
2601
2673
|
end
|
2602
2674
|
|
2603
2675
|
|
2676
|
+
|
2604
2677
|
# Methods for conversion for HDLRuby::Low: type processing, flattening
|
2605
2678
|
# and so on
|
2606
2679
|
|
@@ -2641,14 +2714,19 @@ module HDLRuby::High
|
|
2641
2714
|
#
|
2642
2715
|
# NOTE: it is converted afterward to an expression if required.
|
2643
2716
|
def <=(expr)
|
2717
|
+
# Cast expr to self if required.
|
2718
|
+
expr = expr.to_expr.match_type(self.type)
|
2719
|
+
# Generate the transmit.
|
2644
2720
|
if High.top_user.is_a?(HDLRuby::Low::Block) then
|
2645
2721
|
# We are in a block, so generate and add a Transmit.
|
2646
2722
|
High.top_user.
|
2647
|
-
add_statement(Transmit.new(self.to_ref,expr.to_expr))
|
2723
|
+
# add_statement(Transmit.new(self.to_ref,expr.to_expr))
|
2724
|
+
add_statement(Transmit.new(self.to_ref,expr))
|
2648
2725
|
else
|
2649
2726
|
# We are in a system type, so generate and add a Connection.
|
2650
2727
|
High.top_user.
|
2651
|
-
add_connection(Connection.new(self.to_ref,expr.to_expr))
|
2728
|
+
# add_connection(Connection.new(self.to_ref,expr.to_expr))
|
2729
|
+
add_connection(Connection.new(self.to_ref,expr))
|
2652
2730
|
end
|
2653
2731
|
end
|
2654
2732
|
end
|
@@ -2670,6 +2748,7 @@ module HDLRuby::High
|
|
2670
2748
|
castL =HDLRuby::Low::Cast.new(self.type.to_low,self.child.to_low)
|
2671
2749
|
# For debugging: set the source high object
|
2672
2750
|
castL.properties[:low2high] = self.hdr_id
|
2751
|
+
self.properties[:high2low] = castL
|
2673
2752
|
return castL
|
2674
2753
|
end
|
2675
2754
|
end
|
@@ -2693,6 +2772,7 @@ module HDLRuby::High
|
|
2693
2772
|
self.child.to_low)
|
2694
2773
|
# For debugging: set the source high object
|
2695
2774
|
unaryL.properties[:low2high] = self.hdr_id
|
2775
|
+
self.properties[:high2low] = unaryL
|
2696
2776
|
return unaryL
|
2697
2777
|
end
|
2698
2778
|
end
|
@@ -2717,6 +2797,7 @@ module HDLRuby::High
|
|
2717
2797
|
self.left.to_low, self.right.to_low)
|
2718
2798
|
# For debugging: set the source high object
|
2719
2799
|
binaryL.properties[:low2high] = self.hdr_id
|
2800
|
+
self.properties[:high2low] = binaryL
|
2720
2801
|
return binaryL
|
2721
2802
|
end
|
2722
2803
|
end
|
@@ -2751,6 +2832,7 @@ module HDLRuby::High
|
|
2751
2832
|
end)
|
2752
2833
|
# For debugging: set the source high object
|
2753
2834
|
selectL.properties[:low2high] = self.hdr_id
|
2835
|
+
self.properties[:high2low] = selectL
|
2754
2836
|
return selectL
|
2755
2837
|
end
|
2756
2838
|
end
|
@@ -2784,6 +2866,7 @@ module HDLRuby::High
|
|
2784
2866
|
)
|
2785
2867
|
# For debugging: set the source high object
|
2786
2868
|
concatL.properties[:low2high] = self.hdr_id
|
2869
|
+
self.properties[:high2low] = concatL
|
2787
2870
|
return concatL
|
2788
2871
|
end
|
2789
2872
|
end
|
@@ -2827,6 +2910,7 @@ module HDLRuby::High
|
|
2827
2910
|
valueL = HDLRuby::Low::Value.new(self.type.to_low,self.content)
|
2828
2911
|
# For debugging: set the source high object
|
2829
2912
|
valueL.properties[:low2high] = self.hdr_id
|
2913
|
+
self.properties[:high2low] = valueL
|
2830
2914
|
return valueL
|
2831
2915
|
end
|
2832
2916
|
|
@@ -2929,12 +3013,12 @@ module HDLRuby::High
|
|
2929
3013
|
|
2930
3014
|
# Converts the name reference to a HDLRuby::Low::RefName.
|
2931
3015
|
def to_low
|
2932
|
-
#
|
2933
|
-
# @base.to_ref.to_low,@object.name)
|
3016
|
+
# puts "to_low with base=#{@base} @object=#{@object}"
|
2934
3017
|
refNameL = HDLRuby::Low::RefName.new(self.type.to_low,
|
2935
3018
|
@base.to_ref.to_low,@object.name)
|
2936
3019
|
# For debugging: set the source high object
|
2937
3020
|
refNameL.properties[:low2high] = self.hdr_id
|
3021
|
+
self.properties[:high2low] = refNameL
|
2938
3022
|
return refNameL
|
2939
3023
|
end
|
2940
3024
|
|
@@ -2974,6 +3058,7 @@ module HDLRuby::High
|
|
2974
3058
|
)
|
2975
3059
|
# For debugging: set the source high object
|
2976
3060
|
refConcatL.properties[:low2high] = self.hdr_id
|
3061
|
+
self.properties[:high2low] = refConcatL
|
2977
3062
|
return refConcatL
|
2978
3063
|
end
|
2979
3064
|
end
|
@@ -2997,6 +3082,7 @@ module HDLRuby::High
|
|
2997
3082
|
self.ref.to_low,self.index.to_low)
|
2998
3083
|
# For debugging: set the source high object
|
2999
3084
|
refIndexL.properties[:low2high] = self.hdr_id
|
3085
|
+
self.properties[:high2low] = refIndexL
|
3000
3086
|
return refIndexL
|
3001
3087
|
end
|
3002
3088
|
end
|
@@ -3020,6 +3106,7 @@ module HDLRuby::High
|
|
3020
3106
|
self.ref.to_low,self.range.to_low)
|
3021
3107
|
# For debugging: set the source high object
|
3022
3108
|
refRangeL.properties[:low2high] = self.hdr_id
|
3109
|
+
self.properties[:high2low] = refRangeL
|
3023
3110
|
return refRangeL
|
3024
3111
|
end
|
3025
3112
|
end
|
@@ -3031,7 +3118,7 @@ module HDLRuby::High
|
|
3031
3118
|
|
3032
3119
|
# Converts to a new reference.
|
3033
3120
|
def to_ref
|
3034
|
-
return RefName.new(self.ref.to_ref,self.name)
|
3121
|
+
return RefName.new(self.type,self.ref.to_ref,self.name)
|
3035
3122
|
end
|
3036
3123
|
|
3037
3124
|
# Converts the name reference to HDLRuby::Low.
|
@@ -3042,6 +3129,7 @@ module HDLRuby::High
|
|
3042
3129
|
self.ref.to_low,self.name)
|
3043
3130
|
# For debugging: set the source high object
|
3044
3131
|
refNameL.properties[:low2high] = self.hdr_id
|
3132
|
+
self.properties[:high2low] = refNameL
|
3045
3133
|
return refNameL
|
3046
3134
|
end
|
3047
3135
|
end
|
@@ -3078,14 +3166,49 @@ module HDLRuby::High
|
|
3078
3166
|
refThisL = HDLRuby::Low::RefThis.new
|
3079
3167
|
# For debugging: set the source high object
|
3080
3168
|
refThisL.properties[:low2high] = self.hdr_id
|
3169
|
+
self.properties[:high2low] = refThisL
|
3081
3170
|
return refThisL
|
3082
3171
|
end
|
3083
3172
|
end
|
3084
3173
|
|
3174
|
+
##
|
3175
|
+
# Describes a string.
|
3176
|
+
#
|
3177
|
+
# NOTE: This is not synthesizable!
|
3178
|
+
class StringE < Low::StringE
|
3179
|
+
include HExpression
|
3180
|
+
|
3181
|
+
# Converts to an expression.
|
3182
|
+
def to_expr
|
3183
|
+
return StringE.new(self.content,*self.each_arg.map(&:to_expr))
|
3184
|
+
end
|
3185
|
+
|
3186
|
+
# Converts the connection to HDLRuby::Low.
|
3187
|
+
def to_low
|
3188
|
+
return HDLRuby::Low::StringE.new(self.content,
|
3189
|
+
*self.each_arg.map(&:to_low))
|
3190
|
+
end
|
3191
|
+
end
|
3192
|
+
|
3193
|
+
|
3194
|
+
|
3195
|
+
|
3196
|
+
# Sets the current this to +obj+.
|
3197
|
+
#
|
3198
|
+
# NOTE: do not use a this= style to avoid confusion.
|
3199
|
+
def set_this(obj = proc { RefThis.new })
|
3200
|
+
if (obj.is_a?(Proc)) then
|
3201
|
+
@@this = obj
|
3202
|
+
else
|
3203
|
+
@@this = proc { RefObject.new(RefThis.new,obj) }
|
3204
|
+
end
|
3205
|
+
end
|
3206
|
+
|
3085
3207
|
|
3086
3208
|
# Gives access to the *this* reference.
|
3087
3209
|
def this
|
3088
|
-
RefThis.new
|
3210
|
+
# RefThis.new
|
3211
|
+
@@this.call
|
3089
3212
|
end
|
3090
3213
|
|
3091
3214
|
|
@@ -3116,6 +3239,7 @@ module HDLRuby::High
|
|
3116
3239
|
eventL = HDLRuby::Low::Event.new(self.type,self.ref.to_low)
|
3117
3240
|
# For debugging: set the source high object
|
3118
3241
|
eventL.properties[:low2high] = self.hdr_id
|
3242
|
+
self.properties[:high2low] = eventL
|
3119
3243
|
return eventL
|
3120
3244
|
end
|
3121
3245
|
end
|
@@ -3158,10 +3282,33 @@ module HDLRuby::High
|
|
3158
3282
|
self.right.to_low)
|
3159
3283
|
# For debugging: set the source high object
|
3160
3284
|
transmitL.properties[:low2high] = self.hdr_id
|
3285
|
+
self.properties[:high2low] = transmitL
|
3161
3286
|
return transmitL
|
3162
3287
|
end
|
3163
3288
|
end
|
3164
3289
|
|
3290
|
+
|
3291
|
+
##
|
3292
|
+
# Describes a print statement: not synthesizable!
|
3293
|
+
class Print < Low::Print
|
3294
|
+
High = HDLRuby::High
|
3295
|
+
|
3296
|
+
include HStatement
|
3297
|
+
|
3298
|
+
# Creates a new statement for printing +args+.
|
3299
|
+
def initialize(*args)
|
3300
|
+
# Process the arguments.
|
3301
|
+
super(*args.map(&:to_expr))
|
3302
|
+
end
|
3303
|
+
|
3304
|
+
# Converts the connection to HDLRuby::Low.
|
3305
|
+
def to_low
|
3306
|
+
return HDLRuby::Low::Print.new(*self.each_arg.map(&:to_low))
|
3307
|
+
end
|
3308
|
+
|
3309
|
+
end
|
3310
|
+
|
3311
|
+
|
3165
3312
|
##
|
3166
3313
|
# Describes a connection.
|
3167
3314
|
class Connection < Low::Connection
|
@@ -3228,6 +3375,7 @@ module HDLRuby::High
|
|
3228
3375
|
self.right.to_low)
|
3229
3376
|
# For debugging: set the source high object
|
3230
3377
|
connectionL.properties[:low2high] = self.hdr_id
|
3378
|
+
self.properties[:high2low] = connectionL
|
3231
3379
|
return connectionL
|
3232
3380
|
end
|
3233
3381
|
end
|
@@ -3258,7 +3406,7 @@ module HDLRuby::High
|
|
3258
3406
|
# NOTE: +dir+ can be :input, :output, :inout or :inner
|
3259
3407
|
def initialize(name,type,dir,value = nil)
|
3260
3408
|
# Check the value.
|
3261
|
-
value = value.to_expr if value
|
3409
|
+
value = value.to_expr.match_type(type) if value
|
3262
3410
|
# Initialize the type structure.
|
3263
3411
|
super(name,type,value)
|
3264
3412
|
|
@@ -3341,6 +3489,7 @@ module HDLRuby::High
|
|
3341
3489
|
signalIL = HDLRuby::Low::SignalI.new(name,self.type.to_low)
|
3342
3490
|
# For debugging: set the source high object
|
3343
3491
|
signalIL.properties[:low2high] = self.hdr_id
|
3492
|
+
self.properties[:high2low] = signalIL
|
3344
3493
|
return signalIL
|
3345
3494
|
end
|
3346
3495
|
end
|
@@ -3357,7 +3506,7 @@ module HDLRuby::High
|
|
3357
3506
|
# and +value+.
|
3358
3507
|
def initialize(name,type,value)
|
3359
3508
|
# Check the value is a constant.
|
3360
|
-
value = value.to_expr
|
3509
|
+
value = value.to_expr.match_type(type)
|
3361
3510
|
unless value.constant? then
|
3362
3511
|
raise AnyError,"Non-constant value assignment to constant."
|
3363
3512
|
end
|
@@ -3406,6 +3555,7 @@ module HDLRuby::High
|
|
3406
3555
|
self.value.to_low)
|
3407
3556
|
# For debugging: set the source high object
|
3408
3557
|
signalCL.properties[:low2high] = self.hdr_id
|
3558
|
+
self.properties[:high2low] = signalCL
|
3409
3559
|
return signalCL
|
3410
3560
|
end
|
3411
3561
|
end
|
@@ -3479,13 +3629,6 @@ module HDLRuby::High
|
|
3479
3629
|
# Use its return value.
|
3480
3630
|
return block.return_value
|
3481
3631
|
end
|
3482
|
-
|
3483
|
-
# # Get the current mode of the block.
|
3484
|
-
# #
|
3485
|
-
# # NOTE: for name coherency purpose only.
|
3486
|
-
# def block
|
3487
|
-
# return self.mode
|
3488
|
-
# end
|
3489
3632
|
|
3490
3633
|
# Gets the current block.
|
3491
3634
|
def cur_block
|
@@ -3583,6 +3726,12 @@ module HDLRuby::High
|
|
3583
3726
|
end
|
3584
3727
|
statement.hwhen(match, mode, &ruby_block)
|
3585
3728
|
end
|
3729
|
+
|
3730
|
+
|
3731
|
+
# Prints.
|
3732
|
+
def hprint(*args)
|
3733
|
+
self.add_statement(Print.new(*args))
|
3734
|
+
end
|
3586
3735
|
end
|
3587
3736
|
|
3588
3737
|
|
@@ -3619,6 +3768,7 @@ module HDLRuby::High
|
|
3619
3768
|
blockL = HDLRuby::Low::Block.new(self.mode)
|
3620
3769
|
# For debugging: set the source high object
|
3621
3770
|
blockL.properties[:low2high] = self.hdr_id
|
3771
|
+
self.properties[:high2low] = blockL
|
3622
3772
|
# Push the namespace for the low generation.
|
3623
3773
|
High.space_push(@namespace)
|
3624
3774
|
# Pushes on the name stack for converting the internals of
|
@@ -3688,6 +3838,7 @@ module HDLRuby::High
|
|
3688
3838
|
blockL = HDLRuby::Low::TimeBlock.new(self.mode)
|
3689
3839
|
# For debugging: set the source high object
|
3690
3840
|
blockL.properties[:low2high] = self.hdr_id
|
3841
|
+
self.properties[:high2low] = blockL
|
3691
3842
|
# Add the inner signals
|
3692
3843
|
self.each_inner { |inner| blockL.add_inner(inner.to_low) }
|
3693
3844
|
# Add the statements
|
@@ -3781,6 +3932,7 @@ module HDLRuby::High
|
|
3781
3932
|
behaviorL = HDLRuby::Low::Behavior.new(blockL)
|
3782
3933
|
# For debugging: set the source high object
|
3783
3934
|
behaviorL.properties[:low2high] = self.hdr_id
|
3935
|
+
self.properties[:high2low] = behaviorL
|
3784
3936
|
eventLs.each(&behaviorL.method(:add_event))
|
3785
3937
|
return behaviorL
|
3786
3938
|
end
|
@@ -3810,6 +3962,7 @@ module HDLRuby::High
|
|
3810
3962
|
timeBehaviorL = HDLRuby::Low::TimeBehavior.new(blockL)
|
3811
3963
|
# For debugging: set the source high object
|
3812
3964
|
timeBehaviorL.properties[:low2high] = self.hdr_id
|
3965
|
+
self.properties[:high2low] = timeBehaviorL
|
3813
3966
|
eventLs.each(&timeBehaviorL.method(:add_event))
|
3814
3967
|
return timeBehaviorL
|
3815
3968
|
end
|
@@ -4116,13 +4269,40 @@ module HDLRuby::High
|
|
4116
4269
|
|
4117
4270
|
# Extends the String class for computing conversion to expression.
|
4118
4271
|
class ::String
|
4119
|
-
# Converts to a new high-level expression.
|
4120
|
-
def to_expr
|
4272
|
+
# # Converts to a new high-level expression.
|
4273
|
+
# def to_expr
|
4274
|
+
# # Convert the string to a bit string.
|
4275
|
+
# bstr = BitString.new(self)
|
4276
|
+
# # Use it to create the new value.
|
4277
|
+
# return Value.new(Bit[bstr.width],self)
|
4278
|
+
# end
|
4279
|
+
|
4280
|
+
# Converts to a new high-level value.
|
4281
|
+
def to_value
|
4121
4282
|
# Convert the string to a bit string.
|
4122
4283
|
bstr = BitString.new(self)
|
4123
4284
|
# Use it to create the new value.
|
4124
4285
|
return Value.new(Bit[bstr.width],self)
|
4125
4286
|
end
|
4287
|
+
|
4288
|
+
# Convert to a new high-level string expression
|
4289
|
+
def to_expr
|
4290
|
+
return StringE.new(self)
|
4291
|
+
end
|
4292
|
+
|
4293
|
+
# For now deactivated, needs rethinking.
|
4294
|
+
# # Rework format to generate HDLRuby string.
|
4295
|
+
# alias_method :__format_old__, :%
|
4296
|
+
# def %(args)
|
4297
|
+
# # Is there any HW argument?
|
4298
|
+
# if args.any? { |arg| arg.is_a?(HDLRuby::Low::Hparent) } then
|
4299
|
+
# # Yes generate a HDLRuby string.
|
4300
|
+
# return StringE.new(self,*args)
|
4301
|
+
# else
|
4302
|
+
# # No process the format normally.
|
4303
|
+
# self.__format_old__(args)
|
4304
|
+
# end
|
4305
|
+
# end
|
4126
4306
|
end
|
4127
4307
|
|
4128
4308
|
|
@@ -4216,11 +4396,14 @@ module HDLRuby::High
|
|
4216
4396
|
|
4217
4397
|
# Converts to a new high-level expression.
|
4218
4398
|
def to_expr
|
4219
|
-
# expr = Concat.new
|
4220
|
-
|
4221
|
-
|
4222
|
-
|
4223
|
-
|
4399
|
+
# expr = Concat.new(TypeTuple.new(:"",:little,*self.map do |elem|
|
4400
|
+
# elem.to_expr.type
|
4401
|
+
# end))
|
4402
|
+
elems = self.map {|elem| elem.to_expr }
|
4403
|
+
typ= TypeTuple.new(:"",:little)
|
4404
|
+
elems.each {|elem| typ.add_type(elem.type) }
|
4405
|
+
expr = Concat.new(typ)
|
4406
|
+
elems.each {|elem| expr.add_expression(elem) }
|
4224
4407
|
expr
|
4225
4408
|
end
|
4226
4409
|
|
@@ -4291,6 +4474,11 @@ module HDLRuby::High
|
|
4291
4474
|
end
|
4292
4475
|
end
|
4293
4476
|
|
4477
|
+
# Add support of the left arrow operator.
|
4478
|
+
def <=(expr)
|
4479
|
+
self.to_expr <= expr
|
4480
|
+
end
|
4481
|
+
|
4294
4482
|
# Array construction shortcuts
|
4295
4483
|
|
4296
4484
|
# Create an array whose number of elements is given by the content
|
@@ -4583,6 +4771,9 @@ def self.configure_high
|
|
4583
4771
|
end
|
4584
4772
|
end
|
4585
4773
|
|
4774
|
+
# Initialize the this.
|
4775
|
+
set_this
|
4776
|
+
|
4586
4777
|
# Generate the standard signals
|
4587
4778
|
$clk = Universe.scope.inner :__universe__clk__
|
4588
4779
|
$rst = Universe.scope.inner :__universe__rst__
|