HDLRuby 2.8.1 → 2.10.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
@@ -0,0 +1,51 @@
1
+ # Some abstract system.
2
+ system :sysA do
3
+ input :clk,:rst
4
+ input :d
5
+ output :q
6
+ end
7
+
8
+ # Some inheriting system.
9
+ system :sysH, sysA do
10
+ par(clk.posedge, rst.posedge) do
11
+ hprint("sys1\n")
12
+ q <= d & ~rst
13
+ end
14
+ end
15
+
16
+ # Another system that have nothing to see with the others.
17
+ # Some abstract system.
18
+ system :sysO do
19
+ input :clk,:rst
20
+ input :d
21
+ output :q
22
+
23
+ par(clk.posedge, rst.posedge) do
24
+ hprint("sys1\n")
25
+ q <= d & ~rst
26
+ end
27
+ end
28
+
29
+
30
+ # A system for testing inheritance and of?
31
+ system :with_reconf do
32
+ input :clk,:rst
33
+ input :d
34
+ output :q
35
+
36
+ # Instantiate the abstract system.
37
+ sysA(:my_dffA).(clk,rst,d,q)
38
+
39
+ # Test the of?
40
+ puts "my_dffA.systemT.of?(sysA)=#{my_dffA.systemT.of?(sysA)}"
41
+ puts "my_dffA.systemT.of?(sysH)=#{my_dffA.systemT.of?(sysH)}"
42
+ puts "my_dffA.systemT.of?(sysO)=#{my_dffA.systemT.of?(sysO)}"
43
+
44
+ # Instantiate the inheriting system.
45
+ sysH(:my_dffH).(clk,rst,d,q)
46
+
47
+ # Test the of?
48
+ puts "my_dffH.systemT.of?(sysH)=#{my_dffH.systemT.of?(sysH)}"
49
+ puts "my_dffH.systemT.of?(sysA)=#{my_dffH.systemT.of?(sysA)}"
50
+ puts "my_dffH.systemT.of?(sysO)=#{my_dffH.systemT.of?(sysO)}"
51
+ end
@@ -1,8 +1,3 @@
1
- require 'std/reconf.rb'
2
-
3
- include HDLRuby::High::Std
4
-
5
-
6
1
 
7
2
  # Some system that can be used for reconfiguration.
8
3
  system :sys0 do
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -1,5 +1,41 @@
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
+
3
39
  require 'fileutils'
4
40
  require 'tempfile'
5
41
  require 'HDLRuby'
@@ -267,6 +303,9 @@ def which(cmd)
267
303
  end
268
304
 
269
305
 
306
+ # Used standalone, check the files given in the standard input.
307
+ include HDLRuby
308
+
270
309
 
271
310
  if __FILE__ == $0 then
272
311
  # From hdrcc.rb
@@ -278,9 +317,6 @@ else
278
317
  end
279
318
 
280
319
  require 'optparse'
281
- # Used standalone, check the files given in the standard input.
282
- include HDLRuby
283
-
284
320
  # Process the command line options
285
321
  $options = {}
286
322
  $optparse = OptionParser.new do |opts|
@@ -293,7 +329,10 @@ $optparse = OptionParser.new do |opts|
293
329
  opts.separator "* `<output file>` is the output file"
294
330
  opts.separator ""
295
331
  opts.separator "Options:"
296
-
332
+
333
+ opts.on("-I", "--interactive") do |repl|
334
+ raise "Internal error: the --interactive option should have been processed earlier."
335
+ end
297
336
  opts.on("-y", "--yaml", "Output in YAML format") do |y|
298
337
  $options[:yaml] = y
299
338
  end