-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.rb
executable file
·87 lines (66 loc) · 1.79 KB
/
entrypoint.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env ruby
require 'pathname'
require 'tmpdir'
# ----------- split src & arg
args = []
srcs = []
idx = ARGV.find_index("--")
if idx then
srcs = ARGV.take(idx)
args = ARGV.drop(idx + 1)
else
srcs = ARGV
end
# -------------- split scala src & jar
src_list = []
cp_list = []
psrc_list = [] # src need precompile
opt_list = []
def is_valid_src(s)
s.end_with?(".scala") || s.end_with?(".java") || s.start_with?("@")
end
srcs.each do |s|
if s.start_with?("+")
s1 = s.sub(/^\+/, '')
psrc_list << s1 if is_valid_src(s1)
elsif is_valid_src(s)
src_list << s
elsif s.end_with?(".jar")
cp_list << s
else
# we assume no option:
# 1. start with '+'
# 2. start with '@', end with '.scala', '.java' or '.jar'no option:
opt_list << s
end
end
# ------------- compile
BASE = Pathname "/opt/java/lib"
chisel3_jar = Dir.glob(BASE + "*.jar")
plugin_jar = Dir.glob(BASE + "chisel-plugin*.jar")[0]
chisel3_jar.delete(plugin_jar)
classpath = (chisel3_jar + cp_list).join(':')
target_dir = Dir.mktmpdir("chisel2verilog")
at_exit { FileUtils.remove_entry(target_dir) }
# do precompile if necessary
unless psrc_list.empty?
precompile_cmd = ["scalac", "-cp", classpath, "-Xplugin:#{plugin_jar}",
"-d", target_dir] + opt_list + psrc_list
#pp precompile_cmd
system(precompile_cmd.join(" ")) or begin
abort "precompile fail"
end
classpath += ":#{target_dir}"
end
compile_cmd = ["scalac", "-cp", classpath, "-Xplugin:#{plugin_jar}",
"-d", target_dir] + opt_list + src_list
#pp compile_cmd
system(compile_cmd.join(" ")) or begin
abort "compile fail"
end
# --------------- run
run_cmd = ["scala", "-cp", "#{classpath}:#{target_dir}",
"chisel2verilog.run"] + args
system(run_cmd.join(" ")) or begin
abort "run fail"
end