Skip to content

Commit

Permalink
add 2-pass compile support, to support scala macro
Browse files Browse the repository at this point in the history
  • Loading branch information
yuchangyuan committed Mar 23, 2024
1 parent fc8ab71 commit adaeb3e
Showing 1 changed file with 39 additions and 9 deletions.
48 changes: 39 additions & 9 deletions entrypoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,31 @@
end

# -------------- split scala src & jar
scala_src = []
jar_src = []
filelist_src = []
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|
scala_src << s if s.end_with?(".scala")
jar_src << s if s.end_with?(".jar")
filelist_src << s if s.start_with?("@")
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
Expand All @@ -35,15 +52,28 @@

chisel3_jar.delete(plugin_jar)

classpath = chisel3_jar.join(':')
classpath = (chisel3_jar + cp_list).join(':')

target_dir = Dir.mktmpdir("chisel2verilog")
at_exit { FileUtils.remove_entry(target_dir) }

compile_cmd = ["scalac", "-cp", classpath, "-Xplugin:#{plugin_jar}",
"-d", target_dir] + scala_src + filelist_src
# 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
Expand Down

0 comments on commit adaeb3e

Please sign in to comment.