HDLRuby 3.3.4 → 3.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 160a8c6607e6dd20282a50fa26e0d472e055992ebce5f7cdf62d39e8c6bf7db5
4
- data.tar.gz: 2c44f4edc3e4fdd76d64c2cb349f7083a255b68b1a18c6f41bef77c6d82138ab
3
+ metadata.gz: d4aecd7d8db226fd84031bd58762b442e4882a405a0898b8e87e3118c1ade8be
4
+ data.tar.gz: 9808966d1decc2aae4c9c9b0423b0ab2fbb0543d44dd635b98789f1f07aaabcf
5
5
  SHA512:
6
- metadata.gz: 234d4901bc7ae389c1e0893ad19a7a2aff93c2bc2851066a80ce07b778787a1fa25950af60dd30d32d7e77a8804f0ef4dbc2c43bdf2f026f7b725cd15a943c84
7
- data.tar.gz: 774369895db9a9f30b7a85061aba5190d3e45f962f6ca28e2cee7fe77d7c02c049570dd6e2a0f730640f687bc8069f19e433ea6d4bb2f79b6cb7875a6ef423a4
6
+ metadata.gz: bebd8de17a2e35c7c926fe44feb6ad04cce0fa4558d7a96376125da7a2ec55bc0815a24b6f26936e6dc6ca99781867fd8737a2cf8a3a6c6430c8fdef53bd38fc
7
+ data.tar.gz: 6ca378209e06714804526c8bff40845ccd7663ee4cff033044727035e16ff1ef86bc021342944b633d10cf7a599da4faff739b14b90b0ac5efdb329303e5c4f9
data/HDLRuby.gemspec CHANGED
@@ -8,6 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.version = HDLRuby::VERSION
9
9
  spec.authors = ["Lovic Gauthier"]
10
10
  spec.email = ["lovic@ariake-nct.ac.jp"]
11
+ spec.platform = "ruby"
11
12
 
12
13
  spec.summary = %q{HDLRuby is a library for describing and simulating digital electronic systems.}
13
14
  spec.description = %q{HDLRuby is a library for describing and simulating digital electronic systems. With this library it will possible to describe synthesizable hardware using all the features of the Ruby language, e.g., object orientation, duck typing, closure. This library is also usable through irb for interactive design and simulation.}
data/README.md CHANGED
@@ -17,6 +17,26 @@ hdrcc --get-tuto
17
17
 
18
18
  __What's new__
19
19
 
20
+ For HDLRuby version 3.5.0:
21
+
22
+ * Added direct support for Verilog HDL files as input to 'hdrcc'.
23
+
24
+ * Added the ability to generate a graphical representation of the RTL code in SVG format using the '--svg' option for 'hdrcc'.
25
+
26
+
27
+ For HDLRuby version 3.4.0:
28
+
29
+ * Improved synchronization of the browser-base graphical interface with the HDLRuby simulator.
30
+
31
+ * Added a Verilog HDL parsing library for Ruby. This library will be released separately once it is fully stabilized."
32
+
33
+ * Added a HDLRuby generating library from the a Verilog HDL AST provided by the above-mentioned library.
34
+
35
+ * Added a standalone tool for converting Verilog HDL files to HDLRuby called [v2hdr](#converting-verilog-hdl-to-hdlruby). This tool is still experimental though.
36
+
37
+ * Added a HDLRuby command for [loading a Verilog HDL file from a HDLRuby description](#loading-verilog-hdl-from-hdlruby).
38
+
39
+
20
40
  For HDLRuby version 3.3.0:
21
41
 
22
42
  * Remade the description of software components using the program construct.
@@ -93,14 +113,14 @@ __Warning__:
93
113
  __Usage__:
94
114
 
95
115
  ```
96
- hdrcc [options] <input file> <output directory>
116
+ hdrcc [options] <input file> <output/working directory>
97
117
  ```
98
118
 
99
119
  Where:
100
120
 
101
121
  * `options` is a list of options
102
122
  * `<input file>` is the initial file to compile (mandatory)
103
- * `<output directory>` is the directory where the generated files will be put
123
+ * `<output/working directory>` is the directory where the output and temporary files will be put
104
124
 
105
125
  | Options | |
106
126
  |:------------------|:-----------------------------------------------------|
@@ -115,6 +135,7 @@ Where:
115
135
  | `--rsim` | Perform the simulation with the Ruby engine |
116
136
  | `--rcsim` | Perform the simulation with the Hybrid engine |
117
137
  | `--vcd` | Make the simulator generate a VCD file |
138
+ | `--svg` | Output a graphical representation of the RTL (SVG format) |
118
139
  | `-d, --directory` | Specify the base directory for loading the HDLRuby files |
119
140
  | `-D, --debug` | Set the HDLRuby debug mode |
120
141
  | `-t, --top system`| Specify the top system describing the circuit to compile |
@@ -138,16 +159,16 @@ __Notes__:
138
159
 
139
160
  __Examples__:
140
161
 
141
- * Compile system named `adder` from `adder.rb` input file and generate a low-level YAML description into directory `adder`:
162
+ * Compile `adder.rb` input file and generate a low-level Verilog HDL description into the directory `adder`:
142
163
 
143
164
  ```bash
144
- hdrcc --yaml --top adder adder.rb adder
165
+ hdrcc -v adder.rb adder
145
166
  ```
146
167
 
147
- * Compile `adder.rb` input file and generate a low-level Verilog HDL description into the directory `adder`:
168
+ * Compile `adder8.v` input Verilog HDL file with `adder8` as top module, and generate a graphical representation of its RTL in the `view` directory:
148
169
 
149
170
  ```bash
150
- hdrcc -v adder.rb adder
171
+ hdrcc adder8.v -t adder8 --svg view
151
172
  ```
152
173
 
153
174
  * Compile system `adder` whose bit width is generic from `adder_gen.rb` input file to a 16-bit circuit low-level VHDL description into directory `adder`:
@@ -3929,6 +3950,57 @@ The naming convention of the samples is the following:
3929
3950
  * `<name>_bench.rb`: sample including a simulation benchmark, these are the only samples that can be simulated using `hdrcc -S`. Please notice that such a sample cannot be converted to VHDL or Verilog HDL yet.
3930
3951
  * `with_<name>.rb`: sample illustrating a single aspect of HDLRuby or one of its libraries, usually includes a benchmark.
3931
3952
 
3953
+ # Converting Verilog HDL to HDLRuby
3954
+
3955
+ While the HDLRuby framwork does not support Verilog HDL files as input yet, a standalone tool is provided for converting those files to HDLRuby. For that please use the following command:
3956
+
3957
+ ```bash
3958
+ v2hdr <input Verilog HDL file> <output HDLRuby file>
3959
+ ```
3960
+
3961
+ For example, assuming that you have a Verilog ddHDL named 'adder.v' describing and adder circuit, you can convert it to HDLRuby as follows:
3962
+
3963
+ ```bash
3964
+ v2hdr adder.v adder.v.rb
3965
+ ```
3966
+
3967
+ Another possibility is to directly load the Verilog HDL file from a HDLRuby description using the command `require_verilog`.
3968
+ For example, assuming `adder.v` contains the following code:
3969
+
3970
+ ```verilog
3971
+ module adder(x,y,z);
3972
+ input[7:0] x,y;
3973
+ output[7:0] z;
3974
+
3975
+ assign z = x + y;
3976
+ endmodule
3977
+ ```
3978
+
3979
+ It can be loaded the be instantiated like any other module in HDLRuby as follows:
3980
+
3981
+ ```ruby
3982
+ require_verilog "adder.v"
3983
+
3984
+ system :my_IC do
3985
+ [8].inner :a, :b, :c
3986
+
3987
+ adder(:my_adder).(a,b,c)
3988
+
3989
+ ...
3990
+ end
3991
+ ```
3992
+
3993
+
3994
+ __Notes__:
3995
+
3996
+ * Verilog HDL accepts signal and module names in any letter case, while HDLRuby reserves identifiers starting with a capital letter for constants. To avoid conflicts, Verilog HDL names that begin with a capital letter are prefixed with an underscore (`_`) in HDLRuby. For example, if the Verilog HDL module name in the previous example were `ADDER`, it would be renamed to `_ADDER` in HDLRuby. Instantiating such a module would be done as follows:
3997
+
3998
+ ```ruby
3999
+ _ADDER(:my_add).(a,b,c)
4000
+ ```
4001
+
4002
+ * With the current version of HDLRuby, the Verilog HDL files are first converted to HDLRuby before being loaded using the standalone `v2hdr` tool.
4003
+
3932
4004
 
3933
4005
  # Contributing
3934
4006
 
@@ -3938,7 +4010,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/civol/
3938
4010
  # To do
3939
4011
 
3940
4012
  * Find and fix the (maybe) terrifying number of bugs.
3941
- * Add a GUI (any volunteer to do it?).
3942
4013
 
3943
4014
 
3944
4015
  # License
data/exe/v2hdr ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'HDLRuby/v2hdr.rb'
@@ -554,6 +554,7 @@ VALUE rcsim_make_timeWait(VALUE mod, VALUE unitV, VALUE delayV) {
554
554
  /* Adjust the delay depending on the unit. */
555
555
  const char* unit = rb_id2name(SYM2ID(unitV));
556
556
  switch(unit[0]) {
557
+ case 'f': delay /= 1000; break;
557
558
  case 'p': /* Ok as is. */ break;
558
559
  case 'n': delay *= 1000; break;
559
560
  case 'u': delay *= 1000000; break;
@@ -0,0 +1,6 @@
1
+ module adder8(x,y,z);
2
+ input[7:0] x,y;
3
+ output[7:0] z;
4
+
5
+ assign z = x + y;
6
+ endmodule
@@ -0,0 +1,30 @@
1
+ # A benchmark for testing the router of SVG generation with hard to
2
+ # handle patterns.
3
+ # Note that the circuit is not synthesizable here, it is just for
4
+ # testing difficult routing patterns, even if they are illegal in practice.
5
+
6
+ system :adder do |typ|
7
+ typ.input :x, :y
8
+ typ.output :z
9
+
10
+ z <= x + y
11
+ end
12
+
13
+
14
+ system :hard_to_route do
15
+
16
+ [8].inner :x, :y, :z, :c
17
+
18
+ adder(bit[8]).(:adderI0).(x,y,z)
19
+ adder(bit[8]).(:adderI1).(x: x, y: y, z: z)
20
+
21
+ timed do
22
+ !10.ns
23
+ x <= 0
24
+ y <= 0
25
+ !10.ns
26
+ x <= 1
27
+ y <= 1
28
+ !10.ns
29
+ end
30
+ end
@@ -1,3 +1,5 @@
1
+ raise "Deprecated code."
2
+
1
3
  # require "../hruby_low2c.rb"
2
4
 
3
5
  # An 8-bit register with C encrypting.
@@ -1,3 +1,5 @@
1
+ raise "Deprecated code."
2
+
1
3
  require 'HDLRuby/backend/allocator'
2
4
  require 'HDLRuby/hdr_samples/mei8'
3
5
 
@@ -1,3 +1,5 @@
1
+ raise "Deprecated code."
2
+
1
3
  require 'HDLRuby/backend/allocator'
2
4
 
3
5
  ## A generic CPU description
@@ -0,0 +1,36 @@
1
+ $LOAD_PATH << "#{__dir__}/../../"
2
+
3
+ require "HDLRuby/verilog_hruby.rb"
4
+
5
+ parser = VerilogTools::Parser.new
6
+
7
+ ast = nil
8
+
9
+ begin
10
+ ast = parser.run(filename: ARGV[0], compress: ARGV[1] == "--compress" )
11
+ rescue => error
12
+ puts error
13
+ exit
14
+ end
15
+
16
+ puts "#################################"
17
+ puts "## AST ##"
18
+ puts "#################################"
19
+ puts "\n"
20
+
21
+ puts ast
22
+
23
+ hdlruby = ""
24
+ begin
25
+ hdlruby = ast.to_HDLRuby
26
+ rescue => error
27
+ puts error
28
+ exit
29
+ end
30
+
31
+ puts "\n"
32
+ puts "#################################"
33
+ puts "## HDLRuby ##"
34
+ puts "#################################"
35
+
36
+ puts hdlruby
@@ -0,0 +1,31 @@
1
+ # Samples for testing instantiation of generic system within generic system.
2
+
3
+
4
+ system :inner_generic do |typeI, typeO|
5
+ typeI.input :din
6
+ typeO.output :dout
7
+
8
+ dout <= din * 2
9
+ end
10
+
11
+
12
+ system :outer_generic do |typeI, typeO|
13
+ typeI.input :din_
14
+ typeO.output :dout_
15
+
16
+ inner_generic(typeI,typeO).(:my_inner_generic).(din_,dout_)
17
+ end
18
+
19
+
20
+ system :test_generic_in_generic do
21
+ [8].inner :x, :y
22
+
23
+ outer_generic(bit[8],bit[16]).(:my_outer_generic).(x,y)
24
+
25
+ timed do
26
+ x <= 0
27
+ !10.ns
28
+ x <= 1
29
+ !10.ns
30
+ end
31
+ end
@@ -1,3 +1,5 @@
1
+ raise "Deprecated code."
2
+
1
3
  require 'std/handshakes.rb'
2
4
 
3
5
  include HDLRuby::High::Std
@@ -1,3 +1,5 @@
1
+ raise "Deprecated code."
2
+
1
3
  require 'std/memory.rb'
2
4
 
3
5
  include HDLRuby::High::Std
@@ -11,7 +11,7 @@ system :nand_board do
11
11
  inner :clk
12
12
  # Description of the board.
13
13
  # It is updated at each rising edge of +clk+.
14
- board(:nand,8080) do
14
+ board(:nand,http_port: 8080) do
15
15
  actport clk.posedge
16
16
  sw din0: din0
17
17
  sw din1: din1
@@ -1,3 +1,4 @@
1
+ raise "Deprecated code."
1
2
 
2
3
  # Some system that can be used for reconfiguration.
3
4
  system :sys0 do
@@ -0,0 +1,28 @@
1
+
2
+
3
+ # A benchmark for testing case in seq blocks.
4
+ system :with_seq_case_bench do
5
+ [2].inner :s
6
+ [8].inner :z
7
+
8
+ seq do
9
+ z <= 4
10
+ hcase(s)
11
+ hwhen(0) { z <= 0 }
12
+ hwhen(1) { z <= 1 }
13
+ hwhen(2) { } # Intentionally left blank
14
+ helse { z <= 3 }
15
+ z <= z+1
16
+ end
17
+
18
+ timed do
19
+ s <= 0
20
+ !10.ns
21
+ s <= 1
22
+ !10.ns
23
+ s <= 2
24
+ !10.ns
25
+ s <= 3
26
+ !10.ns
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+
2
+
3
+ # A benchmark for testing if in seq blocks.
4
+ system :with_seq_if_bench do
5
+ [2].inner :s
6
+ [8].inner :z
7
+
8
+ seq do
9
+ hif(s==0) { z <= 0 }
10
+ helsif(s==1) { z <= 1 }
11
+ helsif(s==2) { z <= 2 }
12
+ helse { z <= 3 }
13
+ end
14
+
15
+ timed do
16
+ s <= 0
17
+ !10.ns
18
+ s <= 1
19
+ !10.ns
20
+ s <= 2
21
+ !10.ns
22
+ s <= 3
23
+ !10.ns
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+
2
+
3
+ # A benchmark for testing if in seq blocks.
4
+ system :with_seq_if_bench do
5
+ [2].inner :s
6
+ [8].inner :u, :v
7
+
8
+ seq do
9
+ hif(s==0) { u <= 0; v <= 3 }
10
+ helsif(s==1) { u <= 1; v <= 2 }
11
+ helsif(s==2) { u <= 2; v <= 1 }
12
+ helse { u <= 3; v <= 0 }
13
+ u <= u + 1
14
+ v <= v + 2
15
+ end
16
+
17
+ timed do
18
+ s <= 0
19
+ !10.ns
20
+ s <= 1
21
+ !10.ns
22
+ s <= 2
23
+ !10.ns
24
+ s <= 3
25
+ !10.ns
26
+ end
27
+ end
@@ -0,0 +1,24 @@
1
+ # Sample HDLRuby instantiating a Verilog HDL-described adder (adder8.v)
2
+
3
+ require_verilog "adder8.v"
4
+
5
+ system :verilog_bench do
6
+ [8].inner :a, :b, :c
7
+
8
+ # Instantiate the adder.
9
+ adder8(:my_adder8).(a,b,c)
10
+
11
+ # Testing it.
12
+ timed do
13
+ a <= 0
14
+ b <= 0
15
+ repeat(100) do
16
+ repeat(100) do
17
+ !10.ns
18
+ b <= b + 1
19
+ end
20
+ a <= a + 1
21
+ end
22
+ !10.ns
23
+ end
24
+ end
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -254,15 +254,15 @@ module HDLRuby
254
254
  # No, look for it.
255
255
  @top_system = get_top
256
256
  # show? "@top_system=#{@top_system}"
257
- unless @top_system then
258
- # Not found? Error.
259
- # Maybe it is a parse error, look for it.
260
- bind = TOPLEVEL_BINDING.clone
261
- eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind)
262
- eval(@texts[0],bind,@top_file_name,1)
263
- # No parse error found.
264
- raise "Cannot find a top system." unless @top_system
265
- end
257
+ # unless @top_system then
258
+ # # Not found? Error.
259
+ # # Maybe it is a parse error, look for it.
260
+ # bind = TOPLEVEL_BINDING.clone
261
+ # eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind)
262
+ # eval(@texts[0],bind,@top_file_name,1)
263
+ # # No parse error found.
264
+ # raise "Cannot find a top system." unless @top_system
265
+ # end
266
266
  end
267
267
  # Initialize the environment for processing the hdr file.
268
268
  bind = TOPLEVEL_BINDING.clone
@@ -272,16 +272,20 @@ module HDLRuby
272
272
  end
273
273
  # Process it.
274
274
  eval(@texts[0],bind,@top_file_name,1)
275
- # Get the resulting instance
276
- if @params.empty? then
275
+ # Get the resulting instance if any.
276
+ if @top_system then
277
+ if @params.empty? then
277
278
  # There is no generic parameter
278
279
  @top_instance =
279
- eval("#{@top_system} :#{@top_name}\n#{@top_name}",bind)
280
- else
280
+ eval("#{@top_system} :#{@top_name}\n#{@top_name}",bind)
281
+ else
281
282
  # There are generic parameters
282
283
  @top_instance =
283
- # eval("#{@top_system} :#{@top_name},#{@params.join(",")}\n#{@top_name}",bind)
284
- eval("#{@top_system}(#{@params.join(",")}).(:#{@top_name})\n#{@top_name}",bind)
284
+ eval("#{@top_system}(#{@params.join(",")}).(:#{@top_name})\n#{@top_name}",bind)
285
+ end
286
+ else
287
+ # No top instance.
288
+ @top_instance = nil
285
289
  end
286
290
  end
287
291
  end
@@ -348,13 +352,15 @@ $options = {}
348
352
  $options[:std] = true
349
353
  # Parse the options
350
354
  $optparse = OptionParser.new do |opts|
351
- opts.banner = "Usage: hdrcc.rb [options] <input file> [<output directory or file>]"
355
+ opts.banner = "Usage: hdrcc.rb [options] [<input file>] [<output/working directory>]"
352
356
 
353
357
  opts.separator ""
354
358
  opts.separator "Where:"
355
359
  opts.separator "* `options` is a list of options"
356
- opts.separator "* `<input file>` is the initial file to compile (mandatory)"
357
- opts.separator "* `<output file>` is the output file"
360
+ opts.separator "* `<input file>` is the initial file to compile."
361
+ opts.separator " This input can either be HDLRuby (.rb) or Verilog HDL (.v),"
362
+ opts.separator " however, for the latter the top module must be specified using --top"
363
+ opts.separator "* `<output/working directory>` is the directory where to put temporary and output files"
358
364
  opts.separator ""
359
365
  opts.separator "Options:"
360
366
 
@@ -456,6 +462,11 @@ $optparse = OptionParser.new do |opts|
456
462
  $options[:vhdl08] = true
457
463
  $gen = true
458
464
  end
465
+ opts.on("--svg","Output a graphical representation of the RTL (SVG format)") do |v|
466
+ $options[:svg] = v
467
+ $options[:multiple] = v
468
+ $gen = true
469
+ end
459
470
  opts.on("-s", "--syntax","Output the Ruby syntax tree") do |s|
460
471
  $options[:syntax] = s
461
472
  end
@@ -541,15 +552,15 @@ $optparse.parse!
541
552
  # show? "options=#{$options}"
542
553
 
543
554
  # Check the compatibility of the options
544
- if $options.count {|op| [:yaml,:hdr,:verilog,:vhdl].include?(op) } > 1 then
545
- warn("Please choose either YAML, HDLRuby, Verilog HDL, or VHDL output.")
555
+ if $options.count {|op| [:yaml,:hdr,:verilog,:vhdl,:svg].include?(op) } > 1 then
556
+ warn("Please choose either YAML, HDLRuby, Verilog HDL, VHDL, SVG (visualize) output.")
546
557
  puts $optparse.help()
547
558
  end
548
559
 
549
560
  # Get the the input and the output files.
550
561
  $input,$output = $*
551
- # Get the top system name if name.
552
- $top = $options[:top].to_s
562
+ # Get the top system name if name.
563
+ $top = $options[:top].to_s
553
564
  unless $top == "" || (/^[_[[:alpha:]]][_\w]*$/ =~ $top) then
554
565
  warn("Please provide a valid top system name.")
555
566
  exit
@@ -593,17 +604,42 @@ if $output then
593
604
  FileUtils.mkdir_p($output)
594
605
  end
595
606
  else
596
- # Open the file.
597
- $output = File.open($output,"w")
607
+ # Now, nothing to do: specified output files are not to be
608
+ # handled by hdrcc directly with handles output directories only.
609
+ #
610
+ # # Open the file if it is one, otherwise use a string.
611
+ # if File.file?($output) then
612
+ # $output = File.open($output,"w")
613
+ # else
614
+ # $output = StringIO.new
615
+ # end
598
616
  end
599
617
  else
600
618
  if $options[:multiple] then
601
- raise "Need a target directory in multiple files generation mode."
619
+ # raise "Need a target directory in multiple files generation mode."
620
+ warn("Need a output/working directory.")
621
+ warn($optparse.banner)
622
+ exit
602
623
  end
603
624
  $output = $stdout
604
625
  end
605
626
 
606
- # Load and process the hdr files.
627
+ # Process non-HDLRuby files.
628
+ if $input.end_with?(".v") then
629
+ if $top.empty? then
630
+ warn("The top module must be specified using \"--top <top module>\".")
631
+ exit
632
+ end
633
+ # Processing a Verilog HDL file, embed it into regular HDLRuby
634
+ # Generate a temporary HDLRuby file to process it.
635
+ rinput = $output+"/"+$input.chomp(".v")+".rb"
636
+ File.open(rinput,"w") do |f|
637
+ f << "require_verilog '#{$input}'\n"
638
+ end
639
+ $input = rinput
640
+ end
641
+
642
+ # Load and process the HDLRuby files.
607
643
  $options[:directory] ||= "./"
608
644
  $loader = HDRLoad.new($top,$input,$options[:directory].to_s,*$params)
609
645
  $loader.read_all
@@ -637,7 +673,13 @@ end
637
673
  # Get the top systemT.
638
674
  HDLRuby.show "#{Time.now}#{show_mem}"
639
675
  # Ruby simulation uses the HDLRuby::High tree, other the HDLRuby::Lowais used
640
- $top_system = ($options[:rsim] || $options[:rcsim]) ? $top_instance.systemT : $top_instance.to_low.systemT
676
+ if $top_instance then
677
+ $top_system = ($options[:rsim] || $options[:rcsim]) ? $top_instance.systemT : $top_instance.to_low.systemT
678
+ else
679
+ # No top system, end here.
680
+ HDLRuby.show "##### End here since not top system #####"
681
+ exit
682
+ end
641
683
  $top_intance = nil # Free as much memory as possible.
642
684
  HDLRuby.show "##### Top system built #####"
643
685
  HDLRuby.show "#{Time.now}#{show_mem}"
@@ -1025,6 +1067,21 @@ elsif $options[:vhdl] then
1025
1067
  $output << systemT.to_vhdl
1026
1068
  end
1027
1069
  end
1070
+ elsif $options[:svg] then
1071
+ # Requires the viz library.
1072
+ require "HDLRuby/hruby_viz.rb"
1073
+ # Generate the viz structure.
1074
+ viz = $top_system.to_viz
1075
+ # Do the place and route.
1076
+ viz.place_and_route_deep
1077
+ viz.scale = 30.0
1078
+ # Get the base name of the input file, it will be used for
1079
+ # generating the main name of the multiple result files.
1080
+ $basename = File.basename($input,File.extname($input))
1081
+ $basename = $output + "/" + $basename
1082
+ $name = $basename + ".svg"
1083
+ # Generate the svg file.
1084
+ File.open($name,"w") { |file| file.write(viz.to_svg) }
1028
1085
  end
1029
1086
 
1030
1087
  HDLRuby.show "##### Code generated #####"
@@ -70,7 +70,7 @@ module HDLRuby
70
70
  # Content is not a numeric nor a BitString.
71
71
  @content = []
72
72
  # Ensure it is a string.
73
- val = val.to_s.downcase
73
+ val = val.to_s.chomp.downcase
74
74
  val.each_byte.reverse_each do |c|
75
75
  case c
76
76
  when 48 # "0"
@@ -82,7 +82,7 @@ module HDLRuby
82
82
  when 122 # "z"
83
83
  @content << 2
84
84
  else
85
- raise "Invalid bit: #{b.chr}"
85
+ raise "Invalid bit '#{c.chr}' in #{val}"
86
86
  end
87
87
  end
88
88
  end