-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathcompile
executable file
·33 lines (29 loc) · 992 Bytes
/
compile
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
#!/usr/bin/ruby
fname = ARGV[0]
dir = File.dirname(__FILE__)
bname = File.basename(fname).split(".")[0..-2].join(".")
# If we want to pass the "-g" flag to gas, pass "-g",
# and you will be able to debug at the assembler level.
asmdebug = ARGV.include?("-g") ? "-g" : ""
def dr(cmd)
puts cmd
system("docker run -v #{Dir.pwd}:/app -t -i ruby-compiler-buildenv bash -c '#{cmd}'")
end
puts "*** Compiling with arguments: '#{ARGV.join(" ")}' into out/#{bname}"
if dr("ruby -I. #{dir}/driver.rb #{ARGV.join(" ")} 2>&1 >out/#{bname}.s")
if dr("gcc -Wall #{asmdebug} -c -m32 -o out/tgc.o tgc.c")
puts "+++ \e[32mCompiled tgc\e[37m"
else
STDERR.puts "*** \e[31mCompiling tgc failed.\e[37m"
exit(1)
end
if dr("gcc #{asmdebug} -m32 -o out/#{bname} out/#{bname}.s out/tgc.o")
puts "+++ \e[32mCompiled to out/#{bname}\e[37m"
else
STDERR.puts "*** \e[31mAssembly failed.\e[37m"
exit(1)
end
else
STDERR.puts "*** \e[31mCompilation failed.\e[37m"
exit(1)
end