Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 379 lines (300 sloc) 10.357 kb
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
1 require 'tmpdir'
2
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
3 task :vm => 'vm/vm'
4
5 ############################################################
6 # Files, Flags, & Constants
7
dbe8229 Fix stack GC invariant
Evan Phoenix authored
8 if ENV['LLVM_DEBUG']
9 LLVM_STYLE = "Debug"
10 else
11 LLVM_STYLE = "Release"
12 end
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
13
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
14 ENV.delete 'CDPATH' # confuses llvm_config
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
15 LLVM_CONFIG = "vm/external_libs/llvm/#{LLVM_STYLE}/bin/llvm-config"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
16 tests = FileList["vm/test/test_*.hpp"]
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
17
18 # vm/test/test_instructions.hpp may not have been generated yet
19 tests << 'vm/test/test_instructions.hpp'
20 tests.uniq!
21
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
22 srcs = FileList["vm/*.{cpp,c}"] + FileList["vm/builtin/*.{cpp,c}"]
23 hdrs = FileList["vm/*.{hpp,h}"] + FileList["vm/builtin/*.{hpp,h}"]
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
24 objs = srcs.map { |f| f.sub(/c(pp)?$/, 'o') }
25 dep_file = "vm/.depends.mf"
26 vm_objs = %w[ vm/drivers/cli.o ]
27 vm_srcs = %w[ vm/drivers/cli.cpp ]
28 EX_INC = %w[ libtommath onig libffi/include
29 libltdl libev llvm/include
30 ].map { |f| "vm/external_libs/#{f}" }
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
31
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
32 INSN_GEN = %w[ vm/gen/iseq_instruction_names.cpp
33 vm/gen/iseq_instruction_names.hpp
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
34 vm/gen/iseq_instruction_size.gen
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
35 vm/test/test_instructions.hpp ]
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
36 TYPE_GEN = %w[ vm/gen/includes.hpp
37 vm/gen/simple_field.rb
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
38 vm/gen/typechecks.gen.cpp
39 vm/gen/primitives_declare.hpp
40 vm/gen/primitives_glue.gen.cpp ]
41
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
42 field_extract_headers = %w[
0509b76 Add objects.hpp into list so Integer is processed.
Evan Phoenix authored
43 vm/objects.hpp
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
44 vm/builtin/object.hpp
45 vm/builtin/array.hpp
46 vm/builtin/bignum.hpp
47 vm/builtin/block_environment.hpp
48 vm/builtin/bytearray.hpp
49 vm/builtin/channel.hpp
50 vm/builtin/class.hpp
51 vm/builtin/executable.hpp
464bdfd @brixen Added CompactLookupTable.
brixen authored
52 vm/builtin/compactlookuptable.hpp
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
53 vm/builtin/compiledmethod.hpp
54 vm/builtin/contexts.hpp
55 vm/builtin/dir.hpp
56 vm/builtin/exception.hpp
57 vm/builtin/fixnum.hpp
58 vm/builtin/float.hpp
59 vm/builtin/hash.hpp
60 vm/builtin/immediates.hpp
61 vm/builtin/io.hpp
62 vm/builtin/iseq.hpp
63 vm/builtin/list.hpp
64 vm/builtin/lookuptable.hpp
65 vm/builtin/memorypointer.hpp
66 vm/builtin/methodtable.hpp
67 vm/builtin/nativefunction.hpp
68 vm/builtin/regexp.hpp
69 vm/builtin/selector.hpp
70 vm/builtin/sendsite.hpp
71 vm/builtin/staticscope.hpp
72 vm/builtin/string.hpp
73 vm/builtin/symbol.hpp
74 vm/builtin/task.hpp
75 vm/builtin/thread.hpp
76 vm/builtin/tuple.hpp
77 ]
78
d19313c Compile the kernel, and load it in
Evan Phoenix authored
79 BC = "vm/instructions.bc"
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
80 LLVM_A = "vm/external_libs/llvm/#{LLVM_STYLE}/lib/libLLVMSystem.a"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
81 EXTERNALS = %W[ #{LLVM_A}
82 vm/external_libs/libtommath/libtommath.a
83 vm/external_libs/onig/.libs/libonig.a
84 vm/external_libs/libffi/.libs/libffi.a
85 vm/external_libs/libltdl/.libs/libltdl.a
86 vm/external_libs/libev/.libs/libev.a ]
87 OPTIONS = {
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
88 LLVM_A => "--enable-targets=host-only"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
89 }
90
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
91 if LLVM_STYLE == "Release"
92 OPTIONS[LLVM_A] << " --enable-optimized"
93 end
94
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
95 INCLUDES = (EX_INC + %w[vm/test/cxxtest vm .]).map { |f| "-I#{f}" }
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
96 FLAGS = %w(-Wall -Werror -ggdb -gdwarf-2)
d19313c Compile the kernel, and load it in
Evan Phoenix authored
97 CC = ENV['CC'] || "gcc"
98
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
99
100 FLAGS << "-O2" if ENV['FAST']
101
102
3197850 Fix using strlcpy and strlcat, respect CC
Evan Phoenix authored
103 def compile(obj, src)
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
104 unless defined? $llvm_c then
105 $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
106 $llvm_c.delete_if { |e| e.index("-O") == 0 }
107 end
108
109 flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
110
d19313c Compile the kernel, and load it in
Evan Phoenix authored
111 if ENV['TERSE']
112 puts "CC #{src}"
113 sh "#{CC} #{flags} -c -o #{obj} #{src} 2>&1", :verbose => false
114 else
115 sh "#{CC} #{flags} -c -o #{obj} #{src} 2>&1"
116 end
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
117 end
118
d19313c Compile the kernel, and load it in
Evan Phoenix authored
119 def link t
120 $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
121
122 ld = ENV['LD'] || 'g++'
123 o = t.prerequisites.find_all { |f| f =~ /o$/ }.join(' ')
124 l = ex_libs.join(' ')
125
126 if ENV['TERSE']
127 puts "LD #{t.name}"
128 sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}", :verbose => false
129 else
130 sh "#{ld} #{$link_opts} -o #{t.name} #{o} #{l}"
131 end
132 end
133
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
134 def tmpname(suffix = "cpp")
135 @which ||= 0
136
137 path = File.join(Dir.tmpdir, "rake.#{$$}.#{@which += 1}.#{suffix}")
138
139 yield path
140
141 ensure
142 FileUtils.rm_rf path
143 end
144
933877d Fix instructions.o dep, add newline
Evan Phoenix authored
145 def rubypp_task(target, prerequisite, *extra)
146 file target => [prerequisite, 'vm/rubypp.rb'] + extra do
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
147 path = tmpname do |path|
148 ruby 'vm/rubypp.rb', prerequisite, path
07fb519 @drbrain Fix rubypp_task because I am an idiot.
drbrain authored
149 yield path
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
150 end
151 end
152 end
d19313c Compile the kernel, and load it in
Evan Phoenix authored
153
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
154 ############################################################
155 # Other Tasks
156
157 rule '.o' do |t|
158 obj = t.name
159 src = t.prerequisites.find { |f| f =~ /#{File.basename obj, '.o'}\.c(pp)?$/}
160
161 compile obj, src
162 end
163
164 def files targets, dependencies = nil, &block
165 targets.each do |target|
166 if dependencies then
167 file target => dependencies, &block
168 else
169 file target, &block
170 end
171 end
172 end
173
174 directory "vm/gen"
175 file "vm/type_info.o" => "vm/gen/typechecks.gen.cpp"
176 file "vm/primitives.hpp" => "vm/gen/primitives_declare.hpp"
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
177 files Dir["vm/builtin/*.hpp"], INSN_GEN
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
178 files vm_objs, vm_srcs
179
180 objs.zip(srcs).each do |obj, src|
181 file obj => src
182 end
183
c04cc29 @drbrain Move rubypp stuff into its own task to reduce duplication.
drbrain authored
184 objs += ["vm/instructions.o"] # NOTE: BC isn't added due to llvm-g++ requirement
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
185
186 files EXTERNALS do |t|
187 path = File.join(*split_all(t.name)[0..2])
188 configure_path = File.join(path, 'configure')
189
190 if File.exist? configure_path then
191 sh "cd #{path}; ./configure #{OPTIONS[t.name]} && make"
192 else
193 sh "cd #{path}; make"
194 end
195 end
196
d19313c Compile the kernel, and load it in
Evan Phoenix authored
197 file "vm/primitives.o" => "vm/field_extract.rb"
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
198 file 'vm/instructions_gen.rb' => 'kernel/core/iseq.rb'
6dab41d minor tweak, I doubt it fixes anything
Ryan Davis authored
199 file 'vm/instructions.rb' => "vm/gen"
200 file 'vm/instructions.rb' => "vm/instructions_gen.rb"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
201
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
202 files INSN_GEN, %w[vm/instructions.rb] do
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
203 ruby 'vm/instructions.rb', :verbose => $verbose
204 end
205
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
206 file 'vm/field_extract.rb' => 'vm/gen'
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
207
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
208 files TYPE_GEN, field_extract_headers + %w[vm/field_extract.rb] do
f29d1d4 Fix field_extract and some prims, remove Task->ip.
Evan Phoenix authored
209 puts "GEN field_extract"
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
210 field_extract field_extract_headers
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
211 end
212
213 file 'vm/vm' => EXTERNALS + objs + vm_objs do |t|
214 link t
215 end
216
217 file 'vm/gen/primitives_glue.gen.cpp' => hdrs
218
8684bc6 @drbrain tests depend on objs
drbrain authored
219 file 'vm/test/runner.cpp' => tests + objs do
b598bc7 @dgtized fixed test runner order to always be sorted to ensure dependencies work ...
dgtized authored
220 tests = tests.sort + [{ :verbose => true }]
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
221 sh("vm/test/cxxtest/cxxtestgen.pl", "--error-printer", "--have-eh",
222 "--abort-on-fail", "-o", "vm/test/runner.cpp", *tests)
223 end
224
225 file 'vm/test/runner.o' => 'vm/test/runner.cpp' # no rule .o => .cpp
226
227 file 'vm/test/runner' => EXTERNALS + objs + %w[vm/test/runner.o] do |t|
228 link t
229 end
230
310a461 Cleanup stack usage and fix interpreter
Evan Phoenix authored
231 # A simple JIT tester driver
232
233 file 'vm/drivers/compile.o' => 'vm/drivers/compile.cpp'
234
235 file 'vm/compile' => EXTERNALS + objs + %w[vm/drivers/compile.o] do |t|
236 link t
237 end
238
933877d Fix instructions.o dep, add newline
Evan Phoenix authored
239 rubypp_task 'vm/instructions.o', 'vm/llvm/instructions.cpp', *hdrs do |path|
d19313c Compile the kernel, and load it in
Evan Phoenix authored
240 compile 'vm/instructions.o', path
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
241 end
242
933877d Fix instructions.o dep, add newline
Evan Phoenix authored
243 rubypp_task 'vm/instructions.bc', 'vm/llvm/instructions.cpp', *hdrs do |path|
d19313c Compile the kernel, and load it in
Evan Phoenix authored
244 sh "llvm-g++ -emit-llvm -Ivm -Ivm/external_libs/libffi/include -c -o vm/instructions.bc #{path}"
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
245 end
246
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
247 namespace :vm do
248 desc 'Run all VM tests'
249 task :test => 'vm/test/runner' do
bebd2d1 Add coverage task back in as vm:coverage
Evan Phoenix authored
250 ENV['VERBOSE'] = '1' if $verbose
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
251 sh 'vm/test/runner', :verbose => $verbose
252 end
253
bebd2d1 Add coverage task back in as vm:coverage
Evan Phoenix authored
254 task :coverage do
255 Dir.mkdir "vm/test/coverage" unless File.directory? "vm/test/coverage"
256 unless defined? $llvm_c then
257 $llvm_c = `#{LLVM_CONFIG} --cflags`.split(/\s+/)
258 $llvm_c.delete_if { |e| e.index("-O") == 0 }
259 end
260
261 $link_opts ||= `#{LLVM_CONFIG} --ldflags`.split(/\s+/).join(' ')
262
263 flags = (INCLUDES + FLAGS + $llvm_c).join(' ')
264
265 puts "CC/LD vm/test/coverage/runner"
266 begin
267 path = tmpname do |path|
268 ruby 'vm/rubypp.rb', "vm/llvm/instructions.cpp", path
269 sh "g++ -fprofile-arcs -ftest-coverage #{flags} -o vm/test/coverage/runner vm/test/runner.cpp vm/*.cpp vm/builtin/*.cpp vm/*.c #{path} #{$link_opts} #{(ex_libs + EXTERNALS).join(' ')}"
270 end
271
272 puts "RUN vm/test/coverage/runner"
273 sh "vm/test/coverage/runner"
274 if $verbose
275 sh "vm/test/lcov/bin/lcov --directory . --capture --output-file vm/test/coverage/app.info"
276 else
277 sh "vm/test/lcov/bin/lcov --directory . --capture --output-file vm/test/coverage/app.info > /dev/null 2>&1"
278 end
279
280 puts "GEN vm/test/coverage/index.html"
281 if $verbose
282 sh "cd vm/test/coverage; ../lcov/bin/genhtml app.info"
283 else
284 sh "cd vm/test/coverage; ../lcov/bin/genhtml app.info > /dev/null 2>&1"
285 end
286 ensure
287 sh "rm -f *.gcno *.gcda"
288 end
289 end
290
291
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
292 desc "Clean up vm build files"
293 task :clean do
294 files = [
d19313c Compile the kernel, and load it in
Evan Phoenix authored
295 objs, dep_file, TYPE_GEN, INSN_GEN,
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
296 'vm/gen',
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
297 'vm/test/runner',
298 'vm/test/runner.cpp',
299 'vm/test/test_instructions.cpp',
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
300 'vm/vm'
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
301 ].flatten
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
302
303 files.each do |filename|
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
304 rm_rf filename, :verbose => $verbose
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
305 end
306 end
307
308 desc "Clean up, including all external libs"
309 task :distclean => :clean do
310 EXTERNALS.each do |lib|
311 path = File.join(*lib.split(File::SEPARATOR)[0..2])
312 system "cd #{path}; make clean"
313 end
314 end
315
316 desc "Show which primitives are missing"
317 task :missing_primitives do
3420ff2 @wilson Look in the correct directory for 'missing_primitives'
wilson authored
318 cpp_primitives = `grep 'Ruby.primitive' vm/builtin/*.hpp | awk '{ print $4 }'`
ec70491 Fixed rakefile for vm/builtin move
Ryan Davis authored
319
320 cpp_primitives = cpp_primitives.gsub(':', '').split("\n").sort.uniq
321
322 shotgun_primitives = File.read('vm/shotgun_primitives.txt')
323 shotgun_primitives = shotgun_primitives.split("\n").sort.uniq
324
325 missing = shotgun_primitives - cpp_primitives
326
327 puts missing.join("\n")
328 end
329 end
330
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
331 ############################################################$
332 # Importers & Methods:
333
334 require 'rake/loaders/makefile'
335
d19313c Compile the kernel, and load it in
Evan Phoenix authored
336 generated = (TYPE_GEN + INSN_GEN).select { |f| f =~ /pp$/ }
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
337
338 file dep_file => srcs + hdrs + vm_srcs + generated do |t|
339 includes = INCLUDES.join ' '
340
341 flags = FLAGS.join ' '
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
342 flags << " -D__STDC_LIMIT_MACROS"
343
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
344 cmd = "makedepend -f- #{includes} -- #{flags} -- #{t.prerequisites}"
9901699 @drbrain Fix vm:clean, simplify vm/instructions.{o,bc}
drbrain authored
345 cmd << ' 2>/dev/null' unless $verbose
1ff280a Added top 10 node coloring, include filtering, and minimum edge filterin...
Ryan Davis authored
346 warn "makedepend ..."
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
347
348 dep = `#{cmd}`
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
349 dep.gsub!(%r% /usr/include\S+%, '') # speeds up rake a lot
350 dep.gsub!(%r%^\S+:[^ ]%, '')
351
352 File.open t.name, 'w' do |f|
353 f.puts dep
354 end
355 end
356
357 import dep_file
358
359 def ex_libs # needs to be method to delay running of llvm_config
360 unless defined? $ex_libs then
361 $ex_libs = EXTERNALS + [ "-ldl" ]
362 $ex_libs << "-lrt" if RUBY_PLATFORM =~ /linux/
363
364 llvm_libfiles = `#{LLVM_CONFIG} --libfiles all`.split(/\s+/)
365 llvm_libfiles = llvm_libfiles.select { |f| File.file? f }
366
367 pwd = File.join Dir.pwd, '' # add /
368 llvm_libfiles = llvm_libfiles.map { |f| f.sub pwd, '' }
369 $ex_libs += llvm_libfiles
370 end
371 $ex_libs
372 end
373
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
374 def field_extract(headers)
375 headers += [{ :verbose => $verbose}]
72ad3d4 @drbrain Hook up more dependencies in vm.rake, especially for generated files.
drbrain authored
376
ecc013d @drbrain Ensure that test_instructions.hpp is included in runner.cpp generation.
drbrain authored
377 ruby('vm/field_extract.rb', *headers)
569fccd @drbrain Move vm/Rakefile to rakelib/vm.rake, integrate it into the base rake tas...
drbrain authored
378 end
Something went wrong with that request. Please try again.