HDLRuby 2.5.0 → 2.6.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/lib/HDLRuby/hdr_samples/adder.rb +1 -1
  3. data/lib/HDLRuby/hdr_samples/adder_bench.rb +1 -1
  4. data/lib/HDLRuby/hdr_samples/adder_gen.rb +1 -1
  5. data/lib/HDLRuby/hdr_samples/constant_in_function.rb +27 -0
  6. data/lib/HDLRuby/hdr_samples/dff_unit.rb +54 -0
  7. data/lib/HDLRuby/hdr_samples/huge_rom.rb +25 -0
  8. data/lib/HDLRuby/hdr_samples/logic_bench.rb +21 -0
  9. data/lib/HDLRuby/hdr_samples/mei8_bench.rb +1 -1
  10. data/lib/HDLRuby/hdr_samples/multi_timed_bench.rb +54 -0
  11. data/lib/HDLRuby/hdr_samples/music.rb +79 -0
  12. data/lib/HDLRuby/hdr_samples/named_sub.rb +42 -0
  13. data/lib/HDLRuby/hdr_samples/rom.rb +16 -0
  14. data/lib/HDLRuby/hdr_samples/with_function_generator.rb +25 -0
  15. data/lib/HDLRuby/hdrcc.rb +132 -24
  16. data/lib/HDLRuby/hruby_decorator.rb +3 -1
  17. data/lib/HDLRuby/hruby_high.rb +215 -27
  18. data/lib/HDLRuby/hruby_low.rb +402 -45
  19. data/lib/HDLRuby/hruby_low2c.rb +122 -168
  20. data/lib/HDLRuby/hruby_low2hdr.rb +738 -0
  21. data/lib/HDLRuby/hruby_low2high.rb +331 -549
  22. data/lib/HDLRuby/hruby_low2vhd.rb +39 -2
  23. data/lib/HDLRuby/hruby_low_bool2select.rb +29 -0
  24. data/lib/HDLRuby/hruby_low_casts_without_expression.rb +27 -0
  25. data/lib/HDLRuby/hruby_low_fix_types.rb +25 -0
  26. data/lib/HDLRuby/hruby_low_mutable.rb +70 -0
  27. data/lib/HDLRuby/hruby_low_resolve.rb +28 -0
  28. data/lib/HDLRuby/hruby_low_without_connection.rb +6 -3
  29. data/lib/HDLRuby/hruby_low_without_namespace.rb +7 -4
  30. data/lib/HDLRuby/hruby_low_without_select.rb +13 -0
  31. data/lib/HDLRuby/hruby_tools.rb +11 -1
  32. data/lib/HDLRuby/hruby_verilog.rb +1572 -1723
  33. data/lib/HDLRuby/sim/hruby_sim.h +29 -3
  34. data/lib/HDLRuby/sim/hruby_sim_calc.c +63 -6
  35. data/lib/HDLRuby/sim/hruby_sim_core.c +24 -9
  36. data/lib/HDLRuby/sim/hruby_sim_vcd.c +7 -3
  37. data/lib/HDLRuby/sim/hruby_sim_vizualize.c +22 -6
  38. data/lib/HDLRuby/std/fixpoint.rb +9 -0
  39. data/lib/HDLRuby/std/function_generator.rb +139 -0
  40. data/lib/HDLRuby/std/hruby_unit.rb +75 -0
  41. data/lib/HDLRuby/version.rb +1 -1
  42. metadata +16 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 99c77fd470dae8d84cb066923fc8ed89d18e2aafa8bc826df85e03cae674c4e2
4
- data.tar.gz: 4ef6902aec739f56c398bd653dc30f0dc03227799e1f54a9900b762d1a077aaa
3
+ metadata.gz: 928c0006bc7fee9ebff9356509ed09ad9109d310e64eea92a41f42d751d560b1
4
+ data.tar.gz: d63743942c8c73f79224c129ca8265995ddff3397a5628e185da497b0599a6e0
5
5
  SHA512:
6
- metadata.gz: 8c9972c8567cb1fd496268c4385b7f3caa0bd8718769254542adeceafafdc26ed09d5ce7c47430e0b0732ecbcda4ea5d0220cf4bc7be9721faf5b99bf47057cf
7
- data.tar.gz: d300640fdc354ed55f9210c95d4aee10e52768a59ac39a993b402d8da78dd091f31d97fe307fe96b729d9194b532bf958761070224663e3bf2cd37e165877c21
6
+ metadata.gz: b7508f64a04a6662c035ce362d9193d617b022dd21bbccaa28f8c70d2a38790919f6d995b545a5082df0be6e23654a4bacb158ea6dfaaa673ea592ccac4c67f9
7
+ data.tar.gz: 8e77890ec50610400f848340a4ad4a4eb0d9095aff8c674ecb695cdddf9aabbd7e585b2bf5bfc8b76553612f1e216bcc7e21f00888335f07b95f54c89b88efc2
@@ -3,5 +3,5 @@ system :adder do
3
3
  [15..0].input :x,:y
4
4
  [16..0].output :s
5
5
 
6
- s <= x + y
6
+ s <= x.as(bit[17]) + y
7
7
  end
@@ -3,7 +3,7 @@ system :adder do
3
3
  [15..0].input :x,:y
4
4
  [16..0].output :s
5
5
 
6
- s <= x + y
6
+ s <= x.as(bit[17]) + y
7
7
  end
8
8
 
9
9
  # A benchmark for the adder.
@@ -3,5 +3,5 @@ system :adder do |w|
3
3
  [(w-1)..0].input :x,:y
4
4
  [w..0].output :s
5
5
 
6
- s <= x + y
6
+ s <= x.as(bit[w+1]) + y
7
7
  end
@@ -0,0 +1,27 @@
1
+ # Sample for testing constant declaration in function.
2
+
3
+
4
+ function :func do |addr|
5
+ bit[4][-4].constant tbl: [ _0000, _0001, _0010, _0011 ]
6
+
7
+ tbl[addr]
8
+ end
9
+
10
+
11
+ system :with_func do
12
+ [4].inner :addr, :val
13
+
14
+ val <= func(addr)
15
+ # val <= 1
16
+
17
+ timed do
18
+ addr <= 0
19
+ !10.ns
20
+ addr <= 1
21
+ !10.ns
22
+ addr <= 2
23
+ !10.ns
24
+ addr <= 3
25
+ !10.ns
26
+ end
27
+ end
@@ -0,0 +1,54 @@
1
+ # Testing HDLRuby unit test.
2
+ # require 'std/hruby_unit.rb'
3
+
4
+ # Declare multiple simple dff-systems and their corresponding test.
5
+
6
+ 3.times do |i|
7
+
8
+ # A simple D-FF
9
+ system:"dff#{i}" do
10
+ input :clk, :rst, :d
11
+ output :q, :qb
12
+
13
+ qb <= ~q
14
+
15
+ par(clk.posedge) { q <= d & ~rst }
16
+ end
17
+
18
+ # Code for testing it.
19
+ Unit.system :"test_dff#{i}" do
20
+ inner :clk, :rst, :d, :q, :qb
21
+
22
+ send(:"dff#{i}",:dffI).(clk,rst,d,q,qb)
23
+
24
+ test do
25
+ clk <= 0
26
+ rst <= 0
27
+ d <= 0
28
+ !10.ns
29
+ clk <= 1
30
+ !10.ns
31
+ clk <= 0
32
+ rst <= 1
33
+ !10.ns
34
+ clk <= 1
35
+ !10.ns
36
+ clk <= 0
37
+ rst <= 0
38
+ !10.ns
39
+ clk <= 1
40
+ !10.ns
41
+ clk <= 0
42
+ d <= 1
43
+ !10.ns
44
+ clk <= 1
45
+ !10.ns
46
+ clk <= 0
47
+ d <= 0
48
+ !10.ns
49
+ clk <= 1
50
+ !10.ns
51
+ end
52
+ end
53
+ end
54
+
@@ -0,0 +1,25 @@
1
+ # Describes an 8-bit data 16-bit address ROM.
2
+ system :huge_rom do
3
+ [15..0].input :addr
4
+ [7..0].output :data
5
+
6
+ bit[7..0][-65536].constant content: 65536.times.to_a
7
+
8
+ data <= content[addr]
9
+ end
10
+
11
+
12
+
13
+ system :test_rom do
14
+ [15..0].inner :addr
15
+ [7..0].inner :data
16
+
17
+ huge_rom(:my_rom).(addr,data)
18
+
19
+ timed do
20
+ 8.times do |i|
21
+ addr <= i
22
+ !10.ns
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+
2
+ # A benchmark for the logic operations.
3
+ system :logic_bench do
4
+ [3].inner :x,:y
5
+ [3].inner :s_not, :s_and, :s_or, :s_xor, :s_nxor
6
+
7
+ timed do
8
+ 8.times do |i|
9
+ 8.times do |j|
10
+ x <= i
11
+ y <= j
12
+ s_not <= ~x
13
+ s_and <= x & y
14
+ s_or <= x | y
15
+ s_xor <= x ^ y
16
+ s_nxor <= (x == y)
17
+ !10.ns
18
+ end
19
+ end
20
+ end
21
+ end
@@ -28,7 +28,7 @@ system :mei8 do |prog_file = "./prog.obj"|
28
28
  bit[7..0][-256].constant mem: # The content of the memory
29
29
  ( File.readlines(prog_file).map {|l| l.split[0] }.select do |l|
30
30
  ["0","1"].include?(l[2])
31
- end.map {|l| l[2..9] } )
31
+ end.map {|l| l[2..9].to_i(2) } )
32
32
  instr <= mem[addr] # The access procedure
33
33
  end
34
34
 
@@ -0,0 +1,54 @@
1
+ # Test the execution of multiple timed behaviors
2
+ system :multi_timed do
3
+ inner :clk1, :clk2, :rst, :button
4
+ [8].inner :counter1, :counter2
5
+
6
+ # The process controlling counter1.
7
+ par(clk1.posedge) do
8
+ hif(rst) { counter1 <= 0 }
9
+ helsif(button) { counter1 <= counter1 + 1 }
10
+ end
11
+
12
+ # The process controlling counter2.
13
+ par(clk2.posedge) do
14
+ hif(rst) { counter2 <= 0 }
15
+ helsif(button) { counter2 <= counter2 + 1 }
16
+ end
17
+
18
+ # The process for clk1
19
+ timed do
20
+ 50.times do
21
+ clk1 <= 0
22
+ !10.ns
23
+ clk1 <= 1
24
+ !10.ns
25
+ end
26
+ end
27
+
28
+ # The process for clk2
29
+ timed do
30
+ 80.times do
31
+ clk2 <= 0
32
+ !3.ns
33
+ clk2 <= 1
34
+ !3.ns
35
+ end
36
+ end
37
+
38
+ # The control process
39
+ timed do
40
+ rst <= 0
41
+ button <= 0
42
+ !10.ns
43
+ rst <= 1
44
+ !20.ns
45
+ rst <= 0
46
+ !10.ns
47
+ 10.times do
48
+ button <= 1
49
+ !20.ns
50
+ button <= 0
51
+ !20.ns
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,79 @@
1
+ # require "std/fixpoint.rb"
2
+ # require_relative "activation_function.rb"
3
+ require 'std/function_generator.rb'
4
+
5
+ include HDLRuby::High::Std
6
+
7
+ system :music do
8
+
9
+ input :clk, :rst
10
+ [24].output :sound
11
+
12
+ # func_sin = proc { |i| Math.sin(i) }
13
+ # More efficient:
14
+ func_sin = Math.method(:sin)
15
+
16
+ # bit[8,8].inner :time
17
+ # signed[2,22].inner :sin_val0
18
+ # signed[2,22].inner :sin_val1
19
+ bit[8].inner :time
20
+ signed[24].inner :sin_val0
21
+ signed[24].inner :sin_val1
22
+
23
+ # activation_function(func_sin,signed[2,22],8,8,16).(:func_sin0_generator).(time,sin_val0)
24
+ # activation_function(func_sin,signed[2,22],8,8,16).(:func_sin1_generator).(time/2,sin_val1)
25
+ function_generator(func_sin,bit[8],signed[24],4,-Math::PI..Math::PI,-2..2).(:func_sin0_generator).(time,sin_val0)
26
+ function_generator(func_sin,bit[8],signed[24],4,-Math::PI*2..Math::PI*2,-2..2).(:func_sin1_generator).(time/2,sin_val1)
27
+
28
+ # signed[2,22].inner :sound0
29
+ signed[48].inner :sound0
30
+
31
+ sound0 <= sin_val0.as(signed[24]) * sin_val1
32
+
33
+ sound <= sound0[47..24]
34
+
35
+ par(clk.posedge) do
36
+ hif(rst) { time <= 0 }
37
+ helse do
38
+ # time <= time + _0000000000000001
39
+ time <= time + _00000001
40
+ end
41
+ end
42
+
43
+ end
44
+
45
+
46
+
47
+
48
+ system :music_test do
49
+
50
+ inner :clk,:rst
51
+ [24].inner :sound
52
+
53
+ music(:my_music).(clk,rst,sound)
54
+
55
+ timed do
56
+ clk <= 0
57
+ rst <= 0
58
+ !10.ns
59
+ clk <= 1
60
+ !10.ns
61
+ clk <= 0
62
+ rst <= 1
63
+ !10.ns
64
+ clk <= 1
65
+ !10.ns
66
+ clk <= 0
67
+ !10.ns
68
+ clk <= 1
69
+ !10.ns
70
+ clk <= 0
71
+ rst <= 0
72
+ 256.times do
73
+ !10.ns
74
+ clk <= 1
75
+ !10.ns
76
+ clk <= 0
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,42 @@
1
+ ##
2
+ # Sample testing named sub
3
+ #######################################
4
+
5
+
6
+ # A simple circuit with named sub
7
+ system :named_sub do
8
+ input :x, :y
9
+ output :s
10
+
11
+ sub :somesub do
12
+ inner :sig
13
+ end
14
+
15
+ seq do
16
+ somesub.sig <= x | y
17
+ s <= ~somesub.sig
18
+ end
19
+
20
+ end
21
+
22
+ # A benchmark for the circuit.
23
+ system :named_sub_bench do
24
+ inner :x, :y, :s
25
+
26
+ named_sub(:my_named_sub).(x,y,s)
27
+
28
+ timed do
29
+ x <= 0
30
+ y <= 0
31
+ !10.ns
32
+ x <= 1
33
+ y <= 0
34
+ !10.ns
35
+ x <= 0
36
+ y <= 1
37
+ !10.ns
38
+ x <= 1
39
+ y <= 1
40
+ !10.ns
41
+ end
42
+ end
@@ -14,3 +14,19 @@ system :rom4_8 do
14
14
  data1 <= content1[addr]
15
15
  data2 <= content2[addr]
16
16
  end
17
+
18
+
19
+
20
+ system :test_rom do
21
+ [2..0].inner :addr
22
+ [7..0].inner :data0,:data1,:data2
23
+
24
+ rom4_8(:my_rom).(addr,data0,data1,data2)
25
+
26
+ timed do
27
+ 8.times do |i|
28
+ addr <= i
29
+ !10.ns
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,25 @@
1
+ require 'std/function_generator.rb'
2
+
3
+ include HDLRuby::High::Std
4
+
5
+ # System for testing the function generator standard library.
6
+ system :with_function_generator do
7
+ # signed[8].inner :x
8
+ # signed[32].inner :y
9
+ bit[8].inner :x
10
+ signed[8].inner :y
11
+
12
+ # function_generator(Math.method(:sin).to_proc,
13
+ # signed[8],signed[32],4,-Math::PI..Math::PI,-2..2).
14
+ function_generator(Math.method(:sin).to_proc,
15
+ bit[8],signed[8],4,-Math::PI..Math::PI,-2..2).
16
+ (:my_sin).(x,y)
17
+
18
+ timed do
19
+ # (-128..127).each do |i|
20
+ (0..255).each do |i|
21
+ x <= i
22
+ !10.ns
23
+ end
24
+ end
25
+ end
data/lib/HDLRuby/hdrcc.rb CHANGED
@@ -1,10 +1,11 @@
1
1
  #!/usr/bin/ruby
2
2
 
3
3
  require 'fileutils'
4
+ require 'tempfile'
4
5
  require 'HDLRuby'
5
6
  require 'HDLRuby/hruby_check.rb'
6
7
  # require 'ripper'
7
- require 'HDLRuby/hruby_low2high'
8
+ require 'HDLRuby/hruby_low2hdr'
8
9
  require 'HDLRuby/hruby_low2c'
9
10
  require 'HDLRuby/hruby_low2vhd'
10
11
  require 'HDLRuby/hruby_low_fix_types'
@@ -50,12 +51,21 @@ module HDLRuby
50
51
  # The required files.
51
52
  attr_reader :requires
52
53
 
53
- # Creates a new loader for a +top_system+ system in file +top_file+
54
+ # Creates a new loader for a +top_system+ system in file +top_file_name+
54
55
  # from directory +dir+ with generic parameters +params+.
56
+ #
57
+ # NOTE: +top_file+ can either be a file or a file name.
55
58
  def initialize(top_system,top_file,dir,*params)
56
59
  # Sets the top and the looking directory.
57
60
  @top_system = top_system.to_s
58
- @top_file = top_file.to_s
61
+ # @top_file can either be a file or a string giving the file name.
62
+ if top_file.respond_to?(:path) then
63
+ @top_file = top_file
64
+ @top_file_name = top_file.path
65
+ else
66
+ @top_file = nil
67
+ @top_file_name = top_file.to_s
68
+ end
59
69
  @dir = dir.to_s
60
70
  @params = params
61
71
 
@@ -82,31 +92,48 @@ module HDLRuby
82
92
  end
83
93
 
84
94
  # Loads a single +file+.
95
+ #
96
+ # NOTE: +file+ can either be a file or a file name.
85
97
  def read(file)
86
98
  # Resolve the file.
87
- found = File.join(@dir,file)
88
- unless File.exist?(found) then
89
- founds = Dir.glob(@std_dirs.map {|path| File.join(path,file) })
90
- if founds.empty? then
91
- # No standard file with this name, this is an error.
92
- raise "Unknown required file: #{file}."
93
- else
94
- # A standard file is found, skip it since it does not
95
- # need to be read.
96
- # puts "Standard files: #{founds}"
97
- return false
99
+ if file.respond_to?(:read) then
100
+ found = file
101
+ else
102
+ found = File.join(@dir,file)
103
+ unless File.exist?(found) then
104
+ founds = Dir.glob(@std_dirs.map do |path|
105
+ File.join(path,file)
106
+ end)
107
+ if founds.empty? then
108
+ # No standard file with this name, this is an error.
109
+ raise "Unknown required file: #{file}."
110
+ else
111
+ # A standard file is found, skip it since it does not
112
+ # need to be read.
113
+ # puts "Standard files: #{founds}"
114
+ return false
115
+ end
98
116
  end
99
117
  end
100
118
  # Load the file.
101
- # @texts << File.read(File.join(@dir,file) )
102
119
  @texts << File.read(found)
103
- # @checks << Checker.new(@texts[-1],file)
104
- @checks << Checker.new(@texts[-1],found)
120
+ if found.respond_to?(:path) then
121
+ @checks << Checker.new(@texts[-1],found.path)
122
+ else
123
+ @checks << Checker.new(@texts[-1])
124
+ end
105
125
  return true
106
126
  end
107
127
 
108
128
  # Loads all the files from +file+.
109
- def read_all(file = @top_file)
129
+ def read_all(file = nil)
130
+ unless file then
131
+ if @top_file then
132
+ file = @top_file
133
+ else
134
+ file = @top_file_name
135
+ end
136
+ end
110
137
  # puts "read_all with file=#{file}"
111
138
  # Read the file
112
139
  # read(file)
@@ -174,7 +201,7 @@ module HDLRuby
174
201
  # Maybe it is a parse error, look for it.
175
202
  bind = TOPLEVEL_BINDING.clone
176
203
  eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind)
177
- eval(@texts[0],bind,@top_file,1)
204
+ eval(@texts[0],bind,@top_file_name,1)
178
205
  # No parse error found.
179
206
  raise "Cannot find a top system." unless @top_system
180
207
  end
@@ -183,7 +210,7 @@ module HDLRuby
183
210
  bind = TOPLEVEL_BINDING.clone
184
211
  eval("require 'HDLRuby'\n\nconfigure_high\n\n",bind)
185
212
  # Process it.
186
- eval(@texts[0],bind,@top_file,1)
213
+ eval(@texts[0],bind,@top_file_name,1)
187
214
  # Get the resulting instance
188
215
  if @params.empty? then
189
216
  # There is no generic parameter
@@ -225,6 +252,20 @@ module HDLRuby
225
252
 
226
253
  end
227
254
 
255
+ # Locate an executable from cmd.
256
+ def which(cmd)
257
+ # Get the possible exetensions (for windows case).
258
+ exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
259
+ # Look for the command within the executable paths.
260
+ ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
261
+ exts.each do |ext|
262
+ exe = File.join(path, "#{cmd}#{ext}")
263
+ return exe if File.executable?(exe) && !File.directory?(exe)
264
+ end
265
+ end
266
+ nil
267
+ end
268
+
228
269
 
229
270
 
230
271
  if __FILE__ == $0 then
@@ -310,6 +351,12 @@ $optparse = OptionParser.new do |opts|
310
351
  opts.on("-D", "--debug","Set the HDLRuby debug mode") do |d|
311
352
  $options[:debug] = d
312
353
  end
354
+ opts.on("-T","--test t0,t1,t2","Compile the unit tests named t0,t1,...") do |t|
355
+ $options[:test] = t
356
+ end
357
+ opts.on("--testall","Compile all the available unit tests.") do |t|
358
+ $options[:testall] = t
359
+ end
313
360
  opts.on("-t", "--top system", "Specify the top system to process") do|t|
314
361
  $options[:top] = t
315
362
  end
@@ -320,6 +367,10 @@ $optparse = OptionParser.new do |opts|
320
367
  $options[:dump] = v
321
368
  $options[:multiple] = v
322
369
  end
370
+ opts.on("--version", "Shows the version of HDLRuby.") do |v|
371
+ puts VERSION
372
+ exit
373
+ end
323
374
  # opts.on_tail("-h", "--help", "Show this message") do
324
375
  opts.on("-h", "--help", "Show this message") do
325
376
  puts opts
@@ -370,6 +421,28 @@ if $input == nil then
370
421
  exit
371
422
  end
372
423
 
424
+ if ($options[:test] || $options[:testall]) then
425
+ $top = "__test__"
426
+ tests = $options[:test]
427
+ if tests then
428
+ tests = tests.to_s.split(",")
429
+ tests.map! {|test| ":\"#{test}\"" }
430
+ tests = ", #{tests.join(",")}"
431
+ else
432
+ tests = ""
433
+ end
434
+ # Generate the unit test file.
435
+ $test_file = Tempfile.new('tester.rb',Dir.getwd)
436
+ $test_file.write("require 'std/hruby_unit.rb'\nrequire_relative '#{$input}'\n\n" +
437
+ "HDLRuby::Unit.test(:\"#{$top}\"#{tests})\n")
438
+ # $test_file.rewind
439
+ # puts $test_file.read
440
+ # exit
441
+ $test_file.rewind
442
+ # It is the new input file.
443
+ $input = $test_file
444
+ end
445
+
373
446
  # Open the output.
374
447
  if $output then
375
448
  if $options[:multiple] then
@@ -382,7 +455,7 @@ if $output then
382
455
  $output = File.open($output,"w")
383
456
  end
384
457
  else
385
- if $option[:multiple] then
458
+ if $options[:multiple] then
386
459
  raise "Need a target directory in multiple files generation mode."
387
460
  end
388
461
  $output = $stdout
@@ -394,6 +467,12 @@ $loader = HDRLoad.new($top,$input,$options[:directory].to_s,*$params)
394
467
  $loader.read_all
395
468
  $loader.check_all
396
469
 
470
+ # Remove the test file if any, it is not needed any longer.
471
+ if $test_file then
472
+ $test_file.close
473
+ $test_file.unlink
474
+ end
475
+
397
476
  if $options[:syntax] then
398
477
  if $options[:multiple] then
399
478
  raise "Multiple files generation mode not supported for syntax tree output."
@@ -414,6 +493,24 @@ end
414
493
  # Get the top systemT.
415
494
  $top_system = $top_instance.to_low.systemT
416
495
 
496
+
497
+ # Apply the pre drivers if any.
498
+ Hdecorator.each_with_property(:pre_driver) do |obj, value|
499
+ unless value.is_a?(Array) && value.size == 2 then
500
+ raise "pre_driver requires a driver file name command name."
501
+ end
502
+ # Load the driver.
503
+ require_relative(value[0].to_s)
504
+ # Ensure obj is the low version.
505
+ if obj.properties.key?(:high2low) then
506
+ # obj is high, get the corresponding low.
507
+ obj = obj.properties[:high2low][0]
508
+ end
509
+ # Execute it.
510
+ send(value[1].to_sym,obj,*value[2..-1])
511
+ end
512
+
513
+
417
514
  # Gather the non-HDLRuby code.
418
515
  $non_hdlruby = []
419
516
  $top_system.each_systemT_deep do |systemT|
@@ -455,7 +552,7 @@ elsif $options[:hdr] then
455
552
  # $output << systemT.to_high
456
553
  # end
457
554
  # $output << $top_instance.to_low.systemT.to_high
458
- $output << $top_system.to_high
555
+ $output << $top_system.to_hdr
459
556
  elsif $options[:clang] then
460
557
  # top_system = $top_instance.to_low.systemT
461
558
  # top_system = $top_system
@@ -572,8 +669,19 @@ elsif $options[:clang] then
572
669
  end
573
670
  end
574
671
  Dir.chdir($output)
575
- # Kernel.system("make -s")
576
- Kernel.system("cc -o3 -o hruby_simulator *.c -lpthread")
672
+ # Find the compiler.
673
+ cc_cmd = which('cc')
674
+ unless cc_cmd then
675
+ cc_cmd = which('gcc')
676
+ end
677
+ unless cc_cmd then
678
+ raise "Could not find any compiler, please compile by hand as follows:\n" +
679
+ " In folder #{$output} execute:\n" +
680
+ " <my compiler> -o hruby_simulator *.c -lpthread\n" +
681
+ " Then execute:\n hruby_simulator"
682
+ end
683
+ # Use it.
684
+ Kernel.system("#{cc_cmd} -o3 -o hruby_simulator *.c -lpthread")
577
685
  Kernel.system("./hruby_simulator")
578
686
  end
579
687
  elsif $options[:verilog] then