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.
- checksums.yaml +4 -4
- data/README.md +2245 -1326
- data/ext/hruby_sim/hruby_sim_calc.c +23 -16
- data/lib/HDLRuby/hdr_samples/comparison_bench.rb +36 -0
- data/lib/HDLRuby/hdr_samples/with_henumerable.rb +5 -1
- data/lib/HDLRuby/hdr_samples/with_reduce.rb +10 -10
- data/lib/HDLRuby/hdr_samples/with_sequencer_enumerable.rb +4 -1
- data/lib/HDLRuby/hdrlib.rb +291 -209
- data/lib/HDLRuby/hruby_high.rb +51 -32
- data/lib/HDLRuby/hruby_low2hdr.rb +9 -8
- data/lib/HDLRuby/hruby_low2vhd.rb +1 -1
- data/lib/HDLRuby/std/hruby_enum.rb +26 -5
- data/lib/HDLRuby/std/sequencer.rb +12 -2
- data/lib/HDLRuby/std/sequencer_sw.rb +812 -72
- data/lib/HDLRuby/version.rb +1 -1
- metadata +1 -1
data/lib/HDLRuby/hdrlib.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
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
|
-
|
445
|
-
|
446
|
-
|
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
|
-
|
462
|
-
|
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
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
HDLRuby.show "
|
500
|
-
|
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
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
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
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
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
|