HDLRuby 3.7.8 → 3.7.9
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 +140 -3
- data/lib/HDLRuby/hdr_samples/with_henumerable.rb +366 -0
- data/lib/HDLRuby/std/hruby_enum.rb +924 -0
- data/lib/HDLRuby/std/sequencer.rb +1 -1
- data/lib/HDLRuby/std/sequencer_sw.rb +305 -4
- data/lib/HDLRuby/std/std.rb +1 -0
- data/lib/HDLRuby/version.rb +1 -1
- metadata +3 -1
@@ -991,7 +991,7 @@ module HDLRuby::High::Std
|
|
991
991
|
# Declare the result signal the flag and the result array size index
|
992
992
|
# used for implementing the algorithm (shift-based sorting) in
|
993
993
|
# case of multiple max.
|
994
|
-
res
|
994
|
+
res = nil
|
995
995
|
flg = nil
|
996
996
|
idx = nil
|
997
997
|
HDLRuby::High.cur_system.open do
|
@@ -238,6 +238,28 @@ module RubyHDL::High
|
|
238
238
|
:">=" => "((%{l}) & %{m}%{s} >=(%{r}) & %{m}%{s}) ? 1:0"
|
239
239
|
}
|
240
240
|
|
241
|
+
PYTHON_OPERATOR = {
|
242
|
+
# Unary operators.
|
243
|
+
:"-@" => "-(%{l})", :"+@" => "+(%{l})", :"~" => "~(%{l})",
|
244
|
+
:abs => "(%{l}).abs",
|
245
|
+
:boolean => "%{l}", :bit => "%{l}",
|
246
|
+
:signed => "%{l}", :unsigned => "(%{l}) & 0xFFFFFFFFFFFFFFFF",
|
247
|
+
|
248
|
+
# Binary operators.
|
249
|
+
:"+" => "(%{l})+(%{r})", :"-" => "(%{l})-(%{r})",
|
250
|
+
:"*" => "(%{l})*(%{r})", :"/" => "(%{l})/(%{r})",
|
251
|
+
:"%" => "(%{l})%%(%{r})", :"**" => "(%{l})**(%{r})",
|
252
|
+
:"&" => "(%{l})&(%{r})", :"|" => "(%{l})|(%{r})",
|
253
|
+
:"^" => "(%{l})^(%{r})",
|
254
|
+
:"<<" => "(%{l})<<(%{r})", :">>" => "(%{l})>>(%{r})",
|
255
|
+
:"==" => "1 if ((%{l}) & %{m}==(%{r}) & %{m}) else 0",
|
256
|
+
:"!=" => "1 if ((%{l}) & %{m}!=(%{r}) & %{m}) else 0",
|
257
|
+
:"<" => "1 if ((%{l}) & %{m}%{s} < (%{r}) & %{m}%{s}) else 0",
|
258
|
+
:">" => "1 if ((%{l}) & %{m}%{s} > (%{r}) & %{m}%{s}) else 0",
|
259
|
+
:"<=" => "1 if ((%{l}) & %{m}%{s} <=(%{r}) & %{m}%{s}) else 0",
|
260
|
+
:">=" => "1 if ((%{l}) & %{m}%{s} >=(%{r}) & %{m}%{s}) else 0"
|
261
|
+
}
|
262
|
+
|
241
263
|
# The translation of operators into C code.
|
242
264
|
C_OPERATOR = {
|
243
265
|
# Unary operators.
|
@@ -586,6 +608,11 @@ module RubyHDL::High
|
|
586
608
|
|
587
609
|
# Convert to C code.
|
588
610
|
alias_method :to_c, :to_ruby
|
611
|
+
|
612
|
+
# Convert to Python.
|
613
|
+
def to_python(l = "")
|
614
|
+
to_ruby
|
615
|
+
end
|
589
616
|
end
|
590
617
|
|
591
618
|
|
@@ -609,6 +636,10 @@ module RubyHDL::High
|
|
609
636
|
return self.to_s
|
610
637
|
end
|
611
638
|
|
639
|
+
def to_python(l = "")
|
640
|
+
return self.to_s
|
641
|
+
end
|
642
|
+
|
612
643
|
# Enhance the Integer class with sequencer iterations.
|
613
644
|
|
614
645
|
# HW times iteration.
|
@@ -640,6 +671,10 @@ module RubyHDL::High
|
|
640
671
|
def to_ruby
|
641
672
|
return "(#{self})"
|
642
673
|
end
|
674
|
+
|
675
|
+
def to_python(l = "")
|
676
|
+
return "range(#{self.first.to_python}, #{self.last.to_python} + 1)"
|
677
|
+
end
|
643
678
|
end
|
644
679
|
|
645
680
|
# Modify Range to support HW iterators.
|
@@ -1058,6 +1093,12 @@ module RubyHDL::High
|
|
1058
1093
|
# By default: 0
|
1059
1094
|
return "0"
|
1060
1095
|
end
|
1096
|
+
|
1097
|
+
# Convert to Python initialization code.
|
1098
|
+
def to_python_init
|
1099
|
+
# By default: 0
|
1100
|
+
return "0"
|
1101
|
+
end
|
1061
1102
|
end
|
1062
1103
|
|
1063
1104
|
|
@@ -1343,6 +1384,17 @@ module RubyHDL::High
|
|
1343
1384
|
return "0"
|
1344
1385
|
end
|
1345
1386
|
end
|
1387
|
+
|
1388
|
+
# Convert to Python initialization code.
|
1389
|
+
def to_python_init
|
1390
|
+
if @base.is_a?(TypeVector) then
|
1391
|
+
# Array type case.
|
1392
|
+
base_init = @base.to_python_init
|
1393
|
+
return "[" + ([base_init] * self.size.to_i).join(",") + "]"
|
1394
|
+
else
|
1395
|
+
return "0"
|
1396
|
+
end
|
1397
|
+
end
|
1346
1398
|
end
|
1347
1399
|
|
1348
1400
|
|
@@ -1767,6 +1819,11 @@ module RubyHDL::High
|
|
1767
1819
|
raise "to_c not defined for class: #{self.class}."
|
1768
1820
|
end
|
1769
1821
|
|
1822
|
+
# Convert to Python code.
|
1823
|
+
def to_python(l = "")
|
1824
|
+
raise "to_python not defined for class: #{self.class}."
|
1825
|
+
end
|
1826
|
+
|
1770
1827
|
# Convert to ruby code for left value.
|
1771
1828
|
# By default: the same as to_ruby
|
1772
1829
|
alias_method :to_ruby_left, :to_ruby
|
@@ -1926,6 +1983,11 @@ module RubyHDL::High
|
|
1926
1983
|
return @content.to_s
|
1927
1984
|
end
|
1928
1985
|
end
|
1986
|
+
|
1987
|
+
# Convert to Python code.
|
1988
|
+
def to_python(l = "")
|
1989
|
+
return @content.to_s
|
1990
|
+
end
|
1929
1991
|
end
|
1930
1992
|
|
1931
1993
|
|
@@ -1950,6 +2012,11 @@ module RubyHDL::High
|
|
1950
2012
|
def to_c
|
1951
2013
|
return C_OPERATOR[@operator] % @child.to_c
|
1952
2014
|
end
|
2015
|
+
|
2016
|
+
# Convert to Python code.
|
2017
|
+
def to_python(l = "")
|
2018
|
+
return PYTHON_OPERATOR[@operator] % { l: @child.to_python }
|
2019
|
+
end
|
1953
2020
|
end
|
1954
2021
|
|
1955
2022
|
# Describes the software implementation of an binary operation.
|
@@ -1984,6 +2051,12 @@ module RubyHDL::High
|
|
1984
2051
|
def to_c
|
1985
2052
|
return C_OPERATOR[@operator] % [ @left.to_c, @right.to_c ]
|
1986
2053
|
end
|
2054
|
+
|
2055
|
+
# Convert to Python code.
|
2056
|
+
def to_python(l = "")
|
2057
|
+
return PYTHON_OPERATOR[@operator] %
|
2058
|
+
{ l: @left.to_python, r: @right.to_python, m: @mask, s: @sign_fix }
|
2059
|
+
end
|
1987
2060
|
end
|
1988
2061
|
|
1989
2062
|
# Describes the software implementation of an select operation.
|
@@ -1998,10 +2071,10 @@ module RubyHDL::High
|
|
1998
2071
|
|
1999
2072
|
# Convert to Ruby code.
|
2000
2073
|
def to_ruby
|
2001
|
-
return "
|
2074
|
+
return @sequencer.clk_up + "\ncase(#{@sel.to_ruby}) ; " +
|
2002
2075
|
@choices.map.with_index do |choice,i|
|
2003
2076
|
"when #{i} ; #{choice.to_ruby} ; "
|
2004
|
-
end.join + "end"
|
2077
|
+
end.join + "end\n" + @sequencer.clk_up
|
2005
2078
|
end
|
2006
2079
|
|
2007
2080
|
# Convert to C code.
|
@@ -2010,7 +2083,18 @@ module RubyHDL::High
|
|
2010
2083
|
# @choices.map.with_index do |choice,i|
|
2011
2084
|
# "case #{i}:\n#{choice.to_c}\nbreak;"
|
2012
2085
|
# end.join("\n") + "\n}"
|
2013
|
-
return
|
2086
|
+
return @sequencer.clk_up_c +
|
2087
|
+
"\n#{@sel.to_c} ? #{@choices[1].to_c} : #{@choices[0].to_c}" +
|
2088
|
+
@sequencer.clk_up_c
|
2089
|
+
end
|
2090
|
+
|
2091
|
+
# Convert to Python code.
|
2092
|
+
def to_python(l = "")
|
2093
|
+
return @sequencer.clk_up_python(l) +
|
2094
|
+
"\n#{l}match #{@sel.to_python}:\n" +
|
2095
|
+
@choices.map.with_index do |choice,i|
|
2096
|
+
"#{l} case #{i}:\n #{choice.to_python(l + " ")}\n"
|
2097
|
+
end.join + @sequencer.clk_up_pyhton(l)
|
2014
2098
|
end
|
2015
2099
|
end
|
2016
2100
|
|
@@ -2051,6 +2135,11 @@ module RubyHDL::High
|
|
2051
2135
|
|
2052
2136
|
# Convert to C code.
|
2053
2137
|
alias_method :to_c, :to_ruby
|
2138
|
+
|
2139
|
+
# Convert to Python code.
|
2140
|
+
def to_python(l = "")
|
2141
|
+
return to_ruby
|
2142
|
+
end
|
2054
2143
|
end
|
2055
2144
|
|
2056
2145
|
# Describes a SW implementation of an index reference.
|
@@ -2115,6 +2204,11 @@ module RubyHDL::High
|
|
2115
2204
|
def to_c
|
2116
2205
|
return "#{@base.to_c}[#{@idx.to_c}]"
|
2117
2206
|
end
|
2207
|
+
|
2208
|
+
# Convert to Python code.
|
2209
|
+
def to_python(l = "")
|
2210
|
+
return "#{@base.to_python}[#{@idx.to_python}]"
|
2211
|
+
end
|
2118
2212
|
end
|
2119
2213
|
|
2120
2214
|
# Describes a SW implementation of an range reference.
|
@@ -2195,6 +2289,11 @@ module RubyHDL::High
|
|
2195
2289
|
return "(#{base} & #{cmask.to_c}) >> (#{@rng.last.to_c})"
|
2196
2290
|
end
|
2197
2291
|
end
|
2292
|
+
|
2293
|
+
# Convert to Python code.
|
2294
|
+
def to_python(l = "")
|
2295
|
+
return "#{@base.to_python}[#{@rng.last.to_python}:#{@rng.first.to_python}]"
|
2296
|
+
end
|
2198
2297
|
end
|
2199
2298
|
|
2200
2299
|
|
@@ -2285,6 +2384,32 @@ module RubyHDL::High
|
|
2285
2384
|
return "#{@left.to_c} = #{@right.to_c};"
|
2286
2385
|
end
|
2287
2386
|
end
|
2387
|
+
|
2388
|
+
# Convert to Python code.
|
2389
|
+
def to_python(l = "")
|
2390
|
+
if (@left.is_a?(RefIndex) or @left.is_a?(RefRange)) then
|
2391
|
+
if @left.base.type.base.is_a?(TypeVector) then
|
2392
|
+
# Assign inside array.
|
2393
|
+
base = @left.final_base.to_python
|
2394
|
+
return "#{l}try:\n#{l} #{base}\n" +
|
2395
|
+
"#{l}except NameError:\n#{l} #{base} = []\n" +
|
2396
|
+
"#{l}#{@left.to_python} = #{@right.to_python}"
|
2397
|
+
else
|
2398
|
+
# Get the access range.
|
2399
|
+
rng = @left.range
|
2400
|
+
# Compute the writing and clearing masks
|
2401
|
+
smask = (1.to_value<<(rng.first+1-rng.last))-1
|
2402
|
+
cmask = ~(smask << rng.last)
|
2403
|
+
# Get the final base.
|
2404
|
+
base = left.final_base.to_ruby
|
2405
|
+
# Generate the ruby code.
|
2406
|
+
return "#{l}#{base} &= #{cmask.to_python}\n" +
|
2407
|
+
"#{l}#{base} |= (((#{@right.to_python} & #{smask.to_python}) << (#{rng.last.to_python})))"
|
2408
|
+
end
|
2409
|
+
else
|
2410
|
+
return "#{l}#{@left.to_python} = #{@right.to_python}"
|
2411
|
+
end
|
2412
|
+
end
|
2288
2413
|
end
|
2289
2414
|
|
2290
2415
|
# Describes a SW implementation of a sif statement.
|
@@ -2357,6 +2482,21 @@ module RubyHDL::High
|
|
2357
2482
|
end
|
2358
2483
|
return res + @sequencer.clk_up_c
|
2359
2484
|
end
|
2485
|
+
|
2486
|
+
# Convert to Python code.
|
2487
|
+
def to_python(l = "")
|
2488
|
+
res = @sequencer.clk_up_python(l) +
|
2489
|
+
"\n#{l}if (#{@condition.to_ruby}) != 0:\n" +
|
2490
|
+
"#{@yes_blk.to_python(l + " ")}\n"
|
2491
|
+
@elsifs.each do |(cond,blk)|
|
2492
|
+
res << "#{l}elif (#{cond.to_python}) != 0:\n" +
|
2493
|
+
"#{blk.to_python(l + " ")}\n"
|
2494
|
+
end
|
2495
|
+
if @else_blk then
|
2496
|
+
res << "#{l}else:\n#{@else_blk.to_python(l + " ")}\n"
|
2497
|
+
end
|
2498
|
+
return res + @sequencer.clk_up_python(l)
|
2499
|
+
end
|
2360
2500
|
end
|
2361
2501
|
|
2362
2502
|
# Describes a SW implementation of a hif statement.
|
@@ -2384,6 +2524,20 @@ module RubyHDL::High
|
|
2384
2524
|
end
|
2385
2525
|
return res
|
2386
2526
|
end
|
2527
|
+
|
2528
|
+
# Convert to Python code.
|
2529
|
+
def to_python(l = "")
|
2530
|
+
res = "#{l}if (#{@condition.to_python}) != 0:\n" +
|
2531
|
+
"#{@yes_blk.to_python(l + " ")}\n"
|
2532
|
+
@elsifs.each do |(cond,blk)|
|
2533
|
+
res << "#{l}elif (#{cond.to_python}) != 0:\n" +
|
2534
|
+
"#{blk.to_python(l + " ")}\n"
|
2535
|
+
end
|
2536
|
+
if @else_blk then
|
2537
|
+
res << "#{l}else:\n#{@else_blk.to_python(l + " ")}\n"
|
2538
|
+
end
|
2539
|
+
return res
|
2540
|
+
end
|
2387
2541
|
end
|
2388
2542
|
|
2389
2543
|
# Describes a SW implementation of a loop statement.
|
@@ -2420,6 +2574,12 @@ module RubyHDL::High
|
|
2420
2574
|
def to_c
|
2421
2575
|
return "for(;;){\n#{@blk.to_ruby}\n#{@sequencer.clk_up_c}\n}"
|
2422
2576
|
end
|
2577
|
+
|
2578
|
+
# Convert to Python code.
|
2579
|
+
def to_python(l = "")
|
2580
|
+
return "#{l}while True:\n#{@blk.to_python(l + " ")}\n" +
|
2581
|
+
@sequencer.clk_up_python(l + " ")
|
2582
|
+
end
|
2423
2583
|
end
|
2424
2584
|
|
2425
2585
|
# Describes a SW implementation of a while statement.
|
@@ -2459,6 +2619,14 @@ module RubyHDL::High
|
|
2459
2619
|
def to_c
|
2460
2620
|
"\nwhile(#{@condition.to_c}) {\n#{@yes_blk.to_c}\n#{@sequencer.clk_up_c}\n}"
|
2461
2621
|
end
|
2622
|
+
|
2623
|
+
# Convert to Python code.
|
2624
|
+
def to_python(l = "")
|
2625
|
+
return @sequencer.clk_up_python(l) +
|
2626
|
+
"\n#{l}while (#{@condition.to_python}) != 0:\n" +
|
2627
|
+
"#{@yes_blk.to_python(l + " ")}\n" +
|
2628
|
+
@sequencer.clk_up_python(l + " ")
|
2629
|
+
end
|
2462
2630
|
end
|
2463
2631
|
|
2464
2632
|
# Describes a SW implementation of a step statement.
|
@@ -2477,6 +2645,11 @@ module RubyHDL::High
|
|
2477
2645
|
def to_c
|
2478
2646
|
return @sequencer.clk_up_c
|
2479
2647
|
end
|
2648
|
+
|
2649
|
+
# Convert to Python code.
|
2650
|
+
def to_python(l = "")
|
2651
|
+
return @sequencer.clk_up_python(l)
|
2652
|
+
end
|
2480
2653
|
end
|
2481
2654
|
|
2482
2655
|
# Describes a SW implementation of a break statement.
|
@@ -2495,6 +2668,11 @@ module RubyHDL::High
|
|
2495
2668
|
def to_c
|
2496
2669
|
return @sequencer.clk_up_c + "\nbreak;"
|
2497
2670
|
end
|
2671
|
+
|
2672
|
+
# Convert to Python code.
|
2673
|
+
def to_python(l = "")
|
2674
|
+
return @sequencer.clk_up_python(l) + "\n#{l}brea;"
|
2675
|
+
end
|
2498
2676
|
end
|
2499
2677
|
|
2500
2678
|
# Describes a SW implementation of a continue statement.
|
@@ -2513,6 +2691,11 @@ module RubyHDL::High
|
|
2513
2691
|
def to_c
|
2514
2692
|
return @sequencer.clk_up_c + "\ncontinue;"
|
2515
2693
|
end
|
2694
|
+
|
2695
|
+
# Convert to Python code.
|
2696
|
+
def to_python(l = "")
|
2697
|
+
return @sequencer.clk_up_python(l) + "\n#{l}continue"
|
2698
|
+
end
|
2516
2699
|
end
|
2517
2700
|
|
2518
2701
|
# Describes a SW implementation of a return statement.
|
@@ -2535,6 +2718,11 @@ module RubyHDL::High
|
|
2535
2718
|
def to_c
|
2536
2719
|
return @sequencer.clk_up_c + "\nreturn #{@value.to_c};"
|
2537
2720
|
end
|
2721
|
+
|
2722
|
+
# Convert to Python code.
|
2723
|
+
def to_python(l = "")
|
2724
|
+
return @sequencer.clk_up_python(l) + "\n#{l}return #{@value.to_c}"
|
2725
|
+
end
|
2538
2726
|
end
|
2539
2727
|
|
2540
2728
|
# Describes a SW implementation of a terminate statement.
|
@@ -2555,6 +2743,11 @@ module RubyHDL::High
|
|
2555
2743
|
def to_c
|
2556
2744
|
return @sequencer.clk_up_c + "\nreturn;"
|
2557
2745
|
end
|
2746
|
+
|
2747
|
+
# Convert to Python code.
|
2748
|
+
def to_python(l = "")
|
2749
|
+
return @sequencer.clk_up_python(l) + "\n#{l}return;"
|
2750
|
+
end
|
2558
2751
|
end
|
2559
2752
|
|
2560
2753
|
# Describes a SW synchronization of a signal.
|
@@ -2583,6 +2776,11 @@ module RubyHDL::High
|
|
2583
2776
|
def to_c
|
2584
2777
|
return "yield();"
|
2585
2778
|
end
|
2779
|
+
|
2780
|
+
# Convert to Python code.
|
2781
|
+
def to_python(l = "")
|
2782
|
+
return "#{l}yield()"
|
2783
|
+
end
|
2586
2784
|
end
|
2587
2785
|
|
2588
2786
|
# Describes arbitrary code.
|
@@ -2645,6 +2843,11 @@ module RubyHDL::High
|
|
2645
2843
|
def to_c
|
2646
2844
|
return "rb_eval_string(\"#{@str.to_s}\");"
|
2647
2845
|
end
|
2846
|
+
|
2847
|
+
# Convert to Python code.
|
2848
|
+
def to_python(l = "")
|
2849
|
+
raise "Ruby objects cannot be converted to Python yet."
|
2850
|
+
end
|
2648
2851
|
end
|
2649
2852
|
|
2650
2853
|
|
@@ -2681,7 +2884,12 @@ module RubyHDL::High
|
|
2681
2884
|
|
2682
2885
|
# Convert to C code.
|
2683
2886
|
def to_c
|
2684
|
-
return "\n__#{@name}(" + @args.map {|arg| arg.
|
2887
|
+
return "\n__#{@name}(" + @args.map {|arg| arg.to_c}.join(",") + ");"
|
2888
|
+
end
|
2889
|
+
|
2890
|
+
# Convert to Python code.
|
2891
|
+
def to_python(l = "")
|
2892
|
+
return "#{l}\n__#{@name}(" + @args.map {|arg| arg.to_python}.join(",") + ")"
|
2685
2893
|
end
|
2686
2894
|
|
2687
2895
|
# Create an iterator for a given method +meth+.
|
@@ -3064,6 +3272,23 @@ module RubyHDL::High
|
|
3064
3272
|
end
|
3065
3273
|
end.join(",") + ");"
|
3066
3274
|
end
|
3275
|
+
|
3276
|
+
# Convert to Python code.
|
3277
|
+
def to_python(l = "")
|
3278
|
+
return "" if @arguments.empty?
|
3279
|
+
res = "#{l}print("
|
3280
|
+
@arguments.each do |arg|
|
3281
|
+
if arg.is_a?(::String) then
|
3282
|
+
res << "\"#{arg}\""
|
3283
|
+
else
|
3284
|
+
res << arg.to_python
|
3285
|
+
end
|
3286
|
+
res << ","
|
3287
|
+
end
|
3288
|
+
res[-1] = ")"
|
3289
|
+
res << "\n"
|
3290
|
+
return res
|
3291
|
+
end
|
3067
3292
|
end
|
3068
3293
|
|
3069
3294
|
|
@@ -3125,6 +3350,13 @@ module RubyHDL::High
|
|
3125
3350
|
return res + "(#{@blk.to_c})"
|
3126
3351
|
end
|
3127
3352
|
|
3353
|
+
# Convert to Python code.
|
3354
|
+
def to_python(l = "")
|
3355
|
+
res = @sequencer.clk_up_python(l) + "\n" +
|
3356
|
+
@commands.map { |command| command.to_python }.join("_")
|
3357
|
+
return res + "(#{@blk.to_python})"
|
3358
|
+
end
|
3359
|
+
|
3128
3360
|
# Create an iterator for a given method +meth+.
|
3129
3361
|
def make_iterator(meth,*args,&ruby_block)
|
3130
3362
|
# if ruby_block then
|
@@ -3504,6 +3736,11 @@ module RubyHDL::High
|
|
3504
3736
|
return "__" + self.name.to_s
|
3505
3737
|
end
|
3506
3738
|
|
3739
|
+
# Convert to Python code.
|
3740
|
+
def to_python(l = "")
|
3741
|
+
return "__" + self.name.to_s
|
3742
|
+
end
|
3743
|
+
|
3507
3744
|
# Check if a value is defined for the signal.
|
3508
3745
|
def value?
|
3509
3746
|
if global? then
|
@@ -3670,6 +3907,16 @@ module RubyHDL::High
|
|
3670
3907
|
return res
|
3671
3908
|
end
|
3672
3909
|
|
3910
|
+
# Convert to Python code.
|
3911
|
+
def to_python(l = "")
|
3912
|
+
res = ""
|
3913
|
+
# Generate the statements.
|
3914
|
+
res += @statements.map do |stmnt|
|
3915
|
+
stmnt.to_python(l) + "\n"
|
3916
|
+
end.join
|
3917
|
+
return res
|
3918
|
+
end
|
3919
|
+
|
3673
3920
|
# The interface for describing statements and expressions.
|
3674
3921
|
|
3675
3922
|
# Mark a step.
|
@@ -3818,6 +4065,11 @@ module RubyHDL::High
|
|
3818
4065
|
def to_c
|
3819
4066
|
return "unsigned long long __#{name}(#{@args.map {|arg| "unsigned long long __" + arg.to_c}.join(",")}) {\n#{@blk.sequencer.clk_up_c}\n#{@blk.to_c}\n}\n"
|
3820
4067
|
end
|
4068
|
+
|
4069
|
+
# Convert to Python code.
|
4070
|
+
def to_python(l = "")
|
4071
|
+
return "#{l}def __#{name}(#{@args.map {|arg| "__" + arg.to_ruby}.join(",")}):\n#{@blk.sequencer.clk_python(l + " ")}\n#{@blk.to_python(l + " ")}\n"
|
4072
|
+
end
|
3821
4073
|
end
|
3822
4074
|
|
3823
4075
|
|
@@ -3932,6 +4184,46 @@ BUILDC
|
|
3932
4184
|
return res
|
3933
4185
|
end
|
3934
4186
|
|
4187
|
+
# Convert to Python code.
|
4188
|
+
def to_python(l = "")
|
4189
|
+
typ = nil
|
4190
|
+
res = <<-BUILDPYTHON
|
4191
|
+
#{RubyHDL::High.global_sblock.each_signal.map do |signal|
|
4192
|
+
typ = signal.type
|
4193
|
+
if signal.value? then
|
4194
|
+
if signal.array? then
|
4195
|
+
res = signal.to_python + "= [0] * #{signal.type.range.size}"
|
4196
|
+
signal.value.each_with_index do |v,i|
|
4197
|
+
res += "\n" + signal.to_python + "[#{i}=#{v.to_python}]"
|
4198
|
+
end
|
4199
|
+
res
|
4200
|
+
else
|
4201
|
+
signal.to_python + "=" + signal.value.inspect
|
4202
|
+
end
|
4203
|
+
else
|
4204
|
+
if signal.array? then
|
4205
|
+
signal.to_python + " = " + typ.to_python_init
|
4206
|
+
else
|
4207
|
+
signal.to_python + "=" + typ.to_python_init
|
4208
|
+
end
|
4209
|
+
end
|
4210
|
+
end.join("\n")}
|
4211
|
+
|
4212
|
+
#{@sfunctions.map {|n,f| f.to_c }.join("\n\n")}
|
4213
|
+
|
4214
|
+
def sequencer():
|
4215
|
+
#{RubyHDL::High.global_sblock.each_signal.map do |signal|
|
4216
|
+
" global #{signal.to_python}"
|
4217
|
+
end.join("\n")}
|
4218
|
+
#{@blk.to_python(" ")}
|
4219
|
+
BUILDPYTHON
|
4220
|
+
return res
|
4221
|
+
end
|
4222
|
+
|
4223
|
+
|
4224
|
+
|
4225
|
+
|
4226
|
+
|
3935
4227
|
# Handling of the clock if any.
|
3936
4228
|
|
3937
4229
|
# Generate a clock up of +count+ cycles if any clock.
|
@@ -3952,6 +4244,15 @@ BUILDC
|
|
3952
4244
|
end
|
3953
4245
|
end
|
3954
4246
|
|
4247
|
+
# Generate a clock up of +count+ cycles if any clock.
|
4248
|
+
def clk_up_python(l="", count = 1)
|
4249
|
+
if @clk then
|
4250
|
+
return "#{l}#{clk.to_python} += #{count.to_i}"
|
4251
|
+
else
|
4252
|
+
return ""
|
4253
|
+
end
|
4254
|
+
end
|
4255
|
+
|
3955
4256
|
|
3956
4257
|
# Control of the sequencer.
|
3957
4258
|
|
data/lib/HDLRuby/std/std.rb
CHANGED
data/lib/HDLRuby/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: HDLRuby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.7.
|
4
|
+
version: 3.7.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lovic Gauthier
|
@@ -215,6 +215,7 @@ files:
|
|
215
215
|
- lib/HDLRuby/hdr_samples/with_function_generator.rb
|
216
216
|
- lib/HDLRuby/hdr_samples/with_generic_in_generic.rb
|
217
217
|
- lib/HDLRuby/hdr_samples/with_handshake.rb
|
218
|
+
- lib/HDLRuby/hdr_samples/with_henumerable.rb
|
218
219
|
- lib/HDLRuby/hdr_samples/with_init.rb
|
219
220
|
- lib/HDLRuby/hdr_samples/with_instance.rb
|
220
221
|
- lib/HDLRuby/hdr_samples/with_leftright.rb
|
@@ -413,6 +414,7 @@ files:
|
|
413
414
|
- lib/HDLRuby/std/fsm.rb
|
414
415
|
- lib/HDLRuby/std/function_generator.rb
|
415
416
|
- lib/HDLRuby/std/handshakes.rb
|
417
|
+
- lib/HDLRuby/std/hruby_enum.rb
|
416
418
|
- lib/HDLRuby/std/hruby_unit.rb
|
417
419
|
- lib/HDLRuby/std/linear.rb
|
418
420
|
- lib/HDLRuby/std/loop.rb
|