HDLRuby 2.9.0 → 2.10.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,10 @@ system :dff_bench do
11
11
  inner :d, :clk, :rst
12
12
  inner :q
13
13
 
14
- dff(:my_dff).(d,clk,rst,q)
14
+ # dff(:my_dff).(d,clk,rst,q)
15
+ dff(:my_dff).(d,clk)
16
+ q <= my_dff.q
17
+ my_dff.clk <= clk
15
18
 
16
19
  timed do
17
20
  clk <= 0
@@ -0,0 +1,76 @@
1
+ # A simple D-FF with overridable part.
2
+ system :dff do
3
+ input :d, :clk, :rst
4
+ output :q
5
+
6
+ sub(:process) do
7
+ (q <= d & ~rst).at(clk.posedge)
8
+ end
9
+ end
10
+
11
+ # A new dff overriding process.
12
+ system :dff_neg, dff do
13
+ sub(:process) do
14
+ (q <= d & ~rst).at(clk.negedge)
15
+ end
16
+ end
17
+
18
+ # A benchmark for the dff.
19
+ system :dff_bench do
20
+ inner :d, :clk, :rst
21
+ inner :q
22
+
23
+ dff_neg(:my_dff).(d,clk,rst,q)
24
+ # dff(:my_dff).(d,clk,rst,q)
25
+
26
+ timed do
27
+ clk <= 1
28
+ rst <= 0
29
+ d <= _z
30
+ !10.ns
31
+ clk <= 0
32
+ rst <= 0
33
+ d <= _z
34
+ !10.ns
35
+ clk <= 1
36
+ rst <= 1
37
+ d <= _z
38
+ !10.ns
39
+ clk <= 0
40
+ rst <= 1
41
+ d <= _z
42
+ !10.ns
43
+ clk <= 1
44
+ rst <= 0
45
+ d <= 1
46
+ !10.ns
47
+ clk <= 0
48
+ rst <= 0
49
+ d <= 1
50
+ !10.ns
51
+ clk <= 1
52
+ rst <= 0
53
+ d <= 1
54
+ !10.ns
55
+ clk <= 0
56
+ rst <= 0
57
+ d <= 1
58
+ !10.ns
59
+ clk <= 1
60
+ rst <= 0
61
+ d <= 0
62
+ !10.ns
63
+ clk <= 0
64
+ rst <= 0
65
+ d <= 0
66
+ !10.ns
67
+ clk <= 1
68
+ rst <= 0
69
+ d <= 0
70
+ !10.ns
71
+ clk <= 0
72
+ rst <= 0
73
+ d <= 0
74
+ !10.ns
75
+ end
76
+ end
@@ -0,0 +1,72 @@
1
+ require 'std/delays.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # System descending for delayp for adding a reset.
6
+ system :delayp_rst do |num|
7
+ include(delayp(num))
8
+
9
+ input :rst
10
+
11
+ par(clk.posedge) do
12
+ hif(rst) { state <= 0 }
13
+ end
14
+ end
15
+
16
+
17
+ # System testing delay, delayp and the new delayp_rst.
18
+ system :with_delays do
19
+ num = 10
20
+
21
+ # The clock and reset signals
22
+ inner :clk,:rst
23
+ # The request signals.
24
+ inner :req, :reqp, :reqp_rst
25
+ # The ack signals.
26
+ inner :ack, :ackp, :ackp_rst
27
+
28
+ # Instantiate the delays.
29
+ delay(num).(:delayI).(clk,req,ack)
30
+ delayp(num).(:delaypI).(clk,reqp,ackp)
31
+ delayp_rst(num).(:delaypI_rst).(rst,clk,reqp_rst,ackp_rst)
32
+
33
+ # Test the delays.
34
+ timed do
35
+ clk <= 0
36
+ rst <= 0
37
+ !10.ns
38
+ clk <= 1
39
+ !10.ns
40
+ clk <= 0
41
+ req <= 1
42
+ reqp <= 1
43
+ reqp_rst <= 1
44
+ !10.ns
45
+ clk <= 1
46
+ !10.ns
47
+ req <= 0
48
+ clk <= 0
49
+ rst <= 1
50
+ !10.ns
51
+ clk <= 1
52
+ !10.ns
53
+ clk <= 0
54
+ rst <= 0
55
+ !10.ns
56
+ clk <= 1
57
+ !10.ns
58
+ clk <= 0
59
+ reqp <= 0
60
+ !10.ns
61
+ clk <= 1
62
+ !10.ns
63
+ clk <= 0
64
+ reqp_rst <= 0
65
+ 10.times do
66
+ !10.ns
67
+ clk <= 1
68
+ !10.ns
69
+ clk <= 0
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,110 @@
1
+ require 'std/handshakes.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+
6
+ # System using a handshake for summing inputs.
7
+ system :hs_adder do
8
+ input :clk
9
+ [8].input :x,:y
10
+ [8].output :z
11
+
12
+ inner :read, :write
13
+
14
+ include(hs_pipe(clk.posedge,read,write))
15
+
16
+ par(clk.posedge) do
17
+ hif(read) do
18
+ z <= x + y
19
+ write <= 1
20
+ end
21
+ hif(ackO) do
22
+ z <= _zzzzzzzz
23
+ write <= 0
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ # System testing handshakes.
30
+ system :with_handshake do
31
+
32
+ # The clock signal.
33
+ inner :clk
34
+ # The request and acknoledge signals.
35
+ inner :reqI,:ackI,:reqO,:ackO
36
+
37
+ # The input and output values.
38
+ [8].inner :x, :y, :z
39
+
40
+ # Instantiate the handshake adder.
41
+ hs_adder.(:adderI).(clk: clk, x: x, y: y, z: z,
42
+ reqI: reqI, ackI: ackI, reqO: reqO, ackO: ackO)
43
+
44
+ # Test the handshake adder.
45
+ timed do
46
+ clk <= 0
47
+ x <= 0
48
+ y <= 0
49
+ reqI <= 0
50
+ ackO <= 0
51
+ !10.ns
52
+ clk <= 1
53
+ !10.ns
54
+ clk <= 0
55
+ x <= 1
56
+ y <= 2
57
+ !10.ns
58
+ clk <= 1
59
+ !10.ns
60
+ clk <= 0
61
+ reqI <= 1
62
+ !10.ns
63
+ clk <= 1
64
+ !10.ns
65
+ clk <= 0
66
+ reqI <= 0
67
+ !10.ns
68
+ clk <= 1
69
+ !10.ns
70
+ clk <= 0
71
+ ackO <= 1
72
+ !10.ns
73
+ clk <= 1
74
+ !10.ns
75
+ clk <= 0
76
+ !10.ns
77
+ clk <= 1
78
+ !10.ns
79
+ clk <= 0
80
+ !10.ns
81
+ clk <= 1
82
+ !10.ns
83
+ clk <= 0
84
+ ackO <= 0
85
+ !10.ns
86
+ clk <= 0
87
+ x <= 3
88
+ y <= 4
89
+ !10.ns
90
+ clk <= 1
91
+ !10.ns
92
+ clk <= 0
93
+ reqI <= 1
94
+ !10.ns
95
+ clk <= 1
96
+ !10.ns
97
+ clk <= 0
98
+ reqI <= 0
99
+ !10.ns
100
+ clk <= 1
101
+ !10.ns
102
+ clk <= 0
103
+ ackO <= 1
104
+ !10.ns
105
+ clk <= 1
106
+ !10.ns
107
+ clk <= 0
108
+ ackO <= 0
109
+ end
110
+ end
@@ -37,6 +37,20 @@ system :with_values do
37
37
  v64 <= 128
38
38
  v96 <= 128
39
39
  !10.ns
40
+ v8 <= -1
41
+ v16 <= -1
42
+ v32 <= -1
43
+ v56 <= -1
44
+ v64 <= -1
45
+ v96 <= -1
46
+ !10.ns
47
+ v8 <= -2
48
+ v16 <= -2
49
+ v32 <= -2
50
+ v56 <= -2
51
+ v64 <= -2
52
+ v96 <= -2
53
+ !10.ns
40
54
  v16 <= 0x1000
41
55
  v32 <= 0x1000
42
56
  v56 <= 0x1000
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -1,5 +1,57 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
+
4
+ # Check if run in interactive mode.
5
+ if ARGV.include?("-I") || ARGV.include?("--interactive") then
6
+ # Yes, first check which repl to use.
7
+ idx = ARGV.index("-I")
8
+ idx = ARGV.index("--interactive") unless idx
9
+ if ARGV[idx+1] == "irb" || ARGV[idx+1] == nil then
10
+ repl = :irb
11
+ elsif ARGV[idx+1] == "pry" then
12
+ repl = :pry
13
+ else
14
+ raise "Unknown repl: #{ARGV[idx+1]}"
15
+ end
16
+ # Look for the interactive Ruby library.
17
+ libpath = ""
18
+ $:.each do |dir|
19
+ if File.exist?(dir + "/hdrlib.rb") then
20
+ libpath = dir + "/hdrlib.rb"
21
+ break
22
+ end
23
+ end
24
+ ARGV.clear
25
+ ARGV.concat(['-r', libpath])
26
+ case repl
27
+ when :irb
28
+ require 'irb'
29
+ IRB.start
30
+ when :pry
31
+ require 'pry'
32
+ require libpath
33
+ # Pry.start(binding)
34
+ Pry.start()
35
+ end
36
+ abort
37
+ end
38
+
39
+
40
+ begin
41
+ # We can check the memory.
42
+ require 'get_process_mem'
43
+ $memory_check = GetProcessMem.new
44
+ def show_mem
45
+ " | "+$memory_check.bytes.to_s+"B"
46
+ end
47
+ rescue LoadError
48
+ # We cannot check the memory.
49
+ def show_mem
50
+ ""
51
+ end
52
+ end
53
+
54
+
3
55
  require 'fileutils'
4
56
  require 'tempfile'
5
57
  require 'HDLRuby'
@@ -31,6 +83,7 @@ require 'HDLRuby/backend/hruby_c_allocator'
31
83
 
32
84
  require 'HDLRuby/version.rb'
33
85
 
86
+
34
87
  ##
35
88
  # HDLRuby compiler interface program
36
89
  #####################################
@@ -267,6 +320,9 @@ def which(cmd)
267
320
  end
268
321
 
269
322
 
323
+ # Used standalone, check the files given in the standard input.
324
+ include HDLRuby
325
+
270
326
 
271
327
  if __FILE__ == $0 then
272
328
  # From hdrcc.rb
@@ -278,9 +334,6 @@ else
278
334
  end
279
335
 
280
336
  require 'optparse'
281
- # Used standalone, check the files given in the standard input.
282
- include HDLRuby
283
-
284
337
  # Process the command line options
285
338
  $options = {}
286
339
  $optparse = OptionParser.new do |opts|
@@ -293,7 +346,10 @@ $optparse = OptionParser.new do |opts|
293
346
  opts.separator "* `<output file>` is the output file"
294
347
  opts.separator ""
295
348
  opts.separator "Options:"
296
-
349
+
350
+ opts.on("-I", "--interactive") do |repl|
351
+ raise "Internal error: the --interactive option should have been processed earlier."
352
+ end
297
353
  opts.on("-y", "--yaml", "Output in YAML format") do |y|
298
354
  $options[:yaml] = y
299
355
  end
@@ -486,7 +542,7 @@ if $options[:syntax] then
486
542
  $output << $loader.show_all
487
543
  exit
488
544
  end
489
- HDLRuby.show Time.now
545
+ HDLRuby.show "#{Time.now}#{show_mem}"
490
546
  HDLRuby.show "##### Starting parser #####"
491
547
 
492
548
  if $options[:debug] then
@@ -499,11 +555,11 @@ end
499
555
 
500
556
  # Generate the result.
501
557
  # Get the top systemT.
502
- HDLRuby.show Time.now
558
+ HDLRuby.show "#{Time.now}#{show_mem}"
503
559
  $top_system = $top_instance.to_low.systemT
504
560
  $top_intance = nil # Free as much memory as possible.
505
561
  HDLRuby.show "##### Top system built #####"
506
- HDLRuby.show Time.now
562
+ HDLRuby.show "#{Time.now}#{show_mem}"
507
563
 
508
564
 
509
565
  # # Apply the pre drivers if any.
@@ -574,19 +630,19 @@ elsif $options[:clang] then
574
630
  # Coverts the par blocks in seq blocks to seq blocks to match
575
631
  # the simulation engine.
576
632
  systemT.par_in_seq2seq!
577
- HDLRuby.show Time.now
633
+ HDLRuby.show "#{Time.now}#{show_mem}"
578
634
  HDLRuby.show "connections_to_behaviors step..."
579
635
  # Converts the connections to behaviors.
580
636
  systemT.connections_to_behaviors!
581
- HDLRuby.show Time.now
637
+ HDLRuby.show "#{Time.now}#{show_mem}"
582
638
  # Break the RefConcat.
583
639
  HDLRuby.show "concat_assigns step..."
584
640
  systemT.break_concat_assigns!
585
- HDLRuby.show Time.now
641
+ HDLRuby.show "#{Time.now}#{show_mem}"
586
642
  # Explicits the types.
587
643
  HDLRuby.show "explicit_types step..."
588
644
  systemT.explicit_types!
589
- HDLRuby.show Time.now
645
+ HDLRuby.show "#{Time.now}#{show_mem}"
590
646
  end
591
647
  # Generate the C.
592
648
  if $options[:multiple] then
@@ -729,23 +785,23 @@ elsif $options[:verilog] then
729
785
  # HDLRuby.show Time.now
730
786
  HDLRuby.show "to_upper_space! step..."
731
787
  systemT.to_upper_space!
732
- HDLRuby.show Time.now
788
+ HDLRuby.show "#{Time.now}#{show_mem}"
733
789
  end
734
790
  HDLRuby.show "to_global_space! step (global)..."
735
791
  $top_system.to_global_systemTs!
736
- HDLRuby.show Time.now
792
+ HDLRuby.show "#{Time.now}#{show_mem}"
737
793
  $top_system.each_systemT_deep do |systemT|
738
794
  ## systemT.break_types!
739
795
  ## systemT.expand_types!
740
796
  HDLRuby.show "par_in_seq2seq! step..."
741
797
  systemT.par_in_seq2seq!
742
- HDLRuby.show Time.now
798
+ HDLRuby.show "#{Time.now}#{show_mem}"
743
799
  HDLRuby.show "initial_concat_to_timed! step..."
744
800
  systemT.initial_concat_to_timed!
745
- HDLRuby.show Time.now
801
+ HDLRuby.show "#{Time.now}#{show_mem}"
746
802
  HDLRuby.show "with_port! step..."
747
803
  systemT.with_port!
748
- HDLRuby.show Time.now
804
+ HDLRuby.show "#{Time.now}#{show_mem}"
749
805
  end
750
806
  # # Verilog generation
751
807
  # $output << top_system.to_verilog
@@ -836,7 +892,7 @@ elsif $options[:vhdl] then
836
892
  end
837
893
 
838
894
  HDLRuby.show "##### Code generated #####"
839
- HDLRuby.show Time.now
895
+ HDLRuby.show "#{Time.now}#{show_mem}"
840
896
 
841
897
  # # Apply the post drivers if any.
842
898
  # Hdecorator.each_with_property(:post_driver) do |obj, value|