forked from rubinius/rubinius
/
jit.rake
135 lines (115 loc) · 3.78 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
namespace :jit do
task :regenerate_header do
puts "GEN vm/llvm/types.ll, vm/llvm/types.cpp.gen"
classes = %w!
rubinius::ObjectFlags
rubinius::HeaderWord
rubinius::ObjectHeader
rubinius::Object
rubinius::StackVariables
rubinius::CallFrame
rubinius::UnwindInfo
rubinius::VariableScope
rubinius::CompiledMethod
rubinius::Executable
rubinius::Dispatch
rubinius::Arguments
rubinius::Tuple
rubinius::Array
rubinius::Class
rubinius::Module
rubinius::StaticScope
rubinius::InstructionSequence
rubinius::InlineCache
rubinius::InlineCacheHit
rubinius::BlockEnvironment
rubinius::BlockInvocation
rubinius::Numeric
rubinius::Float
rubinius::jit::RuntimeData
rubinius::CallUnit
rubinius::MethodCacheEntry
memory::Address
jit_state!
require 'tempfile'
files = %w!vm/call_frame.hpp
vm/arguments.hpp
vm/dispatch.hpp
vm/inline_cache.hpp
vm/builtin/block_environment.hpp
vm/builtin/integer.hpp
vm/builtin/float.hpp
vm/llvm/jit_runtime.hpp!
path = "llvm-type-temp.cpp"
File.open(path, "w+") do |f|
files.each do |file|
f.puts "#include \"#{file}\""
end
i = 0
classes.each do |klass|
f.puts "void useme#{i}(#{klass}* thing);"
f.puts "void blah#{i}(#{klass}* thing) { useme#{i}(thing); }"
i += 1
end
end
str = `llvm-g++ -I. -Ivm -Ivendor/libtommath -emit-llvm -S -o - "#{path}"`
return unless $?.exitstatus == 0
File.unlink path
types = []
str.split("\n").each do |line|
classes.each do |klass|
if /%"?(struct|union).#{klass}(::\$[^\s]+)?"? = type/.match(line)
types << line
end
end
end
opaque = %w!VM TypeInfo VMMethod Fixnum Symbol Selector LookupTable MethodTable
jit::RuntimeDataHolder Inliners!
File.open("vm/gen/types.ll","w+") do |f|
opaque.each do |o|
f.puts "%\"struct.rubinius::#{o}\" = type opaque"
end
f.puts(*types)
end
`vendor/llvm/Release/bin/llvm-as < vm/gen/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_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