HDLRuby 3.8.2 → 3.9.1

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.
@@ -277,9 +277,34 @@ else
277
277
  "lib/HDLRuby"
278
278
  end
279
279
 
280
+
280
281
  include HDLRuby
281
282
 
282
283
 
284
+ # Displays the help
285
+ def hdr_help
286
+ puts %{Interactive HDLRuby
287
+ Usage:
288
+ - Getting this help: hdr_help
289
+ - Compiling a module: hdr_make(<module name>[, <parameters>])
290
+ - Generating Verilog code from a compiled module: hdr_verilog
291
+ - Generating VHDL code from a compiled module: hdr_vhdl
292
+ - Generating HDLRuby code from a compiled module: hdr_hdr
293
+ - Generating YAML code from a compiled module: hdr_yaml
294
+ - Simulating the compiled module: hdr_sim
295
+ - Simulating the compiled module with VCD output: hdr_sim_vcd
296
+ - Simulating the compiled module with no output: hdr_sim_mute
297
+
298
+ Note: the folder for output files is HDLRubyWorkspace}
299
+ end
300
+
301
+ # Error handling.
302
+ def hdr_error(mess)
303
+ puts "Error: #{mess}"
304
+ hdr_help
305
+ end
306
+
307
+
283
308
  def hdr_test
284
309
  $top = "__test__"
285
310
  tests = $options[:test]
@@ -311,6 +336,12 @@ $input = "top_system"
311
336
  # Open the output.
312
337
  $output = "HDLRubyWorkspace"
313
338
 
339
+ # Fix the y bug
340
+ undef y
341
+
342
+ # Display the initial help.
343
+ hdr_help
344
+
314
345
  def hdr_output(output = $output)
315
346
  # Create a directory if necessary.
316
347
  unless File.directory?($output)
@@ -334,12 +365,15 @@ end
334
365
 
335
366
 
336
367
  # Process a system for generation.
337
- def hdr_make(sys,params = [])
368
+ def hdr_make(sys,*params)
338
369
  if sys.is_a?(SystemI) then
370
+ $top_system_high = sys.systemT
339
371
  $top_system = sys.to_low.systemT
340
372
  elsif params.empty? then
373
+ $top_system_high = sys.(HDLRuby.uniq_name).systemT
341
374
  $top_system = sys.(HDLRuby.uniq_name).to_low.systemT
342
375
  else
376
+ $top_system_high = sys.(*params).(HDLRuby.uniq_name).systemT
343
377
  $top_system = sys.(*params).(HDLRuby.uniq_name).to_low.systemT
344
378
  end
345
379
  end
@@ -361,232 +395,280 @@ end
361
395
 
362
396
 
363
397
  def hdr_yaml
398
+ unless $top_system
399
+ hdr_error("Need to compile a system first.")
400
+ else
364
401
  puts $top_system.to_yaml
402
+ end
365
403
  end
366
404
 
367
405
  def hdr_hdr
368
- puts $top_system.to_hdr
406
+ unless $top_system
407
+ hdr_error("Need to compile a system first.")
408
+ else
409
+ puts $top_system.to_hdr
410
+ end
369
411
  end
370
412
 
371
- def hdr_sim
372
- $top_system.each_systemT_deep do |systemT|
373
- HDLRuby.show "seq2seq step..."
374
- # Coverts the par blocks in seq blocks to seq blocks to match
375
- # the simulation engine.
376
- systemT.par_in_seq2seq!
377
- HDLRuby.show Time.now
378
- HDLRuby.show "connections_to_behaviors step..."
379
- # Converts the connections to behaviors.
380
- systemT.connections_to_behaviors!
381
- HDLRuby.show Time.now
382
- # Break the RefConcat.
383
- HDLRuby.show "concat_assigns step..."
384
- systemT.break_concat_assigns!
385
- HDLRuby.show Time.now
386
- # Explicits the types.
387
- HDLRuby.show "explicit_types step..."
388
- systemT.explicit_types!
389
- HDLRuby.show Time.now
390
- end
391
- # Generate the C.
392
- # Get the base name of the input file, it will be used for
393
- # generating the main name of the multiple result files.
394
- $basename = File.basename($input,File.extname($input))
395
- $basename = $output + "/" + $basename
396
- # Multiple files generation mode.
397
- # Generate the h file.
398
- $hname = $output + "/hruby_sim_gen.h"
399
- $hnames = [ File.basename($hname) ]
400
- $outfile = File.open($hname,"w")
401
- # Adds the generated globals
402
- $top_system.each_systemT_deep do |systemT|
403
- systemT.to_ch($outfile)
404
- # # # Close the file.
405
- # # output.close
406
- # # # Clears the name.
407
- # # hname = nil
408
- end
409
- # Adds the globals from the non-HDLRuby code
410
- $non_hdlruby.each do |code|
411
- code.each_chunk do |chunk|
412
- if chunk.name == :sim then
413
- $outfile << "extern "
414
- $outfile << HDLRuby::Low::Low2C.prototype(chunk.to_c(""))
415
- end
416
- end
417
- end
418
- $outfile.close
419
-
420
- # Prepare the initial name for the main file.
421
- $name = $basename + ".c"
422
- # Generate the code for it.
423
- $main = File.open($name,"w")
424
-
425
- # Select the vizualizer depending on the options.
426
- init_visualizer = $options[:vcd] ? "init_vcd_visualizer" :
427
- "init_default_visualizer"
428
-
429
- # Gather the system to generate and sort them in the right order
430
- # to ensure references are generated before being used.
431
- # Base: reverse order of the tree.
432
- # Then, multiple configuration of a system instance must be
433
- # reverversed so that the base configuration is generated first.
434
- c_systems = $top_system.each_systemT_deep_ref
435
- # Generate the code of the main function.
436
- # HDLRuby start code
437
- $main << HDLRuby::Low::Low2C.main("hruby_simulator",
438
- init_visualizer,
439
- $top_system,
440
- c_systems,
441
- $hnames)
442
- $main.close
413
+ # def hdr_sim
414
+ # $top_system.each_systemT_deep do |systemT|
415
+ # HDLRuby.show "seq2seq step..."
416
+ # # Coverts the par blocks in seq blocks to seq blocks to match
417
+ # # the simulation engine.
418
+ # systemT.par_in_seq2seq!
419
+ # HDLRuby.show Time.now
420
+ # HDLRuby.show "connections_to_behaviors step..."
421
+ # # Converts the connections to behaviors.
422
+ # systemT.connections_to_behaviors!
423
+ # HDLRuby.show Time.now
424
+ # # Break the RefConcat.
425
+ # HDLRuby.show "concat_assigns step..."
426
+ # systemT.break_concat_assigns!
427
+ # HDLRuby.show Time.now
428
+ # # Explicits the types.
429
+ # HDLRuby.show "explicit_types step..."
430
+ # systemT.explicit_types!
431
+ # HDLRuby.show Time.now
432
+ # end
433
+ # # Generate the C.
434
+ # # Get the base name of the input file, it will be used for
435
+ # # generating the main name of the multiple result files.
436
+ # $basename = File.basename($input,File.extname($input))
437
+ # $basename = $output + "/" + $basename
438
+ # # Multiple files generation mode.
439
+ # # Generate the h file.
440
+ # $hname = $output + "/hruby_sim_gen.h"
441
+ # $hnames = [ File.basename($hname) ]
442
+ # $outfile = File.open($hname,"w")
443
+ # # Adds the generated globals
444
+ # $top_system.each_systemT_deep do |systemT|
445
+ # systemT.to_ch($outfile)
446
+ # # # # Close the file.
447
+ # # # output.close
448
+ # # # # Clears the name.
449
+ # # # hname = nil
450
+ # end
451
+ # # Adds the globals from the non-HDLRuby code
452
+ # $non_hdlruby.each do |code|
453
+ # code.each_chunk do |chunk|
454
+ # if chunk.name == :sim then
455
+ # $outfile << "extern "
456
+ # $outfile << HDLRuby::Low::Low2C.prototype(chunk.to_c(""))
457
+ # end
458
+ # end
459
+ # end
460
+ # $outfile.close
461
+ #
462
+ # # Prepare the initial name for the main file.
463
+ # $name = $basename + ".c"
464
+ # # Generate the code for it.
465
+ # $main = File.open($name,"w")
466
+ #
467
+ # # Select the vizualizer depending on the options.
468
+ # init_visualizer = $options[:vcd] ? "init_vcd_visualizer" :
469
+ # "init_default_visualizer"
470
+ #
471
+ # # Gather the system to generate and sort them in the right order
472
+ # # to ensure references are generated before being used.
473
+ # # Base: reverse order of the tree.
474
+ # # Then, multiple configuration of a system instance must be
475
+ # # reverversed so that the base configuration is generated first.
476
+ # c_systems = $top_system.each_systemT_deep_ref
477
+ # # Generate the code of the main function.
478
+ # # HDLRuby start code
479
+ # $main << HDLRuby::Low::Low2C.main("hruby_simulator",
480
+ # init_visualizer,
481
+ # $top_system,
482
+ # c_systems,
483
+ # $hnames)
484
+ # $main.close
485
+ #
486
+ # $top_system.each_systemT_deep do |systemT|
487
+ # # For the c file.
488
+ # name = $output + "/" +
489
+ # HDLRuby::Low::Low2C.c_name(systemT.name) +
490
+ # ".c"
491
+ # # show? "for systemT=#{systemT.name} generating: #{name}"
492
+ # # Open the file for current systemT
493
+ # outfile = File.open(name,"w")
494
+ # # Generate the C code in to.
495
+ # # outfile << systemT.to_c(0,*$hnames)
496
+ # systemT.to_c(outfile,0,*$hnames)
497
+ # # Close the file.
498
+ # outfile.close
499
+ # # Clears the name.
500
+ # name = nil
501
+ # end
502
+ #
503
+ # # Simulation mode, compile and exectute.
504
+ # # Path of the simulator core files.
505
+ # $simdir = $hdr_dir + "/sim/"
506
+ # # Generate and execute the simulation commands.
507
+ # # Kernel.system("cp -n #{simdir}* #{$output}/; cd #{$output}/ ; make -s ; ./hruby_simulator")
508
+ # Dir.entries($simdir).each do |filename|
509
+ # if !File.directory?(filename) && /\.[ch]$/ === filename then
510
+ # FileUtils.cp($simdir + "/" + filename,$output)
511
+ # end
512
+ # end
513
+ # Dir.chdir($output)
514
+ # # Find the compiler.
515
+ # cc_cmd = which('cc')
516
+ # unless cc_cmd then
517
+ # cc_cmd = which('gcc')
518
+ # end
519
+ # unless cc_cmd then
520
+ # raise "Could not find any compiler, please compile by hand as follows:\n" +
521
+ # " In folder #{$output} execute:\n" +
522
+ # " <my compiler> -o hruby_simulator *.c -lpthread\n" +
523
+ # " Then execute:\n hruby_simulator"
524
+ # end
525
+ # # Use it.
526
+ # Kernel.system("#{cc_cmd} -o3 -o hruby_simulator *.c -lpthread")
527
+ # Kernel.system("./hruby_simulator")
528
+ # Dir.chdir("..")
529
+ # end
530
+
531
+ def hdr_sim(mode = nil)
532
+ unless $top_system_high
533
+ hdr_error("Need to compile a system first.")
534
+ return
535
+ end
536
+ HDLRuby.show "Building the hybrid C-Ruby-level simulator..."
537
+ # C-Ruby-level simulation.
538
+ require 'HDLRuby/hruby_rcsim.rb'
539
+ # Merge the included from the top system.
540
+ $top_system_high.merge_included!
541
+ # Process par in seq.
542
+ $top_system_high.par_in_seq2seq!
543
+ # Generate the C data structures.
544
+ $top_system_high.to_rcsim
545
+ HDLRuby.show "Executing the hybrid C-Ruby-level simulator..."
546
+ HDLRuby::High.rcsim($top_system_high,"hruby_simulator",$output,
547
+ ((mode == :mute) && 1) || ((mode == :vcd) && 2) || 0)
548
+ HDLRuby.show "End of hybrid C-Ruby-level simulation..."
549
+ end
443
550
 
444
- $top_system.each_systemT_deep do |systemT|
445
- # For the c file.
446
- name = $output + "/" +
447
- HDLRuby::Low::Low2C.c_name(systemT.name) +
448
- ".c"
449
- # show? "for systemT=#{systemT.name} generating: #{name}"
450
- # Open the file for current systemT
451
- outfile = File.open(name,"w")
452
- # Generate the C code in to.
453
- # outfile << systemT.to_c(0,*$hnames)
454
- systemT.to_c(outfile,0,*$hnames)
455
- # Close the file.
456
- outfile.close
457
- # Clears the name.
458
- name = nil
459
- end
551
+ def hdr_sim_vcd
552
+ hdr_sim(:vcd)
553
+ end
460
554
 
461
- # Simulation mode, compile and exectute.
462
- # Path of the simulator core files.
463
- $simdir = $hdr_dir + "/sim/"
464
- # Generate and execute the simulation commands.
465
- # Kernel.system("cp -n #{simdir}* #{$output}/; cd #{$output}/ ; make -s ; ./hruby_simulator")
466
- Dir.entries($simdir).each do |filename|
467
- if !File.directory?(filename) && /\.[ch]$/ === filename then
468
- FileUtils.cp($simdir + "/" + filename,$output)
469
- end
470
- end
471
- Dir.chdir($output)
472
- # Find the compiler.
473
- cc_cmd = which('cc')
474
- unless cc_cmd then
475
- cc_cmd = which('gcc')
476
- end
477
- unless cc_cmd then
478
- raise "Could not find any compiler, please compile by hand as follows:\n" +
479
- " In folder #{$output} execute:\n" +
480
- " <my compiler> -o hruby_simulator *.c -lpthread\n" +
481
- " Then execute:\n hruby_simulator"
482
- end
483
- # Use it.
484
- Kernel.system("#{cc_cmd} -o3 -o hruby_simulator *.c -lpthread")
485
- Kernel.system("./hruby_simulator")
486
- Dir.chdir("..")
555
+ def hdr_sim_mute
556
+ hdr_sim(:mute)
487
557
  end
488
558
 
489
559
  def hdr_verilog
490
- # Make description compatible with verilog generation.
491
- $top_system.each_systemT_deep do |systemT|
492
- # HDLRuby.show "casts_without_expression! step..."
493
- # systemT.casts_without_expression!
494
- # HDLRuby.show Time.now
495
- HDLRuby.show "to_upper_space! step..."
496
- systemT.to_upper_space!
497
- HDLRuby.show Time.now
498
- end
499
- HDLRuby.show "to_global_space! step (global)..."
500
- $top_system.to_global_systemTs!
560
+ unless $top_system
561
+ hdr_error("Need to compile a system first.")
562
+ return
563
+ end
564
+ # Make description compatible with verilog generation.
565
+ $top_system.each_systemT_deep do |systemT|
566
+ # HDLRuby.show "casts_without_expression! step..."
567
+ # systemT.casts_without_expression!
568
+ # HDLRuby.show Time.now
569
+ HDLRuby.show "to_upper_space! step..."
570
+ systemT.to_upper_space!
501
571
  HDLRuby.show Time.now
502
- $top_system.each_systemT_deep do |systemT|
503
- ## systemT.break_types!
504
- ## systemT.expand_types!
505
- HDLRuby.show "par_in_seq2seq! step..."
506
- systemT.par_in_seq2seq!
507
- HDLRuby.show Time.now
508
- HDLRuby.show "initial_concat_to_timed! step..."
509
- systemT.initial_concat_to_timed!
510
- HDLRuby.show Time.now
511
- HDLRuby.show "with_port! step..."
512
- systemT.with_port!
513
- HDLRuby.show Time.now
514
- end
515
- # # Verilog generation
516
- # $output << top_system.to_verilog
517
- # Generate the Verilog.
518
- # Get the base name of the input file, it will be used for
519
- # generating the main name of the multiple result files.
520
- $basename = File.basename($input,File.extname($input))
521
- $basename = $output + "/" + $basename
522
- # # File name counter.
523
- # $namecount = 0
524
- # Prepare the initial name for the main file.
525
- $name = $basename + ".v"
526
- # Multiple files generation mode.
527
- $top_system.each_systemT_deep do |systemT|
528
- # Generate the name if necessary.
529
- unless $name
530
- $name = $output + "/" +
531
- HDLRuby::Verilog.name_to_verilog(systemT.name) +
532
- ".v"
533
- end
534
- # Open the file for current systemT
535
- outfile = File.open($name,"w")
536
- # Generate the Verilog code in to.
537
- outfile << systemT.to_verilog
538
- # Close the file.
539
- outfile.close
540
- # Clears the name.
541
- $name = nil
572
+ end
573
+ HDLRuby.show "to_global_space! step (global)..."
574
+ $top_system.to_global_systemTs!
575
+ HDLRuby.show Time.now
576
+ $top_system.each_systemT_deep do |systemT|
577
+ ## systemT.break_types!
578
+ ## systemT.expand_types!
579
+ HDLRuby.show "par_in_seq2seq! step..."
580
+ systemT.par_in_seq2seq!
581
+ HDLRuby.show Time.now
582
+ HDLRuby.show "initial_concat_to_timed! step..."
583
+ systemT.initial_concat_to_timed!
584
+ HDLRuby.show Time.now
585
+ HDLRuby.show "with_port! step..."
586
+ systemT.with_port!
587
+ HDLRuby.show Time.now
588
+ end
589
+ # # Verilog generation
590
+ # $output << top_system.to_verilog
591
+ # Generate the Verilog.
592
+ # Get the base name of the input file, it will be used for
593
+ # generating the main name of the multiple result files.
594
+ $basename = File.basename($input,File.extname($input))
595
+ $basename = $output + "/" + $basename
596
+ # # File name counter.
597
+ # $namecount = 0
598
+ # Prepare the initial name for the main file.
599
+ $name = $basename + ".v"
600
+ # Multiple files generation mode.
601
+ $top_system.each_systemT_deep do |systemT|
602
+ # Generate the name if necessary.
603
+ unless $name
604
+ $name = $output + "/" +
605
+ HDLRuby::Verilog.name_to_verilog(systemT.name) +
606
+ ".v"
542
607
  end
608
+ # Open the file for current systemT
609
+ outfile = File.open($name,"w")
610
+ # Generate the Verilog code in to.
611
+ outfile << systemT.to_verilog
612
+ # Close the file.
613
+ outfile.close
614
+ # Clears the name.
615
+ $name = nil
616
+ end
543
617
  end
544
618
 
545
619
  def hdr_vhdl
546
- # top_system = $top_instance.to_low.systemT
547
- # top_system = $top_system
548
- # Make description compatible with vhdl generation.
549
- $top_system.each_systemT_deep do |systemT|
550
- systemT.outread2inner! unless $options[:vhdl08] || $options[:alliance]
551
- systemT.with_boolean!
552
- systemT.boolean_in_assign2select! unless $options[:alliance]
553
- systemT.bit2vector2inner! unless $options[:vhdl08] || $options[:alliance]
554
- systemT.select2case! # if $options[:alliance]
555
- systemT.break_concat_assigns! # if $options[:alliance]
556
- systemT.to_upper_space!
557
- systemT.to_global_systemTs!
558
- systemT.break_types!
559
- systemT.with_port!
560
- systemT.with_var!
561
- systemT.cleanup!
562
- end
563
- # Generate the vhdl.
564
- # Get the base name of the input file, it will be used for
565
- # generating the main name of the multiple result files.
566
- $basename = File.basename($input,File.extname($input))
567
- $basename = $output + "/" + $basename
568
- # # File name counter.
569
- # $namecount = 0
570
- # Prepare the initial name for the main file.
571
- $name = $basename + ".vhd"
572
- # Multiple files generation mode.
573
- $top_system.each_systemT_deep do |systemT|
574
- # Generate the name if necessary.
575
- unless $name
576
- $name = $output + "/" +
577
- HDLRuby::Low::Low2VHDL.entity_name(systemT.name) +
578
- ".vhd"
579
- end
580
- # Open the file for current systemT
581
- outfile = File.open($name,"w")
582
- # Generate the VHDL code in to.
583
- outfile << systemT.to_vhdl
584
- # Close the file.
585
- outfile.close
586
- # Clears the name.
587
- $name = nil
620
+ unless $top_system
621
+ hdr_error("Need to compile a system first.")
622
+ return
623
+ end
624
+ # top_system = $top_instance.to_low.systemT
625
+ # top_system = $top_system
626
+ # Make description compatible with vhdl generation.
627
+ $top_system.each_systemT_deep do |systemT|
628
+ systemT.outread2inner! unless $options[:vhdl08] || $options[:alliance]
629
+ systemT.with_boolean!
630
+ systemT.boolean_in_assign2select! unless $options[:alliance]
631
+ systemT.bit2vector2inner! unless $options[:vhdl08] || $options[:alliance]
632
+ systemT.select2case! # if $options[:alliance]
633
+ systemT.break_concat_assigns! # if $options[:alliance]
634
+ systemT.to_upper_space!
635
+ systemT.to_global_systemTs!
636
+ systemT.break_types!
637
+ systemT.with_port!
638
+ systemT.with_var!
639
+ systemT.cleanup!
640
+ end
641
+ # Generate the vhdl.
642
+ # Get the base name of the input file, it will be used for
643
+ # generating the main name of the multiple result files.
644
+ $basename = File.basename($input,File.extname($input))
645
+ $basename = $output + "/" + $basename
646
+ # # File name counter.
647
+ # $namecount = 0
648
+ # Prepare the initial name for the main file.
649
+ $name = $basename + ".vhd"
650
+ # Multiple files generation mode.
651
+ $top_system.each_systemT_deep do |systemT|
652
+ # Generate the name if necessary.
653
+ unless $name
654
+ $name = $output + "/" +
655
+ HDLRuby::Low::Low2VHDL.entity_name(systemT.name) +
656
+ ".vhd"
588
657
  end
658
+ # Open the file for current systemT
659
+ outfile = File.open($name,"w")
660
+ # Generate the VHDL code in to.
661
+ outfile << systemT.to_vhdl
662
+ # Close the file.
663
+ outfile.close
664
+ # Clears the name.
665
+ $name = nil
666
+ end
589
667
  end
590
668
 
591
669
 
592
670
  configure_high
671
+
672
+
673
+ require 'std/std.rb'
674
+ include HDLRuby::High::Std