forked from rubinius/rubinius
/
jit.rake
47 lines (40 loc) · 1.15 KB
/
jit.rake
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
namespace :jit do
task :generate_header do
puts "GEN vm/llvm/types.cpp.gen"
`vendor/llvm/Release/bin/llvm-as < vm/llvm/types.ll > vm/gen/types.bc`
`vendor/llvm/Release/bin/llc -march=cpp -cppgen=contents -o vm/llvm/types.cpp.gen vm/gen/types.bc`
end
task :generate_offsets do
classes = {}
File.open "vm/llvm/types.ll" do |f|
while line = f.gets
if m1 = /%"?(struct|union)\.rubinius::([^"]*)"?\s*=\s*type\s*\{\n/.match(line)
line = f.gets
fields = []
while line.strip != "}"
if m2 = /;\s*(.*)/.match(line)
fields << m2[1].strip
else
fields << nil
end
line = f.gets
end
classes[m1[2]] = fields
end
end
end
File.open "vm/llvm/offset_specific.hpp", "w" do |f|
f.puts "namespace offset {"
classes.each do |name, fields|
f.puts "namespace #{name.gsub('::', '_')} {"
fields.each_with_index do |n, idx|
if n
f.puts " const static int #{n} = #{idx};"
end
end
f.puts "}"
end
f.puts "}"
end
end
end