HDLRuby 2.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +5 -0
- data/.yardopts +1 -0
- data/Gemfile +4 -0
- data/HDLRuby.gemspec +36 -0
- data/LICENSE.txt +21 -0
- data/README.md +2774 -0
- data/README.pdf +0 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/hdrcc +3 -0
- data/lib/HDLRuby/alcc.rb +137 -0
- data/lib/HDLRuby/backend/hruby_allocator.rb +69 -0
- data/lib/HDLRuby/backend/hruby_c_allocator.rb +76 -0
- data/lib/HDLRuby/hdr_samples/adder.rb +7 -0
- data/lib/HDLRuby/hdr_samples/adder_assign_error.rb +11 -0
- data/lib/HDLRuby/hdr_samples/adder_bench.rb +27 -0
- data/lib/HDLRuby/hdr_samples/adder_gen.rb +7 -0
- data/lib/HDLRuby/hdr_samples/adder_nodef_error.rb +7 -0
- data/lib/HDLRuby/hdr_samples/addsub.rb +19 -0
- data/lib/HDLRuby/hdr_samples/addsubz.rb +22 -0
- data/lib/HDLRuby/hdr_samples/alu.rb +47 -0
- data/lib/HDLRuby/hdr_samples/calculator.rb +48 -0
- data/lib/HDLRuby/hdr_samples/counter_bench.rb +83 -0
- data/lib/HDLRuby/hdr_samples/dff.rb +9 -0
- data/lib/HDLRuby/hdr_samples/dff_bench.rb +66 -0
- data/lib/HDLRuby/hdr_samples/dff_counter.rb +20 -0
- data/lib/HDLRuby/hdr_samples/include.rb +14 -0
- data/lib/HDLRuby/hdr_samples/instance_open.rb +23 -0
- data/lib/HDLRuby/hdr_samples/mei8.rb +256 -0
- data/lib/HDLRuby/hdr_samples/mei8_bench.rb +309 -0
- data/lib/HDLRuby/hdr_samples/multer_gen.rb +8 -0
- data/lib/HDLRuby/hdr_samples/multer_seq.rb +29 -0
- data/lib/HDLRuby/hdr_samples/neural/a.rb +9 -0
- data/lib/HDLRuby/hdr_samples/neural/a_sub.rb +5 -0
- data/lib/HDLRuby/hdr_samples/neural/bw.rb +23 -0
- data/lib/HDLRuby/hdr_samples/neural/counter.rb +16 -0
- data/lib/HDLRuby/hdr_samples/neural/dadz.rb +9 -0
- data/lib/HDLRuby/hdr_samples/neural/dadz_sub.rb +4 -0
- data/lib/HDLRuby/hdr_samples/neural/forward.rb +153 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub.rb +62 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand.rb +41 -0
- data/lib/HDLRuby/hdr_samples/neural/forward_sub_rand_typedef.rb +47 -0
- data/lib/HDLRuby/hdr_samples/neural/mem.rb +30 -0
- data/lib/HDLRuby/hdr_samples/neural/random.rb +23 -0
- data/lib/HDLRuby/hdr_samples/neural/selector.rb +29 -0
- data/lib/HDLRuby/hdr_samples/neural/sigmoid.rb +20 -0
- data/lib/HDLRuby/hdr_samples/neural/z.rb +33 -0
- data/lib/HDLRuby/hdr_samples/prog.obj +256 -0
- data/lib/HDLRuby/hdr_samples/ram.rb +18 -0
- data/lib/HDLRuby/hdr_samples/register_with_code_bench.rb +98 -0
- data/lib/HDLRuby/hdr_samples/rom.rb +10 -0
- data/lib/HDLRuby/hdr_samples/struct.rb +14 -0
- data/lib/HDLRuby/hdr_samples/sumprod.rb +29 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_bench.rb +103 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_cpu_bench.rb +261 -0
- data/lib/HDLRuby/hdr_samples/sw_encrypt_cpusim_bench.rb +302 -0
- data/lib/HDLRuby/hdr_samples/system_open.rb +11 -0
- data/lib/HDLRuby/hdr_samples/tuple.rb +16 -0
- data/lib/HDLRuby/hdr_samples/with_channel.rb +118 -0
- data/lib/HDLRuby/hdr_samples/with_class.rb +199 -0
- data/lib/HDLRuby/hdr_samples/with_decoder.rb +17 -0
- data/lib/HDLRuby/hdr_samples/with_fsm.rb +34 -0
- data/lib/HDLRuby/hdr_samples/with_reconf.rb +103 -0
- data/lib/HDLRuby/hdrcc.rb +623 -0
- data/lib/HDLRuby/high_samples/_adder_fault.rb +23 -0
- data/lib/HDLRuby/high_samples/_generic_transmission2.rb +146 -0
- data/lib/HDLRuby/high_samples/adder.rb +21 -0
- data/lib/HDLRuby/high_samples/adder_common_errors.rb +25 -0
- data/lib/HDLRuby/high_samples/addsub.rb +33 -0
- data/lib/HDLRuby/high_samples/addsubz.rb +37 -0
- data/lib/HDLRuby/high_samples/after.rb +28 -0
- data/lib/HDLRuby/high_samples/all_signals.rb +29 -0
- data/lib/HDLRuby/high_samples/alu.rb +61 -0
- data/lib/HDLRuby/high_samples/anonymous.rb +41 -0
- data/lib/HDLRuby/high_samples/before.rb +28 -0
- data/lib/HDLRuby/high_samples/blockblock.rb +26 -0
- data/lib/HDLRuby/high_samples/bugs/dadz.rb +22 -0
- data/lib/HDLRuby/high_samples/bugs/misample_instan.rb +20 -0
- data/lib/HDLRuby/high_samples/bugs/misample_updown.rb +22 -0
- data/lib/HDLRuby/high_samples/bugs/sample_add.rb +16 -0
- data/lib/HDLRuby/high_samples/bugs/sample_barrel.rb +13 -0
- data/lib/HDLRuby/high_samples/bugs/sample_daice.rb +57 -0
- data/lib/HDLRuby/high_samples/bugs/sample_kumiawase.rb +52 -0
- data/lib/HDLRuby/high_samples/bugs/sample_multi.rb +18 -0
- data/lib/HDLRuby/high_samples/bugs/sample_sub.rb +14 -0
- data/lib/HDLRuby/high_samples/bugs/z2.rb +32 -0
- data/lib/HDLRuby/high_samples/case.rb +32 -0
- data/lib/HDLRuby/high_samples/case2.rb +30 -0
- data/lib/HDLRuby/high_samples/change.rb +23 -0
- data/lib/HDLRuby/high_samples/clocks.rb +35 -0
- data/lib/HDLRuby/high_samples/comparer.rb +21 -0
- data/lib/HDLRuby/high_samples/conditionals.rb +29 -0
- data/lib/HDLRuby/high_samples/dff.rb +23 -0
- data/lib/HDLRuby/high_samples/each.rb +28 -0
- data/lib/HDLRuby/high_samples/exporter.rb +42 -0
- data/lib/HDLRuby/high_samples/functions.rb +60 -0
- data/lib/HDLRuby/high_samples/if_seq.rb +26 -0
- data/lib/HDLRuby/high_samples/inherit_as_dff.rb +32 -0
- data/lib/HDLRuby/high_samples/inherit_dff.rb +36 -0
- data/lib/HDLRuby/high_samples/instance.rb +37 -0
- data/lib/HDLRuby/high_samples/memory.rb +64 -0
- data/lib/HDLRuby/high_samples/multi_file.rb +27 -0
- data/lib/HDLRuby/high_samples/overload.rb +32 -0
- data/lib/HDLRuby/high_samples/paper_after.rb +49 -0
- data/lib/HDLRuby/high_samples/ram.rb +27 -0
- data/lib/HDLRuby/high_samples/registers.rb +139 -0
- data/lib/HDLRuby/high_samples/rom.rb +23 -0
- data/lib/HDLRuby/high_samples/scopeblockname.rb +37 -0
- data/lib/HDLRuby/high_samples/scopescope.rb +26 -0
- data/lib/HDLRuby/high_samples/shift.rb +31 -0
- data/lib/HDLRuby/high_samples/shift2.rb +40 -0
- data/lib/HDLRuby/high_samples/simple_instance.rb +31 -0
- data/lib/HDLRuby/high_samples/test_all.sh +10 -0
- data/lib/HDLRuby/high_samples/typedef.rb +24 -0
- data/lib/HDLRuby/high_samples/values.rb +70 -0
- data/lib/HDLRuby/high_samples/vector.rb +22 -0
- data/lib/HDLRuby/high_samples/with_decoder.rb +30 -0
- data/lib/HDLRuby/high_samples/with_fsm.rb +46 -0
- data/lib/HDLRuby/high_samples/with_pipe.rb +43 -0
- data/lib/HDLRuby/high_samples/with_seq.rb +25 -0
- data/lib/HDLRuby/hruby_bstr.rb +1085 -0
- data/lib/HDLRuby/hruby_check.rb +317 -0
- data/lib/HDLRuby/hruby_db.rb +432 -0
- data/lib/HDLRuby/hruby_error.rb +44 -0
- data/lib/HDLRuby/hruby_high.rb +4103 -0
- data/lib/HDLRuby/hruby_low.rb +4735 -0
- data/lib/HDLRuby/hruby_low2c.rb +1986 -0
- data/lib/HDLRuby/hruby_low2high.rb +738 -0
- data/lib/HDLRuby/hruby_low2seq.rb +248 -0
- data/lib/HDLRuby/hruby_low2sym.rb +126 -0
- data/lib/HDLRuby/hruby_low2vhd.rb +1437 -0
- data/lib/HDLRuby/hruby_low_bool2select.rb +295 -0
- data/lib/HDLRuby/hruby_low_cleanup.rb +193 -0
- data/lib/HDLRuby/hruby_low_fix_types.rb +437 -0
- data/lib/HDLRuby/hruby_low_mutable.rb +1803 -0
- data/lib/HDLRuby/hruby_low_resolve.rb +165 -0
- data/lib/HDLRuby/hruby_low_skeleton.rb +129 -0
- data/lib/HDLRuby/hruby_low_with_bool.rb +141 -0
- data/lib/HDLRuby/hruby_low_with_port.rb +167 -0
- data/lib/HDLRuby/hruby_low_with_var.rb +302 -0
- data/lib/HDLRuby/hruby_low_without_bit2vector.rb +88 -0
- data/lib/HDLRuby/hruby_low_without_concat.rb +162 -0
- data/lib/HDLRuby/hruby_low_without_connection.rb +113 -0
- data/lib/HDLRuby/hruby_low_without_namespace.rb +718 -0
- data/lib/HDLRuby/hruby_low_without_outread.rb +107 -0
- data/lib/HDLRuby/hruby_low_without_select.rb +206 -0
- data/lib/HDLRuby/hruby_serializer.rb +398 -0
- data/lib/HDLRuby/hruby_tools.rb +37 -0
- data/lib/HDLRuby/hruby_types.rb +239 -0
- data/lib/HDLRuby/hruby_values.rb +64 -0
- data/lib/HDLRuby/hruby_verilog.rb +1888 -0
- data/lib/HDLRuby/hruby_verilog_name.rb +52 -0
- data/lib/HDLRuby/low_samples/adder.yaml +97 -0
- data/lib/HDLRuby/low_samples/after.yaml +228 -0
- data/lib/HDLRuby/low_samples/before.yaml +223 -0
- data/lib/HDLRuby/low_samples/blockblock.yaml +48 -0
- data/lib/HDLRuby/low_samples/bugs/sample_add.yaml +97 -0
- data/lib/HDLRuby/low_samples/bugs/sample_daice.yaml +444 -0
- data/lib/HDLRuby/low_samples/bugs/sample_kumiawase.yaml +332 -0
- data/lib/HDLRuby/low_samples/bugs/sample_sub.yaml +97 -0
- data/lib/HDLRuby/low_samples/bugs/seqpar.yaml +184 -0
- data/lib/HDLRuby/low_samples/case.yaml +327 -0
- data/lib/HDLRuby/low_samples/change.yaml +135 -0
- data/lib/HDLRuby/low_samples/clocks.yaml +674 -0
- data/lib/HDLRuby/low_samples/cloner.rb +22 -0
- data/lib/HDLRuby/low_samples/comparer.yaml +85 -0
- data/lib/HDLRuby/low_samples/conditionals.yaml +133 -0
- data/lib/HDLRuby/low_samples/dff.yaml +107 -0
- data/lib/HDLRuby/low_samples/each.yaml +1328 -0
- data/lib/HDLRuby/low_samples/exporter.yaml +226 -0
- data/lib/HDLRuby/low_samples/functions.yaml +298 -0
- data/lib/HDLRuby/low_samples/generic_transmission.yaml +597 -0
- data/lib/HDLRuby/low_samples/inherit_as_dff.yaml +125 -0
- data/lib/HDLRuby/low_samples/inherit_dff.yaml +107 -0
- data/lib/HDLRuby/low_samples/load_yaml.rb +11 -0
- data/lib/HDLRuby/low_samples/memory.yaml +678 -0
- data/lib/HDLRuby/low_samples/namespace_extractor.rb +23 -0
- data/lib/HDLRuby/low_samples/overload.yaml +226 -0
- data/lib/HDLRuby/low_samples/paper_after.yaml +431 -0
- data/lib/HDLRuby/low_samples/port_maker.rb +14 -0
- data/lib/HDLRuby/low_samples/ram.yaml +207 -0
- data/lib/HDLRuby/low_samples/registers.yaml +228 -0
- data/lib/HDLRuby/low_samples/rom.yaml +2950 -0
- data/lib/HDLRuby/low_samples/shift.yaml +230 -0
- data/lib/HDLRuby/low_samples/shift2.yaml +2095 -0
- data/lib/HDLRuby/low_samples/simple_instance.yaml +102 -0
- data/lib/HDLRuby/low_samples/test_all.sh +43 -0
- data/lib/HDLRuby/low_samples/typedef.yaml +115 -0
- data/lib/HDLRuby/low_samples/values.yaml +577 -0
- data/lib/HDLRuby/low_samples/variable_maker.rb +14 -0
- data/lib/HDLRuby/low_samples/vector.yaml +56 -0
- data/lib/HDLRuby/low_samples/with_seq.yaml +188 -0
- data/lib/HDLRuby/low_samples/yaml2hdr.rb +10 -0
- data/lib/HDLRuby/low_samples/yaml2vhd.rb +19 -0
- data/lib/HDLRuby/sim/Makefile +19 -0
- data/lib/HDLRuby/sim/hruby_sim.h +590 -0
- data/lib/HDLRuby/sim/hruby_sim_calc.c +2362 -0
- data/lib/HDLRuby/sim/hruby_sim_core.c +589 -0
- data/lib/HDLRuby/sim/hruby_sim_list.c +93 -0
- data/lib/HDLRuby/sim/hruby_sim_vizualize.c +91 -0
- data/lib/HDLRuby/sim/hruby_value_pool.c +64 -0
- data/lib/HDLRuby/std/channel.rb +354 -0
- data/lib/HDLRuby/std/clocks.rb +165 -0
- data/lib/HDLRuby/std/counters.rb +82 -0
- data/lib/HDLRuby/std/decoder.rb +214 -0
- data/lib/HDLRuby/std/fsm.rb +516 -0
- data/lib/HDLRuby/std/pipeline.rb +220 -0
- data/lib/HDLRuby/std/reconf.rb +309 -0
- data/lib/HDLRuby/test_hruby_bstr.rb +2259 -0
- data/lib/HDLRuby/test_hruby_high.rb +594 -0
- data/lib/HDLRuby/test_hruby_high_low.rb +99 -0
- data/lib/HDLRuby/test_hruby_low.rb +934 -0
- data/lib/HDLRuby/v_samples/adder.v +10 -0
- data/lib/HDLRuby/v_samples/dff.v +12 -0
- data/lib/HDLRuby/v_samples/ram.v +20 -0
- data/lib/HDLRuby/v_samples/rom.v +270 -0
- data/lib/HDLRuby/version.rb +3 -0
- data/lib/HDLRuby.rb +11 -0
- data/makedoc +1 -0
- data/metadata.yaml +4 -0
- metadata +299 -0
data/README.pdf
ADDED
Binary file
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "HDLRuby"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/hdrcc
ADDED
data/lib/HDLRuby/alcc.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
|
5
|
+
|
6
|
+
##
|
7
|
+
# Front-end to the Alliance tool chain for hdrcc vhdl results
|
8
|
+
##############################################################
|
9
|
+
|
10
|
+
if $*.include?("--clean") then
|
11
|
+
# Clean mode.
|
12
|
+
`rm *.vbe *.vst *.xsc *.ap`
|
13
|
+
exit
|
14
|
+
end
|
15
|
+
|
16
|
+
######################################################
|
17
|
+
# Initialization phase
|
18
|
+
#
|
19
|
+
# Process the options.
|
20
|
+
# For now there should only be the name of the main file.
|
21
|
+
$input = $*[0]
|
22
|
+
|
23
|
+
# Get the extension name, the base name and the path from the main file.
|
24
|
+
$extname = File.extname($input)
|
25
|
+
$basename = File.basename($input,$extname)
|
26
|
+
$path = File.dirname($input)
|
27
|
+
$fullname = $basename + $extname
|
28
|
+
|
29
|
+
# Go the the target directory.
|
30
|
+
Dir.chdir($path)
|
31
|
+
|
32
|
+
# Gather the files other than the main to treat.
|
33
|
+
$subfiles = Dir.foreach("./").select do |name|
|
34
|
+
File.extname(name) == $extname && name != $fullname
|
35
|
+
end
|
36
|
+
# And the all files to treat.
|
37
|
+
$allfiles = [$fullname] + $subfiles
|
38
|
+
|
39
|
+
# Generate the base names for the sub files.
|
40
|
+
# $subbases = $subfiles.map {|file| File.basename(file,$extname) }
|
41
|
+
# $basename_model = $basename + "_model"
|
42
|
+
# $subbases =[ $basename_model ] + $subbases
|
43
|
+
$allbases = $allfiles.map {|file| File.basename(file,$extname) }
|
44
|
+
|
45
|
+
######################################################
|
46
|
+
# Compiling steps
|
47
|
+
|
48
|
+
# Conversion to alliance format.
|
49
|
+
$allfiles.each do |file|
|
50
|
+
cmd = "vasy -Vaop -I vhd #{file}"
|
51
|
+
puts cmd
|
52
|
+
`#{cmd}`
|
53
|
+
end
|
54
|
+
|
55
|
+
# # Check if there is a model have been generated.
|
56
|
+
# unless File.file?($basename_model + ".vbe") then
|
57
|
+
# # No model, single file case.
|
58
|
+
# $subbases = [ $basename ]
|
59
|
+
# end
|
60
|
+
|
61
|
+
# puts "$subbases=#{$subbases}"
|
62
|
+
|
63
|
+
# Boolean minimisation.
|
64
|
+
# $subbases.each do |base|
|
65
|
+
$allbases.each do |base|
|
66
|
+
if File.file?("#{base}.vbe") then
|
67
|
+
cmd = "boom -l 3 -d 50 #{base}.vbe"
|
68
|
+
puts cmd
|
69
|
+
`#{cmd}`
|
70
|
+
end
|
71
|
+
if File.file?("#{base}_model.vbe") then
|
72
|
+
cmd = "boom -l 3 -d 50 #{base}_model.vbe"
|
73
|
+
puts cmd
|
74
|
+
`#{cmd}`
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Structureal description generation.
|
79
|
+
# $subbases.each do |base|
|
80
|
+
$allbases.each do |base|
|
81
|
+
if File.file?("#{base}.vbe") then
|
82
|
+
cmd = "boog #{base}_o #{base} -x 1 -m 2"
|
83
|
+
puts cmd
|
84
|
+
`#{cmd}`
|
85
|
+
end
|
86
|
+
if File.file?("#{base}_model.vbe") then
|
87
|
+
cmd = "boog #{base}_model_o #{base}_model -x 1 -m 2"
|
88
|
+
puts cmd
|
89
|
+
`#{cmd}`
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
# Flattening and global optimization.
|
94
|
+
cmd = "loon #{$basename} #{$basename}_l -x 0 -m 0"
|
95
|
+
puts cmd
|
96
|
+
`#{cmd}`
|
97
|
+
|
98
|
+
# Placement.
|
99
|
+
cmd = "ocp #{$basename}_l #{$basename}_p"
|
100
|
+
puts cmd
|
101
|
+
`#{cmd}`
|
102
|
+
|
103
|
+
# Route.
|
104
|
+
cmd = "nero -V -G -6 -p #{$basename}_p #{$basename}_l #{$basename}_r"
|
105
|
+
puts cmd
|
106
|
+
`#{cmd}`
|
107
|
+
|
108
|
+
# Technology mapping.
|
109
|
+
cmd = "s2r -v #{$basename}_r #{$basename}_core"
|
110
|
+
puts cmd
|
111
|
+
`#{cmd}`
|
112
|
+
|
113
|
+
|
114
|
+
## Other tools
|
115
|
+
#
|
116
|
+
# Simulation:
|
117
|
+
# `asimut #{$basename}_l #{$basename}_in #{$basename}_out`
|
118
|
+
#
|
119
|
+
# View simulation result:
|
120
|
+
# `xpat -l #{basename}_out`
|
121
|
+
#
|
122
|
+
# View P&R result:
|
123
|
+
# `graal`
|
124
|
+
#
|
125
|
+
# Extract netlist:
|
126
|
+
# `cougar #{$basename}_r #{$basename}_c`
|
127
|
+
#
|
128
|
+
# Check P&R result:
|
129
|
+
# `lvx vst al #{$basename} #{$basename}_c` or
|
130
|
+
# `lvx vst vst #{$basename} #{$basename}_c`
|
131
|
+
#
|
132
|
+
# DRC check:
|
133
|
+
# `druc #{$basename}_r`
|
134
|
+
#
|
135
|
+
# View techno mapping result:
|
136
|
+
# `dreal -l #{$basename}_core`
|
137
|
+
#
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "HDLRuby/hruby_error"
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
##
|
6
|
+
# Adds methods for allocating addresses to signals in Code objects.
|
7
|
+
#
|
8
|
+
########################################################################
|
9
|
+
module HDLRuby::Low
|
10
|
+
|
11
|
+
## An allocator.
|
12
|
+
class Allocator
|
13
|
+
|
14
|
+
# The space range for the allocation.
|
15
|
+
attr_reader :range
|
16
|
+
|
17
|
+
# The word size.
|
18
|
+
attr_reader :word
|
19
|
+
|
20
|
+
## Creates a new allocator within +range+ memory space whose word
|
21
|
+
# size is +word+.
|
22
|
+
def initialize(range, word = 8)
|
23
|
+
# Check and set the range.
|
24
|
+
first = range.first.to_i
|
25
|
+
last = range.last.to_i
|
26
|
+
@range = first < last ? first..last : last..first
|
27
|
+
# Check and set the word size.
|
28
|
+
@word = word.to_i
|
29
|
+
# Initialize the allocation counter.
|
30
|
+
@head = first
|
31
|
+
# Initialize the allocation table.
|
32
|
+
@table = {}
|
33
|
+
end
|
34
|
+
|
35
|
+
## Allocates space for +signal+.
|
36
|
+
# NOTE: if the signal is already allocated, returns the previous
|
37
|
+
# allocation result.
|
38
|
+
def allocate(signal)
|
39
|
+
# Has the signal been already allocated?
|
40
|
+
if @table.key?(signal) then
|
41
|
+
# Yes return the allocation result.
|
42
|
+
return @table[signal]
|
43
|
+
end
|
44
|
+
# Get the size to allocate in word.
|
45
|
+
size = signal.type.width / @word
|
46
|
+
size += 1 unless signal.type.width % word == 0
|
47
|
+
# Is there any room left?
|
48
|
+
if @head + size > @range.last then
|
49
|
+
raise AnyError, "Address range overflow."
|
50
|
+
end
|
51
|
+
# Ok, performs the allocation.
|
52
|
+
res = @head
|
53
|
+
@head += size
|
54
|
+
@table[signal] = res
|
55
|
+
return res
|
56
|
+
end
|
57
|
+
|
58
|
+
## Get the address of +signal+ if allocated.
|
59
|
+
def get(signal)
|
60
|
+
return @table[signal]
|
61
|
+
end
|
62
|
+
|
63
|
+
## Iterate over the allocated signals and their corresponding address.
|
64
|
+
def each
|
65
|
+
@table.each
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require "HDLRuby/hruby_error"
|
2
|
+
require "HDLRuby/hruby_low_resolve"
|
3
|
+
require "HDLRuby/backend/hruby_allocator"
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
##
|
8
|
+
# Adds methods for allocating addresses to signals in Code objects and
|
9
|
+
# integrate the result into C code.
|
10
|
+
#
|
11
|
+
########################################################################
|
12
|
+
module HDLRuby::Low
|
13
|
+
|
14
|
+
## Extends the SystemT class with support for C allocation of signals.
|
15
|
+
class SystemT
|
16
|
+
|
17
|
+
## Allocates signals within C code using +allocator+.
|
18
|
+
def c_code_allocate(allocator)
|
19
|
+
self.scope.c_code_allocate(allocator)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
## Extends the scope class with support for C allocation of signals.
|
25
|
+
class Scope
|
26
|
+
|
27
|
+
## Allocates signals within C code using +allocator+.
|
28
|
+
def c_code_allocate(allocator)
|
29
|
+
# Interrate on the sub scopes.
|
30
|
+
self.each_scope { |scope| scope.c_code_allocate(allocator) }
|
31
|
+
# Ally thr allocator on the codes.
|
32
|
+
self.each_code { |code| code.c_code_allocate(allocator) }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
## Extends the chunk class with support for self modification with
|
38
|
+
# allocation.
|
39
|
+
# NOTE: only work if the chunk is in C language.
|
40
|
+
class Chunk
|
41
|
+
|
42
|
+
## Allocates signal within C code using +allocator+ and self-modify
|
43
|
+
# the code correspondingly.
|
44
|
+
# NOTE: non-C chunks are ignored.
|
45
|
+
def c_code_allocate!(allocator)
|
46
|
+
# Checks the chunk is actually C.
|
47
|
+
return self unless self.name == :c
|
48
|
+
# Process each lump.
|
49
|
+
@lumps.map! do |lump|
|
50
|
+
lump_r = lump.resolve if lump.respond_to?(:resolve)
|
51
|
+
if lump_r.is_a?(SignalI) then
|
52
|
+
# The lump is a signal, performs the allocation and
|
53
|
+
# change it to an address access.
|
54
|
+
"*(0x#{allocator.allocate(lump_r).to_s(16)})"
|
55
|
+
else
|
56
|
+
lump
|
57
|
+
end
|
58
|
+
end
|
59
|
+
self
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
## Extends the code class with support for C allocation of signals.
|
65
|
+
class Code
|
66
|
+
|
67
|
+
## Allocates signals within C code using +allocator+.
|
68
|
+
def c_code_allocate(allocator)
|
69
|
+
# Apply the allocator on each C chunk.
|
70
|
+
self.each_chunk do |chunk|
|
71
|
+
chunk.c_code_allocate!(allocator) if chunk.name == :c
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# A simple 16-bit adder
|
2
|
+
system :adder do
|
3
|
+
[15..0].input :x,:y
|
4
|
+
[16..0].output :s
|
5
|
+
|
6
|
+
s <= x + y
|
7
|
+
end
|
8
|
+
|
9
|
+
# A benchmark for the adder.
|
10
|
+
system :adder_bench do
|
11
|
+
[15..0].inner :x,:y
|
12
|
+
[16..0].inner :s
|
13
|
+
|
14
|
+
adder(:my_adder).(x,y,s)
|
15
|
+
|
16
|
+
timed do
|
17
|
+
x <= 0
|
18
|
+
y <= 0
|
19
|
+
!10.ns
|
20
|
+
x <= 1
|
21
|
+
y <= _zzzzzzzzzzzzzzzz
|
22
|
+
!10.ns
|
23
|
+
x <= 2
|
24
|
+
y <= 1
|
25
|
+
!10.ns
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# An adder-suber
|
2
|
+
system :addsub do
|
3
|
+
input :opr
|
4
|
+
[15..0].input :x,:y
|
5
|
+
[16..0].output :s
|
6
|
+
|
7
|
+
# The only adder instance.
|
8
|
+
instance :add do
|
9
|
+
[15..0].input :x,:y
|
10
|
+
input :cin
|
11
|
+
[16..0].output :s
|
12
|
+
|
13
|
+
s <= x+y+cin
|
14
|
+
end
|
15
|
+
|
16
|
+
# Control part for choosing between add and sub.
|
17
|
+
hif(opr) { add.(x,~y,1,s) }
|
18
|
+
helse { add.(x,y,0,s) }
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# An extended adder-suber
|
2
|
+
system :addsubz do
|
3
|
+
[1..0].input :opr
|
4
|
+
[15..0].input :x,:y
|
5
|
+
[16..0].output :s
|
6
|
+
|
7
|
+
# The only adder instance.
|
8
|
+
instance :add do
|
9
|
+
[15..0].input :x,:y
|
10
|
+
input :cin
|
11
|
+
[16..0].output :s
|
12
|
+
|
13
|
+
s <= x+y+cin
|
14
|
+
end
|
15
|
+
|
16
|
+
# The control part for choosing between 0, add, sub and neg.
|
17
|
+
hcase(opr)
|
18
|
+
hwhen(0) { add.(0,0,0,s) }
|
19
|
+
hwhen(1) { add.(x,y,0,s) }
|
20
|
+
hwhen(2) { add.(x,~y,1,s) }
|
21
|
+
helse { add.(0,~y,1,s) }
|
22
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# A simple ALU
|
2
|
+
system :alu do
|
3
|
+
[4].input :opr
|
4
|
+
[16].input :x,:y
|
5
|
+
[16].output :s
|
6
|
+
output :zf, :cf, :sf, :vf
|
7
|
+
|
8
|
+
# The only adder instance.
|
9
|
+
instance :add do
|
10
|
+
[16].input :x,:y
|
11
|
+
input :cin
|
12
|
+
[17].output :s
|
13
|
+
|
14
|
+
s <= x+y+cin
|
15
|
+
end
|
16
|
+
|
17
|
+
# The control part for choosing between 0, add, sub and neg.
|
18
|
+
par do
|
19
|
+
# The main computation: s and cf
|
20
|
+
# Default connections
|
21
|
+
cf <= 0
|
22
|
+
vf <= 0
|
23
|
+
add.(0,0,0)
|
24
|
+
# Depending on the operator
|
25
|
+
hcase(opr)
|
26
|
+
hwhen(1) { s <= x }
|
27
|
+
hwhen(2) { s <= y }
|
28
|
+
hwhen(3) { add.(x ,y ,0,[cf,s])
|
29
|
+
vf <= (~x[15] & ~y[15] & s[15]) | (x[15] & y[15] & ~s[15]) }
|
30
|
+
hwhen(4) { add.(x ,~y,1,[cf,s])
|
31
|
+
vf <= (~x[15] & y[15] & s[15]) | (x[15] & ~y[15] & ~s[15]) }
|
32
|
+
hwhen(5) { add.(0 ,~y,1,[cf,s])
|
33
|
+
vf <= (~y[15] & s[15]) }
|
34
|
+
hwhen(6) { add.(~x,0 ,1,[cf,s])
|
35
|
+
vf <= (x[15] & ~s[15]) }
|
36
|
+
hwhen(7) { s <= x & y }
|
37
|
+
hwhen(8) { s <= x | y }
|
38
|
+
hwhen(9) { s <= x ^ y }
|
39
|
+
hwhen(10){ s <= ~x }
|
40
|
+
hwhen(11){ s <= ~y }
|
41
|
+
helse { s <= 0 }
|
42
|
+
|
43
|
+
# The remaining flags.
|
44
|
+
zf <= (s == 0)
|
45
|
+
sf <= s[15]
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require '../std/fsm.rb'
|
2
|
+
|
3
|
+
include HDLRuby::High::Std
|
4
|
+
|
5
|
+
# Implementation of an 8-bit calculator.
|
6
|
+
system :calculator do
|
7
|
+
input :clk,:rst
|
8
|
+
[1..0].input :opr
|
9
|
+
[7..0].input :x, :y
|
10
|
+
[7..0].output :s
|
11
|
+
output :zf, :sf, :cf, :vf
|
12
|
+
|
13
|
+
[8..0].inner :tmp
|
14
|
+
|
15
|
+
def common
|
16
|
+
s <= tmp[7..0]
|
17
|
+
zf <= (s == 0)
|
18
|
+
sf <= tmp[7]
|
19
|
+
cf <= tmp[8]
|
20
|
+
vf <= tmp[8] ^ tmp[7]
|
21
|
+
goto(:choice)
|
22
|
+
end
|
23
|
+
|
24
|
+
fsm(clk.posedge,rst) do
|
25
|
+
state(:zero) do
|
26
|
+
s <= 0;
|
27
|
+
zf <= 0;
|
28
|
+
sf <= 0;
|
29
|
+
cf <= 0;
|
30
|
+
vf <= 0;
|
31
|
+
end
|
32
|
+
state(:choice) do
|
33
|
+
goto(opr, :add,:sub,:neg, :zero)
|
34
|
+
end
|
35
|
+
state(:add) do
|
36
|
+
tmp <= x + y
|
37
|
+
common
|
38
|
+
end
|
39
|
+
state(:sub) do
|
40
|
+
tmp <= x - y
|
41
|
+
common
|
42
|
+
end
|
43
|
+
state(:neg) do
|
44
|
+
tmp <= -x
|
45
|
+
common
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# A simple counter
|
2
|
+
system :counter do
|
3
|
+
input :clk, :rst
|
4
|
+
input :ctrl
|
5
|
+
[8].output :q
|
6
|
+
output :c
|
7
|
+
|
8
|
+
[8].inner :qq
|
9
|
+
inner :cc
|
10
|
+
|
11
|
+
instance :add do
|
12
|
+
[8].input :x,:y
|
13
|
+
[9].output :z
|
14
|
+
|
15
|
+
z <= x.as([9]) + y
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
par do
|
20
|
+
add.(q,0)
|
21
|
+
hif(rst) { [cc,qq] <= 0 }
|
22
|
+
helse do
|
23
|
+
add.(q,1,[cc,qq])
|
24
|
+
hif(ctrl == 1) { add.(q,-1,[cc,qq]) }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
par(clk.posedge) do
|
29
|
+
q <= qq
|
30
|
+
c <= cc
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# A benchmark for the counter.
|
37
|
+
system :counter_bench do
|
38
|
+
inner :clk, :rst
|
39
|
+
inner :ctrl
|
40
|
+
[8].inner :q
|
41
|
+
inner :c
|
42
|
+
|
43
|
+
counter(:my_counter).(clk,rst,ctrl,q,c)
|
44
|
+
|
45
|
+
timed do
|
46
|
+
clk <= 0
|
47
|
+
rst <= 0
|
48
|
+
ctrl <= 0
|
49
|
+
!10.ns
|
50
|
+
clk <= 1
|
51
|
+
rst <= 0
|
52
|
+
!10.ns
|
53
|
+
clk <= 0
|
54
|
+
rst <= 1
|
55
|
+
!10.ns
|
56
|
+
clk <= 1
|
57
|
+
rst <= 1
|
58
|
+
!10.ns
|
59
|
+
clk <= 0
|
60
|
+
rst <= 0
|
61
|
+
!10.ns
|
62
|
+
clk <= 1
|
63
|
+
rst <= 0
|
64
|
+
!10.ns
|
65
|
+
10.times do
|
66
|
+
clk <= 0
|
67
|
+
rst <= 0
|
68
|
+
!10.ns
|
69
|
+
clk <= 1
|
70
|
+
rst <= 0
|
71
|
+
!10.ns
|
72
|
+
end
|
73
|
+
ctrl <= 1
|
74
|
+
20.times do
|
75
|
+
clk <= 0
|
76
|
+
rst <= 0
|
77
|
+
!10.ns
|
78
|
+
clk <= 1
|
79
|
+
rst <= 0
|
80
|
+
!10.ns
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# A simple D-FF
|
2
|
+
system :dff do
|
3
|
+
input :d, :clk, :rst
|
4
|
+
output :q
|
5
|
+
|
6
|
+
(q <= d & ~rst).at(clk.posedge)
|
7
|
+
end
|
8
|
+
|
9
|
+
# A benchmark for the dff.
|
10
|
+
system :dff_bench do
|
11
|
+
inner :d, :clk, :rst
|
12
|
+
inner :q
|
13
|
+
|
14
|
+
dff(:my_dff).(d,clk,rst,q)
|
15
|
+
|
16
|
+
timed do
|
17
|
+
clk <= 0
|
18
|
+
rst <= 0
|
19
|
+
d <= _z
|
20
|
+
!10.ns
|
21
|
+
clk <= 1
|
22
|
+
rst <= 0
|
23
|
+
d <= _z
|
24
|
+
!10.ns
|
25
|
+
clk <= 0
|
26
|
+
rst <= 1
|
27
|
+
d <= _z
|
28
|
+
!10.ns
|
29
|
+
clk <= 1
|
30
|
+
rst <= 1
|
31
|
+
d <= _z
|
32
|
+
!10.ns
|
33
|
+
clk <= 0
|
34
|
+
rst <= 0
|
35
|
+
d <= 1
|
36
|
+
!10.ns
|
37
|
+
clk <= 1
|
38
|
+
rst <= 0
|
39
|
+
d <= 1
|
40
|
+
!10.ns
|
41
|
+
clk <= 0
|
42
|
+
rst <= 0
|
43
|
+
d <= 1
|
44
|
+
!10.ns
|
45
|
+
clk <= 1
|
46
|
+
rst <= 0
|
47
|
+
d <= 1
|
48
|
+
!10.ns
|
49
|
+
clk <= 0
|
50
|
+
rst <= 0
|
51
|
+
d <= 0
|
52
|
+
!10.ns
|
53
|
+
clk <= 1
|
54
|
+
rst <= 0
|
55
|
+
d <= 0
|
56
|
+
!10.ns
|
57
|
+
clk <= 0
|
58
|
+
rst <= 0
|
59
|
+
d <= 0
|
60
|
+
!10.ns
|
61
|
+
clk <= 1
|
62
|
+
rst <= 0
|
63
|
+
d <= 0
|
64
|
+
!10.ns
|
65
|
+
end
|
66
|
+
end
|